Commit 42eb77c805abbee1837503e05483f51d96e01db4
1 parent
b9d67aab
add begining of BeOS graphic stuff. Not finish at this time
Showing
2 changed files
with
462 additions
and
0 deletions
Show diff stats
| 1 | + | |
| 2 | + | |
| 3 | +/* BeOS dedicated file */ | |
| 4 | + | |
| 5 | + | |
| 6 | +#include <assert.h> | |
| 7 | +#include <string.h> | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <stddef.h> | |
| 10 | +#include <stdlib.h> | |
| 11 | +#include <unistd.h> | |
| 12 | + | |
| 13 | +#include "../host_graph.h" | |
| 14 | +#include "vm.h" | |
| 15 | +#include "dependencies.h" | |
| 16 | +#include <Window.h> | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | +//U8 translate_keyboard_state(unsigned int state); | |
| 21 | +//U16 translate_keysym(KeySym); | |
| 22 | +//U8 translate_button_press_id(int button_number); /* 1, 2, 3 */ | |
| 23 | +//U8 translate_button_release_id(int button_number); | |
| 24 | + | |
| 25 | +//Display * the_display; | |
| 26 | +//Window the_root_window; | |
| 27 | +int the_window_depth; | |
| 28 | +int the_screen; | |
| 29 | +//Visual * the_visual; | |
| 30 | +//Colormap the_colormap; | |
| 31 | +//Atom wm_window_protocols[1]; | |
| 32 | + | |
| 33 | +void host_init_graphism(void) | |
| 34 | +{ | |
| 35 | +/* if ((the_display = XOpenDisplay("")) == NULL) | |
| 36 | + { | |
| 37 | + fprintf(stderr,"X server not available.\n"); | |
| 38 | + my_exit(1); | |
| 39 | + } | |
| 40 | + XSetCloseDownMode(the_display,RetainPermanent); | |
| 41 | + wm_window_protocols[0] = XInternAtom(the_display,"WM_DELETE_WINDOW",False); | |
| 42 | + | |
| 43 | + the_screen = XDefaultScreen(the_display); | |
| 44 | + the_root_window = XDefaultRootWindow(the_display); | |
| 45 | + the_window_depth = XDefaultDepth(the_display,the_screen); | |
| 46 | + the_root_gc = XCreateGC(the_display,the_root_window,0,0); | |
| 47 | + the_visual = XDefaultVisual(the_display,the_screen); | |
| 48 | + the_colormap = DefaultColormap(the_display,the_screen); | |
| 49 | + | |
| 50 | + * put the file descriptor of X display connection in the file descriptor's set waited | |
| 51 | + for input, so that we will be woken up by X events. * | |
| 52 | + FD_SET((unsigned int)ConnectionNumber(the_display),&descriptors_waited_for_input); | |
| 53 | + | |
| 54 | + XSetErrorHandler(error_handler_for_X); | |
| 55 | + XSetIOErrorHandler(fatal_error_handler_for_X); | |
| 56 | + */ | |
| 57 | +} | |
| 58 | + | |
| 59 | +BOOL host_sc_open_host_window(U32 xPos, U32 yPos, U32 wSize, U32 hSize, | |
| 60 | + char *title, BOOL transcientFlag, U32 * the_window, U32 * the_gc) | |
| 61 | +{ | |
| 62 | + BWindow * win; | |
| 63 | + | |
| 64 | + /* Create the (not yet mapped to screen) window. */ | |
| 65 | + win = new BWindow(BRect(xPos, yPos, wSize, hSize), title, B_BORDERED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0); | |
| 66 | + * the_window = (U32)win; | |
| 67 | + return TRUE; | |
| 68 | +} | |
| 69 | + | |
| 70 | +void host_sc_host_window_size(U32 window, int * wSize, int * hSize) | |
| 71 | +{ | |
| 72 | +BWindow * the_window = (BWindow *)window; | |
| 73 | +float w, h; | |
| 74 | + w = *wSize; | |
| 75 | + h = *hSize; | |
| 76 | + | |
| 77 | + the_window->ResizeTo(w, h); | |
| 78 | +} | |
| 79 | + | |
| 80 | +//Get size of bitmap | |
| 81 | +void host_pixmap_size(U32 pixmap, int * wSize, int * hSize) | |
| 82 | +{ | |
| 83 | +BBitmap * the_pixmap = (BBitmap*) pixmap; | |
| 84 | +BRect size; | |
| 85 | + | |
| 86 | + size = the_pixmap->Bounds(); | |
| 87 | + *wSize = (int)size.Width(); | |
| 88 | + *hSize = (int)size.Height(); | |
| 89 | +} | |
| 90 | + | |
| 91 | +void host_sc_show_host_window(U32 theWindow) | |
| 92 | +{ | |
| 93 | + ((BWindow *)theWindow)->Show(); | |
| 94 | +} | |
| 95 | + | |
| 96 | +void host_sc_hide_host_window(U32 theWindow) | |
| 97 | +{ | |
| 98 | + ((BWindow *)theWindow)->Hide(); | |
| 99 | +} | |
| 100 | + | |
| 101 | +void host_change_host_window_title(U32 theWindow, char * title) | |
| 102 | +{ | |
| 103 | + ((BWindow *)theWindow)->SetTitle(title); | |
| 104 | +} | |
| 105 | + | |
| 106 | +void host_sc_paint_rectangle(U32 handle, U32 gc, int x, int y, int w, int h, U32 color) | |
| 107 | +{ | |
| 108 | + BB | |
| 109 | + unsigned long xcolor = RGB_to_X(color); | |
| 110 | +// XSetForeground(the_display,(GC)gc,xcolor); | |
| 111 | +// XFillRectangle(the_display,(Window)handle,(GC)gc,x,y,w,h); | |
| 112 | +} | |
| 113 | + | |
| 114 | +/* buffer functions */ | |
| 115 | +void host_sc_paint_rectangle_to_buffer(U32 pixmap, int x, int y, int w, int h, U32 color) | |
| 116 | +{ | |
| 117 | + unsigned long xcolor = RGB_to_X(color); | |
| 118 | +// XSetForeground(the_display,(GC)the_root_gc,xcolor); | |
| 119 | +// XFillRectangle(the_display,(Drawable)pixmap,(GC)the_root_gc,x,y,w,h); | |
| 120 | +} | |
| 121 | + | |
| 122 | +void host_draw_pixel_to_buffer(U32 buffer, int x, int y, U32 color) | |
| 123 | +{ | |
| 124 | +// XSetForeground(the_display,the_root_gc,RGB_to_X(color)); | |
| 125 | +// XDrawPoint(the_display,buffer,the_root_gc,x,y); | |
| 126 | +} | |
| 127 | + | |
| 128 | +void host_paint_host_image_to_buffer(U32 src, U32 dest, int src_x, int src_y, | |
| 129 | + int src_w, int src_h, | |
| 130 | + int dest_x, int dest_y) | |
| 131 | +{ | |
| 132 | +/* XCopyArea(the_display, | |
| 133 | + (Pixmap)src, | |
| 134 | + (Pixmap)dest, | |
| 135 | + the_root_gc, | |
| 136 | + src_x,src_y,src_w,src_h,dest_x,dest_y); | |
| 137 | +*/ | |
| 138 | +} | |
| 139 | + | |
| 140 | +void host_paint_host_image(U32 window, U32 pixmap, int src_x, int src_y, | |
| 141 | + int src_w, int src_h, | |
| 142 | + int dest_x, int dest_y) | |
| 143 | +{ | |
| 144 | +// XCopyArea(the_display, | |
| 145 | +// (Pixmap)pixmap, | |
| 146 | +// (Window)window, | |
| 147 | +// the_root_gc, | |
| 148 | +// src_x, /* src_x */ | |
| 149 | +// src_y, /* src_y */ | |
| 150 | +// src_w, /* src_w */ | |
| 151 | +// src_h, /* src_h */ | |
| 152 | +// dest_x, /* dest_x */ | |
| 153 | +// dest_y); /* dest_y */ | |
| 154 | +} | |
| 155 | + | |
| 156 | + | |
| 157 | +U32 host_create_pixmap(U32 target_width, U32 target_height) | |
| 158 | +{ | |
| 159 | +BBitmap * bitmap = new BBitmap( | |
| 160 | +} | |
| 161 | + | |
| 162 | +void host_sc_screen_size(int *width, int *height) | |
| 163 | +{ | |
| 164 | + Window dummyw; | |
| 165 | + int dummy; | |
| 166 | + | |
| 167 | + XGetGeometry(the_display,the_root_window, | |
| 168 | + &dummyw,&dummy,&dummy,width,height,&dummy,&dummy); | |
| 169 | + | |
| 170 | +} | |
| 171 | + | |
| 172 | +void host_free_host_window(U32 ptr) | |
| 173 | +{ | |
| 174 | + free_event_queue(ptr); | |
| 175 | + XDestroyWindow(the_display,(Window)ptr); | |
| 176 | +} | |
| 177 | + | |
| 178 | +void host_free_host_pixmap(U32 ptr) | |
| 179 | +{ | |
| 180 | + XFreePixmap(the_display,(Pixmap)ptr); | |
| 181 | +} | |
| 182 | + | |
| 183 | +void host_free_host_gc(U32 ptr) | |
| 184 | +{ | |
| 185 | + XFreeGC(the_display,(GC)ptr); | |
| 186 | +} | |
| 187 | + | |
| 188 | +void host_paint_pixel_to(U32 dest, U32 x, U32 y, U32 color) | |
| 189 | +{ | |
| 190 | + XSetForeground(the_display,the_root_gc, color); | |
| 191 | + XDrawPoint(the_display, (Pixmap)dest, the_root_gc, x, y); | |
| 192 | +} | |
| 193 | + | |
| 194 | +void host_queue_host_window_events(void) | |
| 195 | +{ | |
| 196 | + XEvent the_event; | |
| 197 | + U32 R = 0; | |
| 198 | + U32 handle; | |
| 199 | + char buffer[20]; | |
| 200 | + KeySym key; | |
| 201 | + XComposeStatus cs; | |
| 202 | + | |
| 203 | + begin: | |
| 204 | + | |
| 205 | + if (XEventsQueued(the_display,QueuedAfterFlush) == 0) /* no event pending */ | |
| 206 | + { | |
| 207 | + if (R) | |
| 208 | + free_data_segment((U32 *)R,the_allocator); | |
| 209 | + return; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /* | |
| 213 | + 'HostWindowEvent' (see 'predefined.anubis') is a large type: | |
| 214 | + | |
| 215 | + offsets: 0 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
| 216 | + ---------------------------------------------------------------------------------------------------- | |
| 217 | + quit * ---> | cnt | 0 | | |
| 218 | + expose * ---> | cnt | 1 | | |
| 219 | + pointer_entering * ---> | cnt | 2 | | |
| 220 | + pointer_leaving * ---> | cnt | 3 | | |
| 221 | + key_down * ---> | cnt | 4 | s | k | | |
| 222 | + mouse_move * ---> | cnt | 5 | s | x | y | | |
| 223 | + mouse_click * ---> | cnt | 6 | s | c | x | y | | |
| 224 | + mouse_wheel * ---> | cnt | 7 | s | delta | x | y | | |
| 225 | + other events are never generated here | |
| 226 | + | |
| 227 | + We allocate a segment big enough for any alternative (4 words). | |
| 228 | + */ | |
| 229 | + if (R == 0) /* do not reallocate several times */ | |
| 230 | + if ((R = allocate_data_segment(5,the_allocator)) == 0) return; /* try next time */ | |
| 231 | + | |
| 232 | + XNextEvent(the_display,&the_event); | |
| 233 | + | |
| 234 | + switch(the_event.type) | |
| 235 | + { | |
| 236 | + case DestroyNotify: | |
| 237 | + ((U8 *)R)[4] = 0; /* quit */ | |
| 238 | + handle = the_event.xdestroywindow.window; | |
| 239 | + break; | |
| 240 | + | |
| 241 | + case Expose: | |
| 242 | + ((U8 *)R)[4] = 1; /* expose */ | |
| 243 | + handle = the_event.xexpose.window; | |
| 244 | + break; | |
| 245 | + | |
| 246 | + case MappingNotify: | |
| 247 | + XRefreshKeyboardMapping(&(the_event.xmapping)); | |
| 248 | + goto begin; | |
| 249 | + | |
| 250 | + case EnterNotify: | |
| 251 | + ((U8 *)R)[4] = 2; /* pointer_entering */ | |
| 252 | + handle = the_event.xcrossing.window; | |
| 253 | + break; | |
| 254 | + | |
| 255 | + case LeaveNotify: | |
| 256 | + ((U8 *)R)[4] = 3; /* pointer_leaving */ | |
| 257 | + handle = the_event.xcrossing.window; | |
| 258 | + break; | |
| 259 | + | |
| 260 | + case KeyPress: | |
| 261 | + ((U8 *)R)[4] = 4; /* key_down */ | |
| 262 | + ((U8 *)R)[5] = translate_keyboard_state(the_event.xkey.state); | |
| 263 | + XLookupString(&(the_event.xkey),buffer,20,&key,&cs); | |
| 264 | + *((U16 *)(((U8 *)R)+6)) = translate_keysym(key); | |
| 265 | + handle = the_event.xkey.window; | |
| 266 | + break; | |
| 267 | + | |
| 268 | + case MotionNotify: | |
| 269 | + ((U8 *)R)[4] = 5; /* mouse_move */ | |
| 270 | + ((U8 *)R)[5] = translate_keyboard_state(the_event.xmotion.state) ; | |
| 271 | + *((U32 *)(((U8 *)R)+6)) = (U32)(the_event.xmotion.x); | |
| 272 | + *((U32 *)(((U8 *)R)+10)) = (U32)(the_event.xmotion.y); | |
| 273 | + handle = the_event.xmotion.window; | |
| 274 | + break; | |
| 275 | + | |
| 276 | + case ButtonPress: | |
| 277 | + ((U8 *)R)[4] = 6; /* mouse_click */ | |
| 278 | + ((U8 *)R)[5] = translate_keyboard_state(the_event.xbutton.state) ; | |
| 279 | + ((U8 *)R)[6] = translate_button_press_id(the_event.xbutton.button); | |
| 280 | + *((U32 *)(((U8 *)R)+7)) = (U32)(the_event.xbutton.x); | |
| 281 | + *((U32 *)(((U8 *)R)+11)) = (U32)(the_event.xbutton.y); | |
| 282 | + handle = the_event.xbutton.window; | |
| 283 | + break; | |
| 284 | + | |
| 285 | + case ButtonRelease: | |
| 286 | + ((U8 *)R)[4] = 6; /* mouse_click */ | |
| 287 | + ((U8 *)R)[5] = translate_keyboard_state(the_event.xbutton.state) ; | |
| 288 | + ((U8 *)R)[6] = translate_button_release_id(the_event.xbutton.button); | |
| 289 | + *((U32 *)(((U8 *)R)+7)) = (U32)(the_event.xbutton.x); | |
| 290 | + *((U32 *)(((U8 *)R)+11)) = (U32)(the_event.xbutton.y); | |
| 291 | + handle = the_event.xbutton.window; | |
| 292 | + break; | |
| 293 | + | |
| 294 | + case ClientMessage: | |
| 295 | + if ((the_event.xclient.data.l[0] == wm_window_protocols[0])) | |
| 296 | + { | |
| 297 | + ((U8 *)R)[4] = 0; /* quit */ | |
| 298 | + handle = the_event.xclient.window; | |
| 299 | + break; | |
| 300 | + } | |
| 301 | + else | |
| 302 | + { | |
| 303 | + /* | |
| 304 | + printf("Client message: atom name: %s (%s %lu %lu %lu %lu)\n", | |
| 305 | + XGetAtomName(the_display,the_event.xclient.message_type), | |
| 306 | + XGetAtomName(the_display,(Atom)the_event.xclient.data.l[0]), | |
| 307 | + the_event.xclient.data.l[1], | |
| 308 | + the_event.xclient.data.l[2], | |
| 309 | + the_event.xclient.data.l[3], | |
| 310 | + the_event.xclient.data.l[4]); | |
| 311 | + fflush(stdout); | |
| 312 | + */ | |
| 313 | + goto begin; | |
| 314 | + } | |
| 315 | + | |
| 316 | + default: | |
| 317 | + //printf("Received event number %d \n", the_event.type); fflush(stdout); | |
| 318 | + goto begin; | |
| 319 | + } | |
| 320 | + /* at that point an event has been got from the host */ | |
| 321 | + queue_event(R,handle); | |
| 322 | + R = 0; | |
| 323 | + | |
| 324 | + goto begin; /* continue */ | |
| 325 | +} | |
| 326 | + | |
| 327 | +U8 host_translate_keyboard_state(unsigned int state) | |
| 328 | +{ | |
| 329 | + return ( !!(state&ShiftMask)) | | |
| 330 | + ((!!(state&ControlMask)) << 1) | | |
| 331 | + ((!!(state&Mod1Mask)) << 2) | | |
| 332 | + ((!!(state&Button1Mask)) << 3) | | |
| 333 | + ((!!(state&Button2Mask)) << 4) | | |
| 334 | + ((!!(state&Button3Mask)) << 4) ; | |
| 335 | +} | |
| 336 | + | |
| 337 | + | |
| 338 | +void host_begin_paint(U32 handle) | |
| 339 | +{ | |
| 340 | +} | |
| 341 | + | |
| 342 | +void host_end_paint(U32 handle) | |
| 343 | +{ | |
| 344 | +} | |
| 345 | + | |
| 346 | +void host_free_graphical_resources(void) | |
| 347 | +{ | |
| 348 | +} | |
| 349 | + | |
| 350 | +/* Internal use only */ | |
| 351 | + | |
| 352 | + | |
| 353 | +U16 translate_keysym(KeySym k) | |
| 354 | +{ | |
| 355 | + | |
| 356 | + /* standard ASCII */ | |
| 357 | + if (20 <= k && k <= 126) | |
| 358 | + return KK_char(k); | |
| 359 | + | |
| 360 | + switch (k) | |
| 361 | + { | |
| 362 | + /* accented letters */ | |
| 363 | + case XK_udiaeresis: return KK_char(129); /* u trema */ | |
| 364 | + case XK_eacute: return KK_char(130); /* e accute */ | |
| 365 | + case XK_acircumflex: return KK_char(131); /* a circumflex */ | |
| 366 | + case XK_adiaeresis: return KK_char(132); /* a trema */ | |
| 367 | + case XK_agrave: return KK_char(133); /* a grave */ | |
| 368 | + case XK_ccedilla: return KK_char(135); /* c cedilla */ | |
| 369 | + case XK_ecircumflex: return KK_char(136); /* e circumflex */ | |
| 370 | + case XK_ediaeresis: return KK_char(137); /* e trema */ | |
| 371 | + case XK_egrave: return KK_char(138); /* e grave */ | |
| 372 | + case XK_idiaeresis: return KK_char(139); /* i trema */ | |
| 373 | + case XK_icircumflex: return KK_char(140); /* i circumflex */ | |
| 374 | + case XK_ocircumflex: return KK_char(147); /* o circumflex */ | |
| 375 | + case XK_odiaeresis: return KK_char(148); /* o trema */ | |
| 376 | + case XK_ucircumflex: return KK_char(150); /* u circumflex */ | |
| 377 | + case XK_ugrave: return KK_char(151); /* u grave */ | |
| 378 | + | |
| 379 | + /* special keys */ | |
| 380 | + case XK_Left: return KK_special(KSK_left); | |
| 381 | + case XK_Right: return KK_special(KSK_right); | |
| 382 | + case XK_Up: return KK_special(KSK_up); | |
| 383 | + case XK_Down: return KK_special(KSK_down); | |
| 384 | + case XK_BackSpace: return KK_special(KSK_backspace); | |
| 385 | + case XK_Tab: return KK_special(KSK_tab); | |
| 386 | + case XK_Return: return KK_special(KSK_enter); | |
| 387 | + case XK_Escape: return KK_special(KSK_escape); | |
| 388 | + case XK_Delete: return KK_special(KSK_del); | |
| 389 | + case XK_Insert: return KK_special(KSK_insert); | |
| 390 | + case XK_Home: return KK_special(KSK_home); | |
| 391 | + case XK_End: return KK_special(KSK_end); | |
| 392 | + case XK_Prior: return KK_special(KSK_page_up); | |
| 393 | + case XK_Next: return KK_special(KSK_page_down); | |
| 394 | + case XK_F1: return KK_special(KSK_f1); | |
| 395 | + case XK_F2: return KK_special(KSK_f2); | |
| 396 | + case XK_F3: return KK_special(KSK_f3); | |
| 397 | + case XK_F4: return KK_special(KSK_f4); | |
| 398 | + case XK_F5: return KK_special(KSK_f5); | |
| 399 | + case XK_F6: return KK_special(KSK_f6); | |
| 400 | + case XK_F7: return KK_special(KSK_f7); | |
| 401 | + case XK_F8: return KK_special(KSK_f8); | |
| 402 | + case XK_F9: return KK_special(KSK_f9); | |
| 403 | + case XK_F10: return KK_special(KSK_f10); | |
| 404 | + | |
| 405 | + /* others */ | |
| 406 | + default: return KK_unknown; | |
| 407 | + } | |
| 408 | +} | |
| 409 | + | |
| 410 | +U8 translate_button_press_id(int button_number) /* 1, 2, 3 */ | |
| 411 | +{ | |
| 412 | + switch (button_number) | |
| 413 | + { | |
| 414 | + case 1: return MC_left_down; | |
| 415 | + case 2: return MC_middle_down; | |
| 416 | + default: return MC_right_down; | |
| 417 | + } | |
| 418 | +} | |
| 419 | + | |
| 420 | +U8 translate_button_release_id(int button_number) | |
| 421 | +{ | |
| 422 | + switch (button_number) | |
| 423 | + { | |
| 424 | + case 1: | |
| 425 | + return MC_left_up; | |
| 426 | + case 2: | |
| 427 | + return MC_middle_up; | |
| 428 | + default: | |
| 429 | + return MC_right_up; | |
| 430 | + } | |
| 431 | +} | |
| 432 | + | ... | ... |
| 1 | + | |
| 2 | +#ifndef __HOST_GRAPH_BEOS_H__ | |
| 3 | +#define __HOST_GRAPH_BEOS_H__ | |
| 4 | + | |
| 5 | +#include <Bitmap.h> | |
| 6 | +#include <time.h> | |
| 7 | + | |
| 8 | +typedef BBitmap HostImage; | |
| 9 | +typedef int BOOL; | |
| 10 | + | |
| 11 | +//extern Display * the_display; | |
| 12 | +//extern Window the_root_window; | |
| 13 | +//extern int the_window_depth; | |
| 14 | +//extern GC the_root_gc; | |
| 15 | + | |
| 16 | +#define the_event_mask (ButtonPressMask\ | |
| 17 | + |ButtonReleaseMask\ | |
| 18 | + |StructureNotifyMask\ | |
| 19 | + |KeyPressMask\ | |
| 20 | + |KeyReleaseMask\ | |
| 21 | + |KeymapStateMask\ | |
| 22 | + |EnterWindowMask\ | |
| 23 | + |LeaveWindowMask\ | |
| 24 | + |PointerMotionMask\ | |
| 25 | + |ButtonMotionMask\ | |
| 26 | + |ExposureMask) | |
| 27 | + | |
| 28 | + | |
| 29 | +#endif | |
| 30 | + | ... | ... |