Advanced Strategic Command
Classes | Macros | Functions | Variables
basegfx.h File Reference

basegfx.h is the interface for the legacy graphic routines (of which some are platform dependent). More...

#include "libs/sdlmm/src/sdlmm.h"
#include "global.h"
#include "palette.h"
#include "sdl/graphics.h"
#include "graphics/surface.h"
Include dependency graph for basegfx.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tgraphmodeparameters
 a graphical surface. More...
 
struct  trleheader
 
class  tdrawline
 An abstract class that draws a line. More...
 
class  tvirtualdisplay
 A virtual screen is allocated and the agmp pointer set to it. More...
 
struct  trgbpixel
 A class for a single pixel. More...
 
class  TrueColorImage
 A class for a RGB image. Was an attempt to rewrite the graphics engine, but should be scrapped. Any new code should use SDLmm-Surfaces. More...
 
class  fatalgraphicserror
 a class that is thrown as exception. Should be moved to error.h ... More...
 
class  collategraphicoperations
 Collects all graphic operations and updates the screen on destruction When porting ASC from DOS to SDL, the problem arose that under DOS all graphic operations directly modified the graphics memory and were directly visible without any overhead. More...
 

Macros

#define alphabase   64
 
#define TCalpha   0xfefefe
 

Functions

void bar (int x1, int y1, int x2, int y2, Uint8 color)
 paints a colored bar More...
 
void getimage (int x1, int y1, int x2, int y2, void *buffer)
 copy an image to a buffer. buffer must have been alloced before with malloc ( imagesize ( x1,y1,x2,y2 )) More...
 
void putimage (int x1, int y1, void *buffer)
 puts the image pointed to by buffer to the screen More...
 
void putxlatfilter (int x1, int y1, void *pictbuffer, char *xlattables)
 puts the image in pictbuffer on the screen performing a color translation. More...
 
void putspriteimage (int x1, int y1, void *buffer)
 puts the image pointed to by buffer on the screen. All pixels with color #255 are treated as transparent More...
 
void putrotspriteimage (int x1, int y1, void *buffer, int rotationvalue)
 like putspriteimage, but all color with an 16 <= colorIndex <= 23 are increased by rotationvalue. More...
 
void putrotspriteimage90 (int x1, int y1, void *buffer, int rotationvalue)
 like putspriteimage, but rotates the image by 90 clock-wise More...
 
void putrotspriteimage180 (int x1, int y1, void *buffer, int rotationvalue)
 like putspriteimage, but rotates the image by 180 clock-wise More...
 
void putrotspriteimage270 (int x1, int y1, void *buffer, int rotationvalue)
 like putspriteimage, but rotates the image by 270 clock-wise More...
 
void puttexture (int x1, int y1, int x2, int y2, void *texture)
 function not used any more and obsolete. Use putimageprt instead More...
 
void putspritetexture (int x1, int y1, int x2, int y2, void *texture)
 Puts a part of texture on the screen. More...
 
void putimageprt (int x1, int y1, int x2, int y2, void *texture, int dx, int dy)
 copies a part of texture to the screen. More...
 
int loga2 (int a)
 returns the position of the lowest bit of a which is set. This equals an inter logarithm to the base of 2 More...
 
SPoint getPixelRotationLocation (SPoint pos, int width, int height, int degrees)
 transforms the coordinate for an image rotation More...
 
void putpixel (int x1, int y1, int color)
 puts a single pixel on the screen. This is one of the few functions that work in truecolor mode too More...
 
int getpixel (int x1, int y1)
 gets the color of a single pixel from the screen. This is one of the few functions that work in truecolor mode too More...
 
int imagesize (int x1, int y1, int x2, int y2)
 returns the size for a buffer that can contain an image of the given size. More...
 
void getpicsize (void *p, int &width, int &height)
 write the dimension of the image p to width and height More...
 
int getpicsize2 (void *p)
 returns the size that the picture p occupies in memory More...
 
void * uncompress_rlepict (void *pict)
 uncompresses the RLE-compressed image pict. More...
 
void generategrayxlattable (ppixelxlattable tab, Uint8 offset, Uint8 size, dacpalette256 *pal)
 A translation table ( to be used by xlatpict ) is generated to translate any color of palette pal to its gray value. More...
 
void rahmen (bool invers, int x1, int y1, int x2, int y2)
 paints a pseudo-3D rectangle on the screen. More...
 
void line (int x1, int y1, int x2, int y2, Uint8 color)
 draws a simple line on the screen. Not very fast... More...
 
void xorline (int x1, int y1, int x2, int y2, Uint8 color)
 draws a simple line on the screen, but performs a XOR operation between the pixel already on screen and color. More...
 
void rectangle (int x1, int y1, int x2, int y2, Uint8 color)
 draws a simple rectangl More...
 
void xorrectangle (int x1, int y1, int x2, int y2, Uint8 color)
 draws a simple rectangle on the screen, but performs a XOR operation between the pixel already on screen and color. More...
 
void putinterlacedrotimage (int x1, int y1, void *ptr, int rotation)
 obsolete. not used any more. can be removed. More...
 
void rotatepict90 (void *s, void *d)
 rotates the image s by 90 clockwise and writes it to d. More...
 
void flippict (void *s, void *d, int dir=1)
 mirrors a picture horizontally (dir=1) or vertically (dir=0). More...
 
void * halfpict (void *vbuf)
 reduces a pictures size. More...
 
Uint8 * rotatepict (void *image, int angle)
 rotates the picture image by angle clockwise. More...
 
Uint8 * rotatepict_grw (void *image, int organgle)
 rotates the picture image by angle clockwise. More...
 
int getpixelfromimage (void *buf, int x, int y)
 returns the pixel at position x/y of the image buf or -1 if the pixel does not exist More...
 
void ellipse (int x1, int y1, int x2, int y2, int color, float tolerance)
 paints an ellipse on the screen that fills the rectangle x1/y1 - x2/y2. More...
 
void putmask (int x1, int y1, void *vbuf, int newtransparence)
 puts an image on the screen , with all pixels of newtransparence treated as transparent. More...
 
void putpicturemix (int x1, int y1, void *ptr, int rotation, char *mixbuf)
 puts the image ptr on the screen, mixing it with the colors there. More...
 
void copySurface2screen (void)
 when using SDL, all operations are not performed on the displaymemory itself (as is the case with DOS), but on a buffer. More...
 
void copySurface2screen (int x1, int y1, int x2, int y2)
 
char * convertimage (TrueColorImage *img, dacpalette256 pal)
 the truecolor image img is reduced to 8 bit color using the palette pal. More...
 
void putimage (int x1, int y1, TrueColorImage *tci)
 a table to speed up conversion from truecolor to 8bit palette. More...
 
void putimage_noalpha (int x1, int y1, TrueColorImage *tci)
 
TrueColorImagesmoothimage (TrueColorImage *src)
 
TrueColorImagegetimage (int x1, int y1, int x2, int y2)
 
void setWindowCaption (const char *s)
 sets the caption of the main window More...
 

Variables

const int colorDepth = 4
 
const int black = 0
 
const int blue = 1
 
const int green = 2
 
const int cyan = 3
 
const int red = 4
 
const int magenta = 5
 
const int brown = 6
 
const int lightgray = 7
 
const int darkgray = 8
 
const int lightblue = 9
 
const int lightgreen = 42
 
const int lightcyan = 119
 
const int lightred = 52
 
const int lightmagenta = 5
 
const int yellow = 103
 
const int white = 160
 
tgraphmodeparametersagmp
 
tgraphmodeparametershgmp
 
dacpalette256activepalette256
 
tgraphmodeparameters activegraphmodeparameters
 
tgraphmodeparameters hardwaregraphmodeparameters
 
dacpalette256 activepalette
 
void * xlatbuffer
 

Detailed Description

basegfx.h is the interface for the legacy graphic routines (of which some are platform dependent).

basegfx.h additionally includes the definitions of routines, whose implementation is platform dependant, but whose interface is the same on all platforms. Their implementation is in the various subdirectories for the platforms. The graphic routines are older than ASC itself, first written in 1993 as a protected mode replacement for Borlands BGI. (That's why the uncompressed image structure is exactly the same as in the BGI).

the code here is being replaced by the new graphics system found in the graphics subdirectory

Definition in file basegfx.h.

Macro Definition Documentation

#define alphabase   64

Definition at line 348 of file basegfx.h.

Referenced by getimage(), putimage_noalpha(), putpixel(), and smoothimage().

#define TCalpha   0xfefefe

Definition at line 351 of file basegfx.h.

Referenced by putimage_noalpha().

Function Documentation

void bar ( int  x1,
int  y1,
int  x2,
int  y2,
Uint8  color 
)
char* convertimage ( TrueColorImage img,
dacpalette256  pal 
)

the truecolor image img is reduced to 8 bit color using the palette pal.

A new buffer is allocated and returned. It must be freed after use.

void copySurface2screen ( void  )

when using SDL, all operations are not performed on the displaymemory itself (as is the case with DOS), but on a buffer.

This function copies the buffer to the screen, performing a color conversion if necessary

Definition at line 1208 of file basegfx.cpp.

References copy2screen(), and tgraphmodeparameters::directscreenaccess.

void copySurface2screen ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 1214 of file basegfx.cpp.

References copy2screen(), and tgraphmodeparameters::directscreenaccess.

void ellipse ( int  x1,
int  y1,
int  x2,
int  y2,
int  color,
float  tolerance 
)

paints an ellipse on the screen that fills the rectangle x1/y1 - x2/y2.

The thickness of the ellipse depends on tolerance. This function is just for highlighting elements on the screen, not for drawing nice and mathematically correct ellipse

Definition at line 1043 of file basegfx.cpp.

References putpixel().

void flippict ( void *  s,
void *  d,
int  dir = 1 
)

mirrors a picture horizontally (dir=1) or vertically (dir=0).

d must point to a buffer with the size of imagesize2(s)

Definition at line 675 of file basegfx.cpp.

void generategrayxlattable ( ppixelxlattable  tab,
Uint8  offset,
Uint8  size,
dacpalette256 pal 
)

A translation table ( to be used by xlatpict ) is generated to translate any color of palette pal to its gray value.

The new pixels after the translation are still to be used with the palette pal. offset and size specify a range of colors that are assumed to be a linear transition from white to black. So all colors are mapped to one of the colors of the offset-size range.

Definition at line 44 of file basegfx.cpp.

Referenced by loadpalette().

void getimage ( int  x1,
int  y1,
int  x2,
int  y2,
void *  buffer 
)
TrueColorImage* getimage ( int  x1,
int  y1,
int  x2,
int  y2 
)
void getpicsize ( void *  p,
int &  width,
int &  height 
)

write the dimension of the image p to width and height

Definition at line 52 of file basegfx.cpp.

References trleheader::id, trleheader::size, trleheader::x, and trleheader::y.

Referenced by getimagepixel(), rotatepict(), rotatepict_grw(), and uncompress_rlepict().

int getpicsize2 ( void *  p)

returns the size that the picture p occupies in memory

Definition at line 64 of file basegfx.cpp.

References trleheader::id, and trleheader::size.

int getpixel ( int  x1,
int  y1 
)
int getpixelfromimage ( void *  buf,
int  x,
int  y 
)

returns the pixel at position x/y of the image buf or -1 if the pixel does not exist

Definition at line 798 of file basegfx.cpp.

Referenced by putimageprt(), putrotspriteimage180(), putrotspriteimage270(), and putrotspriteimage90().

SPoint getPixelRotationLocation ( SPoint  pos,
int  width,
int  height,
int  degrees 
)
void* halfpict ( void *  vbuf)

reduces a pictures size.

The new picture will have half the size in x and y direction, resulting in a quarting of the area. The new image will be written to a static buffer that is overwritten the next time halfpict or xlatpict is called. The address of the buffer is returned.

Definition at line 337 of file basegfx.cpp.

References trleheader::id, trleheader::rle, trleheader::size, trleheader::x, xlatbuffer, xlatbuffersize, and trleheader::y.

int imagesize ( int  x1,
int  y1,
int  x2,
int  y2 
)
void line ( int  x1,
int  y1,
int  x2,
int  y2,
Uint8  color 
)
int loga2 ( int  a)

returns the position of the lowest bit of a which is set. This equals an inter logarithm to the base of 2

Definition at line 1793 of file basegfx.cpp.

void putimage ( int  x1,
int  y1,
void *  buffer 
)
void putimage ( int  x1,
int  y1,
TrueColorImage tci 
)

a table to speed up conversion from truecolor to 8bit palette.

The 6 most significant bits of each color component (RGB) form the the index. puts the image pointed to by tci to the screen. Both must be truecolor images. This function is a quick and unoptimized hack!

Definition at line 1334 of file basegfx.cpp.

References trgbpixel::channel, TrueColorImage::getpix(), TrueColorImage::getxsize(), TrueColorImage::getysize(), and putpixel().

void putimage_noalpha ( int  x1,
int  y1,
TrueColorImage tci 
)
void putimageprt ( int  x1,
int  y1,
int  x2,
int  y2,
void *  texture,
int  dx,
int  dy 
)

copies a part of texture to the screen.

Texture and the screen may have different size. x1/y1 and x2/y2 is the rectangle of the screen that texture is copied to. dx/dy is the offset between x1/y1 and the upper left corner of texture. If dx==0 and dy==1, the uppermost line of texture would not be displayed. The rectangle x1/y1 - x2/y2 may be larger than texture.

Definition at line 1693 of file basegfx.cpp.

References tgraphmodeparameters::byteperpix, getpixelfromimage(), tgraphmodeparameters::linearaddress, tgraphmodeparameters::scanlinelength, and tgraphmodeparameters::windowstatus.

Referenced by tviewtext::displaysingleline().

void putinterlacedrotimage ( int  x1,
int  y1,
void *  ptr,
int  rotation 
)

obsolete. not used any more. can be removed.

Definition at line 477 of file basegfx.cpp.

References tgraphmodeparameters::linearaddress, tgraphmodeparameters::scanlinelength, and tgraphmodeparameters::windowstatus.

void putmask ( int  x1,
int  y1,
void *  vbuf,
int  newtransparence 
)

puts an image on the screen , with all pixels of newtransparence treated as transparent.

Definition at line 975 of file basegfx.cpp.

References tgraphmodeparameters::byteperpix, tgraphmodeparameters::bytesperscanline, and tgraphmodeparameters::linearaddress.

void putpicturemix ( int  x1,
int  y1,
void *  ptr,
int  rotation,
char *  mixbuf 
)

puts the image ptr on the screen, mixing it with the colors there.

Mixbuf must point to 256*256 byte large structure, where mixbuf[a][b] contains the colors that results from mixing a and b.

void putpixel ( int  x1,
int  y1,
int  color 
)
void putrotspriteimage ( int  x1,
int  y1,
void *  buffer,
int  rotationvalue 
)

like putspriteimage, but all color with an 16 <= colorIndex <= 23 are increased by rotationvalue.

This is used to display colored units. The mentioned color range are the red colors, which can be made blue by adding 8 to them, 16 makes them brown, etc..

Definition at line 1496 of file basegfx.cpp.

References tgraphmodeparameters::byteperpix, trleheader::id, tgraphmodeparameters::linearaddress, trleheader::rle, tgraphmodeparameters::scanlinelength, trleheader::size, tgraphmodeparameters::windowstatus, trleheader::x, and trleheader::y.

void putrotspriteimage180 ( int  x1,
int  y1,
void *  buffer,
int  rotationvalue 
)
void putrotspriteimage270 ( int  x1,
int  y1,
void *  buffer,
int  rotationvalue 
)
void putrotspriteimage90 ( int  x1,
int  y1,
void *  buffer,
int  rotationvalue 
)
void putspriteimage ( int  x1,
int  y1,
void *  buffer 
)

puts the image pointed to by buffer on the screen. All pixels with color #255 are treated as transparent

Definition at line 1439 of file basegfx.cpp.

References tgraphmodeparameters::byteperpix, trleheader::id, tgraphmodeparameters::linearaddress, trleheader::rle, tgraphmodeparameters::scanlinelength, trleheader::size, tgraphmodeparameters::windowstatus, trleheader::x, and trleheader::y.

void putspritetexture ( int  x1,
int  y1,
int  x2,
int  y2,
void *  texture 
)

Puts a part of texture on the screen.

Texture must be the same size as the screen, so the coordinates x1/y1 and x2/y2 describe the same rectangle on texture and the screen. This rectangle is copied from texture to the screen. color #255 is treated as transparent

Definition at line 1670 of file basegfx.cpp.

References tgraphmodeparameters::linearaddress, tgraphmodeparameters::scanlinelength, and tgraphmodeparameters::windowstatus.

Referenced by tdialogbox::copyvirtualframebuf().

void puttexture ( int  x1,
int  y1,
int  x2,
int  y2,
void *  texture 
)

function not used any more and obsolete. Use putimageprt instead

Definition at line 1648 of file basegfx.cpp.

References tgraphmodeparameters::linearaddress, tgraphmodeparameters::scanlinelength, and tgraphmodeparameters::windowstatus.

Referenced by tdialogbox::paintsurface2().

void putxlatfilter ( int  x1,
int  y1,
void *  pictbuffer,
char *  xlattables 
)

puts the image in pictbuffer on the screen performing a color translation.

xlattables points to an array of n*256 byte. n must be equal or greater than the highest pixel in pictbuffer. Example: you want to paint the tracks on the screen which are left by heavy vehicles. There is an image of a track which contains just pixels of 0, 1 and two. You now provide a set of 3 tables each 256 bytes large. The first one just counts from 0 to 255 The second one has color values that are a bit darker than the original: If color #2 was blue, table[2] would have the index of a dark blue color. The third table is like the second one, but points to even darker colors. If you now paint the track using this function: where there is color #0 in the track image, the pixel on the screen would be unchanged where there is color #1 in the track image, the pixel on the screen is made darker and where there is color #2, the pixel on the screen is becoming even more darker Ok, that's all. A very specialized function. I just checked and noticed that it is not used any more by ASC. Damn, why did I write this description instead of just deleting this procedure ;-)

void rahmen ( bool  invers,
int  x1,
int  y1,
int  x2,
int  y2 
)

paints a pseudo-3D rectangle on the screen.

invers specifies wheather the rectangle seems to be pressed into the screen or coming out

Definition at line 82 of file basegfx.cpp.

References darkgray, line(), and white.

Referenced by tshowhistoryinit().

void rectangle ( int  x1,
int  y1,
int  x2,
int  y2,
Uint8  color 
)
Uint8* rotatepict ( void *  image,
int  angle 
)

rotates the picture image by angle clockwise.

The resulting image will have exactly the same size as the original image, resulting in the image being clipped

Definition at line 553 of file basegfx.cpp.

References fieldxsize, fieldysize, getimagepixel(), getpicsize(), imagesize(), and pi.

void rotatepict90 ( void *  s,
void *  d 
)

rotates the image s by 90 clockwise and writes it to d.

d must point to a buffer with the size of imagesize2(s)

Definition at line 506 of file basegfx.cpp.

Uint8* rotatepict_grw ( void *  image,
int  organgle 
)

rotates the picture image by angle clockwise.

The resulting image will be larger than the original one

Definition at line 613 of file basegfx.cpp.

References fieldxsize, fieldysize, getimagepixel(), getpicsize(), imagesize(), and pi.

void setWindowCaption ( const char *  s)

sets the caption of the main window

Definition at line 34 of file graphics.cpp.

Referenced by main().

TrueColorImage* smoothimage ( TrueColorImage src)
void* uncompress_rlepict ( void *  pict)

uncompresses the RLE-compressed image pict.

A buffer for the uncompressed image is allocated and returned, so it must be freed later

Definition at line 1001 of file basegfx.cpp.

References getpicsize(), trleheader::id, malloc(), trleheader::rle, and trleheader::size.

Referenced by Surface::read().

void xorline ( int  x1,
int  y1,
int  x2,
int  y2,
Uint8  color 
)

draws a simple line on the screen, but performs a XOR operation between the pixel already on screen and color.

Thus the line will always have a color different then the one that was previously there. And it can be undone by displaying it a second time.

Definition at line 241 of file basegfx.cpp.

References getpixel(), and putpixel().

Referenced by tparagraph::displaycursor(), tdialogbox::lne(), and xorrectangle().

void xorrectangle ( int  x1,
int  y1,
int  x2,
int  y2,
Uint8  color 
)

draws a simple rectangle on the screen, but performs a XOR operation between the pixel already on screen and color.

Thus the rectangle will always have a color different then the one that was previously there. And it can be undone by displaying it a second time.

Definition at line 313 of file basegfx.cpp.

References xorline().

Referenced by tdialogbox::run(), and tdialogbox::showtabmark().

Variable Documentation

tgraphmodeparameters activegraphmodeparameters

Definition at line 1223 of file basegfx.cpp.

Referenced by tinitgfxengine::tinitgfxengine().

dacpalette256 activepalette

Definition at line 1229 of file basegfx.cpp.

Referenced by tinitgfxengine::tinitgfxengine().

dacpalette256* activepalette256

Definition at line 1074 of file basegfx.cpp.

const int black = 0
const int blue = 1

Definition at line 88 of file basegfx.h.

Referenced by tparagraph::displaycursor(), and tdialogbox::redraw().

const int brown = 6

Definition at line 93 of file basegfx.h.

const int colorDepth = 4
const int cyan = 3

Definition at line 90 of file basegfx.h.

const int darkgray = 8

Definition at line 95 of file basegfx.h.

Referenced by tdialogbox::init(), BuildingValues::init(), lines(), rahmen(), and tdialogbox::rahmen().

const int green = 2

Definition at line 89 of file basegfx.h.

tgraphmodeparameters hardwaregraphmodeparameters

Definition at line 1224 of file basegfx.cpp.

Referenced by tinitgfxengine::tinitgfxengine().

const int lightblue = 9

Definition at line 96 of file basegfx.h.

Referenced by mapeditorMainThread(), and tstringselect::viewtext().

const int lightcyan = 119

Definition at line 98 of file basegfx.h.

const int lightgray = 7
const int lightgreen = 42

Definition at line 97 of file basegfx.h.

const int lightmagenta = 5

Definition at line 100 of file basegfx.h.

const int lightred = 52

Definition at line 99 of file basegfx.h.

Referenced by tdisplaymessage::init().

const int magenta = 5

Definition at line 92 of file basegfx.h.

const int red = 4
const int white = 160

Definition at line 102 of file basegfx.h.

Referenced by lines(), rahmen(), tdialogbox::rahmen(), and tdialogbox::redraw().

void* xlatbuffer

Definition at line 1231 of file basegfx.cpp.

Referenced by halfpict(), and tinitgfxengine::tinitgfxengine().

const int yellow = 103

Definition at line 101 of file basegfx.h.

Referenced by AttackPanel::dispValue().