1
//============================================================================
5
// SS tttttt eeee ll ll aaaa
6
// SSSS tt ee ee ll ll aa
7
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8
// SS SS tt ee ll ll aa aa
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-1999 by Bradford W. Mott
13
// See the file "license" for information on usage and redistribution of
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: FrameBufferSDL.cxx,v 1.1 2004/05/24 17:18:22 stephena Exp $
17
//============================================================================
20
#include <SDL_syswm.h>
23
#include "Console.hxx"
24
#include "FrameBuffer.hxx"
25
#include "FrameBufferSDL.hxx"
26
#include "MediaSrc.hxx"
27
#include "Settings.hxx"
29
#include "stella.xpm" // The Stella icon
31
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32
FrameBufferSDL::FrameBufferSDL()
33
: x11Available(false),
41
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42
FrameBufferSDL::~FrameBufferSDL()
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47
void FrameBufferSDL::pauseEvent(bool status)
49
myPauseStatus = status;
53
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54
void FrameBufferSDL::setupPalette()
56
// Shade the palette to 75% normal value in pause mode
61
const uInt32* gamePalette = myMediaSource->palette();
62
for(uInt32 i = 0; i < 256; ++i)
66
r = (Uint8) (((gamePalette[i] & 0x00ff0000) >> 16) * shade);
67
g = (Uint8) (((gamePalette[i] & 0x0000ff00) >> 8) * shade);
68
b = (Uint8) ((gamePalette[i] & 0x000000ff) * shade);
70
myPalette[i] = mapRGB(r, g, b);
73
theRedrawEntireFrameIndicator = true;
77
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78
void FrameBufferSDL::toggleFullscreen()
80
bool isFullscreen = !myConsole->settings().getBool("fullscreen");
82
// Update the settings
83
myConsole->settings().setBool("fullscreen", isFullscreen);
86
mySDLFlags |= SDL_FULLSCREEN;
88
mySDLFlags &= ~SDL_FULLSCREEN;
93
if(isFullscreen) // now in fullscreen mode
98
else // now in windowed mode
100
grabMouse(myConsole->settings().getBool("grabmouse"));
101
showCursor(!myConsole->settings().getBool("hidecursor"));
105
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106
void FrameBufferSDL::resize(int mode)
108
// reset size to that given in properties
109
// this is a special case of allowing a resize while in fullscreen mode
112
myWidth = myMediaSource->width() << 1;
113
myHeight = myMediaSource->height();
115
else if(mode == 1) // increase size
117
if(myConsole->settings().getBool("fullscreen"))
120
if(theZoomLevel == theMaxZoomLevel)
125
else if(mode == -1) // decrease size
127
if(myConsole->settings().getBool("fullscreen"))
130
if(theZoomLevel == 1)
131
theZoomLevel = theMaxZoomLevel;
139
// Update the settings
140
myConsole->settings().setInt("zoom", theZoomLevel);
143
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144
void FrameBufferSDL::showCursor(bool show)
147
SDL_ShowCursor(SDL_ENABLE);
149
SDL_ShowCursor(SDL_DISABLE);
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
void FrameBufferSDL::grabMouse(bool grab)
156
SDL_WM_GrabInput(SDL_GRAB_ON);
158
SDL_WM_GrabInput(SDL_GRAB_OFF);
161
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162
bool FrameBufferSDL::fullScreen()
164
return myConsole->settings().getBool("fullscreen");
167
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168
uInt32 FrameBufferSDL::maxWindowSizeForScreen()
174
// Otherwise, lock the screen and get the width and height
175
myWMInfo.info.x11.lock_func();
176
Display* theX11Display = myWMInfo.info.x11.display;
177
myWMInfo.info.x11.unlock_func();
179
int screenWidth = DisplayWidth(theX11Display, DefaultScreen(theX11Display));
180
int screenHeight = DisplayHeight(theX11Display, DefaultScreen(theX11Display));
182
uInt32 multiplier = screenWidth / myWidth;
185
while(!found && (multiplier > 0))
187
// Figure out the desired size of the window
188
int width = (int) (myWidth * multiplier * theAspectRatio);
189
int height = myHeight * multiplier;
191
if((width < screenWidth) && (height < screenHeight))
206
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
void FrameBufferSDL::setWindowAttributes()
209
// Set the window title
211
name << "Stella: \"" << myConsole->properties().get("Cartridge.Name") << "\"";
212
SDL_WM_SetCaption(name.str().c_str(), "stella");
215
// Set the window icon
216
uInt32 w, h, ncols, nbytes;
217
uInt32 rgba[256], icon[32 * 32];
220
sscanf(stella_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes);
221
if((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1))
223
cerr << "ERROR: Couldn't load the icon.\n";
227
for(uInt32 i = 0; i < ncols; i++)
233
sscanf(stella_icon[1 + i], "%c c %s", &code, color);
234
if(!strcmp(color, "None"))
236
else if(!strcmp(color, "black"))
238
else if (color[0] == '#')
240
sscanf(color + 1, "%06x", &col);
245
cerr << "ERROR: Couldn't load the icon.\n";
251
memset(mask, 0, sizeof(mask));
252
for(h = 0; h < 32; h++)
254
const char* line = stella_icon[1 + ncols + h];
255
for(w = 0; w < 32; w++)
257
icon[w + 32 * h] = rgba[(int)line[w]];
258
if(rgba[(int)line[w]] & 0xFF000000)
259
mask[h][w >> 3] |= 1 << (7 - (w & 0x07));
263
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32,
264
32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
265
SDL_WM_SetIcon(surface, (unsigned char *) mask);
266
SDL_FreeSurface(surface);