~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/common/FrameBufferSDL.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//============================================================================
2
 
//
3
 
//   SSSS    tt          lll  lll       
4
 
//  SS  SS   tt           ll   ll        
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
10
 
//
11
 
// Copyright (c) 1995-1999 by Bradford W. Mott
12
 
//
13
 
// See the file "license" for information on usage and redistribution of
14
 
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
 
//
16
 
// $Id: FrameBufferSDL.cxx,v 1.1 2004/05/24 17:18:22 stephena Exp $
17
 
//============================================================================
18
 
 
19
 
#include <SDL.h>
20
 
#include <SDL_syswm.h>
21
 
#include <sstream>
22
 
 
23
 
#include "Console.hxx"
24
 
#include "FrameBuffer.hxx"
25
 
#include "FrameBufferSDL.hxx"
26
 
#include "MediaSrc.hxx"
27
 
#include "Settings.hxx"
28
 
 
29
 
#include "stella.xpm"   // The Stella icon
30
 
 
31
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32
 
FrameBufferSDL::FrameBufferSDL()
33
 
   :  x11Available(false),
34
 
      theZoomLevel(1),
35
 
      theMaxZoomLevel(1),
36
 
      theAspectRatio(1.0),
37
 
      myPauseStatus(false)
38
 
{
39
 
}
40
 
 
41
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42
 
FrameBufferSDL::~FrameBufferSDL()
43
 
{
44
 
}
45
 
 
46
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47
 
void FrameBufferSDL::pauseEvent(bool status)
48
 
{
49
 
  myPauseStatus = status;
50
 
  setupPalette();
51
 
}
52
 
 
53
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54
 
void FrameBufferSDL::setupPalette()
55
 
{
56
 
  // Shade the palette to 75% normal value in pause mode
57
 
  float shade = 1.0;
58
 
  if(myPauseStatus)
59
 
    shade = 0.75;
60
 
 
61
 
  const uInt32* gamePalette = myMediaSource->palette();
62
 
  for(uInt32 i = 0; i < 256; ++i)
63
 
  {
64
 
    Uint8 r, g, b;
65
 
 
66
 
    r = (Uint8) (((gamePalette[i] & 0x00ff0000) >> 16) * shade);
67
 
    g = (Uint8) (((gamePalette[i] & 0x0000ff00) >> 8) * shade);
68
 
    b = (Uint8) ((gamePalette[i] & 0x000000ff) * shade);
69
 
 
70
 
    myPalette[i] = mapRGB(r, g, b);
71
 
  }
72
 
 
73
 
  theRedrawEntireFrameIndicator = true;
74
 
}
75
 
 
76
 
 
77
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78
 
void FrameBufferSDL::toggleFullscreen()
79
 
{
80
 
  bool isFullscreen = !myConsole->settings().getBool("fullscreen");
81
 
 
82
 
  // Update the settings
83
 
  myConsole->settings().setBool("fullscreen", isFullscreen);
84
 
 
85
 
  if(isFullscreen)
86
 
    mySDLFlags |= SDL_FULLSCREEN;
87
 
  else
88
 
    mySDLFlags &= ~SDL_FULLSCREEN;
89
 
 
90
 
  if(!createScreen())
91
 
    return;
92
 
 
93
 
  if(isFullscreen)  // now in fullscreen mode
94
 
  {
95
 
    grabMouse(true);
96
 
    showCursor(false);
97
 
  }
98
 
  else    // now in windowed mode
99
 
  {
100
 
    grabMouse(myConsole->settings().getBool("grabmouse"));
101
 
    showCursor(!myConsole->settings().getBool("hidecursor"));
102
 
  }
103
 
}
104
 
 
105
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106
 
void FrameBufferSDL::resize(int mode)
107
 
{
108
 
  // reset size to that given in properties
109
 
  // this is a special case of allowing a resize while in fullscreen mode
110
 
  if(mode == 0)
111
 
  {
112
 
    myWidth  = myMediaSource->width() << 1;
113
 
    myHeight = myMediaSource->height();
114
 
  }
115
 
  else if(mode == 1)   // increase size
116
 
  {
117
 
    if(myConsole->settings().getBool("fullscreen"))
118
 
      return;
119
 
 
120
 
    if(theZoomLevel == theMaxZoomLevel)
121
 
      theZoomLevel = 1;
122
 
    else
123
 
      theZoomLevel++;
124
 
  }
125
 
  else if(mode == -1)   // decrease size
126
 
  {
127
 
    if(myConsole->settings().getBool("fullscreen"))
128
 
      return;
129
 
 
130
 
    if(theZoomLevel == 1)
131
 
      theZoomLevel = theMaxZoomLevel;
132
 
    else
133
 
      theZoomLevel--;
134
 
  }
135
 
 
136
 
  if(!createScreen())
137
 
    return;
138
 
 
139
 
  // Update the settings
140
 
  myConsole->settings().setInt("zoom", theZoomLevel);
141
 
}
142
 
 
143
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144
 
void FrameBufferSDL::showCursor(bool show)
145
 
{
146
 
  if(show)
147
 
    SDL_ShowCursor(SDL_ENABLE);
148
 
  else
149
 
    SDL_ShowCursor(SDL_DISABLE);
150
 
}
151
 
 
152
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
 
void FrameBufferSDL::grabMouse(bool grab)
154
 
{
155
 
  if(grab)
156
 
    SDL_WM_GrabInput(SDL_GRAB_ON);
157
 
  else
158
 
    SDL_WM_GrabInput(SDL_GRAB_OFF);
159
 
}
160
 
 
161
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162
 
bool FrameBufferSDL::fullScreen()
163
 
{
164
 
  return myConsole->settings().getBool("fullscreen");
165
 
}
166
 
 
167
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168
 
uInt32 FrameBufferSDL::maxWindowSizeForScreen()
169
 
{
170
 
  if(!x11Available)
171
 
    return 4;
172
 
 
173
 
#ifdef UNIX
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();
178
 
 
179
 
  int screenWidth  = DisplayWidth(theX11Display, DefaultScreen(theX11Display));
180
 
  int screenHeight = DisplayHeight(theX11Display, DefaultScreen(theX11Display));
181
 
 
182
 
  uInt32 multiplier = screenWidth / myWidth;
183
 
  bool found = false;
184
 
 
185
 
  while(!found && (multiplier > 0))
186
 
  {
187
 
    // Figure out the desired size of the window
188
 
    int width  = (int) (myWidth * multiplier * theAspectRatio);
189
 
    int height = myHeight * multiplier;
190
 
 
191
 
    if((width < screenWidth) && (height < screenHeight))
192
 
      found = true;
193
 
    else
194
 
      multiplier--;
195
 
  }
196
 
 
197
 
  if(found)
198
 
    return multiplier;
199
 
  else
200
 
    return 1;
201
 
#endif
202
 
 
203
 
  return 4;
204
 
}
205
 
 
206
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
 
void FrameBufferSDL::setWindowAttributes()
208
 
{
209
 
  // Set the window title
210
 
  ostringstream name;
211
 
  name << "Stella: \"" << myConsole->properties().get("Cartridge.Name") << "\"";
212
 
  SDL_WM_SetCaption(name.str().c_str(), "stella");
213
 
 
214
 
#ifndef MAC_OSX
215
 
  // Set the window icon
216
 
  uInt32 w, h, ncols, nbytes;
217
 
  uInt32 rgba[256], icon[32 * 32];
218
 
  uInt8  mask[32][4];
219
 
 
220
 
  sscanf(stella_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes);
221
 
  if((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1))
222
 
  {
223
 
    cerr << "ERROR: Couldn't load the icon.\n";
224
 
    return;
225
 
  }
226
 
 
227
 
  for(uInt32 i = 0; i < ncols; i++)
228
 
  {
229
 
    unsigned char  code;
230
 
        char color[32];
231
 
    uInt32 col;
232
 
 
233
 
    sscanf(stella_icon[1 + i], "%c c %s", &code, color);
234
 
    if(!strcmp(color, "None"))
235
 
      col = 0x00000000;
236
 
    else if(!strcmp(color, "black"))
237
 
      col = 0xFF000000;
238
 
    else if (color[0] == '#')
239
 
    {
240
 
      sscanf(color + 1, "%06x", &col);
241
 
      col |= 0xFF000000;
242
 
    }
243
 
    else
244
 
    {
245
 
      cerr << "ERROR: Couldn't load the icon.\n";
246
 
      return;
247
 
    }
248
 
    rgba[code] = col;
249
 
  }
250
 
 
251
 
  memset(mask, 0, sizeof(mask));
252
 
  for(h = 0; h < 32; h++)
253
 
  {
254
 
    const char* line = stella_icon[1 + ncols + h];
255
 
    for(w = 0; w < 32; w++)
256
 
    {
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));
260
 
    }
261
 
  }
262
 
 
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);
267
 
#endif
268
 
}