1 /*****************************************************************************/
5 /* Tiny graphics interface */
9 /* (C) 2002-2011, 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 /*****************************************************************************/
42 #include <tgi/tgi-error.h>
47 /*****************************************************************************/
49 /*****************************************************************************/
53 /* Font constants for use with tgi_textstyle */
54 #define TGI_FONT_BITMAP 0
55 #define TGI_FONT_VECTOR 1
57 /* Direction constants for use with tgi_textstyle */
58 #define TGI_TEXT_HORIZONTAL 0
59 #define TGI_TEXT_VERTICAL 1
61 /* The name of the standard tgi driver for a platform */
62 extern const char tgi_stddrv[];
64 /* A vector font definition */
65 typedef struct tgi_vectorfont tgi_vectorfont;
69 /*****************************************************************************/
71 /*****************************************************************************/
75 void __fastcall__ tgi_load_driver (const char* name);
76 /* Load and install the given driver. */
78 void tgi_unload (void);
79 /* Uninstall, then unload the currently loaded driver. Will call tgi_done if
83 void __fastcall__ tgi_install (void* driver);
84 /* Install an already loaded driver. */
86 void tgi_uninstall (void);
87 /* Uninstall the currently loaded driver but do not unload it. Will call
88 * tgi_done if necessary.
92 /* Initialize the already loaded graphics driver. */
95 /* End graphics mode, switch back to text mode. Will NOT uninstall or unload
99 const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name);
100 /* Load a vector font into memory and return it. In case of errors, NULL is
101 * returned and an error is set, which can be retrieved using tgi_geterror.
102 * To use the font, it has to be installed using tgi_install_vectorfont.
105 void __fastcall__ tgi_install_vectorfont (const tgi_vectorfont* font);
106 /* Install a vector font for use. More than one vector font can be loaded,
107 * but only one can be active. This function is used to tell which one. Call
108 * with a NULL pointer to uninstall the currently installed font.
111 void tgi_free_vectorfont (const tgi_vectorfont* font);
112 /* Free a vector font that was previously loaded into memory. */
114 unsigned char tgi_geterror (void);
115 /* Return the error code for the last operation. This will also clear the
119 const char* __fastcall__ tgi_geterrormsg (unsigned char code);
120 /* Get an error message describing the error in code. */
122 void tgi_clear (void);
123 /* Clear the drawpage. */
125 unsigned tgi_getpagecount (void);
126 /* Returns the number of screen pages available. */
128 void __fastcall__ tgi_setviewpage (unsigned char page);
129 /* Set the visible page. Will set an error if the page is not available. */
131 void __fastcall__ tgi_setdrawpage (unsigned char page);
132 /* Set the drawable page. Will set an error if the page is not available. */
134 unsigned char tgi_getcolorcount (void);
135 /* Get the number of available colors. */
137 unsigned char tgi_getmaxcolor (void);
138 /* Return the maximum supported color number (the number of colors would
139 * then be getmaxcolor()+1).
142 void __fastcall__ tgi_setcolor (unsigned char color);
143 /* Set the current drawing color. */
145 unsigned char tgi_getcolor (void);
146 /* Return the current drawing color. */
148 void __fastcall__ tgi_setpalette (const unsigned char* palette);
149 /* Set the palette (not available with all drivers/hardware). palette is
150 * a pointer to as many entries as there are colors.
153 const unsigned char* tgi_getpalette (void);
154 /* Return the current palette. */
156 const unsigned char* tgi_getdefpalette (void);
157 /* Return the default palette. */
159 unsigned tgi_getxres (void);
160 /* Return the resolution in X direction. */
162 unsigned tgi_getmaxx (void);
163 /* Return the maximum x coordinate. The resolution in x direction is
167 unsigned tgi_getyres (void);
168 /* Return the resolution in Y direction. */
170 unsigned tgi_getmaxy (void);
171 /* Return the maximum y coordinate. The resolution in y direction is
175 unsigned tgi_getaspectratio (void);
176 /* Returns the aspect ratio for the loaded driver. The aspect ratio is an
177 * 8.8 fixed point value.
180 void __fastcall__ tgi_setaspectratio (unsigned aspectratio);
181 /* Set a new aspect ratio for the loaded driver. The aspect ratio is an
182 * 8.8 fixed point value.
185 unsigned char __fastcall__ tgi_getpixel (int x, int y);
186 /* Get the color value of a pixel. */
188 void __fastcall__ tgi_setpixel (int x, int y);
189 /* Plot a pixel in the current drawing color. */
191 void __fastcall__ tgi_gotoxy (int x, int y);
192 /* Set the graphics cursor to the given position. */
194 void __fastcall__ tgi_line (int x1, int y1, int x2, int y2);
195 /* Draw a line in the current drawing color. The graphics cursor will
196 * be set to x2/y2 by this call.
199 void __fastcall__ tgi_lineto (int x2, int y2);
200 /* Draw a line in the current drawing color from the graphics cursor to the
201 * new end point. The graphics cursor will be updated to x2/y2.
204 void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
205 /* Draw a circle in the current drawing color. */
207 void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);
208 /* Draw a full ellipse with center at x/y and radii rx/ry using the current
212 void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
213 unsigned sa, unsigned ea);
214 /* Draw an ellipse arc with center at x/y and radii rx/ry using the current
215 * drawing color. The arc covers the angle between sa and ea (startangle and
216 * endangle), which must be in the range 0..360 (otherwise the function may
217 * bevave unextectedly).
220 void __fastcall__ tgi_pieslice (int x, int y, unsigned char rx, unsigned char ry,
221 unsigned sa, unsigned ea);
222 /* Draw an ellipse pie slice with center at x/y and radii rx/ry using the
223 * current drawing color. The pie slice covers the angle between sa and ea
224 * (startangle and endangle), which must be in the range 0..360 (otherwise the
225 * function may behave unextectedly).
228 void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
229 /* Draw a bar (a filled rectangle) using the current color. */
231 void __fastcall__ tgi_textscale (unsigned width, unsigned height);
232 /* Set the scaling for text output. The scaling factors for width and height
233 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
236 void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
237 unsigned char dir, unsigned char font);
238 /* Set the style for text output. The scaling factors for width and height
239 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
240 * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
244 unsigned __fastcall__ tgi_textwidth (const char* s);
245 /* Calculate the width of the text in pixels according to the current text
249 unsigned __fastcall__ tgi_textheight (const char* s);
250 /* Calculate the height of the text in pixels according to the current text
254 void __fastcall__ tgi_outtext (const char* s);
255 /* Output text at the current graphics cursor position. The graphics cursor
256 * is moved to the end of the text.
259 void __fastcall__ tgi_outtextxy (int x, int y, const char* s);
260 /* Output text at the given cursor position. The graphics cursor is moved to
261 * the end of the text.
264 unsigned __fastcall__ tgi_ioctl (unsigned char code, void* data);
265 /* Call the driver specific control function. What this function does for
266 * a specific code depends on the driver. The driver will set an error
267 * for unknown codes or values.