A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Johannes Schwarz
11 * based on Will Robertson code in superdom
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "plugin.h"
23#include "display_text.h"
24
25#define MARGIN 5
26
27static bool wait_key_press(void)
28{
29 int button;
30 do {
31 button = rb->button_get(true);
32 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
33 return true;
34 } while(IS_SYSEVENT(button) || ( button == BUTTON_NONE )
35 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
36 return false;
37}
38
39bool display_text(unsigned short words, char** text, struct style_text* style,
40 struct viewport* vp_text, bool wait_key)
41{
42 bool ret = false;
43 int prev_drawmode;
44#ifdef HAVE_LCD_COLOR
45 int standard_fgcolor;
46#endif
47 int space_w, width, height;
48 unsigned short x , y;
49 unsigned short vp_width = LCD_WIDTH;
50 unsigned short vp_height = LCD_HEIGHT;
51 unsigned short i = 0, style_index = 0;
52 if (vp_text != NULL) {
53 vp_width = vp_text->width;
54 vp_height = vp_text->height;
55 }
56 struct viewport *last_vp = rb->screens[SCREEN_MAIN]->set_viewport(vp_text);
57 prev_drawmode = rb->lcd_get_drawmode();
58 rb->lcd_set_drawmode(DRMODE_SOLID);
59#ifdef HAVE_LCD_COLOR
60 standard_fgcolor = rb->lcd_get_foreground();
61#endif
62 rb->screens[SCREEN_MAIN]->clear_viewport();
63 x = MARGIN;
64 y = MARGIN;
65 rb->button_clear_queue();
66 rb->lcd_getstringsize(" ", &space_w, &height);
67 for (i = 0; i < words; i++) {
68 rb->lcd_getstringsize(text[i], &width, NULL);
69 /* skip to next line if the word is an empty string */
70 if (rb->strcmp(text[i], "")==0) {
71 x = MARGIN;
72 y = y + height;
73 continue;
74 /* .. or if the current one can't fit the word */
75 } else if (x + width > vp_width - MARGIN) {
76 x = MARGIN;
77 y = y + height;
78 }
79 /* display the remaining text by button click or exit */
80 if (y + height > vp_height - MARGIN) {
81 y = MARGIN;
82 rb->screens[SCREEN_MAIN]->update_viewport();
83 if (wait_key_press())
84 {
85 ret = true;
86 goto cleanup;
87 }
88 rb->screens[SCREEN_MAIN]->clear_viewport();
89 }
90 /* no text formatting available */
91 if (style==NULL || style[style_index].index != i) {
92 rb->lcd_putsxy(x, y, text[i]);
93 } else {
94 /* set align */
95 if (style[style_index].flags&TEXT_CENTER) {
96 x = (vp_width-width)/2;
97 }
98 /* set font color */
99#ifdef HAVE_LCD_COLOR
100 switch (style[style_index].flags&TEXT_COLOR_MASK) {
101 case C_RED:
102 rb->lcd_set_foreground(LCD_RGBPACK(255,0,0));
103 break;
104 case C_YELLOW:
105 rb->lcd_set_foreground(LCD_RGBPACK(255,255,0));
106 break;
107 case C_GREEN:
108 rb->lcd_set_foreground(LCD_RGBPACK(0,192,0));
109 break;
110 case C_BLUE:
111 rb->lcd_set_foreground(LCD_RGBPACK(0,0,255));
112 break;
113 case C_ORANGE:
114 rb->lcd_set_foreground(LCD_RGBPACK(255,192,0));
115 break;
116 case STANDARD:
117 default:
118 rb->lcd_set_foreground(standard_fgcolor);
119 break;
120 }
121#endif
122 rb->lcd_putsxy(x, y, text[i]);
123 /* underline the word */
124 if (style[style_index].flags&TEXT_UNDERLINE) {
125 rb->lcd_hline(x, x+width, y+height-1);
126 }
127#ifdef HAVE_LCD_COLOR
128 rb->lcd_set_foreground(standard_fgcolor);
129#endif
130 style_index++;
131 }
132 x += width + space_w;
133 }
134 rb->screens[SCREEN_MAIN]->update_viewport();
135 rb->lcd_set_drawmode(prev_drawmode);
136 if (wait_key)
137 {
138 if (wait_key_press())
139 ret = true;
140 }
141
142cleanup:
143 rb->screens[SCREEN_MAIN]->set_viewport(last_vp);
144 return ret;
145}