]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Port the improved scrolling by keys behaviour for lists that don't need to show an...
authorterencehill <piuntn@gmail.com>
Fri, 31 Jul 2015 13:33:48 +0000 (15:33 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 31 Jul 2015 13:33:48 +0000 (15:33 +0200)
qcsrc/menu/item/listbox.qc
qcsrc/menu/xonotic/credits.qc
qcsrc/menu/xonotic/statslist.qc

index f90e3b901378308ec2335190dd12b40e8c2a369d..b5ca74b3caeecf9d6b0772e5db3211905a9a09b0 100644 (file)
@@ -32,6 +32,7 @@ CLASS(ListBox, Item)
        ATTRIB(ListBox, controlBottom, float, 0)
        ATTRIB(ListBox, controlWidth, float, 0)
        ATTRIB(ListBox, dragScrollPos, vector, '0 0 0')
+       ATTRIB(ListBox, selectionDoesntMatter, bool, false) // improves scrolling by keys for lists that don't need to show an active selection
 
        ATTRIB(ListBox, src, string, string_null) // scrollbar
        ATTRIB(ListBox, color, vector, '1 1 1')
@@ -166,6 +167,12 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift)
        }
        else if(key == K_PGUP || key == K_KP_PGUP)
        {
+               if(me.selectionDoesntMatter)
+               {
+                       me.scrollPosTarget = max(me.scrollPosTarget - 0.5, 0);
+                       return 1;
+               }
+
                float i = me.selectedItem;
                float a = me.getItemHeight(me, i);
                for (;;)
@@ -181,6 +188,12 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift)
        }
        else if(key == K_PGDN || key == K_KP_PGDN)
        {
+               if(me.selectionDoesntMatter)
+               {
+                       me.scrollPosTarget = min(me.scrollPosTarget + 0.5, me.nItems * me.itemHeight - 1);
+                       return 1;
+               }
+
                float i = me.selectedItem;
                float a = me.getItemHeight(me, i);
                for (;;)
@@ -195,9 +208,25 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift)
                me.setSelected(me, i - 1);
        }
        else if(key == K_UPARROW || key == K_KP_UPARROW)
+       {
+               if(me.selectionDoesntMatter)
+               {
+                       me.scrollPosTarget = max(me.scrollPosTarget - me.itemHeight, 0);
+                       return 1;
+               }
+
                me.setSelected(me, me.selectedItem - 1);
+       }
        else if(key == K_DOWNARROW || key == K_KP_DOWNARROW)
+       {
+               if(me.selectionDoesntMatter)
+               {
+                       me.scrollPosTarget = min(me.scrollPosTarget + me.itemHeight, me.nItems * me.itemHeight - 1);
+                       return 1;
+               }
+
                me.setSelected(me, me.selectedItem + 1);
+       }
        else if(key == K_HOME || key == K_KP_HOME)
                me.setSelected(me, 0);
        else if(key == K_END || key == K_KP_END)
index ba7f7019b871249048e79692e588e3c23eb26a66..e3bc1c3399f048a5a8968e9d60c8597c4f68c582 100644 (file)
@@ -9,6 +9,7 @@ CLASS(XonoticCreditsList, XonoticListBox)
        METHOD(XonoticCreditsList, resizeNotify, void(entity, vector, vector, vector, vector))
        METHOD(XonoticCreditsList, keyDown, float(entity, float, float, float))
        METHOD(XonoticCreditsList, destroy, void(entity))
+       ATTRIB(XonoticCreditsList, selectionDoesntMatter, bool, true)
 
        ATTRIB(XonoticCreditsList, realFontSize, vector, '0 0 0')
        ATTRIB(XonoticCreditsList, realUpperMargin, float, 0)
@@ -88,19 +89,7 @@ void XonoticCreditsList_drawListBoxItem(entity me, int i, vector absSize, bool i
 
 float XonoticCreditsList_keyDown(entity me, float key, float ascii, float shift)
 {
-       me.dragScrollTimer = time;
        me.scrolling = 0;
-       if(key == K_PGUP || key == K_KP_PGUP)
-               me.scrollPosTarget = max(me.scrollPosTarget - 0.5, 0);
-       else if(key == K_PGDN || key == K_KP_PGDN)
-               me.scrollPosTarget = min(me.scrollPosTarget + 0.5, me.nItems * me.itemHeight - 1);
-       else if(key == K_UPARROW || key == K_KP_UPARROW)
-               me.scrollPosTarget = max(me.scrollPosTarget - me.itemHeight, 0);
-       else if(key == K_DOWNARROW || key == K_KP_DOWNARROW)
-               me.scrollPosTarget = min(me.scrollPosTarget + me.itemHeight, me.nItems * me.itemHeight - 1);
-       else
-               return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
-
-       return 1;
+       return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
 }
 #endif
index d9a22ec6e78f1a8e71aeadf9d3824f44069664c1..bfa050abdbfed30d803b9f88c57dcb1392af8c60 100644 (file)
@@ -14,6 +14,7 @@ CLASS(XonoticStatsList, XonoticListBox)
        METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
        METHOD(XonoticStatsList, destroy, void(entity))
        METHOD(XonoticStatsList, showNotify, void(entity))
+       ATTRIB(XonoticStatsList, selectionDoesntMatter, bool, true)
 
        ATTRIB(XonoticStatsList, listStats, float, -1)
        ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
@@ -317,9 +318,7 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize,
 
 void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
-       if(isSelected)
-               draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
-       else if(isFocused)
+       if(isFocused)
        {
                me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);