X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Flistbox.qc;h=97f08c98113e520e6d55457356befca52319f28b;hp=aa10c20b3b0f6d04bac8d5810e8b53b74bb799f2;hb=0d4410adb034af1a9989862211e49e442fa9b9dd;hpb=26693a3ac060825ce6c7f170d4e65f7ac2a1fb25 diff --git a/qcsrc/menu/item/listbox.qc b/qcsrc/menu/item/listbox.qc index aa10c20b3b..97f08c9811 100644 --- a/qcsrc/menu/item/listbox.qc +++ b/qcsrc/menu/item/listbox.qc @@ -182,10 +182,10 @@ if (me.pressed == 1) { hit = 1; - if (pos.x < 1 - me.controlWidth - me.tolerance.y * me.controlWidth) hit = 0; - if (pos.y < 0 - me.tolerance.x) hit = 0; - if (pos.x >= 1 + me.tolerance.y * me.controlWidth) hit = 0; - if (pos.y >= 1 + me.tolerance.x) hit = 0; + if (pos.x < 1 - me.controlWidth - me.tolerance.x * me.controlWidth) hit = 0; + if (pos.y < 0 - me.tolerance.y) hit = 0; + if (pos.x >= 1 + me.tolerance.x * me.controlWidth) hit = 0; + if (pos.y >= 1 + me.tolerance.y) hit = 0; if (hit) { // calculate new pos to v @@ -208,43 +208,43 @@ } return 1; } - float ListBox_mousePress(entity me, vector pos) + METHOD(ListBox, mousePress, bool(ListBox this, 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; - me.dragScrollPos = pos; - me.updateControlTopBottom(me); - if (pos.x >= 1 - me.controlWidth) + if (pos.x < 0) return false; + if (pos.y < 0) return false; + if (pos.x >= 1) return false; + if (pos.y >= 1) return false; + this.dragScrollPos = pos; + this.updateControlTopBottom(this); + if (pos.x >= 1 - this.controlWidth) { - // if hit, set me.pressed, otherwise scroll by one page - if (pos.y < me.controlTop) + // if hit, set this.pressed, otherwise scroll by one page + if (pos.y < this.controlTop) { // page up - me.scrollPosTarget = max(me.scrollPosTarget - 1, 0); + this.scrollPosTarget = max(this.scrollPosTarget - 1, 0); } - else if (pos.y > me.controlBottom) + else if (pos.y > this.controlBottom) { // page down - me.scrollPosTarget = min(me.scrollPosTarget + 1, me.getTotalHeight(me) - 1); + this.scrollPosTarget = min(this.scrollPosTarget + 1, this.getTotalHeight(this) - 1); } else { - me.pressed = 1; - me.pressOffset = pos.y; - me.previousValue = me.scrollPos; + this.pressed = 1; + this.pressOffset = pos.y; + this.previousValue = this.scrollPos; } } else { // continue doing that while dragging (even when dragging outside). When releasing, forward the click to the then selected item. - me.pressed = 2; + this.pressed = 2; // an item has been clicked. Select it, ... - me.setSelected(me, me.getItemAtPos(me, me.scrollPos + pos.y)); - me.setFocusedItem(me, me.selectedItem); + this.setSelected(this, this.getItemAtPos(this, this.scrollPos + pos.y)); + this.setFocusedItem(this, this.selectedItem); } - return 1; + return true; } void ListBox_setFocusedItem(entity me, int item) { @@ -335,9 +335,7 @@ AUTOCVAR(menu_scroll_averaging_time_pressed, float, 0.06, "smooth scroll averaging time when dragging the scrollbar"); void ListBox_draw(entity me) { - float i; - vector absSize, fillSize = '0 0 0'; - vector oldshift, oldscale; + vector fillSize = '0 0 0'; // we can't do this in mouseMove as the list can scroll without moving the cursor if (me.mouseMoveOffset != -1) me.setFocusedItem(me, me.getItemAtPos(me, me.scrollPos + me.mouseMoveOffset)); @@ -376,19 +374,19 @@ } } draw_SetClip(); - oldshift = draw_shift; - oldscale = draw_scale; + vector oldshift = draw_shift; + vector oldscale = draw_scale; - i = me.getItemAtPos(me, me.scrollPos); - float j = me.getItemStart(me, i) - me.scrollPos; - for ( ; i < me.nItems && j < 1; ++i) + int i = me.getItemAtPos(me, me.scrollPos); + float y = me.getItemStart(me, i) - me.scrollPos; + for ( ; i < me.nItems && y < 1; ++i) { - draw_shift = boxToGlobal(eY * j, oldshift, oldscale); + draw_shift = boxToGlobal(eY * y, oldshift, oldscale); vector relSize = eX * (1 - me.controlWidth) + eY * me.getItemHeight(me, i); - absSize = boxToGlobalSize(relSize, me.size); + vector absSize = boxToGlobalSize(relSize, me.size); draw_scale = boxToGlobalSize(relSize, oldscale); me.drawListBoxItem(me, i, absSize, (me.selectedItem == i), (me.focusedItem == i)); - j += relSize.y; + y += relSize.y; } draw_ClearClip();