Added handler for all window events.
authorMike Gorchak
Tue, 05 May 2009 17:47:41 +0000
changeset 31151102a3305928
parent 3114 979164e58723
child 3116 b17f1ae7ad66
Added handler for all window events.
src/video/photon/SDL_photon.c
src/video/photon/SDL_photon_input.c
     1.1 --- a/src/video/photon/SDL_photon.c	Tue Apr 28 06:04:21 2009 +0000
     1.2 +++ b/src/video/photon/SDL_photon.c	Tue May 05 17:47:41 2009 +0000
     1.3 @@ -567,7 +567,7 @@
     1.4        return;
     1.5     }
     1.6  
     1.7 -   /* Current display dimensions and bpp are no more valid */
     1.8 +   /* Current display dimension and bpp are no more valid */
     1.9     didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
    1.10     didata->current_mode.w=0;
    1.11     didata->current_mode.h=0;
    1.12 @@ -794,25 +794,15 @@
    1.13     /* Disable default window filling on redraw */
    1.14     PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
    1.15  
    1.16 -   /* Set default maximum and minimum window sizes */
    1.17 -   winsize.w=0;
    1.18 -   winsize.h=0;
    1.19 -   PtSetArg(&winargs[winargc++], Pt_ARG_MAX_HEIGHT, 0, 0);
    1.20 -   PtSetArg(&winargs[winargc++], Pt_ARG_MAX_WIDTH, 0, 0);
    1.21 -   PtSetArg(&winargs[winargc++], Pt_ARG_MIN_HEIGHT, 0, 0);
    1.22 -   PtSetArg(&winargs[winargc++], Pt_ARG_MIN_WIDTH, 0, 0);
    1.23 -   PtSetArg(&winargs[winargc++], Pt_ARG_MAXIMUM_DIM, &winsize, 0);
    1.24 -   PtSetArg(&winargs[winargc++], Pt_ARG_MINIMUM_DIM, &winsize, 0);
    1.25 -
    1.26 -   /* Reset default managed events to disable */
    1.27 +   /* Reset default managed flags to disabled state */
    1.28     PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
    1.29              Ph_WM_APP_DEF_MANAGED);
    1.30     /* Set which events we will not handle, let WM to handle them */
    1.31     PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
    1.32              Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT  |
    1.33              Ph_WM_FOCUS    | Ph_WM_HELP    | Ph_WM_HIDE     | Ph_WM_MAX     |
    1.34 -            Ph_WM_MENU     | Ph_WM_MOVE    | Ph_WM_RESIZE   | Ph_WM_RESTORE |
    1.35 -            Ph_WM_TASKBAR  | Ph_WM_TOBACK);
    1.36 +            Ph_WM_MENU     | Ph_WM_MOVE    | Ph_WM_RESTORE  | Ph_WM_TASKBAR |
    1.37 +            Ph_WM_TOBACK   | Ph_WM_RESIZE);
    1.38  
    1.39     /* Reset default notify events to disable */
    1.40     PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
    1.41 @@ -847,6 +837,7 @@
    1.42        if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
    1.43        {
    1.44           decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
    1.45 +         PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
    1.46        }
    1.47        if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS)
    1.48        {
    1.49 @@ -859,7 +850,7 @@
    1.50     PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS);
    1.51     PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
    1.52  
    1.53 -   /* Set window dimensions */
    1.54 +   /* Set window dimension */
    1.55     winsize.w=window->w;
    1.56     winsize.h=window->h;
    1.57     PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
    1.58 @@ -894,9 +885,6 @@
    1.59        PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
    1.60     }
    1.61  
    1.62 -   /* Add SDL window id as user data */
    1.63 -   PtSetArg(&winargs[winargc++], Pt_ARG_POINTER, (void*)window->id, 0);
    1.64 -
    1.65     /* Check if window must support OpenGL ES rendering */
    1.66     if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
    1.67     {
    1.68 @@ -1897,7 +1885,7 @@
    1.69        SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
    1.70        SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
    1.71        SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
    1.72 -      PhRect_t*        dst_rect;
    1.73 +      PhRect_t         dst_rect;
    1.74        PhRect_t         src_rect;
    1.75  
    1.76        if (phdata->gfinitialized!=SDL_TRUE)
    1.77 @@ -1921,7 +1909,7 @@
    1.78        }
    1.79  
    1.80        /* Set blit area */
    1.81 -      dst_rect=PtGetCanvas(wdata->window);
    1.82 +      dst_rect=*PtGetCanvas(wdata->window);
    1.83        src_rect.ul.x=0;
    1.84        src_rect.ul.y=0;
    1.85        src_rect.lr.x=window->w-1;
    1.86 @@ -1931,7 +1919,7 @@
    1.87        PgFFlush(Ph_START_DRAW);
    1.88        PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
    1.89        PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
    1.90 -      PgContextBlit(wdata->phsurface, &src_rect, NULL, dst_rect);
    1.91 +      PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
    1.92        PgFFlush(Ph_DONE_DRAW);
    1.93        PgWaitHWIdle();
    1.94  
    1.95 @@ -2025,6 +2013,7 @@
    1.96                   if (status==0)
    1.97                   {
    1.98                      window=NULL;
    1.99 +                    wdata=NULL;
   1.100                   }
   1.101  
   1.102                   /* Event is ready */
   1.103 @@ -2197,10 +2186,32 @@
   1.104                                            break;
   1.105                                         }
   1.106  
   1.107 -                                       /* Cycle through each rectangle */
   1.108 -                                       for (it=0; it<event->num_rects; it++)
   1.109 +                                       /* Check if expose come to one of the our windows */
   1.110 +                                       if ((wdata!=NULL) && (window!=NULL))
   1.111                                         {
   1.112 -                                          /* TODO: update the damaged rectangles */
   1.113 +                                          /* Check if window uses OpenGL ES */
   1.114 +                                          if (wdata->uses_gles==SDL_TRUE)
   1.115 +                                          {
   1.116 +                                             PhRect_t dst_rect;
   1.117 +                                             PhRect_t src_rect;
   1.118 +
   1.119 +                                             /* Cycle through each rectangle */
   1.120 +                                             for (it=0; it<event->num_rects; it++)
   1.121 +                                             {
   1.122 +                                                /* Blit OpenGL ES pixmap surface directly to window region */
   1.123 +                                                PgFFlush(Ph_START_DRAW);
   1.124 +                                                PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
   1.125 +                                                PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
   1.126 +                                                PgContextBlit(wdata->phsurface, &rects[it], NULL, &rects[it]);
   1.127 +                                                PgFFlush(Ph_DONE_DRAW);
   1.128 +                                                PgWaitHWIdle();
   1.129 +                                             }
   1.130 +                                          }
   1.131 +                                          else
   1.132 +                                          {
   1.133 +                                             /* Normal window */
   1.134 +                                             /* TODO: update the damaged rectangles */
   1.135 +                                          }
   1.136                                         }
   1.137  
   1.138                                         /* Flush all blittings */
   1.139 @@ -2209,12 +2220,38 @@
   1.140                                      break;
   1.141                                 case Ph_CAPTURE_EXPOSE:
   1.142                                      {
   1.143 -                                       /* We need to redraw entire screen */
   1.144 -                                       PgFFlush(Ph_START_DRAW);
   1.145 +                                       /* Check if expose come to one of the our windows */
   1.146 +                                       if ((wdata!=NULL) && (window!=NULL))
   1.147 +                                       {
   1.148 +                                          /* Check if window uses OpenGL ES */
   1.149 +                                          if (wdata->uses_gles==SDL_TRUE)
   1.150 +                                          {
   1.151 +                                             PhRect_t dst_rect;
   1.152 +                                             PhRect_t src_rect;
   1.153 +
   1.154 +                                             /* Set blit area */
   1.155 +                                             dst_rect=*PtGetCanvas(wdata->window);
   1.156 +                                             src_rect.ul.x=0;
   1.157 +                                             src_rect.ul.y=0;
   1.158 +                                             src_rect.lr.x=window->w-1;
   1.159 +                                             src_rect.lr.y=window->h-1;
   1.160  
   1.161 -                                       /* TODO: redraw the whole screen */
   1.162 +                                             /* We need to redraw entire window */
   1.163 +                                             PgFFlush(Ph_START_DRAW);
   1.164 +                                             PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
   1.165 +                                             PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
   1.166 +                                             PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
   1.167 +                                             PgFFlush(Ph_DONE_DRAW);
   1.168 +                                             PgWaitHWIdle();
   1.169 +                                          }
   1.170 +                                          else
   1.171 +                                          {
   1.172 +                                             /* Normal window */
   1.173 +                                             /* TODO: update the damaged rectangles */
   1.174  
   1.175 -                                       PgFFlush(Ph_DONE_DRAW);
   1.176 +                                             /* We need to redraw entire window */
   1.177 +                                          }
   1.178 +                                       }
   1.179                                      }
   1.180                                      break;
   1.181                                 case Ph_GRAPHIC_EXPOSE:
   1.182 @@ -2438,6 +2475,9 @@
   1.183                                               PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
   1.184                                               wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
   1.185                                               PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
   1.186 +
   1.187 +                                             /* If window got a focus, the it is visible */
   1.188 +                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.189                                            }
   1.190                                         }
   1.191                                         if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
   1.192 @@ -2468,6 +2508,10 @@
   1.193                                      {
   1.194                                         if (window!=NULL)
   1.195                                         {
   1.196 +                                          /* Set new window position after resize */
   1.197 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
   1.198 +                                          /* Set new window size after resize */
   1.199 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESIZED, wmevent->size.w, wmevent->size.h);
   1.200                                         }
   1.201                                      }
   1.202                                      break;
   1.203 @@ -2475,6 +2519,10 @@
   1.204                                      {
   1.205                                         if (window!=NULL)
   1.206                                         {
   1.207 +                                          /* Send new window state: minimized */
   1.208 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.209 +                                          /* In case window is minimized, then it is hidden */
   1.210 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.211                                         }
   1.212                                      }
   1.213                                      break;
   1.214 @@ -2482,6 +2530,7 @@
   1.215                                      {
   1.216                                         if (window!=NULL)
   1.217                                         {
   1.218 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   1.219                                         }
   1.220                                      }
   1.221                                      break;
   1.222 @@ -2489,6 +2538,7 @@
   1.223                                      {
   1.224                                         if (window!=NULL)
   1.225                                         {
   1.226 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.227                                         }
   1.228                                      }
   1.229                                      break;
     2.1 --- a/src/video/photon/SDL_photon_input.c	Tue Apr 28 06:04:21 2009 +0000
     2.2 +++ b/src/video/photon/SDL_photon_input.c	Tue May 05 17:47:41 2009 +0000
     2.3 @@ -369,7 +369,8 @@
     2.4  {
     2.5     SDL_VideoDisplay* display;
     2.6     SDL_DisplayData*  didata;
     2.7 -   SDL_Window*  window;
     2.8 +   SDL_Window*       window;
     2.9 +   SDL_WindowData*   wdata;
    2.10     SDL_WindowID window_id;
    2.11     int32_t status;
    2.12  
    2.13 @@ -389,7 +390,15 @@
    2.14           if (display!=NULL)
    2.15           {
    2.16              didata=(SDL_DisplayData*)display->driverdata;
    2.17 -            if (didata==NULL)
    2.18 +            if (didata!=NULL)
    2.19 +            {
    2.20 +               wdata=(SDL_WindowData*)window->driverdata;
    2.21 +               if (wdata==NULL)
    2.22 +               {
    2.23 +                  return;
    2.24 +               }
    2.25 +            }
    2.26 +            else
    2.27              {
    2.28                 return;
    2.29              }
    2.30 @@ -405,7 +414,9 @@
    2.31        }
    2.32     }
    2.33  
    2.34 -/*   cursor->mouse->x, cursor->mouse->y */
    2.35 +   /* No need to move mouse cursor manually in the photon */
    2.36 +
    2.37 +   return;
    2.38  }
    2.39  
    2.40  void photon_freecursor(SDL_Cursor* cursor)
    2.41 @@ -427,8 +438,10 @@
    2.42  {
    2.43     SDL_VideoDisplay* display;
    2.44     SDL_DisplayData*  didata;
    2.45 -   SDL_Window* window;
    2.46 -   int32_t status;
    2.47 +   SDL_Window*       window;
    2.48 +   SDL_WindowData*   wdata;
    2.49 +   int16_t           wx;
    2.50 +   int16_t           wy;
    2.51  
    2.52     /* Sanity checks */
    2.53     window=SDL_GetWindowFromID(windowID);
    2.54 @@ -438,7 +451,15 @@
    2.55        if (display!=NULL)
    2.56        {
    2.57           didata=(SDL_DisplayData*)display->driverdata;
    2.58 -         if (didata==NULL)
    2.59 +         if (didata!=NULL)
    2.60 +         {
    2.61 +            wdata=(SDL_WindowData*)window->driverdata;
    2.62 +            if (wdata==NULL)
    2.63 +            {
    2.64 +               return;
    2.65 +            }
    2.66 +         }
    2.67 +         else
    2.68           {
    2.69              return;
    2.70           }
    2.71 @@ -453,6 +474,10 @@
    2.72        return;
    2.73     }
    2.74  
    2.75 +   PtGetAbsPosition(wdata->window, &wx, &wy);
    2.76 +   PhMoveCursorAbs(PhInputGroup(NULL), wx+x, wy+y);
    2.77 +
    2.78 +   return;
    2.79  }
    2.80  
    2.81  void photon_freemouse(SDL_Mouse* mouse)