From a13e9644b5915215a0617d2c8b279886949f136b Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Mon, 17 Oct 2011 18:28:35 +0000 Subject: [PATCH] - Fix some reds by implementing lcd_get_dpi(). - Use the list item centering capabilities in the plugin lib - Bump plugin ABI for the changed viewport struct (sort the API too). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30775 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.c | 30 ++++++++--------- apps/plugin.h | 41 ++++++++++++------------ apps/plugins/lib/pluginlib_touchscreen.c | 33 +++---------------- apps/plugins/reversi/reversi-gui.c | 6 ++-- firmware/export/lcd.h | 6 +++- 5 files changed, 49 insertions(+), 67 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index 8037dab29a..b9c2e7cb5b 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -517,6 +517,19 @@ static const struct plugin_api rockbox_api = { utf8encode, utf8length, utf8seek, + + /* the buflib memory management library */ + buflib_init, + buflib_available, + buflib_alloc, + buflib_alloc_ex, + buflib_alloc_maximum, + buflib_buffer_in, + buflib_buffer_out, + buflib_free, + buflib_shrink, + buflib_get_data, + buflib_get_name, /* sound */ sound_set, @@ -732,6 +745,8 @@ static const struct plugin_api rockbox_api = { #endif show_logo, tree_get_context, + tree_get_entries, + tree_get_entry_at, set_current_file, set_dirfilter, @@ -790,21 +805,6 @@ static const struct plugin_api rockbox_api = { /* new stuff at the end, sort into place next time the API gets incompatible */ - tree_get_entries, - tree_get_entry_at, - - /* the buflib memory management library */ - buflib_init, - buflib_available, - buflib_alloc, - buflib_alloc_ex, - buflib_alloc_maximum, - buflib_buffer_in, - buflib_buffer_out, - buflib_free, - buflib_shrink, - buflib_get_data, - buflib_get_name, }; int plugin_load(const char* plugin, const void* parameter) diff --git a/apps/plugin.h b/apps/plugin.h index e0ee951185..fa1259cfe3 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -147,12 +147,12 @@ void* plugin_get_buffer(size_t *buffer_size); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 212 +#define PLUGIN_API_VERSION 213 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 210 +#define PLUGIN_MIN_API_VERSION 213 /* plugin return codes */ /* internal returns start at 0x100 to make exit(1..255) work */ @@ -601,6 +601,22 @@ struct plugin_api { unsigned long (*utf8length)(const unsigned char *utf8); int (*utf8seek)(const unsigned char* utf8, int offset); + /* the buflib memory management library */ + void (*buflib_init)(struct buflib_context* ctx, void* buf, size_t size); + size_t (*buflib_available)(struct buflib_context* ctx); + int (*buflib_alloc)(struct buflib_context* ctx, size_t size); + int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size, + const char* name, struct buflib_callbacks *ops); + int (*buflib_alloc_maximum)(struct buflib_context* ctx, const char* name, + size_t* size, struct buflib_callbacks *ops); + void (*buflib_buffer_in)(struct buflib_context* ctx, int size); + void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size); + int (*buflib_free)(struct buflib_context* ctx, int handle); + bool (*buflib_shrink)(struct buflib_context* ctx, int handle, + void* new_start, size_t new_size); + void* (*buflib_get_data)(struct buflib_context* ctx, int handle); + const char* (*buflib_get_name)(struct buflib_context* ctx, int handle); + /* sound */ void (*sound_set)(int setting, int value); int (*sound_default)(int setting); @@ -862,6 +878,9 @@ struct plugin_api { #endif int (*show_logo)(void); struct tree_context* (*tree_get_context)(void); + struct entry* (*tree_get_entries)(struct tree_context* t); + struct entry* (*tree_get_entry_at)(struct tree_context* t, int index); + void (*set_current_file)(const char* path); void (*set_dirfilter)(int l_dirfilter); @@ -928,24 +947,6 @@ struct plugin_api { /* new stuff at the end, sort into place next time the API gets incompatible */ - struct entry* (*tree_get_entries)(struct tree_context* t); - struct entry* (*tree_get_entry_at)(struct tree_context* t, int index); - - /* the buflib memory management library */ - void (*buflib_init)(struct buflib_context* ctx, void* buf, size_t size); - size_t (*buflib_available)(struct buflib_context* ctx); - int (*buflib_alloc)(struct buflib_context* ctx, size_t size); - int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size, - const char* name, struct buflib_callbacks *ops); - int (*buflib_alloc_maximum)(struct buflib_context* ctx, const char* name, - size_t* size, struct buflib_callbacks *ops); - void (*buflib_buffer_in)(struct buflib_context* ctx, int size); - void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size); - int (*buflib_free)(struct buflib_context* ctx, int handle); - bool (*buflib_shrink)(struct buflib_context* ctx, int handle, - void* new_start, size_t new_size); - void* (*buflib_get_data)(struct buflib_context* ctx, int handle); - const char* (*buflib_get_name)(struct buflib_context* ctx, int handle); }; diff --git a/apps/plugins/lib/pluginlib_touchscreen.c b/apps/plugins/lib/pluginlib_touchscreen.c index e510856851..ab617ac488 100644 --- a/apps/plugins/lib/pluginlib_touchscreen.c +++ b/apps/plugins/lib/pluginlib_touchscreen.c @@ -86,8 +86,6 @@ int touchbutton_get(struct touchbutton *data, int button, int num_buttons) { */ void touchbutton_draw(struct touchbutton *data, int num_buttons) { int i; - /* These store the width and height of the title offset */ - int title_width, title_height; struct screen *lcd = rb->screens[SCREEN_MAIN]; /* Loop over all the elements in data */ @@ -98,36 +96,15 @@ void touchbutton_draw(struct touchbutton *data, int num_buttons) { * operations are within the button location. */ lcd->set_viewport(&data[i].vp); - - /* Get the string size so that the title can be centered. */ - lcd->getstringsize(data[i].title, &title_width, &title_height); - - /* Center the title vertically */ - title_height=(data[i].vp.height-title_height)/2; - - /* If the above calculation was negative, reset to 0 */ - if(title_height<0) { - title_height=0; - } - - /* Center the title horizontally */ - title_width=(data[i].vp.width-title_width)/2; - - /* If the above calculation was negative, reset to 0 */ - if(title_width<0) { - title_width=0; - } + + /* Set line_height to height, then it'll center for us */ + data[i].vp.line_height = data[i].vp.height; + data[i].vp.flags |= VP_FLAG_ALIGN_RIGHT; /* If the width offset was 0, use a scrolling puts, else center and * print the title. */ - if(title_width==0) { - lcd->puts_scroll_style_xyoffset(0, 0, data[i].title, - STYLE_DEFAULT, 0, title_height); - } else { - lcd->putsxy(title_width, title_height, data[i].title); - } - + lcd->puts_scroll_style(0, 0, data[i].title, STYLE_DEFAULT); /* Draw bounding box around the button location. */ lcd->draw_border_viewport(); } diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c index 184b5ad7f0..5b5705c7df 100644 --- a/apps/plugins/reversi/reversi-gui.c +++ b/apps/plugins/reversi/reversi-gui.c @@ -202,15 +202,15 @@ static bool game_finished; struct touchbutton reversi_buttons[TOUCHBUTTON_COUNT] = { { {B_MENU_X, B_MENU_Y, B_MENU_W, B_MENU_H, 0, FONT_UI, - STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, + -1, STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, false, REVERSI_BUTTON_MENU, false, "Menu", NULL }, { {B_QUIT_X, B_QUIT_Y, B_QUIT_W, B_QUIT_H, 0, FONT_UI, - STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, + -1, STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, false, REVERSI_BUTTON_QUIT, false, "Quit", NULL }, { {0, 0, XOFS+BOARD_WIDTH, YOFS+BOARD_HEIGHT, 0, 0, - STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, + -1, STYLE_DEFAULT, 0, 0xFFFF, 0, 0, 0}, false, REVERSI_BUTTON_MAKE_MOVE, true, NULL, NULL } }; #endif diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 56e19ddefa..e68795391f 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h @@ -556,8 +556,12 @@ extern void lcd_bitmap_transparent(const fb_data *src, int x, int y, * once needed */ +#if defined(LCD_DPI) && (LCD_DPI > 0) /* returns the pixel density of the display */ +static inline int lcd_get_dpi(void) { return LCD_DPI; } +#else extern int lcd_get_dpi(void); -#endif +#endif /* LCD_DPI */ +#endif /* HAVE_TOUCHSCREEN */ #endif /* __LCD_H__ */