Adonthell  0.4
screen.cc
Go to the documentation of this file.
1 /*
2  $Id: screen.cc,v 1.21 2004/10/25 06:55:01 ksterker Exp $
3 
4  Copyright (C) 1999/2000/2001/2004 Alexandre Courbot
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file screen.cc
17  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
18  *
19  * @brief Defines the screen class.
20  *
21  *
22  */
23 
24 #include "screen.h"
25 #include <iostream>
26 #ifndef __BEOS__
27 #include <sstream>
28 #endif
29 
30 using namespace std;
31 
32 
34 u_int8 screen::bytes_per_pixel_ = 0;
35 u_int32 screen::trans = 0;
36 bool screen::fullscreen_ = false;
37 bool screen::dblmode;
38 
39 void screen::set_video_mode (u_int16 nl, u_int16 nh, u_int8 depth, bool dbl, bool fscreen)
40 {
41  u_int8 bpp;
42  u_int32 SDL_flags = SDL_SWSURFACE;
43  u_int8 emulated = depth;
44 
45  if (fscreen)
46  {
47  SDL_flags |= SDL_FULLSCREEN;
48  fullscreen_ = true;
49  }
50 
51  dblmode = dbl;
52 
53  if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
54  {
55  fprintf (stderr, "couldn't init display: %s\n", SDL_GetError ());
56  exit (1);
57  }
58 
59  // Default video depth if none chosen.
60  if (!depth) depth = 16;
61 
62  if (dblmode)
63  bpp = SDL_VideoModeOK (nl << 1, nh << 1, depth, SDL_flags);
64  else
65  bpp = SDL_VideoModeOK (nl, nh, depth, SDL_flags);
66 
67  if ((emulated) && (bpp) && (bpp != depth)) bpp = depth;
68 
69  switch (bpp)
70  {
71  case 0:
72  fprintf (stderr, "Video mode %dx%d unavailable. Exiting.. \n", nl,
73  nh);
74  exit (1);
75  break;
76  default:
77  bytes_per_pixel_ = bpp / 8;
78  break;
79  }
80  display.set_dbl_mode (dbl);
81  display.set_length (nl);
82  display.set_height (nh);
83 
84  // surface destructor musn't free the screen surface
85  display.not_screen = false;
86 
87  if (dblmode)
88  {
89  nl = nl << 1;
90  nh = nh << 1;
91  }
92 
93  display.vis = SDL_SetVideoMode (nl, nh, bpp, SDL_flags);
94  if (display.vis == NULL)
95  {
96  fprintf (stderr, "error: %s\n", SDL_GetError ());
97  exit (1);
98  }
99 
100  // Setting up transparency color
101  trans = SDL_MapRGB (display.vis->format, 0xFF, 0x00, 0xFF);
102 
103  // Setting up the window title
104  SDL_WM_SetCaption ("Adonthell", NULL);
105 
106  // Turn off SDL cursor
107  SDL_ShowCursor (0);
108 }
109 
110 void screen::show ()
111 {
112  SDL_Flip (display.vis);
113 }
114 
115 string screen::info ()
116 {
117 #ifndef __BEOS__
118  const SDL_VideoInfo * vi = SDL_GetVideoInfo ();
119  ostringstream temp;
120 
121  const int driver_name_length = 500;
122  char drv_name[driver_name_length];
123 
124  temp << "Video information: \n"
125  << "Video driver used: " << SDL_VideoDriverName(drv_name, driver_name_length) << endl
126  << "Internal game depth: " << bytes_per_pixel_ * 8 << endl
127  << "Can create hardware surfaces: " << (vi->hw_available ? "Yes" : "No") << endl
128  << "Window manager available: " << (vi->wm_available ? "Yes" : "No") << endl
129  << "Hardware blits accelerated: " << (vi->blit_hw ? "Yes" : "No") << endl
130  << "Colorkey hardware blits accelerated: " << (vi->blit_hw_CC ? "Yes" : "No") << endl
131  << "Alpha hardware blits accelerated: " << (vi->blit_hw_A ? "Yes" : "No") << endl
132  << "Software blits accelerated: " << (vi->blit_sw ? "Yes" : "No") << endl
133  << "Colorkey software blits accelerated: " << (vi->blit_sw_CC ? "Yes" : "No") << endl
134  << "Alpha software blits accelerated: " << (vi->blit_sw_A ? "Yes" : "No") << endl
135  << "Color fill blits accelerated: " << (vi->blit_fill ? "Yes" : "No") << endl
136  << "Total video memory available: " << vi->video_mem << " Kb" << endl
137  << "Using double size: " << (dblmode ? "Yes" : "No") << endl
138  << "Fullscreen: " << (fullscreen_ ? "Yes" : "No") << endl
139  << ends;
140 
141  string ret = temp.str ();
142 #else
143  string ret = "Sorry, not available under BeOS\n";
144 #endif // __BEOS__
145 
146  return ret;
147 }
148 
150 {
151  if (fullscreen_ != m)
152  {
153  int r = SDL_WM_ToggleFullScreen(display.vis);
154  if (r) fullscreen_ = m;
155  return r;
156  }
157  return 0;
158 }
159 
161 {
162  display.fillrect (0, 0, i, screen::height (), 0);
163  display.fillrect (screen::length () - i, 0, i, screen::height (), 0);
164  display.fillrect (0, 0, screen::length (), i, 0);
165  display.fillrect (0, screen::height () - i, screen::length (), i, 0);
166 }
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
Class where drawables can actually be drawn to.
Definition: surface.h:51
Declares the screen class.
Definition: str_hash.h:36
static u_int16 length()
Returns the length of the screen.
Definition: screen.h:63
static string info()
Returns information about the current screen settings, suitable for being displayed to the user...
Definition: screen.cc:115
#define u_int32
32 bits long unsigned integer
Definition: types.h:35
#define u_int8
8 bits long unsigned integer
Definition: types.h:29
static void transition(u_int16 i)
Make a nice transition effect.
Definition: screen.cc:160
static surface display
The actual screen surface.
Definition: screen.h:51
static bool set_fullscreen(bool m)
Sets fullscreen/windowed mode.
Definition: screen.cc:149
static void show()
Ensure the framebuffer is copied to the physical screen.
Definition: screen.cc:110
static void set_video_mode(u_int16 nl, u_int16 nh, u_int8 depth=0, bool dbl=false, bool fscreen=false)
Sets the video mode.
Definition: screen.cc:39
static u_int16 height()
Returns the height of the screen.
Definition: screen.h:71