1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/***************************************************************************
graphics.cpp - description
-------------------
begin : Sat Dec 18 1999
copyright : (C) 1999 by Martin Bickel
email : bickel@asc-hq.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdlib.h>
#include <SDL.h>
#include "graphics.h"
#include "../basegfx.h"
#include "../global.h"
#include "../ascstring.h"
#include "../messaginghub.h"
#include "sdlstretch.cpp"
SDL_Surface *screen = NULL;
int fullscreen = 1;
void setWindowCaption ( const char* s )
{
SDL_WM_SetCaption ( s, NULL );
}
bool dummyScreenPaletteSetup = false;
void initASCGraphicSubsystem ( SDL_Surface* _screen )
{
screen = _screen;
agmp->resolutionx = screen->w;
agmp->resolutiony = screen->h;
agmp->windowstatus = 100;
agmp->scanlinenumber = screen->h;
agmp->byteperpix = 1 ;
agmp->bitperpix = 8;
agmp->directscreenaccess = 0;
delete agmp->surface;
if ( _screen->format->BitsPerPixel == 8 ) {
agmp->surface = new Surface ( _screen );
dummyScreenPaletteSetup = true;
} else {
agmp->surface = new Surface( Surface::createSurface(screen->w, screen->h, 8 ));
dummyScreenPaletteSetup = false;
}
agmp->linearaddress = (PointerSizedInt) agmp->surface->pixels();
agmp->scanlinelength = agmp->bytesperscanline = agmp->surface->pitch();
*hgmp = *agmp;
}
void shutdownASCGraphicSubsystem()
{
if ( agmp && agmp->surface )
delete agmp->surface;
}
/*
SDL_Surface* getScreen()
{
return screen;
}
*/
Surface& getActiveSurface()
{
return *agmp->surface;
}
//*********** Misc ************
int copy2screen( void )
{
#ifdef _WIN32_
// SDL_ShowCursor(0);
#endif
if ( !dummyScreenPaletteSetup ) {
hgmp->surface->assignDefaultPalette();
dummyScreenPaletteSetup = true;
}
if ( screen->format->BitsPerPixel > 8 )
SDL_BlitSurface( hgmp->surface->getBaseSurface() , NULL, screen, NULL );
SDL_UpdateRect ( screen , 0,0,0,0 );
#ifdef _WIN32_
// SDL_ShowCursor(1);
#endif
return 0;
}
int copy2screen( int x1, int y1, int x2, int y2 )
{
MouseHider mouseHider;
if ( !dummyScreenPaletteSetup ) {
hgmp->surface->assignDefaultPalette();
dummyScreenPaletteSetup = true;
}
if ( screen->format->BitsPerPixel > 8 ) {
SDL_Rect r;
r.x = min(x1,x2);
r.y = min(y1,y2);
r.w = abs(x2-x1)+1;
r.h = abs(y2-y1)+1;
SDL_BlitSurface( hgmp->surface->getBaseSurface() , &r, screen, &r );
}
if ( x1 == -1 || y1 == -1 || x2 == -1 || y2 == -1 )
SDL_UpdateRect ( screen , 0,0,0,0 );
else
if ( x1 <= x2 && y1 <= y2 )
SDL_UpdateRect ( screen , x1, y1, x2-x1+1, y2-y1+1 );
else
if( x1 > x2 )
SDL_UpdateRect ( screen , x2, y1, x1-x2+1, y2-y1+1 );
else
SDL_UpdateRect ( screen , x1, y2, x2-x1+1, y1-y2+1 );
return 0;
}
MouseHider::MouseHider() : locked(true)
{
#ifdef _WIN32_
SDL_GetMouseState(&x, &y);
SDL_ShowCursor(0);
#endif
}
void MouseHider::unlock()
{
#ifdef _WIN32_
SDL_WarpMouse(x, y);
SDL_ShowCursor(1);
// SDL_WarpMouse(x, y);
locked = false;
#endif
}
MouseHider::~MouseHider()
{
if ( locked )
unlock();
}
|