@@ -68,10 +68,6 @@ static const SDL_MessageBoxColor g_default_colors[SDL_MESSAGEBOX_COLOR_COUNT] =
68
68
{ 205 , 202 , 53 }, // SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
69
69
};
70
70
71
- #define SDL_MAKE_RGB (_r , _g , _b ) (((Uint32)(_r) << 16) | \
72
- ((Uint32)(_g) << 8) | \
73
- ((Uint32)(_b)))
74
-
75
71
typedef struct SDL_MessageBoxButtonDataX11
76
72
{
77
73
int x , y ; // Text position
@@ -95,6 +91,8 @@ typedef struct SDL_MessageBoxDataX11
95
91
Display * display ;
96
92
int screen ;
97
93
Window window ;
94
+ Visual * visual ;
95
+ Colormap cmap ;
98
96
#ifdef SDL_VIDEO_DRIVER_X11_XDBE
99
97
XdbeBackBuffer buf ;
100
98
bool xdbe ; // Whether Xdbe is present or not
@@ -122,7 +120,7 @@ typedef struct SDL_MessageBoxDataX11
122
120
const SDL_MessageBoxButtonData * buttondata ;
123
121
SDL_MessageBoxButtonDataX11 buttonpos [MAX_BUTTONS ];
124
122
125
- Uint32 color [SDL_MESSAGEBOX_COLOR_COUNT ];
123
+ XColor xcolor [SDL_MESSAGEBOX_COLOR_COUNT ];
126
124
127
125
const SDL_MessageBoxData * messageboxdata ;
128
126
} SDL_MessageBoxDataX11 ;
@@ -233,9 +231,12 @@ static bool X11_MessageBoxInit(SDL_MessageBoxDataX11 *data, const SDL_MessageBox
233
231
colorhints = g_default_colors ;
234
232
}
235
233
236
- // Convert our SDL_MessageBoxColor r,g,b values to packed RGB format.
234
+ // Convert colors to 16 bpc XColor format
237
235
for (i = 0 ; i < SDL_MESSAGEBOX_COLOR_COUNT ; i ++ ) {
238
- data -> color [i ] = SDL_MAKE_RGB (colorhints [i ].r , colorhints [i ].g , colorhints [i ].b );
236
+ data -> xcolor [i ].flags = DoRed |DoGreen |DoBlue ;
237
+ data -> xcolor [i ].red = colorhints [i ].r * 257 ;
238
+ data -> xcolor [i ].green = colorhints [i ].g * 257 ;
239
+ data -> xcolor [i ].blue = colorhints [i ].b * 257 ;
239
240
}
240
241
241
242
return true;
@@ -418,7 +419,7 @@ static void X11_MessageBoxShutdown(SDL_MessageBoxDataX11 *data)
418
419
// Create and set up our X11 dialog box indow.
419
420
static bool X11_MessageBoxCreateWindow (SDL_MessageBoxDataX11 * data )
420
421
{
421
- int x , y ;
422
+ int x , y , i ;
422
423
XSizeHints * sizehints ;
423
424
XSetWindowAttributes wnd_attr ;
424
425
Atom _NET_WM_WINDOW_TYPE , _NET_WM_WINDOW_TYPE_DIALOG ;
@@ -441,17 +442,24 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
441
442
data -> screen = DefaultScreen (display );
442
443
}
443
444
445
+ data -> visual = DefaultVisual (display , data -> screen );
446
+ data -> cmap = DefaultColormap (display , data -> screen );
447
+ for (i = 0 ; i < SDL_MESSAGEBOX_COLOR_COUNT ; i ++ ) {
448
+ X11_XAllocColor (display , data -> cmap , & data -> xcolor [i ]);
449
+ }
450
+
444
451
data -> event_mask = ExposureMask |
445
452
ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
446
453
StructureNotifyMask | FocusChangeMask | PointerMotionMask ;
447
454
wnd_attr .event_mask = data -> event_mask ;
455
+ wnd_attr .colormap = data -> cmap ;
448
456
449
457
data -> window = X11_XCreateWindow (
450
458
display , RootWindow (display , data -> screen ),
451
459
0 , 0 ,
452
460
data -> dialog_width , data -> dialog_height ,
453
- 0 , CopyFromParent , InputOutput , CopyFromParent ,
454
- CWEventMask , & wnd_attr );
461
+ 0 , DefaultDepth ( display , data -> screen ), InputOutput , data -> visual ,
462
+ CWEventMask | CWColormap , & wnd_attr );
455
463
if (data -> window == None ) {
456
464
return SDL_SetError ("Couldn't create X window" );
457
465
}
@@ -569,10 +577,10 @@ static void X11_MessageBoxDraw(SDL_MessageBoxDataX11 *data, GC ctx)
569
577
}
570
578
#endif
571
579
572
- X11_XSetForeground (display , ctx , data -> color [SDL_MESSAGEBOX_COLOR_BACKGROUND ]);
580
+ X11_XSetForeground (display , ctx , data -> xcolor [SDL_MESSAGEBOX_COLOR_BACKGROUND ]. pixel );
573
581
X11_XFillRectangle (display , window , ctx , 0 , 0 , data -> dialog_width , data -> dialog_height );
574
582
575
- X11_XSetForeground (display , ctx , data -> color [SDL_MESSAGEBOX_COLOR_TEXT ]);
583
+ X11_XSetForeground (display , ctx , data -> xcolor [SDL_MESSAGEBOX_COLOR_TEXT ]. pixel );
576
584
for (i = 0 ; i < data -> numlines ; i ++ ) {
577
585
TextLineData * plinedata = & data -> linedata [i ];
578
586
@@ -596,17 +604,17 @@ static void X11_MessageBoxDraw(SDL_MessageBoxDataX11 *data, GC ctx)
596
604
int border = (buttondata -> flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ) ? 2 : 0 ;
597
605
int offset = ((data -> mouse_over_index == i ) && (data -> button_press_index == data -> mouse_over_index )) ? 1 : 0 ;
598
606
599
- X11_XSetForeground (display , ctx , data -> color [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ]);
607
+ X11_XSetForeground (display , ctx , data -> xcolor [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ]. pixel );
600
608
X11_XFillRectangle (display , window , ctx ,
601
609
buttondatax11 -> rect .x - border , buttondatax11 -> rect .y - border ,
602
610
buttondatax11 -> rect .w + 2 * border , buttondatax11 -> rect .h + 2 * border );
603
611
604
- X11_XSetForeground (display , ctx , data -> color [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ]);
612
+ X11_XSetForeground (display , ctx , data -> xcolor [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ]. pixel );
605
613
X11_XDrawRectangle (display , window , ctx ,
606
614
buttondatax11 -> rect .x , buttondatax11 -> rect .y ,
607
615
buttondatax11 -> rect .w , buttondatax11 -> rect .h );
608
616
609
- X11_XSetForeground (display , ctx , (data -> mouse_over_index == i ) ? data -> color [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] : data -> color [SDL_MESSAGEBOX_COLOR_TEXT ]);
617
+ X11_XSetForeground (display , ctx , (data -> mouse_over_index == i ) ? data -> xcolor [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ]. pixel : data -> xcolor [SDL_MESSAGEBOX_COLOR_TEXT ]. pixel );
610
618
611
619
#ifdef X_HAVE_UTF8_STRING
612
620
if (SDL_X11_HAVE_UTF8 ) {
@@ -657,8 +665,8 @@ static bool X11_MessageBoxLoop(SDL_MessageBoxDataX11 *data)
657
665
#endif
658
666
659
667
SDL_zero (ctx_vals );
660
- ctx_vals .foreground = data -> color [SDL_MESSAGEBOX_COLOR_BACKGROUND ];
661
- ctx_vals .background = data -> color [SDL_MESSAGEBOX_COLOR_BACKGROUND ];
668
+ ctx_vals .foreground = data -> xcolor [SDL_MESSAGEBOX_COLOR_BACKGROUND ]. pixel ;
669
+ ctx_vals .background = data -> xcolor [SDL_MESSAGEBOX_COLOR_BACKGROUND ]. pixel ;
662
670
663
671
if (!have_utf8 ) {
664
672
gcflags |= GCFont ;
0 commit comments