blob: 78abb2f5db9656bec7b01cf13729e5dd0626908b [file] [log] [blame]
Daniel Stenberg9f6733f2002-03-25 14:21:30 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Daniel Stenberg34849802002-03-25 14:44:06 +00008 * $Id$
Daniel Stenberg9f6733f2002-03-25 14:21:30 +00009 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include <stdarg.h>
22#include <stdlib.h>
23#include <ctype.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27
28#include <errno.h>
29#include <ctype.h>
30#include <time.h>
31
Björn Stenbergbbcd7402004-09-16 20:03:03 +000032#include "config.h"
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000033#include "screenhack.h"
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000034
35#include "version.h"
36
Daniel Stenberga1fd2552002-03-26 14:27:03 +000037#include "lcd-x11.h"
Kjell Ericsonf9a912d2002-10-28 20:04:53 +000038#include "lcd-playersim.h"
Daniel Stenberga1fd2552002-03-26 14:27:03 +000039
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000040#define MAX(x,y) ((x)>(y)?(x):(y))
41#define MIN(x,y) ((x)<(y)?(x):(y))
42
43#define PROGNAME "rockboxui"
44
45/* -- -- */
46
Kjell Ericsonc54ff702002-10-16 08:43:13 +000047GC draw_gc;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000048static Colormap cmap;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000049
Kjell Ericson0ca9ccb2003-01-20 09:39:38 +000050int display_zoom=1;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000051
52Display *dpy;
53Window window;
Kjell Ericsonf9a912d2002-10-28 20:04:53 +000054bool lcd_display_redraw=true;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000055
56XrmOptionDescRec options [] = {
57 /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */
58 { "-server", ".server", XrmoptionSepArg, 0 },
59 { "-help", ".help", XrmoptionNoArg, "false" },
60 { 0, 0, 0, 0 }
61};
62char *progclass = "rockboxui";
63
64char *defaults [] = {
Björn Stenbergbbcd7402004-09-16 20:03:03 +000065#ifdef IRIVER_H100
66 ".background: lightblue",
67#else
Daniel Stenberg1ba9fae2002-04-28 09:38:20 +000068 ".background: lightgreen",
Björn Stenbergbbcd7402004-09-16 20:03:03 +000069#endif
Daniel Stenberg1ba9fae2002-04-28 09:38:20 +000070 ".foreground: black",
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000071 "*help: false",
72 0
73};
74
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000075void init_window ()
76{
77 XGCValues gcv;
78 XWindowAttributes xgwa;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000079
80 XGetWindowAttributes (dpy, window, &xgwa);
81
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000082 cmap = xgwa.colormap;
83
84 gcv.function = GXxor;
85 gcv.foreground =
86 get_pixel_resource ("foreground", "Foreground", dpy, cmap);
Kjell Ericsonc54ff702002-10-16 08:43:13 +000087 draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000088
Kjell Ericson93b5f922002-10-21 20:12:55 +000089 screen_resized(LCD_WIDTH, LCD_HEIGHT);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000090}
91
92void screen_resized(int width, int height)
93{
Kjell Ericson93b5f922002-10-21 20:12:55 +000094 int maxx, maxy;
95 maxx = width;
96 maxy = height;
Kjell Ericsonc54ff702002-10-16 08:43:13 +000097
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000098 XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background",
99 dpy, cmap));
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000100 XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom, height*display_zoom);
Kjell Ericsonf9a912d2002-10-28 20:04:53 +0000101 lcd_display_redraw=true;
102 screen_redraw();
103}
104
105void drawrect(int color, int x1, int y1, int x2, int y2)
106{
107 if (color==0) {
108 XSetForeground(dpy, draw_gc,
109 get_pixel_resource("background", "Background", dpy, cmap));
110 }
111 else
112 XSetForeground(dpy, draw_gc,
113 get_pixel_resource("foreground", "Foreground", dpy, cmap));
114 XFillRectangle(dpy, window, draw_gc, x1*display_zoom, y1*display_zoom,
115 x2*display_zoom, y2*display_zoom);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000116
117}
118
119static void help(void)
120{
121 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
122 "usage: " PROGNAME "\n"
123 );
124}
125
126void drawline(int color, int x1, int y1, int x2, int y2)
127{
128 if (color==0) {
129 XSetForeground(dpy, draw_gc,
130 get_pixel_resource("background", "Background", dpy, cmap));
131 }
132 else
133 XSetForeground(dpy, draw_gc,
134 get_pixel_resource("foreground", "Foreground", dpy, cmap));
135
136 XDrawLine(dpy, window, draw_gc,
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000137 (int)(x1*display_zoom),
138 (int)(y1*display_zoom),
139 (int)(x2*display_zoom),
140 (int)(y2*display_zoom));
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000141}
142
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000143void drawdot(int color, int x, int y)
144{
145 if (color==0) {
146 XSetForeground(dpy, draw_gc,
147 get_pixel_resource("background", "Background", dpy, cmap));
148 }
149 else
150 XSetForeground(dpy, draw_gc,
151 get_pixel_resource("foreground", "Foreground", dpy, cmap));
152
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000153 XFillRectangle(dpy, window, draw_gc, x*display_zoom, y*display_zoom,
154 display_zoom, display_zoom);
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000155}
156
Kjell Ericsonf9a912d2002-10-28 20:04:53 +0000157void drawdots(int color, struct coordinate *points, int count)
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000158{
Daniel Stenbergc1543512002-04-27 23:41:41 +0000159 if (color==0) {
160 XSetForeground(dpy, draw_gc,
161 get_pixel_resource("background", "Background", dpy, cmap));
162 }
163 else
164 XSetForeground(dpy, draw_gc,
165 get_pixel_resource("foreground", "Foreground", dpy, cmap));
166
Kjell Ericsonf9a912d2002-10-28 20:04:53 +0000167 while (count--) {
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000168 XFillRectangle(dpy, window, draw_gc,
169 points[count].x*display_zoom,
170 points[count].y*display_zoom,
171 display_zoom,
172 display_zoom);
173 }
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000174}
175
Kjell Ericsonf9a912d2002-10-28 20:04:53 +0000176void drawrectangles(int color, struct rectangle *points, int count)
177{
178 if (color==0) {
179 XSetForeground(dpy, draw_gc,
180 get_pixel_resource("background", "Background", dpy, cmap));
181 }
182 else
183 XSetForeground(dpy, draw_gc,
184 get_pixel_resource("foreground", "Foreground", dpy, cmap));
185
186 while (count--) {
187 XFillRectangle(dpy, window, draw_gc,
188 points[count].x*display_zoom,
189 points[count].y*display_zoom,
190 points[count].width*display_zoom,
191 points[count].height*display_zoom);
192
193 }
194}
195
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000196void drawtext(int color, int x, int y, char *text)
197{
198 if (color==0) {
199 XSetForeground(dpy, draw_gc,
200 get_pixel_resource("background", "Background", dpy, cmap));
201 }
202 else
203 XSetForeground(dpy, draw_gc,
204 get_pixel_resource("foreground", "Foreground", dpy, cmap));
205
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000206 XDrawString(dpy, window, draw_gc, x*display_zoom, y*display_zoom, text, strlen(text));
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000207}
208
Daniel Stenberged6c7e42002-06-14 11:00:13 +0000209/* this is where the applicaton starts */
210extern void app_main(void);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000211
212void
213screenhack (Display *the_dpy, Window the_window)
214{
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000215 Bool helpme;
216
217 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */
218 helpme = get_boolean_resource ("help", "Boolean");
219 if(helpme) {
220 help();
221 }
222 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
223
224 dpy=the_dpy;
225 window=the_window;
226
227 init_window();
228
Daniel Stenberg9b68ef82002-04-30 06:55:45 +0000229 screen_redraw();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000230
Daniel Stenbergc1543512002-04-27 23:41:41 +0000231 app_main();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000232}
233
234void screen_redraw()
235{
Daniel Stenberg0c4589d2002-03-26 14:42:33 +0000236 /* draw a border around the "Recorder" screen */
Daniel Stenberga1fd2552002-03-26 14:27:03 +0000237#define X1 0
238#define Y1 0
239#define X2 (LCD_WIDTH + MARGIN_X*2)
Daniel Stenberg2ed10522002-08-09 09:13:40 +0000240#define Y2 (LCD_HEIGHT + MARGIN_Y)
Daniel Stenberga1fd2552002-03-26 14:27:03 +0000241
242 drawline(1, X1, Y1, X2, Y1);
243 drawline(1, X2, Y1, X2, Y2);
244 drawline(1, X1, Y2, X2, Y2);
245 drawline(1, X1, Y1, X1, Y2);
Daniel Stenberg9b68ef82002-04-30 06:55:45 +0000246 lcd_update();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000247}