1 /*****************************************************************************/
5 /* Tiny graphics interface */
9 /* (C) 2002-2013, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
41 #include <tgi/tgi-error.h>
46 /*****************************************************************************/
48 /*****************************************************************************/
52 /* Font constants for use with tgi_settextstyle */
53 #define TGI_FONT_BITMAP 0
54 #define TGI_FONT_VECTOR 1
56 /* Direction constants for use with tgi_settextstyle */
57 #define TGI_TEXT_HORIZONTAL 0
58 #define TGI_TEXT_VERTICAL 1
60 /* The name of the standard tgi driver for a platform */
61 extern const char tgi_stddrv[];
63 /* The address of the static standard tgi driver for a platform */
64 extern const void tgi_static_stddrv[];
66 /* A vector font definition */
67 typedef struct tgi_vectorfont tgi_vectorfont;
71 /*****************************************************************************/
73 /*****************************************************************************/
77 void __fastcall__ tgi_load_driver (const char* name);
78 /* Load and install the given driver. */
80 void tgi_unload (void);
81 /* Uninstall, then unload the currently loaded driver. Will call tgi_done if
85 void __fastcall__ tgi_install (void* driver);
86 /* Install an already loaded driver. */
88 void tgi_uninstall (void);
89 /* Uninstall the currently loaded driver but do not unload it. Will call
90 ** tgi_done if necessary.
94 /* Initialize the already loaded graphics driver. */
97 /* End graphics mode, switch back to text mode. Will NOT uninstall or unload
101 const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name);
102 /* Load a vector font into memory and return it. In case of errors, NULL is
103 ** returned and an error is set, which can be retrieved using tgi_geterror.
104 ** To use the font, it has to be installed using tgi_install_vectorfont.
107 void __fastcall__ tgi_install_vectorfont (const tgi_vectorfont* font);
108 /* Install a vector font for use. More than one vector font can be loaded,
109 ** but only one can be active. This function is used to tell which one. Call
110 ** with a NULL pointer to uninstall the currently installed font.
113 void __fastcall__ tgi_free_vectorfont (const tgi_vectorfont* font);
114 /* Free a vector font that was previously loaded into memory. */
116 unsigned char tgi_geterror (void);
117 /* Return the error code for the last operation. This will also clear the
121 const char* __fastcall__ tgi_geterrormsg (unsigned char code);
122 /* Get an error message describing the error in code. */
124 void tgi_clear (void);
125 /* Clear the drawpage. */
127 unsigned tgi_getpagecount (void);
128 /* Returns the number of screen pages available. */
130 void __fastcall__ tgi_setviewpage (unsigned char page);
131 /* Set the visible page. Will set an error if the page is not available. */
133 void __fastcall__ tgi_setdrawpage (unsigned char page);
134 /* Set the drawable page. Will set an error if the page is not available. */
136 unsigned char tgi_getcolorcount (void);
137 /* Get the number of available colors. */
139 unsigned char tgi_getmaxcolor (void);
140 /* Return the maximum supported color number (the number of colors would
141 ** then be getmaxcolor()+1).
144 void __fastcall__ tgi_setcolor (unsigned char color);
145 /* Set the current drawing color. */
147 unsigned char tgi_getcolor (void);
148 /* Return the current drawing color. */
150 void __fastcall__ tgi_setpalette (const unsigned char* palette);
151 /* Set the palette (not available with all drivers/hardware). palette is
152 ** a pointer to as many entries as there are colors.
155 const unsigned char* tgi_getpalette (void);
156 /* Return the current palette. */
158 const unsigned char* tgi_getdefpalette (void);
159 /* Return the default palette. */
161 unsigned tgi_getxres (void);
162 /* Return the resolution in X direction. */
164 unsigned tgi_getmaxx (void);
165 /* Return the maximum x coordinate. The resolution in x direction is
169 unsigned tgi_getyres (void);
170 /* Return the resolution in Y direction. */
172 unsigned tgi_getmaxy (void);
173 /* Return the maximum y coordinate. The resolution in y direction is
177 unsigned tgi_getaspectratio (void);
178 /* Returns the aspect ratio for the loaded driver. The aspect ratio is an
179 ** 8.8 fixed point value.
182 void __fastcall__ tgi_setaspectratio (unsigned aspectratio);
183 /* Set a new aspect ratio for the loaded driver. The aspect ratio is an
184 ** 8.8 fixed point value.
187 unsigned char __fastcall__ tgi_getpixel (int x, int y);
188 /* Get the color value of a pixel. */
190 void __fastcall__ tgi_setpixel (int x, int y);
191 /* Plot a pixel in the current drawing color. */
193 void __fastcall__ tgi_gotoxy (int x, int y);
194 /* Set the graphics cursor to the given position. */
196 void __fastcall__ tgi_line (int x1, int y1, int x2, int y2);
197 /* Draw a line in the current drawing color. The graphics cursor will
198 ** be set to x2/y2 by this call.
201 void __fastcall__ tgi_lineto (int x2, int y2);
202 /* Draw a line in the current drawing color from the graphics cursor to the
203 ** new end point. The graphics cursor will be updated to x2/y2.
206 void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
207 /* Draw a circle in the current drawing color. */
209 void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);
210 /* Draw a full ellipse with center at x/y and radii rx/ry using the current
214 void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
215 unsigned sa, unsigned ea);
216 /* Draw an ellipse arc with center at x/y and radii rx/ry using the current
217 ** drawing color. The arc covers the angle between sa and ea (startangle and
218 ** endangle), which must be in the range 0..360 (otherwise the function may
219 ** bevave unextectedly).
222 void __fastcall__ tgi_pieslice (int x, int y, unsigned char rx, unsigned char ry,
223 unsigned sa, unsigned ea);
224 /* Draw an ellipse pie slice with center at x/y and radii rx/ry using the
225 ** current drawing color. The pie slice covers the angle between sa and ea
226 ** (startangle and endangle), which must be in the range 0..360 (otherwise the
227 ** function may behave unextectedly).
230 void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
231 /* Draw a bar (a filled rectangle) using the current color. */
233 void __fastcall__ tgi_settextdir (unsigned char dir);
234 /* Set the direction for text output. dir is one of the TGI_TEXT_XXX
238 void __fastcall__ tgi_settextscale (unsigned width, unsigned height);
239 /* Set the scaling for text output. The scaling factors for width and height
240 ** are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
243 void __fastcall__ tgi_settextstyle (unsigned width, unsigned height,
244 unsigned char dir, unsigned char font);
245 /* Set the style for text output. The scaling factors for width and height
246 ** are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
247 ** dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
251 unsigned __fastcall__ tgi_gettextwidth (const char* s);
252 /* Calculate the width of the text in pixels according to the current text
256 unsigned __fastcall__ tgi_gettextheight (const char* s);
257 /* Calculate the height of the text in pixels according to the current text
261 void __fastcall__ tgi_outtext (const char* s);
262 /* Output text at the current graphics cursor position. The graphics cursor
263 ** is moved to the end of the text.
266 void __fastcall__ tgi_outtextxy (int x, int y, const char* s);
267 /* Output text at the given cursor position. The graphics cursor is moved to
268 ** the end of the text.
271 unsigned __fastcall__ tgi_ioctl (unsigned char code, void* data);
272 /* Call the driver specific control function. What this function does for
273 ** a specific code depends on the driver. The driver will set an error
274 ** for unknown codes or values.
277 int __fastcall__ tgi_imulround (int rhs, int lhs);
278 /* Helper function for functions using sine/cosine: Multiply two values, one
279 ** being an 8.8 fixed point one, and return the rounded and scaled result.