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; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 51 | |
| 52 | Display *dpy; |
| 53 | Window window; |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 54 | bool lcd_display_redraw=true; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 55 | |
| 56 | XrmOptionDescRec options [] = { |
| 57 | /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */ |
| 58 | { "-server", ".server", XrmoptionSepArg, 0 }, |
| 59 | { "-help", ".help", XrmoptionNoArg, "false" }, |
| 60 | { 0, 0, 0, 0 } |
| 61 | }; |
| 62 | char *progclass = "rockboxui"; |
| 63 | |
| 64 | char *defaults [] = { |
Björn Stenberg | bbcd740 | 2004-09-16 20:03:03 +0000 | [diff] [blame] | 65 | #ifdef IRIVER_H100 |
| 66 | ".background: lightblue", |
| 67 | #else |
Daniel Stenberg | 1ba9fae | 2002-04-28 09:38:20 +0000 | [diff] [blame] | 68 | ".background: lightgreen", |
Björn Stenberg | bbcd740 | 2004-09-16 20:03:03 +0000 | [diff] [blame] | 69 | #endif |
Daniel Stenberg | 1ba9fae | 2002-04-28 09:38:20 +0000 | [diff] [blame] | 70 | ".foreground: black", |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 71 | "*help: false", |
| 72 | 0 |
| 73 | }; |
| 74 | |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 75 | void init_window () |
| 76 | { |
| 77 | XGCValues gcv; |
| 78 | XWindowAttributes xgwa; |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 79 | |
| 80 | XGetWindowAttributes (dpy, window, &xgwa); |
| 81 | |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 82 | cmap = xgwa.colormap; |
| 83 | |
| 84 | gcv.function = GXxor; |
| 85 | gcv.foreground = |
| 86 | get_pixel_resource ("foreground", "Foreground", dpy, cmap); |
Kjell Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 87 | draw_gc = XCreateGC (dpy, window, GCForeground, &gcv); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 88 | |
Kjell Ericson | 93b5f92 | 2002-10-21 20:12:55 +0000 | [diff] [blame] | 89 | screen_resized(LCD_WIDTH, LCD_HEIGHT); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void screen_resized(int width, int height) |
| 93 | { |
Kjell Ericson | 93b5f92 | 2002-10-21 20:12:55 +0000 | [diff] [blame] | 94 | int maxx, maxy; |
| 95 | maxx = width; |
| 96 | maxy = height; |
Kjell Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 97 | |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 98 | XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background", |
| 99 | dpy, cmap)); |
Kjell Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 100 | XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom, height*display_zoom); |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 101 | lcd_display_redraw=true; |
| 102 | screen_redraw(); |
| 103 | } |
| 104 | |
| 105 | void 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 Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 116 | |
| 117 | } |
| 118 | |
| 119 | static void help(void) |
| 120 | { |
| 121 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" |
| 122 | "usage: " PROGNAME "\n" |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | void 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 Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 137 | (int)(x1*display_zoom), |
| 138 | (int)(y1*display_zoom), |
| 139 | (int)(x2*display_zoom), |
| 140 | (int)(y2*display_zoom)); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 143 | void 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 Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 153 | XFillRectangle(dpy, window, draw_gc, x*display_zoom, y*display_zoom, |
| 154 | display_zoom, display_zoom); |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 157 | void drawdots(int color, struct coordinate *points, int count) |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 158 | { |
Daniel Stenberg | c154351 | 2002-04-27 23:41:41 +0000 | [diff] [blame] | 159 | 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 Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 167 | while (count--) { |
Kjell Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 168 | 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 Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Kjell Ericson | f9a912d | 2002-10-28 20:04:53 +0000 | [diff] [blame] | 176 | void 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 Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 196 | void 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 Ericson | c54ff70 | 2002-10-16 08:43:13 +0000 | [diff] [blame] | 206 | XDrawString(dpy, window, draw_gc, x*display_zoom, y*display_zoom, text, strlen(text)); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Daniel Stenberg | ed6c7e4 | 2002-06-14 11:00:13 +0000 | [diff] [blame] | 209 | /* this is where the applicaton starts */ |
| 210 | extern void app_main(void); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 211 | |
| 212 | void |
| 213 | screenhack (Display *the_dpy, Window the_window) |
| 214 | { |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 215 | 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 Stenberg | 9b68ef8 | 2002-04-30 06:55:45 +0000 | [diff] [blame] | 229 | screen_redraw(); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 230 | |
Daniel Stenberg | c154351 | 2002-04-27 23:41:41 +0000 | [diff] [blame] | 231 | app_main(); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void screen_redraw() |
| 235 | { |
Daniel Stenberg | 0c4589d | 2002-03-26 14:42:33 +0000 | [diff] [blame] | 236 | /* draw a border around the "Recorder" screen */ |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 237 | #define X1 0 |
| 238 | #define Y1 0 |
| 239 | #define X2 (LCD_WIDTH + MARGIN_X*2) |
Daniel Stenberg | 2ed1052 | 2002-08-09 09:13:40 +0000 | [diff] [blame] | 240 | #define Y2 (LCD_HEIGHT + MARGIN_Y) |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 241 | |
| 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 Stenberg | 9b68ef8 | 2002-04-30 06:55:45 +0000 | [diff] [blame] | 246 | lcd_update(); |
Daniel Stenberg | 9f6733f | 2002-03-25 14:21:30 +0000 | [diff] [blame] | 247 | } |