]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/listbox.c
Merge branch 'master' of git://de.git.xonotic.org/xonotic/xonotic-data.pk3dir
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / listbox.c
index 4d6174cc593cb4bacb484addb4ec9b551e019909..4f8dca622c239e0294ba023b68f8101f737c6f15 100644 (file)
@@ -7,6 +7,7 @@ CLASS(ListBox) EXTENDS(Item)
        METHOD(ListBox, mousePress, float(entity, vector))
        METHOD(ListBox, mouseDrag, float(entity, vector))
        METHOD(ListBox, mouseRelease, float(entity, vector))
+       METHOD(ListBox, focusLeave, void(entity))
        ATTRIB(ListBox, focusable, float, 1)
        ATTRIB(ListBox, selectedItem, float, 0)
        ATTRIB(ListBox, size, vector, '0 0 0')
@@ -188,6 +189,13 @@ float ListBox_mouseRelease(entity me, vector pos)
        me.pressed = 0;
        return 1;
 }
+void ListBox_focusLeave(entity me)
+{
+       // Reset the var pressed in case listbox loses focus
+       // by a mouse click on an item of the list
+       // for example showing a dialog on right click
+       me.pressed = 0;
+}
 void ListBox_updateControlTopBottom(entity me)
 {
        float f;
@@ -269,6 +277,7 @@ void ListBox_draw(entity me)
        oldshift = draw_shift;
        oldscale = draw_scale;
        absSize = boxToGlobalSize(me.size, eX * (1 - me.controlWidth) + eY * me.itemHeight);
+       draw_scale = boxToGlobalSize(eX * (1 - me.controlWidth) + eY * me.itemHeight, oldscale);
        for(i = floor(me.scrollPos / me.itemHeight); i < me.nItems; ++i)
        {
                float y;
@@ -276,10 +285,13 @@ void ListBox_draw(entity me)
                if(y >= 1)
                        break;
                draw_shift = boxToGlobal(eY * y, oldshift, oldscale);
-               draw_scale = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), oldscale);
                me.drawListBoxItem(me, i, absSize, (me.selectedItem == i));
        }
        draw_ClearClip();
+
+       draw_shift = oldshift;
+       draw_scale = oldscale;
+       SUPER(ListBox).draw(me);
 }
 
 void ListBox_clickListBoxItem(entity me, float i, vector where)
@@ -289,6 +301,6 @@ void ListBox_clickListBoxItem(entity me, float i, vector where)
 
 void ListBox_drawListBoxItem(entity me, float i, vector absSize, float selected)
 {
-       draw_Text('0 0 0', strcat("Item ", ftos(i)), eX * (8 / absSize_x) + eY * (8 / absSize_y), (selected ? '0 1 0' : '1 1 1'), 1, 0);
+       draw_Text('0 0 0', sprintf(_("Item %d"), i), eX * (8 / absSize_x) + eY * (8 / absSize_y), (selected ? '0 1 0' : '1 1 1'), 1, 0);
 }
 #endif