A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 186 lines 4.7 kB view raw
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_draw_window(void) 58{ 59 struct tv_screen_pos pos; 60 const unsigned char *text_buf; 61 int line; 62 int size = 0; 63 64 tv_copy_screen_pos(&pos); 65 66 tv_start_display(); 67 68 tv_read_start(cur_window, (cur_column > 0)); 69 70 for (line = 0; line < display_lines; line++) 71 { 72 if (!tv_get_next_line(&text_buf)) 73 break; 74 75 tv_draw_text(line, text_buf, cur_column); 76 } 77 78 size = tv_read_end(); 79 80 tv_draw_bookmarks(&pos); 81 82 tv_update_extra(cur_window, cur_column, &pos, size); 83 84 tv_end_display(); 85} 86 87bool tv_traverse_lines(void) 88{ 89 int i; 90 bool res = true; 91 92 tv_read_start(0, false); 93 for (i = 0; i < display_lines; i++) 94 { 95 if (!tv_get_next_line(NULL)) 96 { 97 res = false; 98 break; 99 } 100 } 101 tv_read_end(); 102 return res; 103} 104 105static int tv_change_preferences(const struct tv_preferences *oldp) 106{ 107 bool need_scrollbar = false; 108 109 (void)oldp; 110 111 tv_set_layout(need_scrollbar); 112 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 113 114 if (tv_exist_scrollbar()) 115 { 116 tv_seek_top(); 117 tv_set_read_conditions(preferences->windows, window_width); 118 if (tv_traverse_lines() && 119 (preferences->vertical_scrollbar || preferences->horizontal_scrollbar)) 120 { 121 need_scrollbar = true; 122 tv_set_layout(need_scrollbar); 123 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 124 } 125 tv_seek_top(); 126 tv_init_scrollbar(tv_get_total_text_size(), need_scrollbar); 127 } 128 129 if (cur_window >= preferences->windows) 130 cur_window = 0; 131 132 cur_column = 0; 133 134 tv_set_read_conditions(preferences->windows, window_width); 135 return TV_CALLBACK_OK; 136} 137 138bool tv_init_window(unsigned char **buf, size_t *size) 139{ 140 tv_add_preferences_change_listner(tv_change_preferences); 141 return tv_init_display(buf, size) && tv_init_text_reader(buf, size); 142} 143 144void tv_finalize_window(void) 145{ 146 tv_finalize_text_reader(); 147 tv_finalize_display(); 148} 149 150void tv_move_window(int window_delta, int column_delta) 151{ 152 cur_window += window_delta; 153 cur_column += column_delta; 154 155 if (cur_window < 0) 156 { 157 cur_window = 0; 158 cur_column = 0; 159 } 160 else if (cur_window >= preferences->windows) 161 { 162 cur_window = preferences->windows - 1; 163 cur_column = 0; 164 } 165 166 if (cur_column < 0) 167 { 168 if (cur_window == 0) 169 cur_column = 0; 170 else 171 { 172 cur_window--; 173 cur_column = window_columns - 1; 174 } 175 } 176 else 177 { 178 if (cur_window == preferences->windows - 1) 179 cur_column = 0; 180 else if (cur_column >= window_columns) 181 { 182 cur_window++; 183 cur_column = 0; 184 } 185 } 186}