44#include " TooltipsLayer.h"
55#include " Notification.h"
66#include " PopupContextMenu.h"
7+ #include " UIColorPicker.h"
78#include " multiwindow.h"
89
910void UITextField::render (XY pos)
@@ -203,6 +204,25 @@ bool UITextField::inputChar(char c) {
203204 return false ;
204205}
205206
207+ void UITextField::renderTextFieldText (XY at)
208+ {
209+ XY textEP = g_fnt->RenderString (text + ((focused && numericFieldCurrentOperation == ' \0 ' ) ? " _" : " " ),
210+ at.x + 2 , at.y + 2 ,
211+ SDL_Color{ textColor.r ,textColor.g ,textColor.b ,(u8 )(focused ? 0xff : 0xa0 ) }, fontsize);
212+
213+ if (numericFieldCurrentOperation != ' \0 ' ) {
214+ textEP.x += 10 ;
215+ double separatorAnimTimer = XM1PW3P1 (numericFieldOperationTimer.percentElapsedTime (400 ));
216+ SDL_SetRenderDrawColor (g_rd, 255 , 255 , 255 , 255 );
217+ drawLine ({ textEP.x + 2 , at.y }, { textEP.x + 2 , at.y + wxHeight }, separatorAnimTimer);
218+
219+ textEP.x += 10 ;
220+
221+ textEP = g_fnt->RenderString (frmt (" {} " , numericFieldCurrentOperation), textEP.x , textEP.y );
222+ g_fnt->RenderString (frmt (" {}_" , numericFieldOperationBuffer), textEP.x , textEP.y , { 255 ,255 ,255 ,0xa0 });
223+ }
224+ }
225+
206226void UITextField::renderTextField (XY at)
207227{
208228 SDL_Rect drawrect = { at.x , at.y , wxWidth, wxHeight };
@@ -253,46 +273,7 @@ void UITextField::renderTextField(XY at)
253273 }
254274#endif
255275
256- if (!isColorField || !isValidOrPartialColor () || text.empty ()) {
257- XY textEP = g_fnt->RenderString (text + ((focused && numericFieldCurrentOperation == ' \0 ' ) ? " _" : " " ), at.x + 2 , at.y + 2 , SDL_Color{ textColor.r ,textColor.g ,textColor.b ,(unsigned char )(focused ? 0xff : 0xa0 ) }, fontsize);
258-
259- if (numericFieldCurrentOperation != ' \0 ' ) {
260- textEP.x += 10 ;
261- double separatorAnimTimer = XM1PW3P1 (numericFieldOperationTimer.percentElapsedTime (400 ));
262- SDL_SetRenderDrawColor (g_rd, 255 ,255 ,255 ,255 );
263- drawLine ({textEP.x +2 , at.y }, {textEP.x +2 , at.y +wxHeight}, separatorAnimTimer);
264-
265- textEP.x += 10 ;
266-
267- textEP = g_fnt->RenderString (frmt (" {} " , numericFieldCurrentOperation), textEP.x , textEP.y );
268- g_fnt->RenderString (frmt (" {}_" , numericFieldOperationBuffer), textEP.x , textEP.y , {255 ,255 ,255 ,0xa0 });
269- }
270- }
271- else {
272- int textPtr = 0 ;
273- XY origin = xyAdd (at, { 2 ,2 });
274- if (text[0 ] == ' #' ) {
275- origin = g_fnt->RenderString (" #" , origin.x , origin.y , SDL_Color{ 0x80 ,0x80 ,0x80 ,255 });
276- textPtr++;
277- }
278- origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 255 ,0x32 ,0x32 ,255 }, fontsize);
279- textPtr += 2 ;
280- if (textPtr < text.size ()) {
281- origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 0x50 ,255 ,0x50 ,255 }, fontsize);
282- textPtr += 2 ;
283- }
284- if (textPtr < text.size ()) {
285- origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 0x18 ,0x9A ,255 ,255 }, fontsize);
286- textPtr += 2 ;
287- }
288- if (textPtr < text.size ()) {
289- origin = g_fnt->RenderString (text.substr (textPtr), origin.x , origin.y , {255 ,255 ,255 ,255 }, fontsize);
290- }
291- if (focused) {
292- g_fnt->RenderString (" _" , origin.x , origin.y , {255 ,255 ,255 ,255 }, fontsize);
293-
294- }
295- }
276+ renderTextFieldText (at);
296277}
297278
298279void UITextField::renderOnScreenTextField ()
@@ -312,25 +293,9 @@ void UITextField::renderOnScreenTextField()
312293 // g_popClip();
313294}
314295
315- bool UITextField::isValidOrPartialColor ()
316- {
317- for (int x = 0 ; x < text.size (); x++) {
318- char c = tolower (text[x]);
319- if (!((c >= ' 0' && c <= ' 9' ) || (c >= ' a' && c <= ' f' ) || (c == ' #' && x == 0 ))) {
320- return false ;
321- }
322- }
323- return true ;
324- }
325-
326296void UITextField::copyToClipboard ()
327297{
328- if (SDL_SetClipboardText (text.c_str ())) {
329- g_addNotification (SuccessShortNotification (TL (" vsp.cmn.copiedtoclipboard" ), " " ));
330- }
331- else {
332- g_addNotification (ErrorNotification (TL (" vsp.cmn.error.clipboardcopy" ), " " ));
333- }
298+ g_copyStringToClipboard (text);
334299}
335300
336301void UITextField::pasteFromClipboard ()
@@ -354,6 +319,90 @@ void UITextField::pasteFromClipboard()
354319 }
355320}
356321
322+ bool UIColorTextField::isValidOrPartialColor ()
323+ {
324+ for (int x = 0 ; x < text.size (); x++) {
325+ char c = tolower (text[x]);
326+ if (!((c >= ' 0' && c <= ' 9' ) || (c >= ' a' && c <= ' f' ) || (c == ' #' && x == 0 ))) {
327+ return false ;
328+ }
329+ }
330+ return true ;
331+ }
332+
333+ void UIColorTextField::copyUnityTMP ()
334+ {
335+ if (linkedToColorPicker != NULL ) {
336+ u32 col = linkedToColorPicker->colorNowU32 & 0xFFFFFF ;
337+ g_copyStringToClipboard (frmt (" <#{:06X}>" , col));
338+ }
339+ }
340+
341+ void UIColorTextField::copyCSSRGB ()
342+ {
343+ if (linkedToColorPicker != NULL ) {
344+ SDL_Color col = uint32ToSDLColor (linkedToColorPicker->colorNowU32 );
345+ g_copyStringToClipboard (frmt (" rgb({} {} {})" , col.r , col.g , col.b ));
346+ }
347+ }
348+
349+ void UIColorTextField::copyCSSHSL ()
350+ {
351+ if (linkedToColorPicker != NULL ) {
352+ auto hsl = g_colorModels[" HSL" ]->fromRGB (linkedToColorPicker->colorNowU32 );
353+ g_copyStringToClipboard (frmt (" hsl({:.1f} {:.1f}% {:.1f}%)" , hsl[" H" ], hsl[" S" ]*100 , hsl[" L" ]*100 ));
354+ }
355+ }
356+
357+ void UIColorTextField::renderTextFieldText (XY at)
358+ {
359+ if (!isValidOrPartialColor () || text.empty ()) {
360+ UITextField::renderTextFieldText (at);
361+ }
362+ else {
363+ int textPtr = 0 ;
364+ XY origin = xyAdd (at, { 2 ,2 });
365+ if (text[0 ] == ' #' ) {
366+ origin = g_fnt->RenderString (" #" , origin.x , origin.y , SDL_Color{ 0x80 ,0x80 ,0x80 ,255 });
367+ textPtr++;
368+ }
369+ origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 255 ,0x32 ,0x32 ,255 }, fontsize);
370+ textPtr += 2 ;
371+ if (textPtr < text.size ()) {
372+ origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 0x50 ,255 ,0x50 ,255 }, fontsize);
373+ textPtr += 2 ;
374+ }
375+ if (textPtr < text.size ()) {
376+ origin = g_fnt->RenderString (text.substr (textPtr, ixmin (2 , text.size () - textPtr)), origin.x , origin.y , SDL_Color{ 0x18 ,0x9A ,255 ,255 }, fontsize);
377+ textPtr += 2 ;
378+ }
379+ if (textPtr < text.size ()) {
380+ origin = g_fnt->RenderString (text.substr (textPtr), origin.x , origin.y , { 255 ,255 ,255 ,255 }, fontsize);
381+ }
382+ if (focused) {
383+ g_fnt->RenderString (" _" , origin.x , origin.y , { 255 ,255 ,255 ,255 }, fontsize);
384+
385+ }
386+ }
387+ }
388+
389+ void UIColorTextField::openActionsMenu ()
390+ {
391+ if (linkedToColorPicker == NULL ) {
392+ UITextField::openActionsMenu ();
393+ }
394+ else {
395+ g_openContextMenu ({
396+ { TL (" vsp.cmn.copy" ), [this ]() { copyToClipboard (); } },
397+ { " Copy as TextMeshPro tag" , [this ]() { copyUnityTMP (); }},
398+ { " Copy as CSS rgb()" , [this ]() { copyCSSRGB (); }},
399+ { " Copy as CSS hsl()" , [this ]() { copyCSSHSL (); }},
400+ { TL (" vsp.cmn.paste" ), [this ]() { pasteFromClipboard (); } },
401+ { TL (" vsp.cmn.erase" ), [this ]() { clearText (); } },
402+ });
403+ }
404+ }
405+
357406void UITextField::runNumericOperation () {
358407 if (isNumericField && numericFieldCurrentOperation != ' \0 ' ) {
359408 try {
0 commit comments