comparison src/video/photon/SDL_photon.c @ 3115:1102a3305928

Added handler for all window events.
author Mike Gorchak <lestat@i.com.ua>
date Tue, 05 May 2009 17:47:41 +0000
parents aa1897bee1e9
children 7f684f249ec9
comparison
equal deleted inserted replaced
3114:979164e58723 3115:1102a3305928
565 { 565 {
566 SDL_SetError("Photon: Can't get video mode list"); 566 SDL_SetError("Photon: Can't get video mode list");
567 return; 567 return;
568 } 568 }
569 569
570 /* Current display dimensions and bpp are no more valid */ 570 /* Current display dimension and bpp are no more valid */
571 didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN; 571 didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
572 didata->current_mode.w=0; 572 didata->current_mode.w=0;
573 didata->current_mode.h=0; 573 didata->current_mode.h=0;
574 574
575 /* Check if custom refresh rate requested */ 575 /* Check if custom refresh rate requested */
792 /* TODO: handle SDL_WINDOW_INPUT_GRABBED */ 792 /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
793 793
794 /* Disable default window filling on redraw */ 794 /* Disable default window filling on redraw */
795 PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL); 795 PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
796 796
797 /* Set default maximum and minimum window sizes */ 797 /* Reset default managed flags to disabled state */
798 winsize.w=0;
799 winsize.h=0;
800 PtSetArg(&winargs[winargc++], Pt_ARG_MAX_HEIGHT, 0, 0);
801 PtSetArg(&winargs[winargc++], Pt_ARG_MAX_WIDTH, 0, 0);
802 PtSetArg(&winargs[winargc++], Pt_ARG_MIN_HEIGHT, 0, 0);
803 PtSetArg(&winargs[winargc++], Pt_ARG_MIN_WIDTH, 0, 0);
804 PtSetArg(&winargs[winargc++], Pt_ARG_MAXIMUM_DIM, &winsize, 0);
805 PtSetArg(&winargs[winargc++], Pt_ARG_MINIMUM_DIM, &winsize, 0);
806
807 /* Reset default managed events to disable */
808 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, 798 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
809 Ph_WM_APP_DEF_MANAGED); 799 Ph_WM_APP_DEF_MANAGED);
810 /* Set which events we will not handle, let WM to handle them */ 800 /* Set which events we will not handle, let WM to handle them */
811 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, 801 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
812 Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT | 802 Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT |
813 Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX | 803 Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX |
814 Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | 804 Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR |
815 Ph_WM_TASKBAR | Ph_WM_TOBACK); 805 Ph_WM_TOBACK | Ph_WM_RESIZE);
816 806
817 /* Reset default notify events to disable */ 807 /* Reset default notify events to disable */
818 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, 808 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
819 Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP); 809 Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
820 /* Set which events we will handle */ 810 /* Set which events we will handle */
845 Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE; 835 Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
846 836
847 if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE) 837 if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
848 { 838 {
849 decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX; 839 decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
840 PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
850 } 841 }
851 if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS) 842 if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS)
852 { 843 {
853 decorations|=Ph_WM_RENDER_BORDER; 844 decorations|=Ph_WM_RENDER_BORDER;
854 } 845 }
857 848
858 /* Set initial window state */ 849 /* Set initial window state */
859 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS); 850 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS);
860 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY); 851 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
861 852
862 /* Set window dimensions */ 853 /* Set window dimension */
863 winsize.w=window->w; 854 winsize.w=window->w;
864 winsize.h=window->h; 855 winsize.h=window->h;
865 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0); 856 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
866 857
867 /* Check if upper level requests WM to position window */ 858 /* Check if upper level requests WM to position window */
891 /* Now set window position */ 882 /* Now set window position */
892 winpos.x=window->x; 883 winpos.x=window->x;
893 winpos.y=window->y; 884 winpos.y=window->y;
894 PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0); 885 PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
895 } 886 }
896
897 /* Add SDL window id as user data */
898 PtSetArg(&winargs[winargc++], Pt_ARG_POINTER, (void*)window->id, 0);
899 887
900 /* Check if window must support OpenGL ES rendering */ 888 /* Check if window must support OpenGL ES rendering */
901 if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL) 889 if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
902 { 890 {
903 #if defined(SDL_VIDEO_OPENGL_ES) 891 #if defined(SDL_VIDEO_OPENGL_ES)
1895 { 1883 {
1896 #if defined(SDL_VIDEO_OPENGL_ES) 1884 #if defined(SDL_VIDEO_OPENGL_ES)
1897 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1885 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
1898 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; 1886 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1899 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 1887 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
1900 PhRect_t* dst_rect; 1888 PhRect_t dst_rect;
1901 PhRect_t src_rect; 1889 PhRect_t src_rect;
1902 1890
1903 if (phdata->gfinitialized!=SDL_TRUE) 1891 if (phdata->gfinitialized!=SDL_TRUE)
1904 { 1892 {
1905 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1893 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
1919 /* to enter to the Direct mode to call PgWaitVSync() */ 1907 /* to enter to the Direct mode to call PgWaitVSync() */
1920 gf_display_wait_vsync(didata->display); 1908 gf_display_wait_vsync(didata->display);
1921 } 1909 }
1922 1910
1923 /* Set blit area */ 1911 /* Set blit area */
1924 dst_rect=PtGetCanvas(wdata->window); 1912 dst_rect=*PtGetCanvas(wdata->window);
1925 src_rect.ul.x=0; 1913 src_rect.ul.x=0;
1926 src_rect.ul.y=0; 1914 src_rect.ul.y=0;
1927 src_rect.lr.x=window->w-1; 1915 src_rect.lr.x=window->w-1;
1928 src_rect.lr.y=window->h-1; 1916 src_rect.lr.y=window->h-1;
1929 1917
1930 /* Blit OpenGL ES pixmap surface directly to window region */ 1918 /* Blit OpenGL ES pixmap surface directly to window region */
1931 PgFFlush(Ph_START_DRAW); 1919 PgFFlush(Ph_START_DRAW);
1932 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); 1920 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
1933 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent())); 1921 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
1934 PgContextBlit(wdata->phsurface, &src_rect, NULL, dst_rect); 1922 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
1935 PgFFlush(Ph_DONE_DRAW); 1923 PgFFlush(Ph_DONE_DRAW);
1936 PgWaitHWIdle(); 1924 PgWaitHWIdle();
1937 1925
1938 eglSwapBuffers(phdata->egldisplay, wdata->gles_surface); 1926 eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
1939 #else 1927 #else
2023 } 2011 }
2024 } 2012 }
2025 if (status==0) 2013 if (status==0)
2026 { 2014 {
2027 window=NULL; 2015 window=NULL;
2016 wdata=NULL;
2028 } 2017 }
2029 2018
2030 /* Event is ready */ 2019 /* Event is ready */
2031 switch(event->type) 2020 switch(event->type)
2032 { 2021 {
2195 if (rects==NULL) 2184 if (rects==NULL)
2196 { 2185 {
2197 break; 2186 break;
2198 } 2187 }
2199 2188
2200 /* Cycle through each rectangle */ 2189 /* Check if expose come to one of the our windows */
2201 for (it=0; it<event->num_rects; it++) 2190 if ((wdata!=NULL) && (window!=NULL))
2202 { 2191 {
2203 /* TODO: update the damaged rectangles */ 2192 /* Check if window uses OpenGL ES */
2193 if (wdata->uses_gles==SDL_TRUE)
2194 {
2195 PhRect_t dst_rect;
2196 PhRect_t src_rect;
2197
2198 /* Cycle through each rectangle */
2199 for (it=0; it<event->num_rects; it++)
2200 {
2201 /* Blit OpenGL ES pixmap surface directly to window region */
2202 PgFFlush(Ph_START_DRAW);
2203 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
2204 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
2205 PgContextBlit(wdata->phsurface, &rects[it], NULL, &rects[it]);
2206 PgFFlush(Ph_DONE_DRAW);
2207 PgWaitHWIdle();
2208 }
2209 }
2210 else
2211 {
2212 /* Normal window */
2213 /* TODO: update the damaged rectangles */
2214 }
2204 } 2215 }
2205 2216
2206 /* Flush all blittings */ 2217 /* Flush all blittings */
2207 PgFlush(); 2218 PgFlush();
2208 } 2219 }
2209 break; 2220 break;
2210 case Ph_CAPTURE_EXPOSE: 2221 case Ph_CAPTURE_EXPOSE:
2211 { 2222 {
2212 /* We need to redraw entire screen */ 2223 /* Check if expose come to one of the our windows */
2213 PgFFlush(Ph_START_DRAW); 2224 if ((wdata!=NULL) && (window!=NULL))
2214 2225 {
2215 /* TODO: redraw the whole screen */ 2226 /* Check if window uses OpenGL ES */
2216 2227 if (wdata->uses_gles==SDL_TRUE)
2217 PgFFlush(Ph_DONE_DRAW); 2228 {
2229 PhRect_t dst_rect;
2230 PhRect_t src_rect;
2231
2232 /* Set blit area */
2233 dst_rect=*PtGetCanvas(wdata->window);
2234 src_rect.ul.x=0;
2235 src_rect.ul.y=0;
2236 src_rect.lr.x=window->w-1;
2237 src_rect.lr.y=window->h-1;
2238
2239 /* We need to redraw entire window */
2240 PgFFlush(Ph_START_DRAW);
2241 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
2242 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
2243 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
2244 PgFFlush(Ph_DONE_DRAW);
2245 PgWaitHWIdle();
2246 }
2247 else
2248 {
2249 /* Normal window */
2250 /* TODO: update the damaged rectangles */
2251
2252 /* We need to redraw entire window */
2253 }
2254 }
2218 } 2255 }
2219 break; 2256 break;
2220 case Ph_GRAPHIC_EXPOSE: 2257 case Ph_GRAPHIC_EXPOSE:
2221 { 2258 {
2222 /* TODO: What this event means ? */ 2259 /* TODO: What this event means ? */
2436 2473
2437 /* Set window region sensible to mouse motion events */ 2474 /* Set window region sensible to mouse motion events */
2438 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0); 2475 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
2439 wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; 2476 wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
2440 PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL); 2477 PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
2478
2479 /* If window got a focus, the it is visible */
2480 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
2441 } 2481 }
2442 } 2482 }
2443 if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST) 2483 if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
2444 { 2484 {
2445 if (window!=NULL) 2485 if (window!=NULL)
2466 break; 2506 break;
2467 case Ph_WM_RESIZE: 2507 case Ph_WM_RESIZE:
2468 { 2508 {
2469 if (window!=NULL) 2509 if (window!=NULL)
2470 { 2510 {
2511 /* Set new window position after resize */
2512 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
2513 /* Set new window size after resize */
2514 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESIZED, wmevent->size.w, wmevent->size.h);
2471 } 2515 }
2472 } 2516 }
2473 break; 2517 break;
2474 case Ph_WM_HIDE: 2518 case Ph_WM_HIDE:
2475 { 2519 {
2476 if (window!=NULL) 2520 if (window!=NULL)
2477 { 2521 {
2522 /* Send new window state: minimized */
2523 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
2524 /* In case window is minimized, then it is hidden */
2525 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
2478 } 2526 }
2479 } 2527 }
2480 break; 2528 break;
2481 case Ph_WM_MAX: 2529 case Ph_WM_MAX:
2482 { 2530 {
2483 if (window!=NULL) 2531 if (window!=NULL)
2484 { 2532 {
2533 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
2485 } 2534 }
2486 } 2535 }
2487 break; 2536 break;
2488 case Ph_WM_RESTORE: 2537 case Ph_WM_RESTORE:
2489 { 2538 {
2490 if (window!=NULL) 2539 if (window!=NULL)
2491 { 2540 {
2541 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
2492 } 2542 }
2493 } 2543 }
2494 break; 2544 break;
2495 } 2545 }
2496 } 2546 }