From 42eb77c805abbee1837503e05483f51d96e01db4 Mon Sep 17 00:00:00 2001 From: David René Date: Tue, 16 Aug 2005 10:51:06 +0000 Subject: [PATCH] add begining of BeOS graphic stuff. Not finish at this time --- anubis_dev/vm/src/beos/host_graph.c | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ anubis_dev/vm/src/beos/host_graph_beos.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+), 0 deletions(-) create mode 100644 anubis_dev/vm/src/beos/host_graph.c create mode 100644 anubis_dev/vm/src/beos/host_graph_beos.h diff --git a/anubis_dev/vm/src/beos/host_graph.c b/anubis_dev/vm/src/beos/host_graph.c new file mode 100644 index 0000000..6518027 --- /dev/null +++ b/anubis_dev/vm/src/beos/host_graph.c @@ -0,0 +1,432 @@ + + +/* BeOS dedicated file */ + + +#include +#include +#include +#include +#include +#include + +#include "../host_graph.h" +#include "vm.h" +#include "dependencies.h" +#include + + + +//U8 translate_keyboard_state(unsigned int state); +//U16 translate_keysym(KeySym); +//U8 translate_button_press_id(int button_number); /* 1, 2, 3 */ +//U8 translate_button_release_id(int button_number); + +//Display * the_display; +//Window the_root_window; +int the_window_depth; +int the_screen; +//Visual * the_visual; +//Colormap the_colormap; +//Atom wm_window_protocols[1]; + +void host_init_graphism(void) +{ +/* if ((the_display = XOpenDisplay("")) == NULL) + { + fprintf(stderr,"X server not available.\n"); + my_exit(1); + } + XSetCloseDownMode(the_display,RetainPermanent); + wm_window_protocols[0] = XInternAtom(the_display,"WM_DELETE_WINDOW",False); + + the_screen = XDefaultScreen(the_display); + the_root_window = XDefaultRootWindow(the_display); + the_window_depth = XDefaultDepth(the_display,the_screen); + the_root_gc = XCreateGC(the_display,the_root_window,0,0); + the_visual = XDefaultVisual(the_display,the_screen); + the_colormap = DefaultColormap(the_display,the_screen); + + * put the file descriptor of X display connection in the file descriptor's set waited + for input, so that we will be woken up by X events. * + FD_SET((unsigned int)ConnectionNumber(the_display),&descriptors_waited_for_input); + + XSetErrorHandler(error_handler_for_X); + XSetIOErrorHandler(fatal_error_handler_for_X); + */ +} + +BOOL host_sc_open_host_window(U32 xPos, U32 yPos, U32 wSize, U32 hSize, + char *title, BOOL transcientFlag, U32 * the_window, U32 * the_gc) +{ + BWindow * win; + + /* Create the (not yet mapped to screen) window. */ + win = new BWindow(BRect(xPos, yPos, wSize, hSize), title, B_BORDERED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0); + * the_window = (U32)win; + return TRUE; +} + +void host_sc_host_window_size(U32 window, int * wSize, int * hSize) +{ +BWindow * the_window = (BWindow *)window; +float w, h; + w = *wSize; + h = *hSize; + + the_window->ResizeTo(w, h); +} + +//Get size of bitmap +void host_pixmap_size(U32 pixmap, int * wSize, int * hSize) +{ +BBitmap * the_pixmap = (BBitmap*) pixmap; +BRect size; + + size = the_pixmap->Bounds(); + *wSize = (int)size.Width(); + *hSize = (int)size.Height(); +} + +void host_sc_show_host_window(U32 theWindow) +{ + ((BWindow *)theWindow)->Show(); +} + +void host_sc_hide_host_window(U32 theWindow) +{ + ((BWindow *)theWindow)->Hide(); +} + +void host_change_host_window_title(U32 theWindow, char * title) +{ + ((BWindow *)theWindow)->SetTitle(title); +} + +void host_sc_paint_rectangle(U32 handle, U32 gc, int x, int y, int w, int h, U32 color) +{ + BB + unsigned long xcolor = RGB_to_X(color); +// XSetForeground(the_display,(GC)gc,xcolor); +// XFillRectangle(the_display,(Window)handle,(GC)gc,x,y,w,h); +} + +/* buffer functions */ +void host_sc_paint_rectangle_to_buffer(U32 pixmap, int x, int y, int w, int h, U32 color) +{ + unsigned long xcolor = RGB_to_X(color); +// XSetForeground(the_display,(GC)the_root_gc,xcolor); +// XFillRectangle(the_display,(Drawable)pixmap,(GC)the_root_gc,x,y,w,h); +} + +void host_draw_pixel_to_buffer(U32 buffer, int x, int y, U32 color) +{ +// XSetForeground(the_display,the_root_gc,RGB_to_X(color)); +// XDrawPoint(the_display,buffer,the_root_gc,x,y); +} + +void host_paint_host_image_to_buffer(U32 src, U32 dest, int src_x, int src_y, + int src_w, int src_h, + int dest_x, int dest_y) +{ +/* XCopyArea(the_display, + (Pixmap)src, + (Pixmap)dest, + the_root_gc, + src_x,src_y,src_w,src_h,dest_x,dest_y); +*/ +} + +void host_paint_host_image(U32 window, U32 pixmap, int src_x, int src_y, + int src_w, int src_h, + int dest_x, int dest_y) +{ +// XCopyArea(the_display, +// (Pixmap)pixmap, +// (Window)window, +// the_root_gc, +// src_x, /* src_x */ +// src_y, /* src_y */ +// src_w, /* src_w */ +// src_h, /* src_h */ +// dest_x, /* dest_x */ +// dest_y); /* dest_y */ +} + + +U32 host_create_pixmap(U32 target_width, U32 target_height) +{ +BBitmap * bitmap = new BBitmap( +} + +void host_sc_screen_size(int *width, int *height) +{ + Window dummyw; + int dummy; + + XGetGeometry(the_display,the_root_window, + &dummyw,&dummy,&dummy,width,height,&dummy,&dummy); + +} + +void host_free_host_window(U32 ptr) +{ + free_event_queue(ptr); + XDestroyWindow(the_display,(Window)ptr); +} + +void host_free_host_pixmap(U32 ptr) +{ + XFreePixmap(the_display,(Pixmap)ptr); +} + +void host_free_host_gc(U32 ptr) +{ + XFreeGC(the_display,(GC)ptr); +} + +void host_paint_pixel_to(U32 dest, U32 x, U32 y, U32 color) +{ + XSetForeground(the_display,the_root_gc, color); + XDrawPoint(the_display, (Pixmap)dest, the_root_gc, x, y); +} + +void host_queue_host_window_events(void) +{ + XEvent the_event; + U32 R = 0; + U32 handle; + char buffer[20]; + KeySym key; + XComposeStatus cs; + + begin: + + if (XEventsQueued(the_display,QueuedAfterFlush) == 0) /* no event pending */ + { + if (R) + free_data_segment((U32 *)R,the_allocator); + return; + } + + /* + 'HostWindowEvent' (see 'predefined.anubis') is a large type: + + offsets: 0 4 5 6 7 8 9 10 11 12 13 14 15 16 17 + ---------------------------------------------------------------------------------------------------- + quit * ---> | cnt | 0 | + expose * ---> | cnt | 1 | + pointer_entering * ---> | cnt | 2 | + pointer_leaving * ---> | cnt | 3 | + key_down * ---> | cnt | 4 | s | k | + mouse_move * ---> | cnt | 5 | s | x | y | + mouse_click * ---> | cnt | 6 | s | c | x | y | + mouse_wheel * ---> | cnt | 7 | s | delta | x | y | + other events are never generated here + + We allocate a segment big enough for any alternative (4 words). + */ + if (R == 0) /* do not reallocate several times */ + if ((R = allocate_data_segment(5,the_allocator)) == 0) return; /* try next time */ + + XNextEvent(the_display,&the_event); + + switch(the_event.type) + { + case DestroyNotify: + ((U8 *)R)[4] = 0; /* quit */ + handle = the_event.xdestroywindow.window; + break; + + case Expose: + ((U8 *)R)[4] = 1; /* expose */ + handle = the_event.xexpose.window; + break; + + case MappingNotify: + XRefreshKeyboardMapping(&(the_event.xmapping)); + goto begin; + + case EnterNotify: + ((U8 *)R)[4] = 2; /* pointer_entering */ + handle = the_event.xcrossing.window; + break; + + case LeaveNotify: + ((U8 *)R)[4] = 3; /* pointer_leaving */ + handle = the_event.xcrossing.window; + break; + + case KeyPress: + ((U8 *)R)[4] = 4; /* key_down */ + ((U8 *)R)[5] = translate_keyboard_state(the_event.xkey.state); + XLookupString(&(the_event.xkey),buffer,20,&key,&cs); + *((U16 *)(((U8 *)R)+6)) = translate_keysym(key); + handle = the_event.xkey.window; + break; + + case MotionNotify: + ((U8 *)R)[4] = 5; /* mouse_move */ + ((U8 *)R)[5] = translate_keyboard_state(the_event.xmotion.state) ; + *((U32 *)(((U8 *)R)+6)) = (U32)(the_event.xmotion.x); + *((U32 *)(((U8 *)R)+10)) = (U32)(the_event.xmotion.y); + handle = the_event.xmotion.window; + break; + + case ButtonPress: + ((U8 *)R)[4] = 6; /* mouse_click */ + ((U8 *)R)[5] = translate_keyboard_state(the_event.xbutton.state) ; + ((U8 *)R)[6] = translate_button_press_id(the_event.xbutton.button); + *((U32 *)(((U8 *)R)+7)) = (U32)(the_event.xbutton.x); + *((U32 *)(((U8 *)R)+11)) = (U32)(the_event.xbutton.y); + handle = the_event.xbutton.window; + break; + + case ButtonRelease: + ((U8 *)R)[4] = 6; /* mouse_click */ + ((U8 *)R)[5] = translate_keyboard_state(the_event.xbutton.state) ; + ((U8 *)R)[6] = translate_button_release_id(the_event.xbutton.button); + *((U32 *)(((U8 *)R)+7)) = (U32)(the_event.xbutton.x); + *((U32 *)(((U8 *)R)+11)) = (U32)(the_event.xbutton.y); + handle = the_event.xbutton.window; + break; + + case ClientMessage: + if ((the_event.xclient.data.l[0] == wm_window_protocols[0])) + { + ((U8 *)R)[4] = 0; /* quit */ + handle = the_event.xclient.window; + break; + } + else + { + /* + printf("Client message: atom name: %s (%s %lu %lu %lu %lu)\n", + XGetAtomName(the_display,the_event.xclient.message_type), + XGetAtomName(the_display,(Atom)the_event.xclient.data.l[0]), + the_event.xclient.data.l[1], + the_event.xclient.data.l[2], + the_event.xclient.data.l[3], + the_event.xclient.data.l[4]); + fflush(stdout); + */ + goto begin; + } + + default: + //printf("Received event number %d \n", the_event.type); fflush(stdout); + goto begin; + } + /* at that point an event has been got from the host */ + queue_event(R,handle); + R = 0; + + goto begin; /* continue */ +} + +U8 host_translate_keyboard_state(unsigned int state) +{ + return ( !!(state&ShiftMask)) | + ((!!(state&ControlMask)) << 1) | + ((!!(state&Mod1Mask)) << 2) | + ((!!(state&Button1Mask)) << 3) | + ((!!(state&Button2Mask)) << 4) | + ((!!(state&Button3Mask)) << 4) ; +} + + +void host_begin_paint(U32 handle) +{ +} + +void host_end_paint(U32 handle) +{ +} + +void host_free_graphical_resources(void) +{ +} + +/* Internal use only */ + + +U16 translate_keysym(KeySym k) +{ + + /* standard ASCII */ + if (20 <= k && k <= 126) + return KK_char(k); + + switch (k) + { + /* accented letters */ + case XK_udiaeresis: return KK_char(129); /* u trema */ + case XK_eacute: return KK_char(130); /* e accute */ + case XK_acircumflex: return KK_char(131); /* a circumflex */ + case XK_adiaeresis: return KK_char(132); /* a trema */ + case XK_agrave: return KK_char(133); /* a grave */ + case XK_ccedilla: return KK_char(135); /* c cedilla */ + case XK_ecircumflex: return KK_char(136); /* e circumflex */ + case XK_ediaeresis: return KK_char(137); /* e trema */ + case XK_egrave: return KK_char(138); /* e grave */ + case XK_idiaeresis: return KK_char(139); /* i trema */ + case XK_icircumflex: return KK_char(140); /* i circumflex */ + case XK_ocircumflex: return KK_char(147); /* o circumflex */ + case XK_odiaeresis: return KK_char(148); /* o trema */ + case XK_ucircumflex: return KK_char(150); /* u circumflex */ + case XK_ugrave: return KK_char(151); /* u grave */ + + /* special keys */ + case XK_Left: return KK_special(KSK_left); + case XK_Right: return KK_special(KSK_right); + case XK_Up: return KK_special(KSK_up); + case XK_Down: return KK_special(KSK_down); + case XK_BackSpace: return KK_special(KSK_backspace); + case XK_Tab: return KK_special(KSK_tab); + case XK_Return: return KK_special(KSK_enter); + case XK_Escape: return KK_special(KSK_escape); + case XK_Delete: return KK_special(KSK_del); + case XK_Insert: return KK_special(KSK_insert); + case XK_Home: return KK_special(KSK_home); + case XK_End: return KK_special(KSK_end); + case XK_Prior: return KK_special(KSK_page_up); + case XK_Next: return KK_special(KSK_page_down); + case XK_F1: return KK_special(KSK_f1); + case XK_F2: return KK_special(KSK_f2); + case XK_F3: return KK_special(KSK_f3); + case XK_F4: return KK_special(KSK_f4); + case XK_F5: return KK_special(KSK_f5); + case XK_F6: return KK_special(KSK_f6); + case XK_F7: return KK_special(KSK_f7); + case XK_F8: return KK_special(KSK_f8); + case XK_F9: return KK_special(KSK_f9); + case XK_F10: return KK_special(KSK_f10); + + /* others */ + default: return KK_unknown; + } +} + +U8 translate_button_press_id(int button_number) /* 1, 2, 3 */ +{ + switch (button_number) + { + case 1: return MC_left_down; + case 2: return MC_middle_down; + default: return MC_right_down; + } +} + +U8 translate_button_release_id(int button_number) +{ + switch (button_number) + { + case 1: + return MC_left_up; + case 2: + return MC_middle_up; + default: + return MC_right_up; + } +} + diff --git a/anubis_dev/vm/src/beos/host_graph_beos.h b/anubis_dev/vm/src/beos/host_graph_beos.h new file mode 100644 index 0000000..3a4f28f --- /dev/null +++ b/anubis_dev/vm/src/beos/host_graph_beos.h @@ -0,0 +1,30 @@ + +#ifndef __HOST_GRAPH_BEOS_H__ +#define __HOST_GRAPH_BEOS_H__ + +#include +#include + +typedef BBitmap HostImage; +typedef int BOOL; + +//extern Display * the_display; +//extern Window the_root_window; +//extern int the_window_depth; +//extern GC the_root_gc; + +#define the_event_mask (ButtonPressMask\ + |ButtonReleaseMask\ + |StructureNotifyMask\ + |KeyPressMask\ + |KeyReleaseMask\ + |KeymapStateMask\ + |EnterWindowMask\ + |LeaveWindowMask\ + |PointerMotionMask\ + |ButtonMotionMask\ + |ExposureMask) + + +#endif + -- libgit2 0.21.4