Advanced Strategic Command
graphics.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  graphics.cpp - description
3  -------------------
4  begin : Sat Dec 18 1999
5  copyright : (C) 1999 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 
20 #include <stdlib.h>
21 #include <SDL.h>
22 #include "graphics.h"
23 #include "../basegfx.h"
24 #include "../global.h"
25 #include "../ascstring.h"
26 #include "../util/messaginghub.h"
27 
28 
29 #include "sdlstretch.cpp"
30 
31 SDL_Surface *screen = NULL;
32 
33 
34 void setWindowCaption ( const char* s )
35 {
36  SDL_WM_SetCaption ( s, NULL );
37 }
38 
39 
41 
42 void initASCGraphicSubsystem ( SDL_Surface* _screen )
43 {
44  screen = _screen;
45  agmp->resolutionx = screen->w;
46  agmp->resolutiony = screen->h;
47  agmp->windowstatus = 100;
49  agmp->byteperpix = 1 ;
50  agmp->bitperpix = 8;
52  delete agmp->surface;
53  if ( _screen->format->BitsPerPixel == 8 ) {
54  agmp->surface = new Surface ( _screen );
56  } else {
59  }
62 
63 
64  *hgmp = *agmp;
65 }
66 
67 
68 
70 {
71  if ( agmp && agmp->surface )
72  delete agmp->surface;
73 }
74 
75 /*
76 SDL_Surface* getScreen()
77 {
78  return screen;
79 }
80 */
81 
83 {
84  return *agmp->surface;
85 }
86 
87 
88 //*********** Misc ************
89 
90 
91 int copy2screen( void )
92 {
93  #ifdef _WIN32_
94  // SDL_ShowCursor(0);
95  #endif
96  if ( !dummyScreenPaletteSetup ) {
99  }
100 
101  if ( screen->format->BitsPerPixel > 8 )
102  SDL_BlitSurface( hgmp->surface->getBaseSurface() , NULL, screen, NULL );
103  SDL_UpdateRect ( screen , 0,0,0,0 );
104  #ifdef _WIN32_
105  // SDL_ShowCursor(1);
106  #endif
107  return 0;
108 }
109 
110 int copy2screen( int x1, int y1, int x2, int y2 )
111 {
112  MouseHider mouseHider;
113 
114  if ( !dummyScreenPaletteSetup ) {
117  }
118 
119  if ( screen->format->BitsPerPixel > 8 ) {
120  SDL_Rect r;
121  r.x = min(x1,x2);
122  r.y = min(y1,y2);
123  r.w = abs(x2-x1)+1;
124  r.h = abs(y2-y1)+1;
125 
126  SDL_BlitSurface( hgmp->surface->getBaseSurface() , &r, screen, &r );
127  }
128 
129  if ( x1 == -1 || y1 == -1 || x2 == -1 || y2 == -1 )
130  SDL_UpdateRect ( screen , 0,0,0,0 );
131  else
132  if ( x1 <= x2 && y1 <= y2 )
133  SDL_UpdateRect ( screen , x1, y1, x2-x1+1, y2-y1+1 );
134  else
135  if( x1 > x2 )
136  SDL_UpdateRect ( screen , x2, y1, x1-x2+1, y2-y1+1 );
137  else
138  SDL_UpdateRect ( screen , x1, y2, x2-x1+1, y1-y2+1 );
139 
140  return 0;
141 }
142 
143 MouseHider::MouseHider() : locked(true)
144 {
145  #ifdef _WIN32_
146  SDL_GetMouseState(&x, &y);
147  SDL_ShowCursor(0);
148  #endif
149 }
150 
152 {
153  #ifdef _WIN32_
154  SDL_WarpMouse(x, y);
155  SDL_ShowCursor(1);
156  // SDL_WarpMouse(x, y);
157  locked = false;
158  #endif
159 
160 }
161 
163 {
164  if ( locked )
165  unlock();
166 }
bool dummyScreenPaletteSetup
Definition: graphics.cpp:40
void unlock()
Definition: graphics.cpp:151
tgraphmodeparameters * hgmp
Definition: basegfx.cpp:40
Uint8 bitperpix
the size of a pixel(?) in bits
Definition: basegfx.h:71
int resolutiony
the number of visible pixels in y direction
Definition: basegfx.h:53
unsigned long PointerSizedInt
static Surface createSurface(int width, int height, SDLmm::Color color=255)
Definition: surface.cpp:387
tgraphmodeparameters * agmp
Definition: basegfx.cpp:39
SDL_Surface * getBaseSurface()
Definition: surface.h:116
int directscreenaccess
if 0 no call to an update function (which copies the buffer to the screen) is performed ...
Definition: basegfx.h:73
void initASCGraphicSubsystem(SDL_Surface *_screen)
Definition: graphics.cpp:42
int scanlinenumber
the number of lines (may be larger than resolutiony due to offscreen memory)
Definition: basegfx.h:58
PointerSizedInt linearaddress
the pointer to the actual memory (typecast to char* )
Definition: basegfx.h:63
int byteperpix
the distance between two pixel
Definition: basegfx.h:62
Surface * surface
Definition: basegfx.h:74
void shutdownASCGraphicSubsystem()
Definition: graphics.cpp:69
void assignDefaultPalette()
assigns the default ASC palette to the surface (only for 8 Bit surfaces)
Definition: surface.cpp:429
Surface & getActiveSurface()
Definition: graphics.cpp:82
int copy2screen(void)
Definition: graphics.cpp:91
int resolutionx
the number of visible pixels in x direction
Definition: basegfx.h:52
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
int scanlinelength
the size of a line in byte (may be larger than resolutionx due to offscreen memory) ...
Definition: basegfx.h:57
int windowstatus
determines whether the memory is a linear (windowstatus==100) or paged. When using SDL...
Definition: basegfx.h:55
SDL_Surface * screen
Definition: graphics.cpp:31
void setWindowCaption(const char *s)
sets the caption of the main window
Definition: graphics.cpp:34
int bytesperscanline
the size of a line in byte
Definition: basegfx.h:59