mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Two new lcd/multi screen api convinience functions: draw_viewport(), fill_viewport().
They work as the drawrect/fillrect pendants but work on a viewport basis; pass NULL to draw the current viewport (the one set with set_viewport()). In conjunction with action_get_touchscreen_press_in_vp() it should be less of a pain to draw buttons and get presses on them. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28239 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
752c91b50d
commit
8a0152bd4a
9 changed files with 47 additions and 14 deletions
|
@ -66,16 +66,17 @@ static void gui_buttonbar_draw_button(struct gui_buttonbar * buttonbar, int num)
|
||||||
struct viewport vp = bb_vp[display->screen_type];
|
struct viewport vp = bb_vp[display->screen_type];
|
||||||
|
|
||||||
button_width = display->lcdwidth/BUTTONBAR_MAX_BUTTONS;
|
button_width = display->lcdwidth/BUTTONBAR_MAX_BUTTONS;
|
||||||
vp.width = button_width;
|
vp.width = button_width-1;
|
||||||
vp.x = button_width * num;
|
vp.x = button_width * num;
|
||||||
display->set_viewport(&vp);
|
display->set_viewport(&vp);
|
||||||
display->fillrect(0, 0, button_width - 1, vp.height);
|
display->fill_viewport(NULL);
|
||||||
if(buttonbar->caption[num][0] != 0)
|
if(buttonbar->caption[num][0] != 0)
|
||||||
{
|
{
|
||||||
display->getstringsize(buttonbar->caption[num], &fw, &fh);
|
display->getstringsize(buttonbar->caption[num], &fw, &fh);
|
||||||
display->putsxy((button_width - fw)/2,
|
display->putsxy((button_width - fw)/2,
|
||||||
(vp.height-fh)/2, buttonbar->caption[num]);
|
(vp.height-fh)/2, buttonbar->caption[num]);
|
||||||
}
|
}
|
||||||
|
display->set_viewport(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
|
void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
|
||||||
|
|
|
@ -163,7 +163,7 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
|
||||||
#endif
|
#endif
|
||||||
vp.drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
|
vp.drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
|
||||||
|
|
||||||
screen->fillrect(0, 0, vp.width, vp.height);
|
screen->fill_viewport(NULL);
|
||||||
|
|
||||||
#if LCD_DEPTH > 1
|
#if LCD_DEPTH > 1
|
||||||
if (screen->depth > 1)
|
if (screen->depth > 1)
|
||||||
|
@ -174,7 +174,7 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
|
||||||
#endif
|
#endif
|
||||||
vp.drawmode = DRMODE_SOLID;
|
vp.drawmode = DRMODE_SOLID;
|
||||||
|
|
||||||
screen->drawrect(0, 0, vp.width, vp.height);
|
screen->draw_viewport(NULL);
|
||||||
|
|
||||||
/* prepare putting the text */
|
/* prepare putting the text */
|
||||||
y = RECT_SPACING;
|
y = RECT_SPACING;
|
||||||
|
|
|
@ -280,7 +280,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw, struct vi
|
||||||
{
|
{
|
||||||
display->set_viewport(vp);
|
display->set_viewport(vp);
|
||||||
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
||||||
display->fillrect(0, 0, display->getwidth(), STATUSBAR_HEIGHT);
|
display->fill_viewport(NULL);
|
||||||
display->set_drawmode(DRMODE_SOLID);
|
display->set_drawmode(DRMODE_SOLID);
|
||||||
|
|
||||||
if (bar->info.battery_state)
|
if (bar->info.battery_state)
|
||||||
|
|
|
@ -88,7 +88,8 @@ void touchbutton_draw(struct touchbutton *data, int num_buttons) {
|
||||||
int i;
|
int i;
|
||||||
/* These store the width and height of the title offset */
|
/* These store the width and height of the title offset */
|
||||||
int title_width, title_height;
|
int title_width, title_height;
|
||||||
|
struct screen *lcd = rb->screens[SCREEN_MAIN];
|
||||||
|
|
||||||
/* Loop over all the elements in data */
|
/* Loop over all the elements in data */
|
||||||
for(i=0; i<num_buttons; i++) {
|
for(i=0; i<num_buttons; i++) {
|
||||||
/* Is this a visible button? */
|
/* Is this a visible button? */
|
||||||
|
@ -96,10 +97,10 @@ void touchbutton_draw(struct touchbutton *data, int num_buttons) {
|
||||||
/* Set the current viewport to the button so that all drawing
|
/* Set the current viewport to the button so that all drawing
|
||||||
* operations are within the button location.
|
* operations are within the button location.
|
||||||
*/
|
*/
|
||||||
rb->screens[SCREEN_MAIN]->set_viewport(&data[i].vp);
|
lcd->set_viewport(&data[i].vp);
|
||||||
|
|
||||||
/* Get the string size so that the title can be centered. */
|
/* Get the string size so that the title can be centered. */
|
||||||
rb->lcd_getstringsize(data[i].title, &title_width, &title_height);
|
lcd->getstringsize(data[i].title, &title_width, &title_height);
|
||||||
|
|
||||||
/* Center the title vertically */
|
/* Center the title vertically */
|
||||||
title_height=(data[i].vp.height-title_height)/2;
|
title_height=(data[i].vp.height-title_height)/2;
|
||||||
|
@ -121,16 +122,17 @@ void touchbutton_draw(struct touchbutton *data, int num_buttons) {
|
||||||
* print the title.
|
* print the title.
|
||||||
*/
|
*/
|
||||||
if(title_width==0) {
|
if(title_width==0) {
|
||||||
rb->lcd_puts_scroll(0, 0, data[i].title);
|
lcd->puts_scroll_style_xyoffset(0, 0, data[i].title,
|
||||||
|
STYLE_DEFAULT, 0, title_height);
|
||||||
} else {
|
} else {
|
||||||
rb->lcd_putsxy(title_width, title_height, data[i].title);
|
lcd->putsxy(title_width, title_height, data[i].title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw bounding box around the button location. */
|
/* Draw bounding box around the button location. */
|
||||||
rb->lcd_drawrect( 0, 0, data[i].vp.width, data[i].vp.height);
|
lcd->draw_viewport(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb->screens[SCREEN_MAIN]->set_viewport(NULL); /* Go back to the default viewport */
|
lcd->set_viewport(NULL); /* Go back to the default viewport */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
|
@ -162,6 +162,8 @@ struct screen screens[NB_SCREENS] =
|
||||||
.update_viewport_rect=&lcd_update_viewport_rect,
|
.update_viewport_rect=&lcd_update_viewport_rect,
|
||||||
.fillrect=&lcd_fillrect,
|
.fillrect=&lcd_fillrect,
|
||||||
.drawrect=&lcd_drawrect,
|
.drawrect=&lcd_drawrect,
|
||||||
|
.draw_viewport=&lcd_draw_viewport,
|
||||||
|
.fill_viewport=&lcd_fill_viewport,
|
||||||
.drawpixel=&lcd_drawpixel,
|
.drawpixel=&lcd_drawpixel,
|
||||||
.drawline=&lcd_drawline,
|
.drawline=&lcd_drawline,
|
||||||
.vline=&lcd_vline,
|
.vline=&lcd_vline,
|
||||||
|
@ -253,6 +255,8 @@ struct screen screens[NB_SCREENS] =
|
||||||
.update_viewport_rect=&lcd_remote_update_viewport_rect,
|
.update_viewport_rect=&lcd_remote_update_viewport_rect,
|
||||||
.fillrect=&lcd_remote_fillrect,
|
.fillrect=&lcd_remote_fillrect,
|
||||||
.drawrect=&lcd_remote_drawrect,
|
.drawrect=&lcd_remote_drawrect,
|
||||||
|
.draw_viewport=&lcd_remote_draw_viewport,
|
||||||
|
.fill_viewport=&lcd_remote_fill_viewport,
|
||||||
.drawpixel=&lcd_remote_drawpixel,
|
.drawpixel=&lcd_remote_drawpixel,
|
||||||
.drawline=&lcd_remote_drawline,
|
.drawline=&lcd_remote_drawline,
|
||||||
.vline=&lcd_remote_vline,
|
.vline=&lcd_remote_vline,
|
||||||
|
|
|
@ -117,6 +117,8 @@ struct screen
|
||||||
void (*update_viewport_rect)(int x, int y, int width, int height);
|
void (*update_viewport_rect)(int x, int y, int width, int height);
|
||||||
void (*fillrect)(int x, int y, int width, int height);
|
void (*fillrect)(int x, int y, int width, int height);
|
||||||
void (*drawrect)(int x, int y, int width, int height);
|
void (*drawrect)(int x, int y, int width, int height);
|
||||||
|
void (*fill_viewport)(const struct viewport *vp);
|
||||||
|
void (*draw_viewport)(const struct viewport *vp);
|
||||||
void (*drawpixel)(int x, int y);
|
void (*drawpixel)(int x, int y);
|
||||||
void (*drawline)(int x1, int y1, int x2, int y2);
|
void (*drawline)(int x1, int y1, int x2, int y2);
|
||||||
void (*vline)(int x, int y1, int y2);
|
void (*vline)(int x, int y1, int y2);
|
||||||
|
@ -139,8 +141,6 @@ struct screen
|
||||||
void (*puts_scroll)(int x, int y, const unsigned char *string);
|
void (*puts_scroll)(int x, int y, const unsigned char *string);
|
||||||
void (*puts_scroll_offset)(int x, int y, const unsigned char *string,
|
void (*puts_scroll_offset)(int x, int y, const unsigned char *string,
|
||||||
int x_offset);
|
int x_offset);
|
||||||
void (*puts_scroll_xyoffset)(int x, int y, const unsigned char *string,
|
|
||||||
int x_offset, int y_offset);
|
|
||||||
void (*scroll_speed)(int speed);
|
void (*scroll_speed)(int speed);
|
||||||
void (*scroll_delay)(int ms);
|
void (*scroll_delay)(int ms);
|
||||||
void (*stop_scroll)(void);
|
void (*stop_scroll)(void);
|
||||||
|
|
|
@ -81,6 +81,28 @@ static void lcd_gradient_rect(int x1, int x2, int y, unsigned h,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* draws the borders of the viewport, or of current_vp if vp == NULL
|
||||||
|
**/
|
||||||
|
void LCDFN(draw_viewport)(const struct viewport *vp)
|
||||||
|
{
|
||||||
|
if (vp == NULL)
|
||||||
|
LCDFN(drawrect)(0, 0, current_vp->width, current_vp->height);
|
||||||
|
else
|
||||||
|
LCDFN(drawrect)(vp->x, vp->y, vp->width, vp->height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fills the rectangle formed by vp or by current_vp if vp == NULL
|
||||||
|
**/
|
||||||
|
void LCDFN(fill_viewport)(const struct viewport *vp)
|
||||||
|
{
|
||||||
|
if (vp == NULL)
|
||||||
|
LCDFN(fillrect)(0, 0, current_vp->width, current_vp->height);
|
||||||
|
else
|
||||||
|
LCDFN(fillrect)(vp->x, vp->y, vp->width, vp->height);
|
||||||
|
}
|
||||||
|
|
||||||
/* put a string at a given pixel position, skipping first ofs pixel columns */
|
/* put a string at a given pixel position, skipping first ofs pixel columns */
|
||||||
static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
|
static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -178,6 +178,8 @@ extern void lcd_remote_hline(int x1, int x2, int y);
|
||||||
extern void lcd_remote_vline(int x, int y1, int y2);
|
extern void lcd_remote_vline(int x, int y1, int y2);
|
||||||
extern void lcd_remote_drawrect(int x, int y, int width, int height);
|
extern void lcd_remote_drawrect(int x, int y, int width, int height);
|
||||||
extern void lcd_remote_fillrect(int x, int y, int width, int height);
|
extern void lcd_remote_fillrect(int x, int y, int width, int height);
|
||||||
|
extern void lcd_remote_draw_viewport(const struct viewport *vp);
|
||||||
|
extern void lcd_remote_fill_viewport(const struct viewport *vp);
|
||||||
extern void lcd_remote_bitmap_part(const fb_remote_data *src, int src_x,
|
extern void lcd_remote_bitmap_part(const fb_remote_data *src, int src_x,
|
||||||
int src_y, int stride, int x, int y,
|
int src_y, int stride, int x, int y,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
|
|
|
@ -507,6 +507,8 @@ extern void lcd_hline(int x1, int x2, int y);
|
||||||
extern void lcd_vline(int x, int y1, int y2);
|
extern void lcd_vline(int x, int y1, int y2);
|
||||||
extern void lcd_drawrect(int x, int y, int width, int height);
|
extern void lcd_drawrect(int x, int y, int width, int height);
|
||||||
extern void lcd_fillrect(int x, int y, int width, int height);
|
extern void lcd_fillrect(int x, int y, int width, int height);
|
||||||
|
extern void lcd_draw_viewport(const struct viewport *vp);
|
||||||
|
extern void lcd_fill_viewport(const struct viewport *vp);
|
||||||
extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
||||||
int stride, int x, int y, int width, int height);
|
int stride, int x, int y, int width, int height);
|
||||||
extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
|
extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue