00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <SDL.h>
00022 #include "graphics.h"
00023 #include "../basegfx.h"
00024 #include "../global.h"
00025 #include "../ascstring.h"
00026 #include "../messaginghub.h"
00027
00028
00029 #include "sdlstretch.cpp"
00030
00031 SDL_Surface *screen = NULL;
00032 int fullscreen = 1;
00033
00034
00035 void setWindowCaption ( const char* s )
00036 {
00037 SDL_WM_SetCaption ( s, NULL );
00038 }
00039
00040
00041 bool dummyScreenPaletteSetup = false;
00042
00043 void initASCGraphicSubsystem ( SDL_Surface* _screen )
00044 {
00045 screen = _screen;
00046 agmp->resolutionx = screen->w;
00047 agmp->resolutiony = screen->h;
00048 agmp->windowstatus = 100;
00049 agmp->scanlinenumber = screen->h;
00050 agmp->byteperpix = 1 ;
00051 agmp->bitperpix = 8;
00052 agmp->directscreenaccess = 0;
00053 delete agmp->surface;
00054 if ( _screen->format->BitsPerPixel == 8 ) {
00055 agmp->surface = new Surface ( _screen );
00056 dummyScreenPaletteSetup = true;
00057 } else {
00058 agmp->surface = new Surface( Surface::createSurface(screen->w, screen->h, 8 ));
00059 dummyScreenPaletteSetup = false;
00060 }
00061 agmp->linearaddress = (PointerSizedInt) agmp->surface->pixels();
00062 agmp->scanlinelength = agmp->bytesperscanline = agmp->surface->pitch();
00063
00064
00065 *hgmp = *agmp;
00066 }
00067
00068
00069
00070 void shutdownASCGraphicSubsystem()
00071 {
00072 if ( agmp && agmp->surface )
00073 delete agmp->surface;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 Surface& getActiveSurface()
00084 {
00085 return *agmp->surface;
00086 }
00087
00088
00089
00090
00091
00092 int copy2screen( void )
00093 {
00094 #ifdef _WIN32_
00095
00096 #endif
00097 if ( !dummyScreenPaletteSetup ) {
00098 hgmp->surface->assignDefaultPalette();
00099 dummyScreenPaletteSetup = true;
00100 }
00101
00102 if ( screen->format->BitsPerPixel > 8 )
00103 SDL_BlitSurface( hgmp->surface->getBaseSurface() , NULL, screen, NULL );
00104 SDL_UpdateRect ( screen , 0,0,0,0 );
00105 #ifdef _WIN32_
00106
00107 #endif
00108 return 0;
00109 }
00110
00111 int copy2screen( int x1, int y1, int x2, int y2 )
00112 {
00113 MouseHider mouseHider;
00114
00115 if ( !dummyScreenPaletteSetup ) {
00116 hgmp->surface->assignDefaultPalette();
00117 dummyScreenPaletteSetup = true;
00118 }
00119
00120 if ( screen->format->BitsPerPixel > 8 ) {
00121 SDL_Rect r;
00122 r.x = min(x1,x2);
00123 r.y = min(y1,y2);
00124 r.w = abs(x2-x1)+1;
00125 r.h = abs(y2-y1)+1;
00126
00127 SDL_BlitSurface( hgmp->surface->getBaseSurface() , &r, screen, &r );
00128 }
00129
00130 if ( x1 == -1 || y1 == -1 || x2 == -1 || y2 == -1 )
00131 SDL_UpdateRect ( screen , 0,0,0,0 );
00132 else
00133 if ( x1 <= x2 && y1 <= y2 )
00134 SDL_UpdateRect ( screen , x1, y1, x2-x1+1, y2-y1+1 );
00135 else
00136 if( x1 > x2 )
00137 SDL_UpdateRect ( screen , x2, y1, x1-x2+1, y2-y1+1 );
00138 else
00139 SDL_UpdateRect ( screen , x1, y2, x2-x1+1, y1-y2+1 );
00140
00141 return 0;
00142 }
00143
00144 MouseHider::MouseHider() : locked(true)
00145 {
00146 #ifdef _WIN32_
00147 SDL_GetMouseState(&x, &y);
00148 SDL_ShowCursor(0);
00149 #endif
00150 }
00151
00152 void MouseHider::unlock()
00153 {
00154 #ifdef _WIN32_
00155 SDL_WarpMouse(x, y);
00156 SDL_ShowCursor(1);
00157
00158 locked = false;
00159 #endif
00160
00161 }
00162
00163 MouseHider::~MouseHider()
00164 {
00165 if ( locked )
00166 unlock();
00167 }