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