]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/slider.qc
Merge branch 'Mario/warmup_timer' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / slider.qc
index dcfe68a75ff718c929c0babfcbc0a38c79503f48..b569c3b0c4c228bec7d158f558129e21fded4f7c 100644 (file)
@@ -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)
 
                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)
        {
                SUPER(Slider).draw(me);
                me.text = string_null;  // TEMPSTRING!
        }
-#endif