]> git.rm.cloudns.org Git - voretournament/voretournament.git/commitdiff
Attempt to port the Xonotic string color picker, not yet tested
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 6 Nov 2011 14:38:14 +0000 (16:38 +0200)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 6 Nov 2011 14:38:14 +0000 (16:38 +0200)
data/qcsrc/menu/classes.c
data/qcsrc/menu/voret/colorpicker_string.c [new file with mode: 0644]

index 4e46eba75aeb533096b3da1d809cef54b1ded4ca..933f01d3f9efdd6db864337ea3f65ffc09037a80 100644 (file)
@@ -77,5 +77,6 @@
 #include "voret/dialog_multiplayer_demo.c"\r
 #include "voret/demolist.c"\r
 #include "voret/colorpicker.c"\r
+#include "voret/colorpicker_string.c"\r
 #include "voret/cvarlist.c"\r
 #include "voret/dialog_settings_misc_cvars.c"\r
diff --git a/data/qcsrc/menu/voret/colorpicker_string.c b/data/qcsrc/menu/voret/colorpicker_string.c
new file mode 100644 (file)
index 0000000..c94faba
--- /dev/null
@@ -0,0 +1,98 @@
+#ifdef INTERFACE
+CLASS(VoretColorpickerString) EXTENDS(Image)
+       METHOD(VoretColorpickerString, configureVoretColorpickerString, void(entity, string, string))
+       METHOD(VoretColorpickerString, mousePress, float(entity, vector))
+       METHOD(VoretColorpickerString, mouseRelease, float(entity, vector))
+       METHOD(VoretColorpickerString, mouseDrag, float(entity, vector))
+       ATTRIB(VoretColorpickerString, cvarName, string, string_null)
+       ATTRIB(VoretColorpickerString, prevcoords, vector, '0 0 0')
+       ATTRIB(VoretColorpickerString, image, string, SKINGFX_COLORPICKER)
+       ATTRIB(VoretColorpickerString, imagemargin, vector, SKINMARGIN_COLORPICKER)
+       ATTRIB(VoretColorpickerString, focusable, float, 1)
+       METHOD(VoretColorpickerString, focusLeave, void(entity))
+       METHOD(VoretColorpickerString, keyDown, float(entity, float, float, float))
+       METHOD(VoretColorpickerString, draw, void(entity))
+ENDCLASS(VoretColorpickerString)
+entity makeVoretColorpickerString(string theCvar, string theDefaultCvar);
+#endif
+
+#ifdef IMPLEMENTATION
+entity makeVoretColorpickerString(string theCvar, string theDefaultCvar)
+{
+       entity me;
+       me = spawnVoretColorpickerString();
+       me.configureVoretColorpickerString(me, theCvar, theDefaultCvar);
+       return me;
+}
+
+void configureVoretColorpickerStringVoretColorpickerString(entity me, string theCvar, string theDefaultCvar)
+{
+       me.cvarName = theCvar;
+       me.configureImage(me, me.image);
+       if(cvar_string(theCvar) != "")
+               me.prevcoords = hslimage_color(stov(cvar_string(theCvar)), me.imagemargin);
+       else // use default
+               me.prevcoords = hslimage_color(stov(cvar_string(theDefaultCvar)), me.imagemargin);
+}
+
+float mousePressVoretColorpickerString(entity me, vector coords)
+{
+       me.mouseDrag(me, coords);
+       return 1;
+}
+
+// must match hslimage.c
+
+
+float mouseDragVoretColorpickerString(entity me, vector coords)
+{
+       if(me.disabled)
+               return 0;
+       vector margin;
+       margin = me.imagemargin;
+       if(coords_x >= margin_x)
+       if(coords_y >= margin_y)
+       if(coords_x <= 1 - margin_x)
+       if(coords_y <= 1 - margin_y)
+       {
+               me.prevcoords = coords;
+       }
+
+       return 1;
+}
+
+float mouseReleaseVoretColorpickerString(entity me, vector coords)
+{
+       me.mouseDrag(me, coords);
+       return 1;
+}
+
+void focusLeaveVoretColorpickerString(entity me)
+{
+       me.controlledTextbox.saveCvars(me.controlledTextbox);
+}
+float keyDownVoretColorpickerString(entity me, float key, float ascii, float shift)
+{
+       return me.controlledTextbox.keyDown(me.controlledTextbox, key, ascii, shift);
+}
+void drawVoretColorpickerString(entity me)
+{
+       drawImage(me);
+
+       float B, C, aC;
+       C = cvar("r_textcontrast");
+       B = cvar("r_textbrightness");
+
+       // for this to work, C/(1-B) must be in 0..1
+       // B must be < 1
+       // C must be < 1-B
+       
+       B = bound(0, B, 1);
+       C = bound(0, C, 1-B);
+
+       aC = 1 - C / (1 - B);
+
+       draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, '0 0 0', aC);
+       draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, me.color, B);
+}
+#endif