From: MirceaKitsune Date: Sun, 6 Nov 2011 14:38:14 +0000 (+0200) Subject: Attempt to port the Xonotic string color picker, not yet tested X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=aa3b2066f10f5de9c33eb3982c232e3e20aa258f;p=voretournament%2Fvoretournament.git Attempt to port the Xonotic string color picker, not yet tested --- diff --git a/data/qcsrc/menu/classes.c b/data/qcsrc/menu/classes.c index 4e46eba7..933f01d3 100644 --- a/data/qcsrc/menu/classes.c +++ b/data/qcsrc/menu/classes.c @@ -77,5 +77,6 @@ #include "voret/dialog_multiplayer_demo.c" #include "voret/demolist.c" #include "voret/colorpicker.c" +#include "voret/colorpicker_string.c" #include "voret/cvarlist.c" #include "voret/dialog_settings_misc_cvars.c" diff --git a/data/qcsrc/menu/voret/colorpicker_string.c b/data/qcsrc/menu/voret/colorpicker_string.c new file mode 100644 index 00000000..c94faba3 --- /dev/null +++ b/data/qcsrc/menu/voret/colorpicker_string.c @@ -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