Hash :
cb58dbb4
Author :
Date :
2000-01-17T11:04:55
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
#include "grobjs.h"
#include "grdevice.h"
#include <stdlib.h>
#include <string.h>
grDeviceChain gr_device_chain[ GR_MAX_DEVICES ];
int gr_num_devices = 0;
static
grDevice* find_device( const char* device_name )
{
int index = 0;
if (device_name)
{
for ( index = gr_num_devices-1; index > 0; index-- )
if ( strcmp( device_name, gr_device_chain[index].name ) == 0 )
break;
}
if ( index < 0 || gr_num_devices <= 0 || !gr_device_chain[index].device )
{
grError = gr_err_invalid_device;
return 0;
}
return gr_device_chain[index].device;
}
/**********************************************************************
*
* <Function>
* grGetDeviceModes
*
* <Description>
* queries the available pixel modes for a device.
*
* <Input>
* device_name :: name of device to be used. 0 for the default
* device. For a list of available devices, see
* grInitDevices.
*
* <Output>
* num_modes :: number of available modes. 0 in case of error,
* which really is an invalid device name.
*
* pixel_modes :: array of available pixel modes for this device
* this table is internal to the device and should
* not be freed by client applications.
*
* <Return>
* error code. 0 means success. invalid device name otherwise
*
* <Note>
* All drivers are _required_ to support at least the following
* pixel formats :
*
* - gr_pixel_mode_mono : i.e. monochrome bitmaps
* - gr_pixel_mode_gray : with any number of gray levels between
* 2 and 256.
*
* the pixel modes do not provide the number of grays in the case
* of "gray" devices. You should try to create a surface with the
* maximal number (256, that is) and see the value returned in
* the bitmap descriptor.
*
**********************************************************************/
extern void grGetDeviceModes( const char* device_name,
int *num_modes,
grPixelMode* *pixel_modes )
{
grDevice* device;
*num_modes = 0;
*pixel_modes = 0;
device = find_device( device_name );
if (device)
{
*num_modes = device->num_pixel_modes;
*pixel_modes = device->pixel_modes;
}
}
/**********************************************************************
*
* <Function>
* grNewSurface
*
* <Description>
* creates a new device-specific surface. A surface is either
* a window or a screen, depending on the device.
*
* <Input>
* device :: name of the device to use. A value of NULL means
* the default device (which depends on the system).
* for a list of available devices, see grInitDevices.
*
* <InOut>
* bitmap :: handle to a bitmap descriptor containing the
* requested pixel mode, number of grays and dimensions
* for the surface. the bitmap's 'pitch' and 'buffer'
* fields are ignored on input.
*
* On output, the bitmap describes the surface's image
* completely. It is possible to write directly in it
* with grBlitGlyphToBitmap, even though the use of
* grBlitGlyphToSurface is recommended.
*
* <Return>
* handle to the corresponding surface object. 0 in case of error
*
* <Note>
* All drivers are _required_ to support at least the following
* pixel formats :
*
* - gr_pixel_mode_mono : i.e. monochrome bitmaps
* - gr_pixel_mode_gray : with any number of gray levels between
* 2 and 256.
*
* This function might change the bitmap descriptor's fields. For
* example, when displaying a full-screen surface, the bitmap's
* dimensions will be set to those of the screen (e.g. 640x480
* or 800x600); also, the bitmap's 'buffer' field might point to
* the Video Ram depending on the mode requested..
*
* The surface contains a copy of the returned bitmap descriptor,
* you can thus discard the 'bitmap' parameter after the call.
*
**********************************************************************/
extern grSurface* grNewSurface( const char* device_name,
grBitmap* bitmap )
{
grDevice* device;
grSurface* surface;
/* Now find the device */
device = find_device( device_name );
if (!device) return 0;
surface = (grSurface*)grAlloc( device->surface_objsize );
if (!surface) return 0;
if ( !device->init_surface( surface, bitmap ) )
{
grFree( surface );
surface = 0;
}
return surface;
}
/**********************************************************************
*
* <Function>
* grRefreshRectangle
*
* <Description>
* this function is used to indicate that a given surface rectangle
* was modified and thus needs re-painting. It really is useful for
* windowed or gray surfaces.
*
* <Input>
* surface :: handle to target surface
* x :: x coordinate of the top-left corner of the rectangle
* y :: y coordinate of the top-left corner of the rectangle
* width :: rectangle width in pixels
* height :: rectangle height in pixels
*
**********************************************************************/
extern void grRefreshRectangle( grSurface* surface,
grPos x,
grPos y,
grPos width,
grPos height )
{
if (surface->refresh_rect)
surface->refresh_rect( surface, x, y, width, height );
}
/**********************************************************************
*
* <Function>
* grWriteSurfaceChar
*
* <Description>
* This function is equivalent to calling grWriteCellChar on the
* surface's bitmap, then invoking grRefreshRectangle.
*
* The graphics sub-system contains an internal Latin1 8x8 font
* which can be used to display simple strings of text without
* using FreeType.
*
* This function writes a single 8x8 character on the target bitmap.
*
* <Input>
* target :: handle to target surface
* x :: x pixel position of character cell's top left corner
* y :: y pixel position of character cell's top left corner
* charcode :: Latin-1 character code
* color :: color to be used to draw the character
*
**********************************************************************/
extern
void grWriteSurfaceChar( grSurface* target,
int x,
int y,
int charcode,
grColor color )
{
grWriteCellChar( &target->bitmap, x, y, charcode, color );
if (target->refresh_rect)
target->refresh_rect( target, x, y, 8, 8 );
}
/**********************************************************************
*
* <Function>
* grWriteSurfaceString
*
* <Description>
* This function is equivalent to calling grWriteCellString on the
* surface's bitmap, then invoking grRefreshRectangle.
*
* The graphics sub-system contains an internal Latin1 8x8 font
* which can be used to display simple strings of text without
* using FreeType.
*
* This function writes a string with the internal font
*
* <Input>
* target :: handle to target bitmap
* x :: x pixel position of string's top left corner
* y :: y pixel position of string's top left corner
* string :: Latin-1 text string
* color :: color to be used to draw the character
*
**********************************************************************/
extern
void grWriteSurfaceString( grSurface* target,
int x,
int y,
const char* string,
grColor color )
{
int len;
len = strlen(string);
grWriteCellString( &target->bitmap, x, y, string, color );
if (target->refresh_rect)
target->refresh_rect( target, x, y, 8*len, 8 );
}
/**********************************************************************
*
* <Function>
* grRefreshSurface
*
* <Description>
* a variation of grRefreshRectangle which repaints the whole surface
* to the screen.
*
* <Input>
* surface :: handle to target surface
*
**********************************************************************/
extern void grRefreshSurface( grSurface* surface )
{
if (surface->refresh_rect)
surface->refresh_rect( surface, 0, 0,
surface->bitmap.width,
surface->bitmap.rows );
}
/**********************************************************************
*
* <Function>
* grSetTitle
*
* <Description>
* set the window title of a given windowed surface.
*
* <Input>
* surface :: handle to target surface
* title_string :: the new title
*
**********************************************************************/
extern void grSetTitle( grSurface* surface,
const char* title_string )
{
if (surface->set_title)
surface->set_title( surface, title_string );
}
/**********************************************************************
*
* <Function>
* grListenSurface
*
* <Description>
* listen the events for a given surface
*
* <Input>
* surface :: handle to target surface
* event_mask :: the event mask (mode)
*
* <Output>
* event :: the returned event
*
* <Note>
* XXX : For now, only keypresses are supported.
*
**********************************************************************/
extern
int grListenSurface( grSurface* surface,
int event_mask,
grEvent *event )
{
return surface->listen_event( surface, event_mask, event );
}
#if 0
static
void gr_done_surface( grSurface* surface )
{
if (surface)
{
/* first of all, call the device-specific destructor */
surface->done(surface);
/* then remove the bitmap if we're owner */
if (surface->owner)
grFree( surface->bitmap.buffer );
surface->owner = 0;
surface->bitmap.buffer = 0;
grFree( surface );
}
}
#endif