freemyipod r820 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r819‎ | r820 | r821 >
Date:03:24, 4 December 2011
Author:theseven
Status:new
Tags:
Comment:
libUI: Add item rendering callback to chooser renderers and add setting chooser module
Modified paths:
  • /libs/ui/SOURCES (modified) (history)
  • /libs/ui/chooser.c (modified) (history)
  • /libs/ui/chooser.h (modified) (history)
  • /libs/ui/chooser_action_handler_wheel.c (modified) (history)
  • /libs/ui/chooser_renderer_iconflow.c (modified) (history)
  • /libs/ui/chooser_renderer_iconflow.h (modified) (history)
  • /libs/ui/chooser_renderer_list.c (modified) (history)
  • /libs/ui/chooser_renderer_list.h (modified) (history)
  • /libs/ui/export/libui.h (modified) (history)
  • /libs/ui/libui.h (modified) (history)
  • /libs/ui/main.c (modified) (history)

Diff [purge]

Index: libs/ui/export/libui.h
@@ -31,6 +31,7 @@
3232 #include "../chooser_action_handler_wheel.h"
3333 #include "../chooser_renderer_list.h"
3434 #include "../chooser_renderer_iconflow.h"
 35+#include "../settingchooser.h"
3536
3637
3738 /* emCORE library identifier */
@@ -37,12 +38,12 @@
3839 #define LIBUI_IDENTIFIER 0x49554365
3940
4041 /* increase this every time the api struct changes */
41 -#define LIBUI_API_VERSION 2
 42+#define LIBUI_API_VERSION 3
4243
4344 /* update this to latest version if a change to the api struct breaks
4445 backwards compatibility (and please take the opportunity to sort in any
4546 new function which are "waiting" at the end of the function table) */
46 -#define LIBUI_MIN_API_VERSION 2
 47+#define LIBUI_MIN_API_VERSION 3
4748
4849 /* NOTE: To support backwards compatibility, only add new functions at
4950 the end of the structure. Every time you add a new function,
@@ -61,6 +62,10 @@
6263 typeof(chooser_action_handler_wheel)* chooser_action_handler_wheel;
6364 typeof(chooser_renderer_list)* chooser_renderer_list;
6465 typeof(chooser_renderer_iconflow)* chooser_renderer_iconflow;
 66+ typeof(chooser_renderer_list_render_attached_text)* chooser_renderer_list_render_attached_text;
 67+ typeof(chooser_renderer_list_show_arrow_right)* chooser_renderer_list_show_arrow_right;
 68+ typeof(chooser_renderer_list_show_arrow_left)* chooser_renderer_list_show_arrow_left;
 69+ typeof(settingchooser_run)* settingchooser_run;
6570 };
6671
6772 #endif
Index: libs/ui/SOURCES
@@ -4,3 +4,4 @@
55 chooser_action_handler_wheel.c
66 chooser_renderer_list.c
77 chooser_renderer_iconflow.c
 8+settingchooser.c
Index: libs/ui/chooser.c
@@ -31,24 +31,24 @@
3232 struct chooser_data* data = (struct chooser_data*)user;
3333 switch (data->info->actionhandler->handleevent(data, event, which, value))
3434 {
35 - case CHOOSER_RESULT_REDRAW:
36 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
37 - data->redrawneeded = true;
38 - wakeup_signal(&data->eventwakeup);
39 - mutex_unlock(&data->statemutex);
40 - break;
41 - case CHOOSER_RESULT_CANCEL:
42 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
43 - data->canceled = true;
44 - wakeup_signal(&data->eventwakeup);
45 - mutex_unlock(&data->statemutex);
46 - break;
47 - case CHOOSER_RESULT_FINISHED:
48 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
49 - data->finished = true;
50 - wakeup_signal(&data->eventwakeup);
51 - mutex_unlock(&data->statemutex);
52 - break;
 35+ case CHOOSER_RESULT_REDRAW:
 36+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 37+ data->redrawneeded = true;
 38+ wakeup_signal(&data->eventwakeup);
 39+ mutex_unlock(&data->statemutex);
 40+ break;
 41+ case CHOOSER_RESULT_CANCEL:
 42+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 43+ data->canceled = true;
 44+ wakeup_signal(&data->eventwakeup);
 45+ mutex_unlock(&data->statemutex);
 46+ break;
 47+ case CHOOSER_RESULT_FINISHED:
 48+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 49+ data->finished = true;
 50+ wakeup_signal(&data->eventwakeup);
 51+ mutex_unlock(&data->statemutex);
 52+ break;
5353 }
5454 }
5555
@@ -99,13 +99,13 @@
100100 if (info->actionhandler->handletick)
101101 switch (info->actionhandler->handletick(&data))
102102 {
103 - case CHOOSER_RESULT_REDRAW:
104 - redrawneeded = true;
105 - break;
106 - case CHOOSER_RESULT_CANCEL:
107 - goto cancel;
108 - case CHOOSER_RESULT_FINISHED:
109 - goto finished;
 103+ case CHOOSER_RESULT_REDRAW:
 104+ redrawneeded = true;
 105+ break;
 106+ case CHOOSER_RESULT_CANCEL:
 107+ goto cancel;
 108+ case CHOOSER_RESULT_FINISHED:
 109+ goto finished;
110110 }
111111 lasttick = USEC_TIMER;
112112 }
Index: libs/ui/chooser.h
@@ -83,7 +83,7 @@
8484 long tickinterval;
8585 int itemcount;
8686 int defaultitem;
87 - const struct chooser_item items[];
 87+ struct chooser_item items[];
8888 };
8989
9090 struct chooser_data
Index: libs/ui/libui.h
@@ -35,6 +35,7 @@
3636 .addr = a, \
3737 .stride = b \
3838 }
 39+#define LIBUI_BUFFER_NULL LIBUI_BUFFER(NULL, 0)
3940
4041 struct libui_point
4142 {
@@ -46,6 +47,7 @@
4748 .x = a, \
4849 .y = b \
4950 }
 51+#define LIBUI_POINT_NULL LIBUI_POINT(0, 0)
5052
5153 struct libui_box
5254 {
@@ -57,6 +59,7 @@
5860 .pos = a, \
5961 .size = b \
6062 }
 63+#define LIBUI_BOX_NULL LIBUI_BOX(LIBUI_POINT_NULL, LIBUI_POINT_NULL)
6164
6265 struct libui_location
6366 {
@@ -68,6 +71,7 @@
6972 .buf = a, \
7073 .pos = b \
7174 }
 75+#define LIBUI_LOCATION_NULL LIBUI_LOCATION(LIBUI_BUFFER_NULL, LIBUI_POINT_NULL)
7276
7377 struct libui_surface
7478 {
@@ -79,5 +83,6 @@
8084 .loc = a, \
8185 .size = b \
8286 }
 87+#define LIBUI_SURFACE_NULL LIBUI_SURFACE(LIBUI_LOCATION_NULL, LIBUI_POINT_NULL)
8388
8489 #endif
Index: libs/ui/chooser_action_handler_wheel.c
@@ -55,35 +55,36 @@
5656 int spi = params->stepsperitem;
5757 switch (event)
5858 {
59 - case BUTTON_PRESS:
60 - if (which < params->buttoncount)
61 - switch (params->buttonmap[which])
62 - {
63 - case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV:
64 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
65 - data->position = MIN(data->info->itemcount * spi,
66 - MAX(spi, data->position & ~(spi - 1))) - spi / 2;
67 - data->selected = &data->info->items[data->position / spi];
68 - mutex_unlock(&data->statemutex);
69 - return CHOOSER_RESULT_REDRAW;
70 - case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT:
71 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
72 - data->position = MIN(data->info->itemcount * spi,
73 - MAX(spi, (data->position & ~(spi - 1)) + 2 * spi)) - spi / 2;
74 - data->selected = &data->info->items[data->position / spi];
75 - mutex_unlock(&data->statemutex);
76 - return CHOOSER_RESULT_REDRAW;
77 - case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT:
78 - return CHOOSER_RESULT_FINISHED;
79 - case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL:
80 - return CHOOSER_RESULT_CANCEL;
81 - }
82 - case WHEEL_MOVED_ACCEL:
83 - mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
84 - data->position = MIN(data->info->itemcount * spi - 1, MAX(0, data->position + value));
85 - data->selected = &data->info->items[data->position / spi];
86 - mutex_unlock(&data->statemutex);
87 - return CHOOSER_RESULT_REDRAW;
 59+ case BUTTON_PRESS:
 60+ if (which < params->buttoncount)
 61+ switch (params->buttonmap[which])
 62+ {
 63+ case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV:
 64+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 65+ data->position = MIN(data->info->itemcount * spi,
 66+ MAX(spi, data->position & ~(spi - 1))) - spi / 2;
 67+ data->selected = &data->info->items[data->position / spi];
 68+ mutex_unlock(&data->statemutex);
 69+ return CHOOSER_RESULT_REDRAW;
 70+ case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT:
 71+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 72+ data->position = MIN(data->info->itemcount * spi,
 73+ MAX(spi, (data->position & ~(spi - 1)) + 2 * spi))
 74+ - spi / 2;
 75+ data->selected = &data->info->items[data->position / spi];
 76+ mutex_unlock(&data->statemutex);
 77+ return CHOOSER_RESULT_REDRAW;
 78+ case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT:
 79+ return CHOOSER_RESULT_FINISHED;
 80+ case CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL:
 81+ return CHOOSER_RESULT_CANCEL;
 82+ }
 83+ case WHEEL_MOVED_ACCEL:
 84+ mutex_lock(&data->statemutex, TIMEOUT_BLOCK);
 85+ data->position = MIN(data->info->itemcount * spi - 1, MAX(0, data->position + value));
 86+ data->selected = &data->info->items[data->position / spi];
 87+ mutex_unlock(&data->statemutex);
 88+ return CHOOSER_RESULT_REDRAW;
8889 }
8990 return CHOOSER_RESULT_OK;
9091 }
Index: libs/ui/chooser_renderer_list.c
@@ -187,6 +187,7 @@
188188 if (iparams->text && iparams->text_color)
189189 rendertext(buf, x + iparams->text_pos.x, y + iparams->text_pos.y,
190190 stride, text_color, 0, iparams->text);
 191+ if (iparams->render) iparams->render(data, item, item == selected, x, y);
191192 y += iparams->size.y;
192193 item++;
193194 }
@@ -225,7 +226,37 @@
226227 free(data->rendererdata);
227228 }
228229
 230+void chooser_renderer_list_render_attached_text(struct chooser_data* data,
 231+ const struct chooser_item* item,
 232+ bool selected, int x, int y, const char* text)
 233+{
 234+ struct chooser_renderer_list_params* rparams;
 235+ rparams = (struct chooser_renderer_list_params*)data->info->rendererparams;
 236+ struct chooser_renderer_list_itemdata* ritem;
 237+ ritem = (struct chooser_renderer_list_itemdata*)item->renderparams;
 238+ void* buf = rparams->viewport.loc.buf.addr;
 239+ int stride = rparams->viewport.loc.buf.stride;
 240+ x += ritem->size.x - ritem->text_pos.x - strlen(text) * get_font_width();
 241+ y += ritem->text_pos.y;
 242+ uint32_t color = selected ? ritem->text_color_selected : ritem->text_color;
 243+ rendertext(buf, x, y, stride, color, 0, text);
 244+}
229245
 246+void chooser_renderer_list_show_arrow_right(struct chooser_data* data,
 247+ const struct chooser_item* item,
 248+ bool selected, int x, int y)
 249+{
 250+ chooser_renderer_list_render_attached_text(data, item, selected, x, y, ">");
 251+}
 252+
 253+void chooser_renderer_list_show_arrow_left(struct chooser_data* data,
 254+ const struct chooser_item* item,
 255+ bool selected, int x, int y)
 256+{
 257+ chooser_renderer_list_render_attached_text(data, item, selected, x, y, "<");
 258+}
 259+
 260+
230261 const struct chooser_renderer chooser_renderer_list =
231262 {
232263 .version = CHOOSER_RENDERER_VERSION,
Index: libs/ui/main.c
@@ -36,7 +36,11 @@
3737 .chooser_run = chooser_run,
3838 .chooser_action_handler_wheel = &chooser_action_handler_wheel,
3939 .chooser_renderer_list = &chooser_renderer_list,
40 - .chooser_renderer_iconflow = &chooser_renderer_iconflow
 40+ .chooser_renderer_iconflow = &chooser_renderer_iconflow,
 41+ .chooser_renderer_list_render_attached_text = &chooser_renderer_list_render_attached_text,
 42+ .chooser_renderer_list_show_arrow_right = &chooser_renderer_list_show_arrow_right,
 43+ .chooser_renderer_list_show_arrow_left = &chooser_renderer_list_show_arrow_left,
 44+ .settingchooser_run = &settingchooser_run
4145 };
4246
4347 EMCORE_LIB_HEADER(LIBUI_IDENTIFIER, LIBUI_API_VERSION, LIBUI_MIN_API_VERSION, NULL, NULL, apitable)
Index: libs/ui/chooser_renderer_iconflow.c
@@ -158,7 +158,7 @@
159159 const struct libui_surface* icon;
160160 if (item == selected) icon = &iparams->icon_selected;
161161 else icon = &iparams->icon;
162 - int ix, iy, io;
 162+ int ix, iy, io, tx = 0, ty = 0;
163163 int dist = pos - vpos;
164164 chooser_renderer_iconflow_geticondata(x, y, w, h, spi * iiv, dist, icon, &ix, &iy, &io);
165165 if (item == selected)
@@ -165,13 +165,17 @@
166166 {
167167 io = 255;
168168 if (iparams->text && iparams->text_color)
169 - rendertext(buf, params->text_pos.x - strlen(iparams->text) * get_font_width() / 2,
170 - params->text_pos.y, stride, iparams->text_color, 0, iparams->text);
 169+ {
 170+ tx = params->text_pos.x - strlen(iparams->text) * get_font_width() / 2;
 171+ ty = params->text_pos.y;
 172+ rendertext(buf, tx, ty, stride, iparams->text_color, 0, iparams->text);
 173+ }
171174 }
172175 if (icon->loc.buf.addr && io && ix >= x && iy >= y
173176 && ix + icon->size.x <= x + w && iy + icon->size.y <= y + h)
174177 blenda(icon->size.x, icon->size.y, io, buf, ix, iy, stride, buf, ix, iy, stride,
175178 icon->loc.buf.addr, icon->loc.pos.x, icon->loc.pos.y, icon->loc.buf.stride);
 179+ if (iparams->render) iparams->render(data, item, item == selected, ix, iy, io, tx, ty);
176180 if (item == selected) break;
177181 item += dir;
178182 pos += dir * spi;
Index: libs/ui/chooser_renderer_list.h
@@ -29,7 +29,7 @@
3030 #include "chooser.h"
3131
3232
33 -#define CHOOSER_RENDERER_LIST_PARAMS_VERSION 1
 33+#define CHOOSER_RENDERER_LIST_PARAMS_VERSION 2
3434
3535 struct chooser_renderer_list_params
3636 {
@@ -59,10 +59,12 @@
6060 int icon_opacity;
6161 struct libui_surface icon_selected;
6262 int icon_selected_opacity;
63 - char* text;
 63+ const char* text;
6464 struct libui_point text_pos;
6565 uint32_t text_color;
6666 uint32_t text_color_selected;
 67+ void (*render)(struct chooser_data* data, const struct chooser_item* item,
 68+ bool selected, int x, int y);
6769 };
6870
6971 struct chooser_renderer_list_data
@@ -74,5 +76,16 @@
7577
7678 extern const struct chooser_renderer chooser_renderer_list;
7779
 80+extern void chooser_renderer_list_render_attached_text(struct chooser_data* data,
 81+ const struct chooser_item* item,
 82+ bool selected, int x, int y,
 83+ const char* text);
 84+extern void chooser_renderer_list_show_arrow_right(struct chooser_data* data,
 85+ const struct chooser_item* item,
 86+ bool selected, int x, int y);
 87+extern void chooser_renderer_list_show_arrow_left(struct chooser_data* data,
 88+ const struct chooser_item* item,
 89+ bool selected, int x, int y);
7890
 91+
7992 #endif
Index: libs/ui/chooser_renderer_iconflow.h
@@ -29,7 +29,7 @@
3030 #include "chooser.h"
3131
3232
33 -#define CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION 1
 33+#define CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION 2
3434
3535 struct chooser_renderer_iconflow_params
3636 {
@@ -56,8 +56,10 @@
5757 {
5858 struct libui_surface icon;
5959 struct libui_surface icon_selected;
60 - char* text;
 60+ const char* text;
6161 uint32_t text_color;
 62+ void (*render)(struct chooser_data* data, const struct chooser_item* item,
 63+ bool selected, int x, int y, int opacity, int textx, int texty);
6264 };
6365
6466 struct chooser_renderer_iconflow_data

Follow-up revisions

RevisionCommit summaryAuthorDate
r824libUI: Fix red (add files that were overlooked when committing r820)theseven03:45, 4 December 2011