diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-04-27 23:48:49 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-04-27 23:48:49 +0000 |
commit | 3caa3c08717ad745b49da01bf70a4c0da195ac14 (patch) | |
tree | 486f9d59673e537cd100957c8748b351e0a64ce4 /uisimulator/x11/uibasic.c | |
parent | c1543511b342162b2b537485c6646186037d8845 (diff) | |
download | rockbox-3caa3c08717ad745b49da01bf70a4c0da195ac14.tar.gz rockbox-3caa3c08717ad745b49da01bf70a4c0da195ac14.zip |
moved X11-specific files into a separate subdir to keep root clean for
target files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@282 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/x11/uibasic.c')
-rw-r--r-- | uisimulator/x11/uibasic.c | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/uisimulator/x11/uibasic.c b/uisimulator/x11/uibasic.c new file mode 100644 index 0000000000..85cfb7d911 --- /dev/null +++ b/uisimulator/x11/uibasic.c | |||
@@ -0,0 +1,253 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
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 | |||
32 | #include "screenhack.h" | ||
33 | |||
34 | #include "version.h" | ||
35 | |||
36 | #include "lcd-x11.h" | ||
37 | |||
38 | #define MAX(x,y) ((x)>(y)?(x):(y)) | ||
39 | #define MIN(x,y) ((x)<(y)?(x):(y)) | ||
40 | |||
41 | #define PROGNAME "rockboxui" | ||
42 | |||
43 | /* -- -- */ | ||
44 | |||
45 | GC draw_gc, erase_gc; | ||
46 | static Colormap cmap; | ||
47 | static XColor color_track, color_car; | ||
48 | |||
49 | static long maxx, maxy; | ||
50 | static double track_zoom=1; | ||
51 | |||
52 | Display *dpy; | ||
53 | Window window; | ||
54 | |||
55 | XrmOptionDescRec options [] = { | ||
56 | /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */ | ||
57 | { "-server", ".server", XrmoptionSepArg, 0 }, | ||
58 | { "-help", ".help", XrmoptionNoArg, "false" }, | ||
59 | { 0, 0, 0, 0 } | ||
60 | }; | ||
61 | char *progclass = "rockboxui"; | ||
62 | |||
63 | char *defaults [] = { | ||
64 | ".background: black", | ||
65 | ".foreground: white", | ||
66 | "*help: false", | ||
67 | 0 | ||
68 | }; | ||
69 | |||
70 | #define LOGFILE "xgui.log" | ||
71 | void Logf(char *fmt, ...) | ||
72 | { | ||
73 | va_list args; | ||
74 | FILE *log; | ||
75 | struct tm *t; | ||
76 | time_t now=time(NULL); | ||
77 | |||
78 | va_start(args, fmt); | ||
79 | |||
80 | t = localtime(&now); | ||
81 | log = fopen(LOGFILE, "a"); | ||
82 | if(log) { | ||
83 | fprintf(log, "%02d:%02d:%02d ", | ||
84 | t->tm_hour, t->tm_min, t->tm_sec); | ||
85 | vfprintf(log, fmt, args); | ||
86 | fprintf(log, "\n"); | ||
87 | |||
88 | fclose(log); | ||
89 | } | ||
90 | |||
91 | fprintf(stderr, "%02d:%02d:%02d ", | ||
92 | t->tm_hour, t->tm_min, t->tm_sec); | ||
93 | vfprintf(stderr, fmt, args); | ||
94 | fprintf(stderr, "\n"); | ||
95 | va_end(args); | ||
96 | } | ||
97 | |||
98 | void init_window () | ||
99 | { | ||
100 | XGCValues gcv; | ||
101 | XWindowAttributes xgwa; | ||
102 | char *test_p; | ||
103 | |||
104 | XGetWindowAttributes (dpy, window, &xgwa); | ||
105 | |||
106 | color_track.red=65535; | ||
107 | color_track.green=65535; | ||
108 | color_track.blue=65535; | ||
109 | |||
110 | color_car.red=65535; | ||
111 | color_car.green=65535; | ||
112 | color_car.blue=0; | ||
113 | |||
114 | cmap = xgwa.colormap; | ||
115 | |||
116 | gcv.function = GXxor; | ||
117 | gcv.foreground = | ||
118 | get_pixel_resource ("foreground", "Foreground", dpy, cmap); | ||
119 | draw_gc = erase_gc = XCreateGC (dpy, window, GCForeground, &gcv); | ||
120 | XAllocColor (dpy, cmap, &color_track); | ||
121 | XAllocColor (dpy, cmap, &color_car); | ||
122 | |||
123 | screen_resized(200, 100); | ||
124 | } | ||
125 | |||
126 | void screen_resized(int width, int height) | ||
127 | { | ||
128 | #if 0 | ||
129 | XWindowAttributes xgwa; | ||
130 | XGetWindowAttributes (dpy, window, &xgwa); | ||
131 | maxx = ((long)(xgwa.width)); | ||
132 | maxy = ((long)(xgwa.height)); | ||
133 | #else | ||
134 | maxx = width-1; | ||
135 | maxy = height-1; | ||
136 | #endif | ||
137 | XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background", | ||
138 | dpy, cmap)); | ||
139 | XFillRectangle(dpy, window, draw_gc, 0, 0, width, height); | ||
140 | |||
141 | } | ||
142 | |||
143 | static void help(void) | ||
144 | { | ||
145 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" | ||
146 | "usage: " PROGNAME "\n" | ||
147 | ); | ||
148 | } | ||
149 | |||
150 | void drawline(int color, int x1, int y1, int x2, int y2) | ||
151 | { | ||
152 | if (color==0) { | ||
153 | XSetForeground(dpy, draw_gc, | ||
154 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
155 | } | ||
156 | else | ||
157 | XSetForeground(dpy, draw_gc, | ||
158 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
159 | |||
160 | XDrawLine(dpy, window, draw_gc, | ||
161 | (int)(x1*track_zoom), | ||
162 | (int)(y1*track_zoom), | ||
163 | (int)(x2*track_zoom), | ||
164 | (int)(y2*track_zoom)); | ||
165 | } | ||
166 | |||
167 | void drawdot(int color, int x, int y) | ||
168 | { | ||
169 | if (color==0) { | ||
170 | XSetForeground(dpy, draw_gc, | ||
171 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
172 | } | ||
173 | else | ||
174 | XSetForeground(dpy, draw_gc, | ||
175 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
176 | |||
177 | XDrawPoint(dpy, window, draw_gc, x, y); | ||
178 | } | ||
179 | |||
180 | void drawdots(int color, XPoint *points, int count) | ||
181 | { | ||
182 | if (color==0) { | ||
183 | XSetForeground(dpy, draw_gc, | ||
184 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
185 | } | ||
186 | else | ||
187 | XSetForeground(dpy, draw_gc, | ||
188 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
189 | |||
190 | |||
191 | XDrawPoints(dpy, window, draw_gc, points, count, CoordModeOrigin); | ||
192 | } | ||
193 | |||
194 | void drawtext(int color, int x, int y, char *text) | ||
195 | { | ||
196 | if (color==0) { | ||
197 | XSetForeground(dpy, draw_gc, | ||
198 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
199 | } | ||
200 | else | ||
201 | XSetForeground(dpy, draw_gc, | ||
202 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
203 | |||
204 | XDrawString(dpy, window, draw_gc, x, y, text, strlen(text)); | ||
205 | } | ||
206 | |||
207 | |||
208 | void | ||
209 | screenhack (Display *the_dpy, Window the_window) | ||
210 | { | ||
211 | unsigned short porttouse=0; | ||
212 | char *proxy = NULL; | ||
213 | char *url = NULL; | ||
214 | int i; | ||
215 | char *guiname="Rock-the-box"; | ||
216 | Bool helpme; | ||
217 | |||
218 | /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ | ||
219 | helpme = get_boolean_resource ("help", "Boolean"); | ||
220 | if(helpme) { | ||
221 | help(); | ||
222 | } | ||
223 | printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); | ||
224 | |||
225 | dpy=the_dpy; | ||
226 | window=the_window; | ||
227 | |||
228 | init_window(); | ||
229 | |||
230 | Logf("Rockbox will kill ya!"); | ||
231 | |||
232 | app_main(); | ||
233 | } | ||
234 | |||
235 | void screen_redraw() | ||
236 | { | ||
237 | int y, x; | ||
238 | |||
239 | lcd_update(); | ||
240 | |||
241 | /* draw a border around the "Recorder" screen */ | ||
242 | |||
243 | #define X1 0 | ||
244 | #define Y1 0 | ||
245 | #define X2 (LCD_WIDTH + MARGIN_X*2) | ||
246 | #define Y2 (LCD_HEIGHT + MARGIN_Y*2) | ||
247 | |||
248 | drawline(1, X1, Y1, X2, Y1); | ||
249 | drawline(1, X2, Y1, X2, Y2); | ||
250 | drawline(1, X1, Y2, X2, Y2); | ||
251 | drawline(1, X1, Y1, X1, Y2); | ||
252 | |||
253 | } | ||