blob: 57870c39d3b73490e5c7795997a111aa74e9d6a6 [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;
Kjell Ericsonf9a912d2002-10-28 20:04:53 +000051bool lcd_display_redraw=true;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000052
53XrmOptionDescRec options [] = {
Jens Arnold31b28f52005-03-18 00:03:22 +000054 /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */
55 { "-server", ".server", XrmoptionSepArg, 0 },
56 { "-help", ".help", XrmoptionNoArg, "false" },
57 { 0, 0, 0, 0 }
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000058};
59char *progclass = "rockboxui";
60
Jens Arnolda5ef8f02005-07-08 19:26:17 +000061#ifdef IRIVER_H100_SERIES
Daniel Stenberg98728132005-07-14 10:02:04 +000062#define BGCOLOR "lightblue"
Jens Arnold424d5052005-01-23 01:06:01 +000063#elif defined ARCHOS_GMINI120
Daniel Stenberg98728132005-07-14 10:02:04 +000064#define BGCOLOR "royalblue"
Björn Stenbergbbcd7402004-09-16 20:03:03 +000065#else
Daniel Stenberg98728132005-07-14 10:02:04 +000066#define BGCOLOR "lightgreen"
Björn Stenbergbbcd7402004-09-16 20:03:03 +000067#endif
Daniel Stenberg98728132005-07-14 10:02:04 +000068
69
70char *defaults [] = {
71 ".background: " BGCOLOR,
Jens Arnold31b28f52005-03-18 00:03:22 +000072 ".foreground: black",
73 "*help: false",
74 0
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000075};
76
Daniel Stenberg98728132005-07-14 10:02:04 +000077static XColor getcolor[4];
78
79/* set a range of bitmap indices to a gradient from startcolour to endcolour
80 inherited from the win32 sim code by Jens Arnold */
81static void lcdcolors(int index, int count, XColor *start, XColor *end)
82{
83 int i;
84 count--;
85 for (i = 0; i <= count; i++)
86 {
87 getcolor[i+index].red = start->red
88 + (end->red - start->red) * i / count;
89 getcolor[i+index].green = start->green
90 + (end->green - start->green) * i / count;
91 getcolor[i+index].blue = start->blue
92 + (end->blue - start->blue) * i / count;
93 XAllocColor (dpy, cmap, &getcolor[i+index]);
94 }
95}
96
97
Daniel Stenberg9f6733f2002-03-25 14:21:30 +000098void init_window ()
99{
Jens Arnold31b28f52005-03-18 00:03:22 +0000100 XGCValues gcv;
101 XWindowAttributes xgwa;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000102
Jens Arnold31b28f52005-03-18 00:03:22 +0000103 XGetWindowAttributes (dpy, window, &xgwa);
Daniel Stenberg98728132005-07-14 10:02:04 +0000104 XColor bg;
105 XColor fg;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000106
Jens Arnold31b28f52005-03-18 00:03:22 +0000107 cmap = xgwa.colormap;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000108
Daniel Stenberg98728132005-07-14 10:02:04 +0000109 XParseColor (dpy, cmap, BGCOLOR, &bg);
110 XParseColor (dpy, cmap, "black", &fg);
111 getcolor[0] = bg;
112 getcolor[1] = bg;
113 getcolor[2] = bg;
114 getcolor[3] = bg;
115
116 lcdcolors(0, 4, &bg, &fg);
117
118#if 0
119 for(i=0; i<4; i++) {
120 printf("color %d: %d %d %d\n",
121 i,
122 getcolor[i].red,
123 getcolor[i].green,
124 getcolor[i].blue);
125 }
126#endif
127
Jens Arnold31b28f52005-03-18 00:03:22 +0000128 gcv.function = GXxor;
Daniel Stenberg98728132005-07-14 10:02:04 +0000129 gcv.foreground = getcolor[3].pixel;
Jens Arnold31b28f52005-03-18 00:03:22 +0000130 draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000131
Jens Arnold31b28f52005-03-18 00:03:22 +0000132 screen_resized(LCD_WIDTH, LCD_HEIGHT);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000133}
134
135void screen_resized(int width, int height)
136{
Jens Arnold31b28f52005-03-18 00:03:22 +0000137 int maxx, maxy;
138 maxx = width;
139 maxy = height;
Kjell Ericsonc54ff702002-10-16 08:43:13 +0000140
Jens Arnold74b731e2005-03-18 23:51:52 +0000141 XtAppLock(app);
Daniel Stenberg98728132005-07-14 10:02:04 +0000142 XSetForeground(dpy, draw_gc, getcolor[0].pixel);
143
Jens Arnold31b28f52005-03-18 00:03:22 +0000144 XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom,
145 height*display_zoom);
Jens Arnold74b731e2005-03-18 23:51:52 +0000146 XtAppUnlock(app);
Jens Arnold31b28f52005-03-18 00:03:22 +0000147 screen_redraw();
Kjell Ericsonf9a912d2002-10-28 20:04:53 +0000148}
149
150void drawrect(int color, int x1, int y1, int x2, int y2)
151{
Jens Arnold74b731e2005-03-18 23:51:52 +0000152 XtAppLock(app);
Daniel Stenberg98728132005-07-14 10:02:04 +0000153 XSetForeground(dpy, draw_gc, getcolor[color].pixel);
Jens Arnold31b28f52005-03-18 00:03:22 +0000154 XFillRectangle(dpy, window, draw_gc, x1*display_zoom, y1*display_zoom,
155 x2*display_zoom, y2*display_zoom);
Jens Arnold74b731e2005-03-18 23:51:52 +0000156 XtAppUnlock(app);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000157}
158
159static void help(void)
160{
Jens Arnold31b28f52005-03-18 00:03:22 +0000161 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
162 "usage: " PROGNAME "\n");
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000163}
164
Daniel Stenberg98728132005-07-14 10:02:04 +0000165static void drawline(int color, int x1, int y1, int x2, int y2)
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000166{
Jens Arnold74b731e2005-03-18 23:51:52 +0000167 XtAppLock(app);
Daniel Stenberg98728132005-07-14 10:02:04 +0000168 XSetForeground(dpy, draw_gc, getcolor[color].pixel);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000169
Jens Arnold31b28f52005-03-18 00:03:22 +0000170 XDrawLine(dpy, window, draw_gc,
171 (int)(x1*display_zoom),
172 (int)(y1*display_zoom),
173 (int)(x2*display_zoom),
174 (int)(y2*display_zoom));
Jens Arnold74b731e2005-03-18 23:51:52 +0000175 XtAppUnlock(app);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000176}
177
Daniel Stenberg98728132005-07-14 10:02:04 +0000178void dots(int *colors, struct coordinate *points, int count)
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000179{
Daniel Stenberg98728132005-07-14 10:02:04 +0000180 int color;
Jens Arnold74b731e2005-03-18 23:51:52 +0000181 XtAppLock(app);
Daniel Stenbergc1543512002-04-27 23:41:41 +0000182
Jens Arnold31b28f52005-03-18 00:03:22 +0000183 while (count--) {
Daniel Stenberg98728132005-07-14 10:02:04 +0000184 color = colors[count];
185 XSetForeground(dpy, draw_gc, getcolor[color].pixel);
Jens Arnold31b28f52005-03-18 00:03:22 +0000186 XFillRectangle(dpy, window, draw_gc,
187 points[count].x*display_zoom,
188 points[count].y*display_zoom,
189 display_zoom,
190 display_zoom);
191 }
Jens Arnold74b731e2005-03-18 23:51:52 +0000192 XtAppUnlock(app);
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000193}
194
Daniel Stenberged6c7e42002-06-14 11:00:13 +0000195/* this is where the applicaton starts */
196extern void app_main(void);
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000197
Jens Arnold74b731e2005-03-18 23:51:52 +0000198void screenhack()
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000199{
Jens Arnold31b28f52005-03-18 00:03:22 +0000200 Bool helpme;
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000201
Jens Arnold31b28f52005-03-18 00:03:22 +0000202 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */
203 helpme = get_boolean_resource ("help", "Boolean");
204 if(helpme)
205 help();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000206
Jens Arnold31b28f52005-03-18 00:03:22 +0000207 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000208
Jens Arnold31b28f52005-03-18 00:03:22 +0000209 init_window();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000210
Jens Arnold31b28f52005-03-18 00:03:22 +0000211 screen_redraw();
212
213 app_main();
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000214}
215
Daniel Stenberg1c475992005-07-14 10:35:26 +0000216/* used for the player sim */
217void drawdots(int color, struct coordinate *points, int count)
218{
219 XtAppLock(app);
220 XSetForeground(dpy, draw_gc, getcolor[color==0?0:3].pixel);
221
222 while (count--) {
223 XFillRectangle(dpy, window, draw_gc,
224 points[count].x*display_zoom,
225 points[count].y*display_zoom,
226 display_zoom,
227 display_zoom);
228 }
229 XtAppUnlock(app);
230}
231
232/* used for the player sim */
233void drawrectangles(int color, struct rectangle *points, int count)
234{
235 XtAppLock(app);
236
237 XSetForeground(dpy, draw_gc, getcolor[color==0?0:3].pixel);
238 while (count--) {
239 XFillRectangle(dpy, window, draw_gc,
240 points[count].x*display_zoom,
241 points[count].y*display_zoom,
242 points[count].width*display_zoom,
243 points[count].height*display_zoom);
244 }
245 XtAppUnlock(app);
246}
247
248
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000249void screen_redraw()
250{
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000251 /* draw a border around the screen */
Daniel Stenberga1fd2552002-03-26 14:27:03 +0000252#define X1 0
253#define Y1 0
Jens Arnoldfc03c8e2005-10-23 13:06:25 +0000254#define X2 (LCD_WIDTH + 2*MARGIN_X - 1)
255#define Y2 (LCD_HEIGHT + 2*MARGIN_Y - 1)
Daniel Stenberga1fd2552002-03-26 14:27:03 +0000256
Jens Arnold31b28f52005-03-18 00:03:22 +0000257 drawline(1, X1, Y1, X2, Y1);
258 drawline(1, X2, Y1, X2, Y2);
259 drawline(1, X1, Y2, X2, Y2);
260 drawline(1, X1, Y1, X1, Y2);
Jens Arnold48be8e62005-10-23 23:49:46 +0000261 lcd_display_redraw = true;
Jens Arnold31b28f52005-03-18 00:03:22 +0000262 lcd_update();
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000263#ifdef LCD_REMOTE_HEIGHT
264 /* draw a border around the remote LCD screen */
265#define RX1 0
Jens Arnoldfc03c8e2005-10-23 13:06:25 +0000266#define RY1 (Y2 + 1)
267#define RX2 (LCD_REMOTE_WIDTH + 2*MARGIN_X - 1)
268#define RY2 (RY1 + LCD_REMOTE_HEIGHT + 2*MARGIN_Y - 1)
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000269
270 drawline(1, RX1, RY1, RX2, RY1);
271 drawline(1, RX2, RY1, RX2, RY2);
272 drawline(1, RX1, RY2, RX2, RY2);
273 drawline(1, RX1, RY1, RX1, RY2);
Jens Arnold48be8e62005-10-23 23:49:46 +0000274 lcd_display_redraw = true;
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000275 lcd_remote_update();
276#endif
Daniel Stenberg9f6733f2002-03-25 14:21:30 +0000277}