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) 2002 Gilles Roux
11 * 2003 Garrett Derner
12 * 2010 Yoshihisa Uchida
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "plugin.h"
24#include "tv_bookmark.h"
25#include "tv_display.h"
26#include "tv_preferences.h"
27#include "tv_screen_pos.h"
28#include "tv_text_reader.h"
29#include "tv_window.h"
30
31static int window_width;
32static int window_columns;
33static int display_lines;
34
35static int cur_window;
36static int cur_column;
37
38static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos)
39{
40 struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS];
41 int disp_bookmarks[TV_MAX_BOOKMARKS];
42 int count = tv_get_bookmark_positions(bookmarks);
43 int disp_count = 0;
44 int line;
45
46 while (count--)
47 {
48 line = (bookmarks[count].page - top_pos->page) * display_lines
49 + (bookmarks[count].line - top_pos->line);
50 if (line >= 0 && line < display_lines)
51 disp_bookmarks[disp_count++] = line;
52 }
53
54 tv_show_bookmarks(disp_bookmarks, disp_count);
55}
56
57void tv_update_sbs_title(void)
58{
59 if (tv_set_sbs_title())
60 rb->send_event(GUI_EVENT_ACTIONUPDATE, (void*)1);
61}
62
63void tv_draw_window(void)
64{
65 struct tv_screen_pos pos;
66 const unsigned char *text_buf;
67 int line;
68 int size = 0;
69
70 tv_copy_screen_pos(&pos);
71
72 tv_start_display();
73
74 tv_read_start(cur_window, (cur_column > 0));
75
76 for (line = 0; line < display_lines; line++)
77 {
78 if (!tv_get_next_line(&text_buf))
79 break;
80
81 tv_draw_text(line, text_buf, cur_column);
82 }
83
84 size = tv_read_end();
85
86 tv_draw_bookmarks(&pos);
87
88 tv_update_extra(cur_window, cur_column, &pos, size);
89
90 tv_end_display();
91}
92
93bool tv_traverse_lines(void)
94{
95 int i;
96 bool res = true;
97
98 tv_read_start(0, false);
99 for (i = 0; i < display_lines; i++)
100 {
101 if (!tv_get_next_line(NULL))
102 {
103 res = false;
104 break;
105 }
106 }
107 tv_read_end();
108 return res;
109}
110
111static int tv_change_preferences(const struct tv_preferences *oldp)
112{
113 bool need_scrollbar = false;
114
115 (void)oldp;
116
117 tv_set_layout(need_scrollbar);
118 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
119
120 if (tv_exist_scrollbar())
121 {
122 tv_seek_top();
123 tv_set_read_conditions(preferences->windows, window_width);
124 if (tv_traverse_lines() &&
125 (preferences->vertical_scrollbar || preferences->horizontal_scrollbar))
126 {
127 need_scrollbar = true;
128 tv_set_layout(need_scrollbar);
129 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
130 }
131 tv_seek_top();
132 tv_init_scrollbar(tv_get_total_text_size(), need_scrollbar);
133 }
134
135 if (cur_window >= preferences->windows)
136 cur_window = 0;
137
138 cur_column = 0;
139
140 tv_set_read_conditions(preferences->windows, window_width);
141 return TV_CALLBACK_OK;
142}
143
144bool tv_init_window(unsigned char **buf, size_t *size)
145{
146 tv_add_preferences_change_listner(tv_change_preferences);
147 return tv_init_display(buf, size) && tv_init_text_reader(buf, size);
148}
149
150void tv_finalize_window(void)
151{
152 tv_finalize_text_reader();
153 tv_finalize_display();
154}
155
156void tv_move_window(int window_delta, int column_delta)
157{
158 cur_window += window_delta;
159 cur_column += column_delta;
160
161 if (cur_window < 0)
162 {
163 cur_window = 0;
164 cur_column = 0;
165 }
166 else if (cur_window >= preferences->windows)
167 {
168 cur_window = preferences->windows - 1;
169 cur_column = 0;
170 }
171
172 if (cur_column < 0)
173 {
174 if (cur_window == 0)
175 cur_column = 0;
176 else
177 {
178 cur_window--;
179 cur_column = window_columns - 1;
180 }
181 }
182 else
183 {
184 if (cur_window == preferences->windows - 1)
185 cur_column = 0;
186 else if (cur_column >= window_columns)
187 {
188 cur_window++;
189 cur_column = 0;
190 }
191 }
192}