Jean-Philippe Bernardy: removed bad emu_debugf() call
[kugel-rb.git] / uisimulator / x11 / uibasic.c
blob78abb2f5db9656bec7b01cf13729e5dd0626908b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
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>
28 #include <errno.h>
29 #include <ctype.h>
30 #include <time.h>
32 #include "config.h"
33 #include "screenhack.h"
35 #include "version.h"
37 #include "lcd-x11.h"
38 #include "lcd-playersim.h"
40 #define MAX(x,y) ((x)>(y)?(x):(y))
41 #define MIN(x,y) ((x)<(y)?(x):(y))
43 #define PROGNAME "rockboxui"
45 /* -- -- */
47 GC draw_gc;
48 static Colormap cmap;
50 int display_zoom=1;
52 Display *dpy;
53 Window window;
54 bool lcd_display_redraw=true;
56 XrmOptionDescRec options [] = {
57 /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */
58 { "-server", ".server", XrmoptionSepArg, 0 },
59 { "-help", ".help", XrmoptionNoArg, "false" },
60 { 0, 0, 0, 0 }
62 char *progclass = "rockboxui";
64 char *defaults [] = {
65 #ifdef IRIVER_H100
66 ".background: lightblue",
67 #else
68 ".background: lightgreen",
69 #endif
70 ".foreground: black",
71 "*help: false",
75 void init_window ()
77 XGCValues gcv;
78 XWindowAttributes xgwa;
80 XGetWindowAttributes (dpy, window, &xgwa);
82 cmap = xgwa.colormap;
84 gcv.function = GXxor;
85 gcv.foreground =
86 get_pixel_resource ("foreground", "Foreground", dpy, cmap);
87 draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
89 screen_resized(LCD_WIDTH, LCD_HEIGHT);
92 void screen_resized(int width, int height)
94 int maxx, maxy;
95 maxx = width;
96 maxy = height;
98 XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background",
99 dpy, cmap));
100 XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom, height*display_zoom);
101 lcd_display_redraw=true;
102 screen_redraw();
105 void drawrect(int color, int x1, int y1, int x2, int y2)
107 if (color==0) {
108 XSetForeground(dpy, draw_gc,
109 get_pixel_resource("background", "Background", dpy, cmap));
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);
119 static void help(void)
121 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
122 "usage: " PROGNAME "\n"
126 void drawline(int color, int x1, int y1, int x2, int y2)
128 if (color==0) {
129 XSetForeground(dpy, draw_gc,
130 get_pixel_resource("background", "Background", dpy, cmap));
132 else
133 XSetForeground(dpy, draw_gc,
134 get_pixel_resource("foreground", "Foreground", dpy, cmap));
136 XDrawLine(dpy, window, draw_gc,
137 (int)(x1*display_zoom),
138 (int)(y1*display_zoom),
139 (int)(x2*display_zoom),
140 (int)(y2*display_zoom));
143 void drawdot(int color, int x, int y)
145 if (color==0) {
146 XSetForeground(dpy, draw_gc,
147 get_pixel_resource("background", "Background", dpy, cmap));
149 else
150 XSetForeground(dpy, draw_gc,
151 get_pixel_resource("foreground", "Foreground", dpy, cmap));
153 XFillRectangle(dpy, window, draw_gc, x*display_zoom, y*display_zoom,
154 display_zoom, display_zoom);
157 void drawdots(int color, struct coordinate *points, int count)
159 if (color==0) {
160 XSetForeground(dpy, draw_gc,
161 get_pixel_resource("background", "Background", dpy, cmap));
163 else
164 XSetForeground(dpy, draw_gc,
165 get_pixel_resource("foreground", "Foreground", dpy, cmap));
167 while (count--) {
168 XFillRectangle(dpy, window, draw_gc,
169 points[count].x*display_zoom,
170 points[count].y*display_zoom,
171 display_zoom,
172 display_zoom);
176 void drawrectangles(int color, struct rectangle *points, int count)
178 if (color==0) {
179 XSetForeground(dpy, draw_gc,
180 get_pixel_resource("background", "Background", dpy, cmap));
182 else
183 XSetForeground(dpy, draw_gc,
184 get_pixel_resource("foreground", "Foreground", dpy, cmap));
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);
196 void drawtext(int color, int x, int y, char *text)
198 if (color==0) {
199 XSetForeground(dpy, draw_gc,
200 get_pixel_resource("background", "Background", dpy, cmap));
202 else
203 XSetForeground(dpy, draw_gc,
204 get_pixel_resource("foreground", "Foreground", dpy, cmap));
206 XDrawString(dpy, window, draw_gc, x*display_zoom, y*display_zoom, text, strlen(text));
209 /* this is where the applicaton starts */
210 extern void app_main(void);
212 void
213 screenhack (Display *the_dpy, Window the_window)
215 Bool helpme;
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();
222 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
224 dpy=the_dpy;
225 window=the_window;
227 init_window();
229 screen_redraw();
231 app_main();
234 void screen_redraw()
236 /* draw a border around the "Recorder" screen */
237 #define X1 0
238 #define Y1 0
239 #define X2 (LCD_WIDTH + MARGIN_X*2)
240 #define Y2 (LCD_HEIGHT + MARGIN_Y)
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);
246 lcd_update();