diff options
Diffstat (limited to 'uisimulator/uibasic.c')
-rw-r--r-- | uisimulator/uibasic.c | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/uisimulator/uibasic.c b/uisimulator/uibasic.c new file mode 100644 index 0000000000..df35fac79c --- /dev/null +++ b/uisimulator/uibasic.c | |||
@@ -0,0 +1,220 @@ | |||
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 | #include "alpha.h" | ||
34 | |||
35 | #include "version.h" | ||
36 | |||
37 | #define MAX(x,y) ((x)>(y)?(x):(y)) | ||
38 | #define MIN(x,y) ((x)<(y)?(x):(y)) | ||
39 | |||
40 | #define PROGNAME "rockboxui" | ||
41 | |||
42 | /* -- -- */ | ||
43 | |||
44 | static GC draw_gc, erase_gc; | ||
45 | static Colormap cmap; | ||
46 | static XColor color_track, color_car; | ||
47 | |||
48 | static long maxx, maxy; | ||
49 | static double track_zoom=1; | ||
50 | |||
51 | Display *dpy; | ||
52 | Window window; | ||
53 | |||
54 | XrmOptionDescRec options [] = { | ||
55 | /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */ | ||
56 | { "-server", ".server", XrmoptionSepArg, 0 }, | ||
57 | { "-help", ".help", XrmoptionNoArg, "false" }, | ||
58 | { 0, 0, 0, 0 } | ||
59 | }; | ||
60 | char *progclass = "rockboxui"; | ||
61 | |||
62 | char *defaults [] = { | ||
63 | ".background: black", | ||
64 | ".foreground: white", | ||
65 | "*help: false", | ||
66 | 0 | ||
67 | }; | ||
68 | |||
69 | #define LOGFILE "xgui.log" | ||
70 | void Logf(char *fmt, ...) | ||
71 | { | ||
72 | va_list args; | ||
73 | FILE *log; | ||
74 | struct tm *t; | ||
75 | time_t now=time(NULL); | ||
76 | |||
77 | va_start(args, fmt); | ||
78 | |||
79 | t = localtime(&now); | ||
80 | log = fopen(LOGFILE, "a"); | ||
81 | if(log) { | ||
82 | fprintf(log, "%02d.%02d.%02d ", | ||
83 | t->tm_hour, t->tm_min, t->tm_sec); | ||
84 | vfprintf(log, fmt, args); | ||
85 | fprintf(log, "\n"); | ||
86 | |||
87 | fclose(log); | ||
88 | } | ||
89 | |||
90 | fprintf(stderr, "%02d.%02d.%02d ", | ||
91 | t->tm_hour, t->tm_min, t->tm_sec); | ||
92 | vfprintf(stderr, fmt, args); | ||
93 | fprintf(stderr, "\n"); | ||
94 | va_end(args); | ||
95 | } | ||
96 | |||
97 | void init_window () | ||
98 | { | ||
99 | XGCValues gcv; | ||
100 | XWindowAttributes xgwa; | ||
101 | char *test_p; | ||
102 | |||
103 | XGetWindowAttributes (dpy, window, &xgwa); | ||
104 | |||
105 | color_track.red=65535; | ||
106 | color_track.green=65535; | ||
107 | color_track.blue=65535; | ||
108 | |||
109 | color_car.red=65535; | ||
110 | color_car.green=65535; | ||
111 | color_car.blue=0; | ||
112 | |||
113 | cmap = xgwa.colormap; | ||
114 | |||
115 | gcv.function = GXxor; | ||
116 | gcv.foreground = | ||
117 | get_pixel_resource ("foreground", "Foreground", dpy, cmap); | ||
118 | draw_gc = erase_gc = XCreateGC (dpy, window, GCForeground, &gcv); | ||
119 | XAllocColor (dpy, cmap, &color_track); | ||
120 | XAllocColor (dpy, cmap, &color_car); | ||
121 | |||
122 | screen_resized(200, 100); | ||
123 | } | ||
124 | |||
125 | void screen_resized(int width, int height) | ||
126 | { | ||
127 | #if 0 | ||
128 | XWindowAttributes xgwa; | ||
129 | XGetWindowAttributes (dpy, window, &xgwa); | ||
130 | maxx = ((long)(xgwa.width)); | ||
131 | maxy = ((long)(xgwa.height)); | ||
132 | #else | ||
133 | maxx = width-1; | ||
134 | maxy = height-1; | ||
135 | #endif | ||
136 | XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background", | ||
137 | dpy, cmap)); | ||
138 | XFillRectangle(dpy, window, draw_gc, 0, 0, width, height); | ||
139 | |||
140 | } | ||
141 | |||
142 | static void help(void) | ||
143 | { | ||
144 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" | ||
145 | "usage: " PROGNAME "\n" | ||
146 | ); | ||
147 | } | ||
148 | |||
149 | void drawline(int color, int x1, int y1, int x2, int y2) | ||
150 | { | ||
151 | if (color==0) { | ||
152 | XSetForeground(dpy, draw_gc, | ||
153 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
154 | } | ||
155 | else | ||
156 | XSetForeground(dpy, draw_gc, | ||
157 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
158 | |||
159 | XDrawLine(dpy, window, draw_gc, | ||
160 | (int)(x1*track_zoom), | ||
161 | (int)(y1*track_zoom), | ||
162 | (int)(x2*track_zoom), | ||
163 | (int)(y2*track_zoom)); | ||
164 | } | ||
165 | |||
166 | void drawtext(int color, int x, int y, char *text) | ||
167 | { | ||
168 | if (color==0) { | ||
169 | XSetForeground(dpy, draw_gc, | ||
170 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
171 | } | ||
172 | else | ||
173 | XSetForeground(dpy, draw_gc, | ||
174 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
175 | |||
176 | XDrawString(dpy, window, draw_gc, x, y, text, strlen(text)); | ||
177 | } | ||
178 | |||
179 | |||
180 | void | ||
181 | screenhack (Display *the_dpy, Window the_window) | ||
182 | { | ||
183 | unsigned short porttouse=0; | ||
184 | char *proxy = NULL; | ||
185 | char *url = NULL; | ||
186 | int i; | ||
187 | char *guiname="Rock-the-box"; | ||
188 | Bool helpme; | ||
189 | |||
190 | /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ | ||
191 | helpme = get_boolean_resource ("help", "Boolean"); | ||
192 | if(helpme) { | ||
193 | help(); | ||
194 | } | ||
195 | printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); | ||
196 | |||
197 | dpy=the_dpy; | ||
198 | window=the_window; | ||
199 | |||
200 | init_window(); | ||
201 | |||
202 | drawtext(1, 20, 20, PROGNAME); | ||
203 | drawline(1, 0, 0, 40, 50); | ||
204 | |||
205 | Logf("Rockbox will kill ya!"); | ||
206 | |||
207 | while (1) { | ||
208 | /* deal with input here */ | ||
209 | |||
210 | XSync (dpy, False); | ||
211 | screenhack_handle_events (dpy); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | void screen_redraw() | ||
216 | { | ||
217 | /* does nothing yet */ | ||
218 | drawtext(1, 20, 20, PROGNAME); | ||
219 | drawline(1, 0, 0, 40, 50); | ||
220 | } | ||