Mercurial > sdl-ios-xcode
changeset 320:66f815c147ed
Date: Thu, 28 Mar 2002 09:20:03 +0200
From: "Mike Gorchak" <mike@malva.ua>
Subject: New QNX patch.
Hi !
1. Removed warning (possible bug) with invalid type, passing to the function
in ph_WarpedMotion.
2. Rewritten handler of Ph_WM_RESIZE message, now works, but buggy (old
handler doesn't work at all).
3. Added stub handler for Ph_WM_MAX (maximize) message.
4. Added more #ifdef HAVE_OPENGL to disable OpenGL stuff when it not needed.
5. Added support for SDL_NOFRAME and SDL_RESIZABLE flags (in OpenGL windows
too).
6. Added cosmetic changes, if no SDL_RESIZABLE flag defined, disable resize
handlers in window border and maximize button at caption.
7. Fixed my bug with invalid arguments count passed to PtCreateWidget call.
8. Fixed some palette problems.
9. Updated README.QNX file.
And I changed testgl.c test application:
10. Added in testgl.c application support for SDL_NOFRAME flag and
option -noframe.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 28 Mar 2002 16:20:10 +0000 |
parents | 189a6a3416c7 |
children | af42e7c4c860 |
files | README.QNX src/video/photon/SDL_ph_events.c src/video/photon/SDL_ph_video.c test/testgl.c |
diffstat | 4 files changed, 244 insertions(+), 212 deletions(-) [+] |
line wrap: on
line diff
--- a/README.QNX Tue Mar 26 17:37:31 2002 +0000 +++ b/README.QNX Thu Mar 28 16:20:10 2002 +0000 @@ -7,10 +7,11 @@ of OS before 6.1.0 are not supported. Problems: -1. While creating OpenGL context artificially selected software - renderer mode (QSSL made acceleration only for Voodoo boards - in fullscreen mode, sorry but I don't have this board, if you - want acceleration - you may remove some line in source). +1. While creating OpenGL context software renderer mode is + artificially selected (QSSL made acceleration only for Voodoo + boards in fullscreen mode, sorry but I don't have this board, + if you want acceleration - you may remove some line in source + code). 2. Photon has some errors in detecting how much bits per pixel videomode has. 3. No shared libraries yet. We need manually set flag to @@ -31,7 +32,8 @@ --disable-shared \ --disable-video-opengl - In test directory also run ./configure script without x11 support, e.g.: + In test directory also run ./configure script without x11 +support, e.g.: ./configure --with-sdl-prefix=/usr/local \ --with-sdl-exec-prefix=/usr/local \
--- a/src/video/photon/SDL_ph_events.c Tue Mar 26 17:37:31 2002 +0000 +++ b/src/video/photon/SDL_ph_events.c Thu Mar 28 16:20:10 2002 +0000 @@ -74,7 +74,7 @@ (peekevent->timestamp == event->timestamp) ) { repeated = 1; - //PhEventNext( peekevent, EVENT_SIZE ); + /* PhEventNext( peekevent, EVENT_SIZE ); */ } } } @@ -85,7 +85,7 @@ } break; - default: // no events pending + default: /* no events pending */ } return(repeated); } @@ -93,11 +93,12 @@ static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) { - PhPointerEvent_t *pointer = PhGetData( winEvent ); +/* PhPointerEvent_t *pointer = PhGetData( winEvent ); */ PhRect_t *rect = PhGetRects( winEvent ); int centre_x, centre_y; - int dx, dy, abs_x, abs_y; + int dx, dy; + short abs_x, abs_y; int posted; centre_x = SDL_VideoSurface->w / 2; @@ -155,177 +156,168 @@ static int ph_DispatchEvent(_THIS) { - int posted; - PhRect_t* rect; - PhPointerEvent_t* pointerEvent; - PhKeyEvent_t* keyEvent; - PhWindowEvent_t* winEvent; - int i, buttons; - SDL_Rect sdlrects[50]; + int posted; + PhRect_t* rect; + PhPointerEvent_t* pointerEvent; + PhKeyEvent_t* keyEvent; + PhWindowEvent_t* winEvent; + int i, buttons; + SDL_Rect sdlrects[50]; - posted = 0; + posted = 0; - switch (event->type) { - case Ph_EV_BOUNDARY: - { - if (event->subtype == Ph_EV_PTR_ENTER) - posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); - else if (event->subtype ==Ph_EV_PTR_LEAVE) - posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); - } - break; + switch (event->type) + { + case Ph_EV_BOUNDARY: + { + if (event->subtype == Ph_EV_PTR_ENTER) + { + posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); + } + else if (event->subtype ==Ph_EV_PTR_LEAVE) + { + posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); + } + } + break; + + case Ph_EV_PTR_MOTION_BUTTON: + case Ph_EV_PTR_MOTION_NOBUTTON: + { + if (SDL_VideoSurface) + { + pointerEvent = PhGetData(event); + rect = PhGetRects(event); - case Ph_EV_PTR_MOTION_BUTTON: - case Ph_EV_PTR_MOTION_NOBUTTON: - { - if ( SDL_VideoSurface ) { - pointerEvent = PhGetData( event ); - rect = PhGetRects( event ); - if( mouse_relative ) - { - posted = ph_WarpedMotion(this, event); - } - else - posted = SDL_PrivateMouseMotion(0, 0, - rect->ul.x, rect->ul.y); - } - } - break; + if (mouse_relative) + { + posted = ph_WarpedMotion(this, event); + } + else + { + posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y); + } + } + } + break; - case Ph_EV_BUT_PRESS: + case Ph_EV_BUT_PRESS: + { + pointerEvent = PhGetData( event ); + buttons = ph2sdl_mousebutton( pointerEvent->buttons ); + if (buttons != 0) + { + posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0); + } + } + break; + + case Ph_EV_BUT_RELEASE: + { + pointerEvent = PhGetData(event); + buttons = ph2sdl_mousebutton(pointerEvent->buttons); + if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0) + { + posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); + } + else if(event->subtype == Ph_EV_RELEASE_PHANTOM) + { + /* If the mouse is outside the window, + * only a phantom release event is sent, so + * check if the window doesn't have mouse focus. + * Not perfect, maybe checking the mouse button + * state for Ph_EV_BOUNDARY events would be + * better. */ + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) { - pointerEvent = PhGetData( event ); - buttons = ph2sdl_mousebutton( pointerEvent->buttons ); - if( buttons != 0 ) - posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons, - 0, 0 ); - } - break; - - case Ph_EV_BUT_RELEASE: - { - pointerEvent = PhGetData(event); - buttons = ph2sdl_mousebutton(pointerEvent->buttons); - if( event->subtype == Ph_EV_RELEASE_REAL && - buttons != 0 ) - { - posted = SDL_PrivateMouseButton( SDL_RELEASED, - buttons, 0, 0 ); - } - else if( event->subtype == Ph_EV_RELEASE_PHANTOM ) - { - /* If the mouse is outside the window, - * only a phantom release event is sent, so - * check if the window doesn't have mouse focus. - * Not perfect, maybe checking the mouse button - * state for Ph_EV_BOUNDARY events would be - * better. */ - if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 ) - { - posted = SDL_PrivateMouseButton( SDL_RELEASED, - buttons, 0, 0 ); - } - } - } - break; - - case Ph_EV_WM: - { - winEvent = PhGetData( event ); - - /* losing focus */ - if ((winEvent->event_f==Ph_WM_FOCUS)&& - (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) - { - set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); - posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); + posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); + } + } + } + break; - /* Queue leaving fullscreen mode */ - switch_waiting = 0x01; - switch_time = SDL_GetTicks() + 200; - } + case Ph_EV_WM: + { + winEvent = PhGetData(event); - /* gaining focus */ - else if ((winEvent->event_f==Ph_WM_FOCUS)&& - (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) - { - set_motion_sensitivity(this, -1); - posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); -#if 0 - /* Queue entry into fullscreen mode */ - switch_waiting = 0x01 | SDL_FULLSCREEN; - switch_time = SDL_GetTicks() + 1500; -#endif - } + /* losing focus */ + if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) + { + set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); + posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); - /* request to quit */ - else if (winEvent->event_f==Ph_WM_CLOSE) - { - posted = SDL_PrivateQuit(); - } - else if (winEvent->event_f==Ph_WM_RESIZE) - { - PhDim_t *size; - - PtGetResource( window, Pt_ARG_DIM, &size, 0 ); - SDL_PrivateResize(size->w,size->h); - } - } - break; - - /* window has been resized, moved or removed */ - case Ph_EV_EXPOSE: - { - if (SDL_VideoSurface) - { - rect = PhGetRects( event ); + /* Queue leaving fullscreen mode */ + switch_waiting = 0x01; + switch_time = SDL_GetTicks() + 200; + } + /* gaining focus */ + else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) + { + set_motion_sensitivity(this, -1); + posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); + } + /* request to quit */ + else if (winEvent->event_f==Ph_WM_CLOSE) + { + posted = SDL_PrivateQuit(); + } + /* request to resize */ + else if (winEvent->event_f==Ph_WM_RESIZE) + { + SDL_PrivateResize(winEvent->size.w, winEvent->size.h); + } + /* request to maximize */ + else if (winEvent->event_f==Ph_WM_MAX) + { + /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */ + } + } + break; - //PgSetClipping(1, rect ); - for(i=0;i<event->num_rects;i++) - { - sdlrects[i].x = rect[i].ul.x; - sdlrects[i].y = rect[i].ul.y; - sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; - sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; - } + /* window has been resized, moved or removed */ + case Ph_EV_EXPOSE: + { + if (SDL_VideoSurface) + { + rect = PhGetRects(event); - this->UpdateRects(this, event->num_rects, sdlrects); + for(i=0;i<event->num_rects;i++) + { + sdlrects[i].x = rect[i].ul.x; + sdlrects[i].y = rect[i].ul.y; + sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; + sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; + } - } - } - break; + this->UpdateRects(this, event->num_rects, sdlrects); + } + } + break; - case Ph_EV_KEY: - { - - SDL_keysym keysym; - - posted = 0; - - keyEvent = PhGetData( event ); + case Ph_EV_KEY: + { + SDL_keysym keysym; + + posted = 0; + + keyEvent = PhGetData( event ); - if (Pk_KF_Key_Down & keyEvent->key_flags) - { - - posted = SDL_PrivateKeyboard(SDL_PRESSED, - ph_TranslateKey( keyEvent, &keysym)); - } - else /* must be key release */ - { - /* Ignore repeated key release events */ - /*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/ - - posted = SDL_PrivateKeyboard(SDL_RELEASED, - ph_TranslateKey( keyEvent, &keysym)); - /*}*/ - } - } - break; - } - - - - return(posted); + if (Pk_KF_Key_Down & keyEvent->key_flags) + { + posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym)); + } + else /* must be key release */ + { + /* Ignore repeated key release events */ + /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */ + + posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym)); + } + } + break; + } + + return(posted); } /* perform a blocking read if no events available */
--- a/src/video/photon/SDL_ph_video.c Tue Mar 26 17:37:31 2002 +0000 +++ b/src/video/photon/SDL_ph_video.c Thu Mar 28 16:20:10 2002 +0000 @@ -175,15 +175,14 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) { - int i; - unsigned long *tempptr; - int rtnval; PgVideoModeInfo_t my_mode_info; PgHWCaps_t my_hwcaps; window=NULL; + desktoppal=SDLPH_PAL_NONE; +#ifdef HAVE_OPENGL oglctx=NULL; - desktoppal=SDLPH_PAL_NONE; +#endif /* HAVE_OPENGL */ captionflag=0; old_video_mode=-1; @@ -218,31 +217,13 @@ vformat->BitsPerPixel = my_mode_info.bits_per_pixel; vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; desktopbpp = my_mode_info.bits_per_pixel; - - /* return a palette if we are in 256 color mode */ - if (vformat->BitsPerPixel == 8) + + /* save current palette */ + if (desktopbpp==8) { - vformat->palette = malloc(sizeof(SDL_Palette)); - memset(vformat->palette, 0, sizeof(SDL_Palette)); - vformat->palette->ncolors = 256; - vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); - - /* fill the palette */ - rtnval = PgGetPalette(ph_palette); - if (rtnval < 0) - { - fprintf(stderr, "ph_VideoInit: PgGetPalette failed\n"); - } - - tempptr = (unsigned long *)vformat->palette->colors; - - for(i=0;i<256; i++) - { - *tempptr = (((unsigned long)ph_palette[i]) << 8); - tempptr++; - } + PgGetPalette(ph_palette); } - + currently_fullscreen = 0; this->info.wm_available = 1; @@ -268,6 +249,8 @@ /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); + current->flags = flags; + /* create window if no OpenGL support selected */ if ((flags & SDL_OPENGL)!=SDL_OPENGL) { @@ -276,6 +259,34 @@ PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0); PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); + /* enable window minimizing */ + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); + + /* remove border and caption if no frame flag selected */ + if ((flags & SDL_NOFRAME) == SDL_NOFRAME) + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + else + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + + /* if window is not resizable then remove resize handles and maximize button */ + if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + } + else + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); + /* it is need to be Pt_FALSE to allow the application to process the resize callback */ + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX); + } + if (window!=NULL) { PtUnrealizeWidget(window); @@ -283,7 +294,7 @@ window=NULL; } - window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); + window=PtCreateWidget(PtWindow, NULL, pargc, arg); PtRealizeWidget(window); PtFlush(); @@ -295,7 +306,6 @@ /* ph_SetupOpenGLContext creates also window as need */ if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) { - current->flags=flags; /* setup OGL update function ... ugly method */ ph_ResizeImage(this, current, flags); } @@ -363,15 +373,13 @@ } /* end fullscreen flag */ else { - if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ + /* Use offscreen memory iff SDL_HWSURFACE flag is set */ + if (flags & SDL_HWSURFACE) { - /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */ - current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ + /* no stretch blit in offscreen context */ + current->flags = (flags & (~SDL_RESIZABLE)); } - else /* must be SDL_SWSURFACE */ - { - current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */ - } + /* using palette emulation code in window mode */ if (bpp==8) { @@ -425,6 +433,9 @@ ph_SetCaption(this, this->wm_title, NULL); } + /* finish window drawing */ + PtFlush(); + SDL_Unlock_EventThread(); /* We're done! */ @@ -433,7 +444,9 @@ static void ph_VideoQuit(_THIS) { +#ifdef HAVE_OPENGL PhRegion_t region_info; +#endif /* HAVE_OPENGL */ ph_DestroyImage(this, SDL_VideoSurface); @@ -443,7 +456,7 @@ } #ifdef HAVE_OPENGL - /* prevent double SEGFAULT with parachute mode */ + /* prevent double SEGFAULT during parachute mode */ if (this->screen) { if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && @@ -518,14 +531,14 @@ if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { /* window mode must use soft palette */ - PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); + PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); /* image needs to be redrawed, very slow method */ PgDrawPhImage(&point, SDL_Image, 0); } else { /* fullscreen mode must use hardware palette */ - PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); + PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); } } else @@ -586,9 +599,10 @@ { oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); } + if (oglctx==NULL) { - fprintf(stderr,"error: cannot create OpenGL context.\n"); + fprintf(stderr,"ph_SetupOpenGLContext: cannot create OpenGL context.\n"); return (-1); } @@ -608,10 +622,26 @@ pos.y=0; PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0); - PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS); PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0); } + else + { + /* remove border and caption if no frame flag selected */ + if ((flags & SDL_NOFRAME) == SDL_NOFRAME) + { + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + else + { + /* if window is not resizable then remove resize handles */ + if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) + { + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE); + } + } + } if (window!=NULL) { @@ -620,7 +650,7 @@ window=NULL; } - window=PtCreateWidget(PtWindow, NULL, pargc-1, args); + window=PtCreateWidget(PtWindow, NULL, pargc, args); PtRealizeWidget(window); /* disable mouse for fullscreen */
--- a/test/testgl.c Tue Mar 26 17:37:31 2002 +0000 +++ b/test/testgl.c Thu Mar 28 16:20:10 2002 +0000 @@ -393,7 +393,7 @@ } int RunGLTest( int argc, char* argv[], - int logo, int slowly, int bpp, float gamma ) + int logo, int slowly, int bpp, float gamma, int noframe ) { int i; int rgb_size[3]; @@ -447,6 +447,10 @@ } } + if (noframe) { + video_flags |= SDL_NOFRAME; + } + /* Initialize the display */ switch (bpp) { case 8: @@ -686,6 +690,7 @@ int bpp = 0; int slowly; float gamma = 0.0; + int noframe = 0; logo = 0; slowly = 0; @@ -711,15 +716,18 @@ if ( strcmp(argv[i], "-gamma") == 0 ) { gamma = (float)atof(argv[++i]); } + if ( strcmp(argv[i], "-noframe") == 0 ) { + noframe = 1; + } if ( strncmp(argv[i], "-h", 2) == 0 ) { printf( -"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n", +"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe]\n", argv[0]); exit(0); } } for ( i=0; i<numtests; ++i ) { - RunGLTest(argc, argv, logo, slowly, bpp, gamma); + RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe); } return 0; }