No more password prompts
[kugel-rb.git] / uisimulator / x11 / uibasic.c
blob82ce39973ca8316693ed308793d27cf19822aa7f
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 "screenhack.h"
34 #include "version.h"
36 #include "lcd-x11.h"
37 #include "lcd-playersim.h"
39 #define MAX(x,y) ((x)>(y)?(x):(y))
40 #define MIN(x,y) ((x)<(y)?(x):(y))
42 #define PROGNAME "rockboxui"
44 /* -- -- */
46 GC draw_gc;
47 static Colormap cmap;
49 int display_zoom=1;
51 Display *dpy;
52 Window window;
53 bool lcd_display_redraw=true;
55 XrmOptionDescRec options [] = {
56 /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */
57 { "-server", ".server", XrmoptionSepArg, 0 },
58 { "-help", ".help", XrmoptionNoArg, "false" },
59 { 0, 0, 0, 0 }
61 char *progclass = "rockboxui";
63 char *defaults [] = {
64 ".background: lightgreen",
65 ".foreground: black",
66 "*help: false",
70 void init_window ()
72 XGCValues gcv;
73 XWindowAttributes xgwa;
75 XGetWindowAttributes (dpy, window, &xgwa);
77 cmap = xgwa.colormap;
79 gcv.function = GXxor;
80 gcv.foreground =
81 get_pixel_resource ("foreground", "Foreground", dpy, cmap);
82 draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
84 screen_resized(LCD_WIDTH, LCD_HEIGHT);
87 void screen_resized(int width, int height)
89 int maxx, maxy;
90 maxx = width;
91 maxy = height;
93 XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background",
94 dpy, cmap));
95 XFillRectangle(dpy, window, draw_gc, 0, 0, width*display_zoom, height*display_zoom);
96 lcd_display_redraw=true;
97 screen_redraw();
100 void drawrect(int color, int x1, int y1, int x2, int y2)
102 if (color==0) {
103 XSetForeground(dpy, draw_gc,
104 get_pixel_resource("background", "Background", dpy, cmap));
106 else
107 XSetForeground(dpy, draw_gc,
108 get_pixel_resource("foreground", "Foreground", dpy, cmap));
109 XFillRectangle(dpy, window, draw_gc, x1*display_zoom, y1*display_zoom,
110 x2*display_zoom, y2*display_zoom);
114 static void help(void)
116 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
117 "usage: " PROGNAME "\n"
121 void drawline(int color, int x1, int y1, int x2, int y2)
123 if (color==0) {
124 XSetForeground(dpy, draw_gc,
125 get_pixel_resource("background", "Background", dpy, cmap));
127 else
128 XSetForeground(dpy, draw_gc,
129 get_pixel_resource("foreground", "Foreground", dpy, cmap));
131 XDrawLine(dpy, window, draw_gc,
132 (int)(x1*display_zoom),
133 (int)(y1*display_zoom),
134 (int)(x2*display_zoom),
135 (int)(y2*display_zoom));
138 void drawdot(int color, int x, int y)
140 if (color==0) {
141 XSetForeground(dpy, draw_gc,
142 get_pixel_resource("background", "Background", dpy, cmap));
144 else
145 XSetForeground(dpy, draw_gc,
146 get_pixel_resource("foreground", "Foreground", dpy, cmap));
148 XFillRectangle(dpy, window, draw_gc, x*display_zoom, y*display_zoom,
149 display_zoom, display_zoom);
152 void drawdots(int color, struct coordinate *points, int count)
154 if (color==0) {
155 XSetForeground(dpy, draw_gc,
156 get_pixel_resource("background", "Background", dpy, cmap));
158 else
159 XSetForeground(dpy, draw_gc,
160 get_pixel_resource("foreground", "Foreground", dpy, cmap));
162 while (count--) {
163 XFillRectangle(dpy, window, draw_gc,
164 points[count].x*display_zoom,
165 points[count].y*display_zoom,
166 display_zoom,
167 display_zoom);
171 void drawrectangles(int color, struct rectangle *points, int count)
173 if (color==0) {
174 XSetForeground(dpy, draw_gc,
175 get_pixel_resource("background", "Background", dpy, cmap));
177 else
178 XSetForeground(dpy, draw_gc,
179 get_pixel_resource("foreground", "Foreground", dpy, cmap));
181 while (count--) {
182 XFillRectangle(dpy, window, draw_gc,
183 points[count].x*display_zoom,
184 points[count].y*display_zoom,
185 points[count].width*display_zoom,
186 points[count].height*display_zoom);
191 void drawtext(int color, int x, int y, char *text)
193 if (color==0) {
194 XSetForeground(dpy, draw_gc,
195 get_pixel_resource("background", "Background", dpy, cmap));
197 else
198 XSetForeground(dpy, draw_gc,
199 get_pixel_resource("foreground", "Foreground", dpy, cmap));
201 XDrawString(dpy, window, draw_gc, x*display_zoom, y*display_zoom, text, strlen(text));
204 /* this is where the applicaton starts */
205 extern void app_main(void);
207 void
208 screenhack (Display *the_dpy, Window the_window)
210 Bool helpme;
212 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */
213 helpme = get_boolean_resource ("help", "Boolean");
214 if(helpme) {
215 help();
217 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
219 dpy=the_dpy;
220 window=the_window;
222 init_window();
224 screen_redraw();
226 app_main();
229 void screen_redraw()
231 /* draw a border around the "Recorder" screen */
232 #define X1 0
233 #define Y1 0
234 #define X2 (LCD_WIDTH + MARGIN_X*2)
235 #define Y2 (LCD_HEIGHT + MARGIN_Y)
237 drawline(1, X1, Y1, X2, Y1);
238 drawline(1, X2, Y1, X2, Y2);
239 drawline(1, X1, Y2, X2, Y2);
240 drawline(1, X1, Y1, X1, Y2);
241 lcd_update();