X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Fslider.qc;h=b98f59bbb444f663643e9860645b820ada792052;hb=8411e8405dcb67853bc15a238932becc1aee66a9;hp=dcfe68a75ff718c929c0babfcbc0a38c79503f48;hpb=724a41faf2cbfd86d41f3ab59ff8326a831a8326;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index dcfe68a75..b98f59bbb 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -1,56 +1,10 @@ -// Note: -// to use this, you FIRST call configureSliderVisuals, then configureSliderValues -#ifndef ITEM_SLIDER_H - #define ITEM_SLIDER_H - #include "label.qc" - CLASS(Slider, Label) - METHOD(Slider, resizeNotify, void(entity, vector, vector, vector, vector)); - METHOD(Slider, configureSliderVisuals, void(entity, float, float, float, string)); - METHOD(Slider, configureSliderValues, void(entity, float, float, float, float, float, float)); - METHOD(Slider, draw, void(entity)); - METHOD(Slider, keyDown, float(entity, float, float, float)); - METHOD(Slider, keyUp, float(entity, float, float, float)); - METHOD(Slider, mousePress, float(entity, vector)); - METHOD(Slider, mouseDrag, float(entity, vector)); - METHOD(Slider, mouseRelease, float(entity, vector)); - METHOD(Slider, valueToText, string(entity, float)); - METHOD(Slider, toString, string(entity)); - METHOD(Slider, setValue_allowAnim, void(entity, float, bool)); - METHOD(Slider, setValue_noAnim, void(entity, float)); - METHOD(Slider, setValue, void(entity, float)); - METHOD(Slider, setSliderValue, void(entity, float)); - METHOD(Slider, showNotify, void(entity)); - ATTRIB(Slider, src, string, string_null) - ATTRIB(Slider, focusable, float, 1) - ATTRIB(Slider, allowFocusSound, float, 1) - ATTRIB(Slider, value, float, 0) - ATTRIB(Slider, animated, float, 1) - ATTRIB(Slider, sliderValue, float, 0) - ATTRIB(Slider, sliderAnim, entity, NULL) - ATTRIB(Slider, valueMin, float, 0) - ATTRIB(Slider, valueMax, float, 0) - ATTRIB(Slider, valueStep, float, 0) - ATTRIB(Slider, valueDigits, float, 0) - ATTRIB(Slider, valueKeyStep, float, 0) - ATTRIB(Slider, valuePageStep, float, 0) - ATTRIB(Slider, valueDisplayMultiplier, float, 1.0) - ATTRIB(Slider, textSpace, float, 0) - ATTRIB(Slider, controlWidth, float, 0) - ATTRIB(Slider, pressed, float, 0) - ATTRIB(Slider, pressOffset, float, 0) - ATTRIB(Slider, previousValue, float, 0) - ATTRIB(Slider, tolerance, vector, '0 0 0') - ATTRIB(Slider, disabled, float, 0) - ATTRIB(Slider, color, vector, '1 1 1') - ATTRIB(Slider, color2, vector, '1 1 1') - ATTRIB(Slider, colorD, vector, '1 1 1') - ATTRIB(Slider, colorC, vector, '1 1 1') - ATTRIB(Slider, colorF, vector, '1 1 1') - ATTRIB(Slider, disabledAlpha, float, 0.3) - ENDCLASS(Slider) -#endif +#include "slider.qh" + +#include "../anim/easing.qh" +#include "../anim/animhost.qh" + +.entity applyButton; -#ifdef IMPLEMENTATION void Slider_setValue_allowAnim(entity me, float val, bool allowAnim) { if (allowAnim && me.animated) @@ -203,8 +157,12 @@ // handle dragging me.pressed = 2; - v = median(0, (pos.x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.textSpace - me.controlWidth), 1) * (me.valueMax - me.valueMin) + me.valueMin; - if (me.valueStep) v = floor(0.5 + v / me.valueStep) * me.valueStep; + float f = bound(0, (pos.x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.textSpace - me.controlWidth), 1); + v = f * (me.valueMax - me.valueMin) + me.valueMin; + // there's no need to round min and max value... also if we did, v could be set + // to an out of bounds value due to precision errors + if (f > 0 && f < 1 && me.valueStep) + v = floor(0.5 + v / me.valueStep) * me.valueStep; me.setValue_noAnim(me, v); if(me.applyButton) if(me.previousValue != me.value) @@ -218,53 +176,53 @@ return 1; } - float Slider_mousePress(entity me, vector pos) + METHOD(Slider, mousePress, bool(Slider this, vector pos)) { float controlCenter; - if (me.disabled) return 0; - if (pos.x < 0) return 0; - if (pos.y < 0) return 0; - if (pos.x >= 1 - me.textSpace) return 0; - if (pos.y >= 1) return 0; - controlCenter = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.textSpace - me.controlWidth) + 0.5 * me.controlWidth; - if (fabs(pos.x - controlCenter) <= 0.5 * me.controlWidth) + if (this.disabled) return false; + if (pos.x < 0) return false; + if (pos.y < 0) return false; + if (pos.x >= 1 - this.textSpace) return false; + if (pos.y >= 1) return false; + controlCenter = (this.value - this.valueMin) / (this.valueMax - this.valueMin) * (1 - this.textSpace - this.controlWidth) + 0.5 * this.controlWidth; + if (fabs(pos.x - controlCenter) <= 0.5 * this.controlWidth) { - me.pressed = 1; - me.pressOffset = pos.x - controlCenter; - me.previousValue = me.value; - // me.mouseDrag(me, pos); + this.pressed = 1; + this.pressOffset = pos.x - controlCenter; + this.previousValue = this.value; + // this.mouseDrag(this, pos); } else { float clickValue, pageValue, inRange; - clickValue = median(0, (pos.x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.textSpace - me.controlWidth), 1) * (me.valueMax - me.valueMin) + me.valueMin; - inRange = (almost_in_bounds(me.valueMin, me.value, me.valueMax)); + clickValue = median(0, (pos.x - this.pressOffset - 0.5 * this.controlWidth) / (1 - this.textSpace - this.controlWidth), 1) * (this.valueMax - this.valueMin) + this.valueMin; + inRange = (almost_in_bounds(this.valueMin, this.value, this.valueMax)); if (pos.x < controlCenter) { - pageValue = me.value - me.valuePageStep; - if (me.valueStep) clickValue = floor(clickValue / me.valueStep) * me.valueStep; + pageValue = this.value - this.valuePageStep; + if (this.valueStep) clickValue = floor(clickValue / this.valueStep) * this.valueStep; pageValue = max(pageValue, clickValue); } else { - pageValue = me.value + me.valuePageStep; - if (me.valueStep) clickValue = ceil(clickValue / me.valueStep) * me.valueStep; + pageValue = this.value + this.valuePageStep; + if (this.valueStep) clickValue = ceil(clickValue / this.valueStep) * this.valueStep; pageValue = min(pageValue, clickValue); } - if (inRange) me.setValue(me, median(me.valueMin, pageValue, me.valueMax)); - else me.setValue(me, me.valueMax); - if(me.applyButton) - me.applyButton.disabled = false; + if (inRange) this.setValue(this, median(this.valueMin, pageValue, this.valueMax)); + else this.setValue(this, this.valueMax); + if(this.applyButton) + this.applyButton.disabled = false; if (pageValue == clickValue) { - controlCenter = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.textSpace - me.controlWidth) + 0.5 * me.controlWidth; - me.pressed = 1; - me.pressOffset = pos.x - controlCenter; - me.previousValue = me.value; - // me.mouseDrag(me, pos); + controlCenter = (this.value - this.valueMin) / (this.valueMax - this.valueMin) * (1 - this.textSpace - this.controlWidth) + 0.5 * this.controlWidth; + this.pressed = 1; + this.pressOffset = pos.x - controlCenter; + this.previousValue = this.value; + // this.mouseDrag(this, pos); } } - return 1; + return true; } float Slider_mouseRelease(entity me, vector pos) { @@ -308,4 +266,3 @@ SUPER(Slider).draw(me); me.text = string_null; // TEMPSTRING! } -#endif