1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 /* This file contains the code to draw the list widget on BITMAP LCDs. */
33 #include "screen_access.h"
35 #include "scrollbar.h"
36 #include "statusbar.h"
44 #define SCROLLBAR_WIDTH 6
45 #define ICON_PADDING 1
48 struct viewport title_text
[NB_SCREENS
], title_icons
[NB_SCREENS
],
49 list_text
[NB_SCREENS
], list_icons
[NB_SCREENS
];
51 /* should probably be moved somewhere else */
52 int list_title_height(struct gui_synclist
*list
, struct viewport
*vp
)
55 return font_get(vp
->font
)->height
;
57 int gui_list_get_item_offset(struct gui_synclist
* gui_list
, int item_width
,
58 int text_pos
, struct screen
* display
,
60 bool list_display_title(struct gui_synclist
*list
, struct viewport
*vp
);
63 internal screen layout:
65 |TI| title | TI is title icon
69 | | | items | I - icons
73 static bool draw_title(struct screen
*display
, struct viewport
*parent
,
74 struct gui_synclist
*list
)
76 struct viewport
*vp_icons
= &title_icons
[display
->screen_type
];
77 struct viewport
*vp_text
= &title_text
[display
->screen_type
];
78 if (!list_display_title(list
, parent
))
81 vp_text
->height
= list_title_height(list
, parent
);
82 if (list
->title_icon
!= Icon_NOICON
&& global_settings
.show_icons
)
85 vp_icons
->width
= get_icon_width(display
->screen_type
)
87 vp_icons
->x
+= ICON_PADDING
;
89 vp_text
->width
-= vp_icons
->width
+ vp_icons
->x
;
90 vp_text
->x
+= vp_icons
->width
+ vp_icons
->x
;
92 display
->set_viewport(vp_icons
);
93 screen_put_icon(display
, 0, 0, list
->title_icon
);
95 display
->set_viewport(vp_text
);
96 vp_text
->drawmode
= STYLE_DEFAULT
;
98 if (list
->title_color
>= 0)
100 vp_text
->drawmode
|= (STYLE_COLORED
|list
->title_color
);}
102 display
->puts_scroll_style_offset(0, 0, list
->title
,
103 vp_text
->drawmode
, 0);
107 void list_draw(struct screen
*display
, struct viewport
*parent
,
108 struct gui_synclist
*list
)
110 int start
, end
, line_height
, i
;
111 int icon_width
= get_icon_width(display
->screen_type
) + ICON_PADDING
;
112 bool show_cursor
= !global_settings
.cursor_style
&&
113 list
->show_selection_marker
;
114 #ifdef HAVE_LCD_COLOR
115 unsigned char cur_line
= 0;
119 line_height
= font_get(parent
->font
)->height
;
120 display
->set_viewport(parent
);
121 display
->clear_viewport();
122 display
->stop_scroll();
123 list_text
[display
->screen_type
] = *parent
;
124 if ((show_title
= draw_title(display
, parent
, list
)))
126 list_text
[display
->screen_type
].y
+= list_title_height(list
, parent
);
127 list_text
[display
->screen_type
].height
-= list_title_height(list
, parent
);
130 start
= list
->start_item
[display
->screen_type
];
131 end
= start
+ viewport_get_nb_lines(&list_text
[display
->screen_type
]);
133 /* draw the scrollbar if its needed */
134 if (global_settings
.scrollbar
&&
135 viewport_get_nb_lines(&list_text
[display
->screen_type
]) < list
->nb_items
)
138 vp
= list_text
[display
->screen_type
];
139 vp
.width
= SCROLLBAR_WIDTH
;
140 list_text
[display
->screen_type
].width
-= SCROLLBAR_WIDTH
;
141 list_text
[display
->screen_type
].x
+= SCROLLBAR_WIDTH
;
142 vp
.height
= line_height
*
143 viewport_get_nb_lines(&list_text
[display
->screen_type
]);
145 display
->set_viewport(&vp
);
146 gui_scrollbar_draw(display
, 0, 0, SCROLLBAR_WIDTH
-1,
147 vp
.height
, list
->nb_items
,
148 list
->start_item
[display
->screen_type
],
149 list
->start_item
[display
->screen_type
] + end
-start
,
154 /* shift everything right a bit... */
155 list_text
[display
->screen_type
].width
-= SCROLLBAR_WIDTH
;
156 list_text
[display
->screen_type
].x
+= SCROLLBAR_WIDTH
;
159 /* setup icon placement */
160 list_icons
[display
->screen_type
] = list_text
[display
->screen_type
];
161 int icon_count
= global_settings
.show_icons
&&
162 (list
->callback_get_item_icon
!= NULL
) ? 1 : 0;
167 list_icons
[display
->screen_type
].width
= icon_width
* icon_count
;
168 list_text
[display
->screen_type
].width
-=
169 list_icons
[display
->screen_type
].width
+ ICON_PADDING
;
170 list_text
[display
->screen_type
].x
+=
171 list_icons
[display
->screen_type
].width
+ ICON_PADDING
;
174 for (i
=start
; i
<end
&& i
<list
->nb_items
; i
++)
178 char entry_buffer
[MAX_PATH
];
179 unsigned char *entry_name
;
181 s
= list
->callback_get_item_name(i
, list
->data
, entry_buffer
);
182 entry_name
= P2STR(s
);
183 display
->set_viewport(&list_text
[display
->screen_type
]);
184 list_text
[display
->screen_type
].drawmode
= STYLE_DEFAULT
;
185 /* position the string at the correct offset place */
187 display
->getstringsize(entry_name
, &item_width
, &h
);
188 item_offset
= gui_list_get_item_offset(list
, item_width
,
190 &list_text
[display
->screen_type
]);
192 #ifdef HAVE_LCD_COLOR
193 /* if the list has a color callback */
194 if (list
->callback_get_item_color
)
196 int color
= list
->callback_get_item_color(i
, list
->data
);
197 /* if color selected */
200 list_text
[display
->screen_type
].drawmode
|= STYLE_COLORED
|color
;
205 if(list
->show_selection_marker
&& global_settings
.cursor_style
&&
206 i
>= list
->selected_item
&&
207 i
< list
->selected_item
+ list
->selected_size
)
208 {/* The selected item must be displayed scrolling */
209 if (global_settings
.cursor_style
== 1 || display
->depth
< 16)
211 /* Display inverted-line-style */
212 list_text
[display
->screen_type
].drawmode
|= STYLE_INVERT
;
214 #ifdef HAVE_LCD_COLOR
215 else if (global_settings
.cursor_style
== 2)
217 /* Display colour line selector */
218 list_text
[display
->screen_type
].drawmode
|= STYLE_COLORBAR
;
220 else if (global_settings
.cursor_style
== 3)
222 /* Display gradient line selector */
223 list_text
[display
->screen_type
].drawmode
= STYLE_GRADIENT
;
225 /* Make the lcd driver know how many lines the gradient should
226 cover and current line number */
227 /* number of selected lines */
228 list_text
[display
->screen_type
].drawmode
|= NUMLN_PACK(list
->selected_size
);
229 /* current line number, zero based */
230 list_text
[display
->screen_type
].drawmode
|= CURLN_PACK(cur_line
);
234 /* if the text is smaller than the viewport size */
235 if (item_offset
> item_width
- (list_text
[display
->screen_type
].width
- text_pos
))
238 display
->puts_style_offset(0, i
-start
, entry_name
,
239 list_text
[display
->screen_type
].drawmode
, item_offset
);
243 display
->puts_scroll_style_offset(0, i
-start
, entry_name
,
244 list_text
[display
->screen_type
].drawmode
, item_offset
);
248 display
->puts_style_offset(0, i
-start
, entry_name
,
249 list_text
[display
->screen_type
].drawmode
, item_offset
);
251 if (list
->callback_get_item_icon
&& global_settings
.show_icons
)
253 display
->set_viewport(&list_icons
[display
->screen_type
]);
254 screen_put_icon_with_offset(display
, show_cursor
?1:0,
255 (i
-start
),show_cursor
?ICON_PADDING
:0,0,
256 list
->callback_get_item_icon(i
, list
->data
));
257 if (show_cursor
&& i
>= list
->selected_item
&&
258 i
< list
->selected_item
+ list
->selected_size
)
260 screen_put_icon(display
, 0, i
-start
, Icon_Cursor
);
263 else if (show_cursor
&& i
>= list
->selected_item
&&
264 i
< list
->selected_item
+ list
->selected_size
)
266 display
->set_viewport(&list_icons
[display
->screen_type
]);
267 screen_put_icon(display
, 0, (i
-start
), Icon_Cursor
);
271 display
->set_viewport(parent
);
272 display
->update_viewport();
273 display
->set_viewport(NULL
);