src/video/x11/SDL_x11messagebox.c
changeset 6603 fc815cb0a2de
parent 6602 533131e24aeb
child 6615 d7a463bde4d7
equal deleted inserted replaced
6602:533131e24aeb 6603:fc815cb0a2de
    34 
    34 
    35 static const char g_MessageBoxFont[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
    35 static const char g_MessageBoxFont[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
    36 
    36 
    37 static const SDL_MessageBoxColor g_default_colors[ SDL_MESSAGEBOX_COLOR_MAX ] =
    37 static const SDL_MessageBoxColor g_default_colors[ SDL_MESSAGEBOX_COLOR_MAX ] =
    38 {
    38 {
    39 	{ 56,  54,  53  }, // SDL_MESSAGEBOX_COLOR_BACKGROUND,       
    39     { 56,  54,  53  }, // SDL_MESSAGEBOX_COLOR_BACKGROUND,       
    40 	{ 209, 207, 205 }, // SDL_MESSAGEBOX_COLOR_TEXT,             
    40     { 209, 207, 205 }, // SDL_MESSAGEBOX_COLOR_TEXT,             
    41 	{ 140, 135, 129 }, // SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,    
    41     { 140, 135, 129 }, // SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,    
    42 	{ 105, 102, 99  }, // SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
    42     { 105, 102, 99  }, // SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
    43 	{ 205, 202, 53  }, // SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,  
    43     { 205, 202, 53  }, // SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,  
    44 };
    44 };
    45 
    45 
    46 #define SDL_MAKE_RGB( _r, _g, _b )  ( ( ( Uint32 )( _r ) << 16 ) | \
    46 #define SDL_MAKE_RGB( _r, _g, _b )  ( ( ( Uint32 )( _r ) << 16 ) | \
    47                                       ( ( Uint32 )( _g ) << 8 ) |  \
    47                                       ( ( Uint32 )( _g ) << 8 ) |  \
    48                                       ( ( Uint32 )( _b ) ) )
    48                                       ( ( Uint32 )( _b ) ) )
    68 typedef struct SDL_MessageBoxDataX11
    68 typedef struct SDL_MessageBoxDataX11
    69 {
    69 {
    70     Font hfont;
    70     Font hfont;
    71     Window window;
    71     Window window;
    72     Display *display;
    72     Display *display;
    73 	long event_mask;
    73     long event_mask;
    74     Atom wm_protocols;
    74     Atom wm_protocols;
    75     Atom wm_delete_message;
    75     Atom wm_delete_message;
    76 
    76 
    77     int dialog_width;                   /* Dialog box width. */
    77     int dialog_width;                   /* Dialog box width. */
    78     int dialog_height;                  /* Dialog box height. */
    78     int dialog_height;                  /* Dialog box height. */
    89 
    89 
    90     int numbuttons;                     /* Count of buttons. */
    90     int numbuttons;                     /* Count of buttons. */
    91     const SDL_MessageBoxButtonData *buttondata;
    91     const SDL_MessageBoxButtonData *buttondata;
    92     SDL_MessageBoxButtonDataX11 buttonpos[ MAX_BUTTONS ];
    92     SDL_MessageBoxButtonDataX11 buttonpos[ MAX_BUTTONS ];
    93 
    93 
    94 	Uint32 color[ SDL_MESSAGEBOX_COLOR_MAX ];
    94     Uint32 color[ SDL_MESSAGEBOX_COLOR_MAX ];
    95 
    95 
    96     const SDL_MessageBoxData *messageboxdata;
    96     const SDL_MessageBoxData *messageboxdata;
    97 } SDL_MessageBoxDataX11;
    97 } SDL_MessageBoxDataX11;
    98 
    98 
    99 /* Maximum helper for ints. */
    99 /* Maximum helper for ints. */
   144 
   144 
   145 /* Initialize SDL_MessageBoxData structure and Display, etc. */
   145 /* Initialize SDL_MessageBoxData structure and Display, etc. */
   146 static int
   146 static int
   147 X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * messageboxdata, int * pbuttonid )
   147 X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * messageboxdata, int * pbuttonid )
   148 {
   148 {
   149 	int i;
   149     int i;
   150     int numbuttons = messageboxdata->numbuttons;
   150     int numbuttons = messageboxdata->numbuttons;
   151     const SDL_MessageBoxButtonData *buttondata = messageboxdata->buttons;
   151     const SDL_MessageBoxButtonData *buttondata = messageboxdata->buttons;
   152 	const SDL_MessageBoxColor *colorhints;
   152     const SDL_MessageBoxColor *colorhints;
   153 
   153 
   154     if ( numbuttons > MAX_BUTTONS ) {
   154     if ( numbuttons > MAX_BUTTONS ) {
   155         SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS);
   155         SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS);
   156         return -1;
   156         return -1;
   157     }
   157     }
   173     if ( data->hfont == None ) {
   173     if ( data->hfont == None ) {
   174         SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
   174         SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
   175         return -1;
   175         return -1;
   176     }
   176     }
   177 
   177 
   178 	if ( messageboxdata->colorScheme ) {
   178     if ( messageboxdata->colorScheme ) {
   179 		colorhints = messageboxdata->colorScheme->colors;
   179         colorhints = messageboxdata->colorScheme->colors;
   180 	} else {
   180     } else {
   181 		colorhints = g_default_colors;
   181         colorhints = g_default_colors;
   182 	}
   182     }
   183 
   183 
   184 	/* Convert our SDL_MessageBoxColor r,g,b values to packed RGB format. */
   184     /* Convert our SDL_MessageBoxColor r,g,b values to packed RGB format. */
   185 	for ( i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++ ) {
   185     for ( i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++ ) {
   186 		data->color[ i ] = SDL_MAKE_RGB( colorhints[ i ].r, colorhints[ i ].g, colorhints[ i ].b );
   186         data->color[ i ] = SDL_MAKE_RGB( colorhints[ i ].r, colorhints[ i ].g, colorhints[ i ].b );
   187 	}
   187     }
   188 
   188 
   189     return 0;
   189     return 0;
   190 }
   190 }
   191 
   191 
   192 /* Calculate and initialize text and button locations. */
   192 /* Calculate and initialize text and button locations. */
   356     }
   356     }
   357 
   357 
   358     data->event_mask = ExposureMask |
   358     data->event_mask = ExposureMask |
   359         ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
   359         ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
   360         StructureNotifyMask | FocusChangeMask | PointerMotionMask;
   360         StructureNotifyMask | FocusChangeMask | PointerMotionMask;
   361 	wnd_attr.event_mask = data->event_mask;
   361     wnd_attr.event_mask = data->event_mask;
   362 
   362 
   363     data->window = XCreateWindow(
   363     data->window = XCreateWindow(
   364                             display, DefaultRootWindow( display ),
   364                             display, DefaultRootWindow( display ),
   365                             0, 0,
   365                             0, 0,
   366                             data->dialog_width, data->dialog_height,
   366                             data->dialog_width, data->dialog_height,
   456                         buttondatax11->rect.x, buttondatax11->rect.y,
   456                         buttondatax11->rect.x, buttondatax11->rect.y,
   457                         buttondatax11->rect.w, buttondatax11->rect.h );
   457                         buttondatax11->rect.w, buttondatax11->rect.h );
   458 
   458 
   459         XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
   459         XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
   460                         data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
   460                         data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
   461 						data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
   461                         data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
   462         XDrawString( display, window, ctx,
   462         XDrawString( display, window, ctx,
   463             buttondatax11->x + offset, buttondatax11->y + offset,
   463             buttondatax11->x + offset, buttondatax11->y + offset,
   464             buttondata->text, buttondatax11->length );
   464             buttondata->text, buttondatax11->length );
   465     }
   465     }
   466 }
   466 }
   490 
   490 
   491     while( !close_dialog ) {
   491     while( !close_dialog ) {
   492         XEvent e;
   492         XEvent e;
   493         SDL_bool draw = SDL_TRUE;
   493         SDL_bool draw = SDL_TRUE;
   494 
   494 
   495 		XWindowEvent( data->display, data->window, data->event_mask, &e );
   495         XWindowEvent( data->display, data->window, data->event_mask, &e );
   496 
   496 
   497         /* If XFilterEvent returns True, then some input method has filtered the
   497         /* If XFilterEvent returns True, then some input method has filtered the
   498            event, and the client should discard the event. */
   498            event, and the client should discard the event. */
   499         if ( ( e.type != Expose ) && XFilterEvent( &e, None ) )
   499         if ( ( e.type != Expose ) && XFilterEvent( &e, None ) )
   500             continue;
   500             continue;