Added anchor, so actual song does not run away from window during playback.
[herrie-working.git] / herrie / src / gui_draw.c
blobb685cab043ed7c2ed92abd4a1184f13c415eee85
1 /*
2 * Copyright (c) 2006-2011 Ed Schouten <ed@80386.nl>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 /**
27 * @file gui_draw.c
28 * @brief Initialization, destruction and rendering functions for interface.
31 #include "stdinc.h"
33 #include "config.h"
34 #include "gui.h"
35 #include "gui_internal.h"
37 GMutex *gui_mtx;
38 int gui_draw_colors;
39 int gui_draw_ratio;
41 void
42 gui_draw_init_pre(void)
44 /* We need the termcap before chroot() */
45 initscr();
48 void
49 gui_draw_init_post(void)
51 /* Lock playq from main thread */
52 gui_mtx = g_mutex_new();
54 #ifdef PDCURSES
55 PDC_set_title(APP_NAME);
56 #endif /* PDCURSES */
57 nonl();
58 cbreak();
59 noecho();
60 keypad(stdscr, TRUE);
61 raw();
62 wnoutrefresh(stdscr);
64 gui_draw_colors =
65 config_getopt_bool("gui.color.enabled") && has_colors();
66 gui_draw_ratio = config_getopt_percentage("gui.ratio");
68 if (gui_draw_colors) {
69 start_color();
70 #ifdef NCURSES_VERSION
71 use_default_colors();
72 #endif /* NCURSES_VERSION */
74 init_pair(GUI_COLOR_BAR,
75 config_getopt_color("gui.color.bar.fg"),
76 config_getopt_color("gui.color.bar.bg"));
77 init_pair(GUI_COLOR_BLOCK,
78 config_getopt_color("gui.color.block.fg"),
79 config_getopt_color("gui.color.block.bg"));
80 init_pair(GUI_COLOR_SELECT,
81 config_getopt_color("gui.color.select.fg"),
82 config_getopt_color("gui.color.select.bg"));
83 init_pair(GUI_COLOR_DESELECT,
84 config_getopt_color("gui.color.deselect.fg"),
85 config_getopt_color("gui.color.deselect.bg"));
86 init_pair(GUI_COLOR_MARKED,
87 config_getopt_color("gui.color.marked.fg"),
88 config_getopt_color("gui.color.marked.bg"));
91 gui_msgbar_init();
92 gui_playq_init();
93 gui_browser_init();
94 gui_draw_done();
97 void
98 gui_draw_init_abort(void)
100 endwin();
103 void
104 gui_draw_destroy(void)
106 gui_lock();
107 gui_msgbar_destroy();
108 gui_playq_destroy();
109 gui_browser_destroy();
111 endwin();
112 gui_unlock();
115 void
116 gui_draw_resize(void)
118 gui_lock();
119 wnoutrefresh(stdscr);
120 gui_unlock();
121 gui_msgbar_resize();
122 gui_playq_resize();
123 gui_browser_resize();
124 gui_draw_done();
128 gui_draw_color_number(const char *name)
130 if (strcmp(name, "black") == 0)
131 return (COLOR_BLACK);
132 else if (strcmp(name, "red") == 0)
133 return (COLOR_RED);
134 else if (strcmp(name, "green") == 0)
135 return (COLOR_GREEN);
136 else if (strcmp(name, "yellow") == 0)
137 return (COLOR_YELLOW);
138 else if (strcmp(name, "blue") == 0)
139 return (COLOR_BLUE);
140 else if (strcmp(name, "magenta") == 0)
141 return (COLOR_MAGENTA);
142 else if (strcmp(name, "cyan") == 0)
143 return (COLOR_CYAN);
144 else if (strcmp(name, "white") == 0)
145 return (COLOR_WHITE);
146 #ifdef NCURSES_VERSION
147 else if (strcmp(name, "default") == 0)
148 return (-1);
149 #endif /* NCURSES_VERSION */
151 return (-2);
154 void
155 gui_draw_done(void)
157 gui_msgbar_refresh();
158 gui_lock();
159 doupdate();
160 gui_unlock();