Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Daniel Stenberg | 3484980 | 2002-03-25 14:44:06 +0000 | [diff] [blame] | 8 | * $Id$ |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 9 | * |
| 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 Stenberg | bbcd740 | 2004-09-16 20:03:03 +0000 | [diff] [blame] | 32 | #include "config.h" |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 33 | #include "screenhack.h" |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 34 | |
| 35 | #include "version.h" |
| 36 | |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 37 | #include "lcd-x11.h" |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 38 | #include "lcd-playersim.h" |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 39 | |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 40 | #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 Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 47 | GC draw_gc; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 48 | static Colormap cmap; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 49 | |
Kjell Ericson | 0ca9ccb | 2003-01-20 09:39:38 +0000 | [diff] [blame] | 50 | int display_zoom=1; |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 51 | bool lcd_display_redraw=true; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 52 | |
| 53 | XrmOptionDescRec options [] = { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 54 | /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */ |
| 55 | { "-server", ".server", XrmoptionSepArg, 0 }, |
| 56 | { "-help", ".help", XrmoptionNoArg, "false" }, |
| 57 | { 0, 0, 0, 0 } |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 58 | }; |
| 59 | char *progclass = "rockboxui"; |
| 60 | |
Jens Arnold | a5ef8f0 | 2005-07-08 19:26:17 +0000 | [diff] [blame] | 61 | #ifdef IRIVER_H100_SERIES |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 62 | #define BGCOLOR "lightblue" |
Jens Arnold | 424d505 | 2005-01-23 01:06:01 +0000 | [diff] [blame] | 63 | #elif defined ARCHOS_GMINI120 |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 64 | #define BGCOLOR "royalblue" |
Björn Stenberg | bbcd740 | 2004-09-16 20:03:03 +0000 | [diff] [blame] | 65 | #else |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 66 | #define BGCOLOR "lightgreen" |
Björn Stenberg | bbcd740 | 2004-09-16 20:03:03 +0000 | [diff] [blame] | 67 | #endif |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | char *defaults [] = { |
| 71 | ".background: " BGCOLOR, |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 72 | ".foreground: black", |
| 73 | "*help: false", |
| 74 | 0 |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 77 | static 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 */ |
| 81 | static 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 Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 98 | void init_window () |
| 99 | { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 100 | XGCValues gcv; |
| 101 | XWindowAttributes xgwa; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 102 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 103 | XGetWindowAttributes (dpy, window, &xgwa); |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 104 | XColor bg; |
| 105 | XColor fg; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 106 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 107 | cmap = xgwa.colormap; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 108 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 109 | 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 Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 128 | gcv.function = GXxor; |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 129 | gcv.foreground = getcolor[3].pixel; |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 130 | draw_gc = XCreateGC (dpy, window, GCForeground, &gcv); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 131 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 132 | screen_resized(LCD_WIDTH, LCD_HEIGHT); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void screen_resized(int width, int height) |
| 136 | { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 137 | int maxx, maxy; |
| 138 | maxx = width; |
| 139 | maxy = height; |
Kjell Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 140 | |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 141 | XtAppLock(app); |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 142 | XSetForeground(dpy, draw_gc, getcolor[0].pixel); |
| 143 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 144 | XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom, |
| 145 | height*display_zoom); |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 146 | XtAppUnlock(app); |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 147 | screen_redraw(); |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void drawrect(int color, int x1, int y1, int x2, int y2) |
| 151 | { |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 152 | XtAppLock(app); |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 153 | XSetForeground(dpy, draw_gc, getcolor[color].pixel); |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 154 | XFillRectangle(dpy, window, draw_gc, x1*display_zoom, y1*display_zoom, |
| 155 | x2*display_zoom, y2*display_zoom); |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 156 | XtAppUnlock(app); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void help(void) |
| 160 | { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 161 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" |
| 162 | "usage: " PROGNAME "\n"); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 165 | static void drawline(int color, int x1, int y1, int x2, int y2) |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 166 | { |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 167 | XtAppLock(app); |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 168 | XSetForeground(dpy, draw_gc, getcolor[color].pixel); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 169 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 170 | 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 Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 175 | XtAppUnlock(app); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 178 | void dots(int *colors, struct coordinate *points, int count) |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 179 | { |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 180 | int color; |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 181 | XtAppLock(app); |
Daniel Stenberg | c154351 | 2002-04-27 23:41:41 +0000 | [diff] [blame] | 182 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 183 | while (count--) { |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 184 | color = colors[count]; |
| 185 | XSetForeground(dpy, draw_gc, getcolor[color].pixel); |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 186 | 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 Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 192 | XtAppUnlock(app); |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Daniel Stenberg | ed6c7e4 | 2002-06-14 11:00:13 +0000 | [diff] [blame] | 195 | /* this is where the applicaton starts */ |
| 196 | extern void app_main(void); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 197 | |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 198 | void screenhack() |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 199 | { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 200 | Bool helpme; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 201 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 202 | /* 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 Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 206 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 207 | printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 208 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 209 | init_window(); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 210 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 211 | screen_redraw(); |
| 212 | |
| 213 | app_main(); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Daniel Stenberg | 1c47599 | 2005-07-14 10:35:26 +0000 | [diff] [blame] | 216 | /* used for the player sim */ |
| 217 | void 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 */ |
| 233 | void 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 Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 249 | void screen_redraw() |
| 250 | { |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 251 | /* draw a border around the screen */ |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 252 | #define X1 0 |
| 253 | #define Y1 0 |
Jens Arnold | fc03c8e | 2005-10-23 13:06:25 +0000 | [diff] [blame] | 254 | #define X2 (LCD_WIDTH + 2*MARGIN_X - 1) |
| 255 | #define Y2 (LCD_HEIGHT + 2*MARGIN_Y - 1) |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 256 | |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 257 | 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 Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 261 | lcd_display_redraw = true; |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 262 | lcd_update(); |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 263 | #ifdef LCD_REMOTE_HEIGHT |
| 264 | /* draw a border around the remote LCD screen */ |
| 265 | #define RX1 0 |
Jens Arnold | fc03c8e | 2005-10-23 13:06:25 +0000 | [diff] [blame] | 266 | #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 Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 269 | |
| 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 Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 274 | lcd_display_redraw = true; |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 275 | lcd_remote_update(); |
| 276 | #endif |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 277 | } |