2 Copyright 2009-2010 volca
3 Licenced under Academic Free License version 3.0
4 Review OpenUsbLd README & LICENSE files for further details.
7 #include "include/usbld.h"
8 #include "include/dia.h"
9 #include "include/gui.h"
10 #include "include/lang.h"
11 #include "include/pad.h"
12 #include "include/renderman.h"
13 #include "include/fntsys.h"
14 #include "include/themes.h"
15 #include "include/util.h"
17 // UI spacing of the dialogues (pixels between consecutive items)
18 #define UI_SPACING_H 10
19 #define UI_SPACING_V 2
20 // spacer ui element width (simulates tab)
21 #define UI_SPACER_WIDTH 50
22 // minimal pixel width of spacer
23 #define UI_SPACER_MINIMAL 30
24 // length of breaking line in pixels
25 #define UI_BREAK_LEN 600
26 // scroll speed (delay in ms!) when in dialogs
27 #define DIA_SCROLL_SPEED 300
28 // scroll speed (delay in ms!) when setting int value
29 #define DIA_INT_SET_SPEED 100
31 static int screenWidth
;
32 static int screenHeight
;
38 #define KEYB_ITEMS (KEYB_WIDTH * KEYB_HEIGHT)
40 static void diaDrawBoundingBox(int x
, int y
, int w
, int h
, int focus
) {
42 rmDrawRect(x
- 5, y
, w
+ 10, h
+ 10, gTheme
->selTextColor
& gColFocus
);
44 rmDrawRect(x
- 5, y
, w
+ 10, h
+ 10, gTheme
->textColor
& gColFocus
);
47 int diaShowKeyb(char* text
, int maxLen
) {
48 int i
, j
, len
= strlen(text
), selkeyb
= 0, x
, w
;
49 int selchar
= 0, selcommand
= -1;
51 char keyb0
[KEYB_ITEMS
] = {
52 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
53 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
54 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\\',
55 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '`', ':' };
57 char keyb1
[KEYB_ITEMS
] = {
58 '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
59 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
60 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '|',
61 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '~', '.' };
64 char *commands
[KEYB_HEIGHT
] = {_l(_STR_BACKSPACE
), _l(_STR_SPACE
), _l(_STR_ENTER
), _l(_STR_MODE
)};
65 GSTEXTURE
*cmdicons
[KEYB_HEIGHT
];
66 cmdicons
[0] = thmGetTexture(SQUARE_ICON
);
67 cmdicons
[1] = thmGetTexture(TRIANGLE_ICON
);
68 cmdicons
[2] = thmGetTexture(START_ICON
);
69 cmdicons
[3] = thmGetTexture(SELECT_ICON
);
76 rmDrawRect(0, 0, screenWidth
, screenHeight
, gColDarker
);
79 fntRenderString(gTheme
->fonts
[0], 50, 120, ALIGN_NONE
, 0, 0, text
, gTheme
->textColor
);
81 // separating line for simpler orientation
82 rmDrawLine(25, 138, 615, 138, gColWhite
);
83 rmDrawLine(25, 139, 615, 139, gColWhite
);
85 for (j
= 0; j
< KEYB_HEIGHT
; j
++) {
86 for (i
= 0; i
< KEYB_WIDTH
; i
++) {
87 c
[0] = keyb
[i
+ j
* KEYB_WIDTH
];
90 w
= fntRenderString(gTheme
->fonts
[0], x
, 170 + 3 * UI_SPACING_H
* j
, ALIGN_NONE
, 0, 0, c
, gTheme
->uiTextColor
) - x
;
91 if ((i
+ j
* KEYB_WIDTH
) == selchar
)
92 diaDrawBoundingBox(x
, 170 + 3 * UI_SPACING_H
* j
, w
, UI_SPACING_H
, 0);
97 for (i
= 0; i
< KEYB_HEIGHT
; i
++) {
99 rmDrawPixmap(cmdicons
[i
], 436, 170 + 3 * UI_SPACING_H
* i
, ALIGN_NONE
, cmdicons
[i
]->Width
, cmdicons
[i
]->Height
, SCALING_RATIO
, gDefaultCol
);
102 w
= fntRenderString(gTheme
->fonts
[0], x
, 170 + 3 * UI_SPACING_H
* i
, ALIGN_NONE
, 0, 0, commands
[i
], gTheme
->uiTextColor
) - x
;
104 diaDrawBoundingBox(x
, 170 + 3 * UI_SPACING_H
* i
, w
, UI_SPACING_H
, 0);
109 if (getKey(KEY_LEFT
)) {
111 if (selchar
% KEYB_WIDTH
)
114 selcommand
= selchar
/ KEYB_WIDTH
;
118 selchar
= (selcommand
+ 1) * KEYB_WIDTH
- 1;
121 } else if (getKey(KEY_RIGHT
)) {
123 if ((selchar
+ 1) % KEYB_WIDTH
)
126 selcommand
= selchar
/ KEYB_WIDTH
;
130 selchar
= selcommand
* KEYB_WIDTH
;
133 } else if (getKey(KEY_UP
)) {
135 selchar
= (selchar
+ KEYB_ITEMS
- KEYB_WIDTH
) % KEYB_ITEMS
;
137 selcommand
= (selcommand
+ KEYB_HEIGHT
- 1) % KEYB_HEIGHT
;
138 } else if (getKey(KEY_DOWN
)) {
140 selchar
= (selchar
+ KEYB_WIDTH
) % KEYB_ITEMS
;
142 selcommand
= (selcommand
+ 1) % KEYB_HEIGHT
;
143 } else if (getKeyOn(KEY_CROSS
)) {
144 if (len
< (maxLen
- 1) && selchar
> -1) {
146 c
[0] = keyb
[selchar
];
148 } else if (selcommand
== 0) {
149 if (len
> 0) { // BACKSPACE
153 } else if (selcommand
== 1) {
154 if (len
< (maxLen
- 1)) { // SPACE
159 } else if (selcommand
== 2) {
161 } else if (selcommand
== 3) {
162 selkeyb
= (selkeyb
+ 1) % KEYB_MODE
; // MODE
168 } else if (getKey(KEY_SQUARE
)) {
169 if (len
>0) { // BACKSPACE
173 } else if (getKey(KEY_TRIANGLE
)) {
174 if (len
< (maxLen
- 1) && selchar
> -1) { // SPACE
179 } else if (getKeyOn(KEY_START
)) {
181 } else if (getKeyOn(KEY_SELECT
)) {
182 selkeyb
= (selkeyb
+ 1) % KEYB_MODE
; // MODE
189 if (getKey(KEY_CIRCLE
))
196 static int colPadSettings
[16];
198 static int diaShowColSel(unsigned char *r
, unsigned char *g
, unsigned char *b
) {
201 unsigned char col
[3];
203 padStoreSettings(colPadSettings
);
205 col
[0] = *r
; col
[1] = *g
; col
[2] = *b
;
206 setButtonDelay(KEY_LEFT
, 1);
207 setButtonDelay(KEY_RIGHT
, 1);
214 rmDrawRect(0, 0, screenWidth
, screenHeight
, gColDarker
);
217 fntRenderString(gTheme
->fonts
[0], 50, 50, ALIGN_NONE
, 0, 0, _l(_STR_COLOR_SELECTION
), GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
219 // 3 bars representing the colors...
223 for (co
= 0; co
< 3; ++co
) {
224 unsigned char cc
[3] = {0,0,0};
230 u64 dcol
= GS_SETREG_RGBA(cc
[0], cc
[1], cc
[2], 0x80);
233 rmDrawRect(x
, y
, 200, 20, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x60));
235 rmDrawRect(x
, y
, 200, 20, GS_SETREG_RGBA(0x020, 0x020, 0x020, 0x60));
237 rmDrawRect(x
+ 2, y
+ 2, 190.0f
*(cc
[co
]*100/255)/100, 16, dcol
);
240 // target color itself
241 u64 dcol
= GS_SETREG_RGBA(col
[0],col
[1],col
[2], 0x80);
246 rmDrawRect(x
, y
, 70, 70, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x60));
247 rmDrawRect(x
+ 5, y
+ 5, 60, 60, dcol
);
251 if (getKey(KEY_LEFT
)) {
254 } else if (getKey(KEY_RIGHT
)) {
257 } else if (getKey(KEY_UP
)) {
260 } else if (getKey(KEY_DOWN
)) {
263 } else if (getKeyOn(KEY_CROSS
)) {
269 } else if (getKeyOn(KEY_CIRCLE
)) {
275 padRestoreSettings(colPadSettings
);
281 // ----------------------------------------------------------------------------
282 // --------------------------- Dialogue handling ------------------------------
283 // ----------------------------------------------------------------------------
284 static const char *diaGetLocalisedText(const char* def
, int id
) {
291 /// returns true if the item is controllable (e.g. a value can be changed on it)
292 static int diaIsControllable(struct UIItem
*ui
) {
293 return (ui
->enabled
&& (ui
->type
>= UI_OK
));
296 /// returns true if the given item should be preceded with nextline
297 static int diaShouldBreakLine(struct UIItem
*ui
) {
298 return (ui
->type
== UI_SPLITTER
|| ui
->type
== UI_OK
|| ui
->type
== UI_BREAK
);
301 /// returns true if the given item should be superseded with nextline
302 static int diaShouldBreakLineAfter(struct UIItem
*ui
) {
303 return (ui
->type
== UI_SPLITTER
);
306 static void diaDrawHint(int text_id
) {
309 char* text
= _l(text_id
);
311 x
= screenWidth
- fntCalcDimensions(gTheme
->fonts
[0], text
) - 10;
312 y
= gTheme
->usedHeight
- 40;
314 // render hint on the lower side of the screen.
315 rmDrawRect(x
, y
, screenWidth
- x
, MENU_ITEM_HEIGHT
+ 10, gColDarker
);
316 fntRenderString(gTheme
->fonts
[0], x
+ 5, y
+ 5, ALIGN_NONE
, 0, 0, text
, gTheme
->textColor
);
319 /// renders an ui item (either selected or not)
320 /// sets width and height of the render into the parameters
321 static void diaRenderItem(int x
, int y
, struct UIItem
*item
, int selected
, int haveFocus
, int *w
, int *h
) {
324 // all texts are rendered up from the given point!
327 if (diaIsControllable(item
))
328 txtcol
= gTheme
->uiTextColor
;
330 txtcol
= gTheme
->textColor
;
332 // let's see what do we have here?
333 switch (item
->type
) {
339 // width is text length in pixels...
340 const char *txt
= diaGetLocalisedText(item
->label
.text
, item
->label
.stringId
);
341 if(txt
&& strlen(txt
))
342 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, txt
, txtcol
) - x
;
344 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, _l(_STR_NOT_SET
), txtcol
) - x
;
350 // a line. Thanks to the font rendering, we need to shift up by one font line
351 *w
= 0; // nothing to render at all
352 int ypos
= y
- UI_SPACING_V
/ 2; // gsFont->CharHeight +
357 // two lines for lesser eye strain :)
358 rmDrawLine(x
, ypos
, x
+ UI_BREAK_LEN
, ypos
, gColWhite
);
359 rmDrawLine(x
, ypos
+ 1, x
+ UI_BREAK_LEN
, ypos
+ 1, gColWhite
);
364 *w
= 0; // nothing to render at all
368 // next column divisible by spacer
369 *w
= (UI_SPACER_WIDTH
- x
% UI_SPACER_WIDTH
);
371 if (*w
< UI_SPACER_MINIMAL
) {
372 x
+= *w
+ UI_SPACER_MINIMAL
;
373 *w
+= (UI_SPACER_WIDTH
- x
% UI_SPACER_WIDTH
);
381 const char *txt
= _l(_STR_OK
);
382 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, txt
, txtcol
) - x
;
389 snprintf(tmp
, 10, "%d", item
->intvalue
.current
);
390 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, tmp
, txtcol
) - x
;
395 if(strlen(item
->stringvalue
.text
))
396 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, item
->stringvalue
.text
, txtcol
) - x
;
398 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, _l(_STR_NOT_SET
), txtcol
) - x
;
406 int len
= min(strlen(item
->stringvalue
.text
), 30);
407 for (i
= 0; i
< len
; ++i
)
411 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, stars
, txtcol
) - x
;
416 const char *txtval
= _l((item
->intvalue
.current
) ? _STR_ON
: _STR_OFF
);
417 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, txtval
, txtcol
) - x
;
422 const char* tv
= item
->intvalue
.enumvalues
[item
->intvalue
.current
];
425 tv
= _l(_STR_NO_ITEMS
);
427 *w
= fntRenderString(gTheme
->fonts
[0], x
, y
, ALIGN_NONE
, 0, 0, tv
, txtcol
) - x
;
432 rmDrawRect(x
, y
+ 3, 25, 17, txtcol
);
433 u64 dcol
= GS_SETREG_RGBA(item
->colourvalue
.r
, item
->colourvalue
.g
, item
->colourvalue
.b
, 0x80);
434 rmDrawRect(x
+ 2, y
+ 5, 21, 13, dcol
);
443 diaDrawBoundingBox(x
, y
, *w
, *h
, haveFocus
);
445 if (item
->fixedWidth
!= 0) {
447 if (item
->fixedWidth
< 0)
448 newSize
= item
->fixedWidth
* screenWidth
/ -100;
450 newSize
= item
->fixedWidth
;
455 if (item
->fixedHeight
!= 0) {
457 if (item
->fixedHeight
< 0)
458 newSize
= item
->fixedHeight
* screenHeight
/ -100;
460 newSize
= item
->fixedHeight
;
466 /// renders whole ui screen (for given dialog setup)
467 void diaRenderUI(struct UIItem
*ui
, short inMenu
, struct UIItem
*cur
, int haveFocus
) {
474 struct UIItem
*rc
= ui
;
475 int x
= x0
, y
= y0
, hmax
= 0;
477 while (rc
->type
!= UI_TERMINATOR
) {
480 if (diaShouldBreakLine(rc
)) {
484 y
+= hmax
+ UI_SPACING_H
;
489 diaRenderItem(x
, y
, rc
, rc
== cur
, haveFocus
, &w
, &h
);
492 x
+= w
+ UI_SPACING_V
;
494 hmax
= (h
> hmax
) ? h
: hmax
;
496 if (diaShouldBreakLineAfter(rc
)) {
500 y
+= hmax
+ UI_SPACING_H
;
508 if ((cur
!= NULL
) && (!haveFocus
) && (cur
->hintId
!= -1)) {
509 diaDrawHint(cur
->hintId
);
513 /// sets the ui item value to the default again
514 static void diaResetValue(struct UIItem
*item
) {
518 item
->intvalue
.current
= item
->intvalue
.def
;
522 strncpy(item
->stringvalue
.text
, item
->stringvalue
.def
, 32);
529 static int diaHandleInput(struct UIItem
*item
, int *modified
) {
530 // circle loses focus, sets old values first
531 if (getKeyOn(KEY_CIRCLE
)) {
536 // cross loses focus without setting default
537 if (getKeyOn(KEY_CROSS
)) {
542 // UI item type dependant part:
543 if (item
->type
== UI_BOOL
) {
544 // a trick. Set new value, lose focus
545 item
->intvalue
.current
= !item
->intvalue
.current
;
547 } if (item
->type
== UI_INT
) {
549 setButtonDelay(KEY_UP
, DIA_INT_SET_SPEED
);
550 setButtonDelay(KEY_DOWN
, DIA_INT_SET_SPEED
);
553 if (getKey(KEY_UP
) && (item
->intvalue
.current
< item
->intvalue
.max
))
554 item
->intvalue
.current
++;
555 else if (getKey(KEY_DOWN
) && (item
->intvalue
.current
> item
->intvalue
.min
))
556 item
->intvalue
.current
--;
559 } else if ((item
->type
== UI_STRING
) || (item
->type
== UI_PASSWORD
)) {
561 strncpy(tmp
, item
->stringvalue
.text
, 32);
563 if (item
->stringvalue
.handler
) {
564 if (item
->stringvalue
.handler(tmp
, 32))
565 strncpy(item
->stringvalue
.text
, tmp
, 32);
567 if (diaShowKeyb(tmp
, 32))
568 strncpy(item
->stringvalue
.text
, tmp
, 32);
572 } else if (item
->type
== UI_ENUM
) {
573 int cur
= item
->intvalue
.current
;
575 if (item
->intvalue
.enumvalues
[cur
] == NULL
) {
577 item
->intvalue
.current
--;
582 if (getKey(KEY_UP
) && (item
->intvalue
.current
> 0))
583 item
->intvalue
.current
--;
584 else if (getKey(KEY_DOWN
) && (item
->intvalue
.enumvalues
[item
->intvalue
.current
+ 1] != NULL
))
585 item
->intvalue
.current
++;
588 } else if (item
->type
== UI_COLOUR
) {
589 if (!diaShowColSel(&item
->colourvalue
.r
, &item
->colourvalue
.g
, &item
->colourvalue
.b
))
598 static struct UIItem
*diaGetFirstControl(struct UIItem
*ui
) {
599 struct UIItem
*cur
= ui
;
601 while (!diaIsControllable(cur
)) {
602 if (cur
->type
== UI_TERMINATOR
)
611 static struct UIItem
*diaGetLastControl(struct UIItem
*ui
) {
612 struct UIItem
*last
= diaGetFirstControl(ui
);
613 struct UIItem
*cur
= last
;
615 while (cur
->type
!= UI_TERMINATOR
) {
618 if (diaIsControllable(cur
))
625 static struct UIItem
*diaGetNextControl(struct UIItem
*cur
, struct UIItem
* dflt
) {
626 while (cur
->type
!= UI_TERMINATOR
) {
629 if (diaIsControllable(cur
))
636 static struct UIItem
*diaGetPrevControl(struct UIItem
* cur
, struct UIItem
*ui
) {
637 struct UIItem
*newf
= cur
;
642 if (diaIsControllable(newf
))
649 /// finds first control on previous line...
650 static struct UIItem
*diaGetPrevLine(struct UIItem
* cur
, struct UIItem
*ui
) {
651 struct UIItem
*newf
= cur
;
654 int hadCtrl
= 0; // had the scanned line any control?
659 if ((lb
> 0) && (diaIsControllable(newf
)))
662 if (diaShouldBreakLine(newf
)) {// is this a line break?
663 if (hadCtrl
|| lb
== 0) {
669 // twice the break? find first control
671 return diaGetFirstControl(newf
);
677 static struct UIItem
*diaGetNextLine(struct UIItem
* cur
, struct UIItem
*ui
) {
678 struct UIItem
*newf
= cur
;
682 while (newf
->type
!= UI_TERMINATOR
) {
685 if (diaShouldBreakLine(newf
)) {// is this a line break?
690 return diaGetNextControl(newf
, cur
);
696 static int diaPadSettings
[16];
698 static void diaStoreScrollSpeed(void) {
699 padStoreSettings(diaPadSettings
);
702 static void diaRestoreScrollSpeed(void) {
703 padRestoreSettings(diaPadSettings
);
706 static struct UIItem
* diaFindByID(struct UIItem
* ui
, int id
) {
707 while (ui
->type
!= UI_TERMINATOR
) {
717 int diaExecuteDialog(struct UIItem
*ui
, int uiId
, short inMenu
, int (*updater
)(int modified
)) {
718 rmGetScreenExtents(&screenWidth
, &screenHeight
);
720 struct UIItem
*cur
= NULL
;
722 cur
= diaFindByID(ui
, uiId
);
725 cur
= diaGetFirstControl(ui
);
727 // what? no controllable item? Exit!
731 int haveFocus
= 0, modified
;
733 diaStoreScrollSpeed();
735 // slower controls for dialogs
736 setButtonDelay(KEY_UP
, DIA_SCROLL_SPEED
);
737 setButtonDelay(KEY_DOWN
, DIA_SCROLL_SPEED
);
739 // okay, we have the first selectable item
740 // we can proceed with rendering etc. etc.
743 diaRenderUI(ui
, inMenu
, cur
, haveFocus
);
750 haveFocus
= diaHandleInput(cur
, &modified
);
753 setButtonDelay(KEY_UP
, DIA_SCROLL_SPEED
);
754 setButtonDelay(KEY_DOWN
, DIA_SCROLL_SPEED
);
758 if (getKey(KEY_LEFT
)) {
759 struct UIItem
*newf
= diaGetPrevControl(cur
, ui
);
762 cur
= diaGetLastControl(ui
);
767 if (getKey(KEY_RIGHT
)) {
768 struct UIItem
*newf
= diaGetNextControl(cur
, cur
);
771 cur
= diaGetFirstControl(ui
);
778 struct UIItem
*newf
= diaGetPrevLine(cur
, ui
);
781 cur
= diaGetLastControl(ui
);
786 if(getKey(KEY_DOWN
)) {
788 struct UIItem
*newf
= diaGetNextLine(cur
, ui
);
791 cur
= diaGetFirstControl(ui
);
796 // circle breaks focus or exits with false result
797 if (getKeyOn(KEY_CIRCLE
)) {
798 diaRestoreScrollSpeed();
802 // see what key events we have
803 if (getKeyOn(KEY_CROSS
)) {
806 if (cur
->type
== UI_BUTTON
) {
807 diaRestoreScrollSpeed();
811 if (cur
->type
== UI_OK
) {
812 diaRestoreScrollSpeed();
819 int updResult
= updater(modified
);
826 void diaSetEnabled(struct UIItem
* ui
, int id
, int enabled
) {
827 struct UIItem
*item
= diaFindByID(ui
, id
);
832 item
->enabled
= enabled
;
835 int diaGetInt(struct UIItem
* ui
, int id
, int *value
) {
836 struct UIItem
*item
= diaFindByID(ui
, id
);
841 if ((item
->type
== UI_INT
) || (item
->type
== UI_BOOL
) || (item
->type
== UI_ENUM
)) {
842 *value
= item
->intvalue
.current
;
849 int diaSetInt(struct UIItem
* ui
, int id
, int value
) {
850 struct UIItem
*item
= diaFindByID(ui
, id
);
855 if ((item
->type
== UI_INT
) || (item
->type
== UI_BOOL
) || (item
->type
== UI_ENUM
)) {
856 item
->intvalue
.def
= value
;
857 item
->intvalue
.current
= value
;
864 int diaGetString(struct UIItem
* ui
, int id
, char *value
) {
865 struct UIItem
*item
= diaFindByID(ui
, id
);
870 if ((item
->type
== UI_STRING
) || (item
->type
== UI_PASSWORD
)) {
871 strncpy(value
, item
->stringvalue
.text
, 32);
878 int diaSetString(struct UIItem
* ui
, int id
, const char *text
) {
879 struct UIItem
*item
= diaFindByID(ui
, id
);
884 if ((item
->type
== UI_STRING
) || (item
->type
== UI_PASSWORD
)) {
885 strncpy(item
->stringvalue
.def
, text
, 32);
886 strncpy(item
->stringvalue
.text
, text
, 32);
893 int diaGetColor(struct UIItem
* ui
, int id
, unsigned char *col
) {
894 struct UIItem
*item
= diaFindByID(ui
, id
);
899 if (item
->type
!= UI_COLOUR
)
902 col
[0] = item
->colourvalue
.r
;
903 col
[1] = item
->colourvalue
.g
;
904 col
[2] = item
->colourvalue
.b
;
908 int diaSetColor(struct UIItem
* ui
, int id
, const unsigned char *col
) {
909 struct UIItem
*item
= diaFindByID(ui
, id
);
914 if (item
->type
!= UI_COLOUR
)
917 item
->colourvalue
.r
= col
[0];
918 item
->colourvalue
.g
= col
[1];
919 item
->colourvalue
.b
= col
[2];
923 int diaSetU64Color(struct UIItem
* ui
, int id
, u64 col
) {
924 struct UIItem
*item
= diaFindByID(ui
, id
);
929 if (item
->type
!= UI_COLOUR
)
932 item
->colourvalue
.r
= col
& 0xFF;
934 item
->colourvalue
.g
= col
& 0xFF;
936 item
->colourvalue
.b
= col
& 0xFF;
940 int diaSetLabel(struct UIItem
* ui
, int id
, const char *text
) {
941 struct UIItem
*item
= diaFindByID(ui
, id
);
946 if ((item
->type
== UI_LABEL
) || (item
->type
== UI_BUTTON
)) {
947 item
->label
.text
= text
;
954 int diaSetEnum(struct UIItem
* ui
, int id
, const char **enumvals
) {
955 struct UIItem
*item
= diaFindByID(ui
, id
);
960 if (item
->type
!= UI_ENUM
)
963 item
->intvalue
.enumvalues
= enumvals
;