X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Flistbox.qc;h=558c8a4ea7d92176d3cd40b1b31442aeed6e5694;hp=2f2979509e37d6df91b3d4129bb24da44f9ba767;hb=20387ff9f8cef7536362de05c76cc0062416a64c;hpb=165d542813201a21cb6152ea5d22454e43e117c7 diff --git a/qcsrc/menu/item/listbox.qc b/qcsrc/menu/item/listbox.qc index 2f2979509e..558c8a4ea7 100644 --- a/qcsrc/menu/item/listbox.qc +++ b/qcsrc/menu/item/listbox.qc @@ -4,12 +4,16 @@ CLASS(ListBox) EXTENDS(Item) METHOD(ListBox, configureListBox, void(entity, float, float)) METHOD(ListBox, draw, void(entity)) METHOD(ListBox, keyDown, float(entity, float, float, float)) + METHOD(ListBox, mouseMove, float(entity, vector)) 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, highlightedItem, int, -1) + ATTRIB(ListBox, highlightedItemTime, float, 0) + ATTRIB(ListBox, allowFocusSound, float, 1) + ATTRIB(ListBox, selectedItem, int, 0) ATTRIB(ListBox, size, vector, '0 0 0') ATTRIB(ListBox, origin, vector, '0 0 0') ATTRIB(ListBox, scrollPos, float, 0) // measured in window heights, fixed when needed @@ -39,7 +43,7 @@ CLASS(ListBox) EXTENDS(Item) ATTRIB(ListBox, lastClickedItem, float, -1) ATTRIB(ListBox, lastClickedTime, float, 0) - METHOD(ListBox, drawListBoxItem, void(entity, float, vector, float)) // item number, width/height, selected + METHOD(ListBox, drawListBoxItem, void(entity, int, vector, bool, float)) // item number, width/height, isSelected, highlightedTime METHOD(ListBox, clickListBoxItem, void(entity, float, vector)) // item number, relative clickpos METHOD(ListBox, doubleClickListBoxItem, void(entity, float, vector)) // item number, relative clickpos METHOD(ListBox, setSelected, void(entity, float)) @@ -175,6 +179,22 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift) return 0; return 1; } +float ListBox_mouseMove(entity me, vector pos) +{ + if(pos_x < 0) return 0; + if(pos_y < 0) return 0; + if(pos_x >= 1) return 0; + if(pos_y >= 1) return 0; + if(pos_x < 1 - me.controlWidth) + { + float x; + x = me.highlightedItem; + me.highlightedItem = me.getItemAtPos(me, me.scrollPos + pos.y); + if(x != me.highlightedItem) + me.highlightedItemTime = time; + } + return 1; +} float ListBox_mouseDrag(entity me, vector pos) { float hit; @@ -285,6 +305,7 @@ void ListBox_focusLeave(entity me) // by a mouse click on an item of the list // for example showing a dialog on right click me.pressed = 0; + me.highlightedItem = -1; } void ListBox_updateControlTopBottom(entity me) { @@ -366,6 +387,7 @@ void ListBox_draw(entity me) draw_SetClip(); oldshift = draw_shift; oldscale = draw_scale; + float y; i = me.getItemAtPos(me, me.scrollPos); y = me.getItemStart(me, i) - me.scrollPos; @@ -375,7 +397,7 @@ void ListBox_draw(entity me) vector relSize = eX * (1 - me.controlWidth) + eY * me.getItemHeight(me, i); absSize = boxToGlobalSize(relSize, me.size); draw_scale = boxToGlobalSize(relSize, oldscale); - me.drawListBoxItem(me, i, absSize, (me.selectedItem == i)); + me.drawListBoxItem(me, i, absSize, (me.selectedItem == i), (me.highlightedItem == i) ? me.highlightedItemTime : 0); y += relSize.y; } draw_ClearClip(); @@ -395,8 +417,8 @@ void ListBox_doubleClickListBoxItem(entity me, float i, vector where) // template method } -void ListBox_drawListBoxItem(entity me, float i, vector absSize, float selected) +void ListBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, float highlightedTime) { - 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); + draw_Text('0 0 0', sprintf(_("Item %d"), i), eX * (8 / absSize.x) + eY * (8 / absSize.y), (isSelected ? '0 1 0' : '1 1 1'), 1, 0); } #endif