Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
bitmap.h
Go to the documentation of this file.
1
2
3/*
4 * bitmap.h
5 *
6* Created on: Mar 10, 2022
7 * Author: micahbly
8 */
9
10#ifndef LIB_BITMAP_H_
11#define LIB_BITMAP_H_
12
13
14/* about this library: Bitmap
15 *
16 * This provides functionality for accessing the VICKY's bitmaps, sprites, etc.
17 *
18 *** things this library needs to be able to do
19 * initialize/enter graphics mode
20 * exit graphics mode
21 * fill an entire screen of bitmap
22 * fill a rect
23 * draw a rect
24 * allocate a bitmap
25 * copy a bitmap
26 * load a bitmap from disk
27 * draw a circle
28 * fill an enclosed area
29 * draw a round rect
30 * draw a line
31 * get the value of a pixel, from specified x/y coords
32 * set the value of a pixel, from specified x/y coords
33 * copy a rect of pixel mem from one bitmap to another
34 * copy a rect of pixel mem from place to place within the same bitmap
35 *
36 * STRETCH GOALS
37 * load a graphical (proportional width or fixed width) font from disk or memory
38 * draw string using graphical font on screen, at specified x/y
39 * draw string using graphical font on screen, wrapping and fitting to specified rectangle
40 *
41 * SUPER STRETCH GOALS
42 * have a clipping system that prevents drawing to non-clipped parts of the screen
43 * have a layers system that prevents drawing to portions of layers that are under other layers
44 *
45 */
46
47
48/*****************************************************************************/
49/* Includes */
50/*****************************************************************************/
51
52// project includes
53#include "general.h"
54#include "text.h"
55
56
57// C includes
58#include <stdbool.h>
59
60
61// A2560 includes
62#include <mcp/syscalls.h>
63#include "a2560k.h"
64
65
66/*****************************************************************************/
67/* Macro Definitions */
68/*****************************************************************************/
69
70#define PARAM_DRAW_NE true
71#define PARAM_DRAW_SE true
72#define PARAM_DRAW_SW true
73#define PARAM_DRAW_NW true
74#define PARAM_SKIP_NE false
75#define PARAM_SKIP_SE false
76#define PARAM_SKIP_SW false
77#define PARAM_SKIP_NW false
78
79#define PARAM_DO_FILL true
80#define PARAM_DO_NOT_FILL false
81
82#define PARAM_IN_VRAM true
83#define PARAM_NOT_IN_VRAM false
84
85
86/*****************************************************************************/
87/* Enumerations */
88/*****************************************************************************/
89
90
91
92/*****************************************************************************/
93/* Structs */
94/*****************************************************************************/
95
96struct Bitmap
97{
98 int16_t width_;
99 int16_t height_;
100 int16_t x_;
101 int16_t y_;
102 uint8_t color_;
103 uint8_t reserved_;
105 unsigned char* addr_;
106 uint32_t addr_int_;
107 bool in_vram_;
108};
109
110
111/*****************************************************************************/
112/* Global Variables */
113/*****************************************************************************/
114
115
116/*****************************************************************************/
117/* Public Function Prototypes */
118/*****************************************************************************/
119
120
121// **** CONSTRUCTOR AND DESTRUCTOR *****
122
123// constructor
124
131Bitmap* Bitmap_New(int16_t width, int16_t height, Font* the_font, bool in_vram);
132
133// destructor
134// frees all allocated memory associated with the passed object, and the object itself
135bool Bitmap_Destroy(Bitmap** the_bitmap);
136
143bool Bitmap_Resize(Bitmap* the_bitmap, int16_t width, int16_t height);
144
145
146
147
148// **** Block copy functions ****
149
158bool Bitmap_BlitRect(Bitmap* src_bm, Rectangle* src_rect, Bitmap* dst_bm, int16_t dst_x, int16_t dst_y);
159
170bool Bitmap_Blit(Bitmap* src_bm, int16_t src_x, int16_t src_y, Bitmap* dst_bm, int16_t dst_x, int16_t dst_y, int16_t width, int16_t height);
171
180bool Bitmap_Tile(Bitmap* src_bm, int16_t src_x, int16_t src_y, Bitmap* dst_bm, int16_t width, int16_t height);
181
190bool Bitmap_TileV1(Bitmap* src_bm, int16_t src_x, int16_t src_y, Bitmap* dst_bm, int16_t width, int16_t height);
191
200bool Bitmap_TileV2(Bitmap* src_bm, int16_t src_x, int16_t src_y, Bitmap* dst_bm, int16_t width, int16_t height);
201
210bool Bitmap_TileV3(Bitmap* src_bm, int16_t src_x, int16_t src_y, Bitmap* dst_bm, int16_t width, int16_t height);
211
212
213
214// **** Block fill functions ****
215
216// Fill graphics memory with specified value
219bool Bitmap_FillMemory(Bitmap* the_bitmap, uint8_t the_color);
220
224bool Bitmap_FillBoxRect(Bitmap* the_bitmap, Rectangle* the_coords, uint8_t the_color);
225
226// Fill pixel values for a specific box area, using the specified LUT value
227// calling function must validate screen id, coords!
230bool Bitmap_FillBox(Bitmap* the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color);
231
232
233
234
235// **** Bitmap functions *****
236
242bool Bitmap_SetFont(Bitmap* the_bitmap, Font* the_font);
243
250bool Bitmap_SetColor(Bitmap* the_bitmap, uint8_t the_color);
251
260bool Bitmap_SetXY(Bitmap* the_bitmap, int16_t x, int16_t y);
261
265uint8_t Bitmap_GetColor(Bitmap* the_bitmap);
266
270int16_t Bitmap_GetX(Bitmap* the_bitmap);
271
275int16_t Bitmap_GetY(Bitmap* the_bitmap);
276
280unsigned char* Bitmap_GetMemLoc(Bitmap* the_bitmap);
281
285uint32_t Bitmap_GetMemLocInt(Bitmap* the_bitmap);
286
290Font* Bitmap_GetFont(Bitmap* the_bitmap);
291
292
293
294// **** Set pixel functions *****
295
296
300bool Bitmap_SetPixelAtXY(Bitmap* the_bitmap, int16_t x, int16_t y, uint8_t the_color);
301
302
303
304// **** Get pixel functions *****
305
306
309uint8_t Bitmap_GetPixelAtXY(Bitmap* the_bitmap, int16_t x, int16_t y);
310
311
312
313// **** Drawing functions *****
314
315
319bool Bitmap_DrawLine(Bitmap* the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color);
320
324bool Bitmap_DrawHLine(Bitmap* the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color);
325
329bool Bitmap_DrawVLine(Bitmap* the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color);
330
334bool Bitmap_DrawBoxRect(Bitmap* the_bitmap, Rectangle* the_coords, uint8_t the_color);
335
339bool Bitmap_DrawBoxCoords(Bitmap* the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color);
340
347bool Bitmap_DrawBox(Bitmap* the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color, bool do_fill);
348
356bool Bitmap_DrawRoundBox(Bitmap* the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius, uint8_t the_color, bool do_fill);
357
360bool Bitmap_DrawCircle(Bitmap* the_bitmap, int16_t x1, int16_t y1, int16_t radius, uint8_t the_color);
361
362
363
364
365
366#endif /* LIB_BITMAP_H_ */
367
368
bool Bitmap_TileV2(Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can...
Definition: bitmap.c:827
bool Bitmap_SetColor(Bitmap *the_bitmap, uint8_t the_color)
Set the "pen" color This is the color that the next pen-based graphics function will use This only af...
Definition: bitmap.c:1223
int16_t Bitmap_GetX(Bitmap *the_bitmap)
Get the current X position of the pen.
Definition: bitmap.c:1284
bool Bitmap_Tile(Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can...
Definition: bitmap.c:706
bool Bitmap_DrawHLine(Bitmap *the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color)
Draws a horizontal line from specified coords, for n pixels, using the specified pixel value.
Definition: bitmap.c:1548
uint8_t Bitmap_GetColor(Bitmap *the_bitmap)
Get the current color of the pen.
Definition: bitmap.c:1269
bool Bitmap_FillBoxRect(Bitmap *the_bitmap, Rectangle *the_coords, uint8_t the_color)
Fill pixel values for the passed Rectangle object, using the specified LUT value.
Definition: bitmap.c:1126
bool Bitmap_Blit(Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t dst_x, int16_t dst_y, int16_t width, int16_t height)
Blit from source bitmap to distination bitmap.
Definition: bitmap.c:457
bool Bitmap_SetFont(Bitmap *the_bitmap, Font *the_font)
Set the font This is the font that will be used for all font drawing in this bitmap.
Definition: bitmap.c:1197
uint32_t Bitmap_GetMemLocInt(Bitmap *the_bitmap)
Calculate the VRAM location of the current coordinate within the bitmap.
Definition: bitmap.c:1405
bool Bitmap_Resize(Bitmap *the_bitmap, int16_t width, int16_t height)
Resize and existing bitmap by setting new width/height and allocating bigger storage if necessary NOT...
Definition: bitmap.c:371
bool Bitmap_DrawCircle(Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t radius, uint8_t the_color)
Draw a circle Based on http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#C.
Definition: bitmap.c:1841
Font * Bitmap_GetFont(Bitmap *the_bitmap)
Get the current font of the pen.
Definition: bitmap.c:1313
bool Bitmap_FillBox(Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color)
Fill pixel values for a specific box area calling function must validate screen id,...
Definition: bitmap.c:1138
bool Bitmap_TileV1(Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can...
Definition: bitmap.c:955
uint8_t Bitmap_GetPixelAtXY(Bitmap *the_bitmap, int16_t x, int16_t y)
Get the pixel CLUT index at a specified x, y coord.
Definition: bitmap.c:1455
Bitmap * Bitmap_New(int16_t width, int16_t height, Font *the_font, bool in_vram)
Create a new bitmap object by allocating space for the bitmap struct in regular memory,...
Definition: bitmap.c:253
bool Bitmap_SetPixelAtXY(Bitmap *the_bitmap, int16_t x, int16_t y, uint8_t the_color)
Set a char at a specified x, y coord.
Definition: bitmap.c:1421
bool Bitmap_DrawRoundBox(Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius, uint8_t the_color, bool do_fill)
Draws a rounded rectangle with the specified size and radius, and optionally fills the rectangle.
Definition: bitmap.c:1759
bool Bitmap_SetXY(Bitmap *the_bitmap, int16_t x, int16_t y)
Set the "pen" position This is the location that the next pen-based graphics function will use for a ...
Definition: bitmap.c:1245
bool Bitmap_DrawVLine(Bitmap *the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color)
Draws a vertical line from specified coords, for n pixels.
Definition: bitmap.c:1578
bool Bitmap_DrawBoxCoords(Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color)
Draws a rectangle based on 2 sets of coords, using the specified LUT value.
Definition: bitmap.c:1617
unsigned char * Bitmap_GetMemLoc(Bitmap *the_bitmap)
Calculate the VRAM location of the current coordinate within the bitmap.
Definition: bitmap.c:1393
bool Bitmap_BlitRect(Bitmap *src_bm, Rectangle *src_rect, Bitmap *dst_bm, int16_t dst_x, int16_t dst_y)
Blit a rect from source bitmap to distination bitmap This is a wrapper around Bitmap_Blit() The sourc...
Definition: bitmap.c:429
bool Bitmap_TileV3(Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can...
Definition: bitmap.c:564
bool Bitmap_DrawBoxRect(Bitmap *the_bitmap, Rectangle *the_coords, uint8_t the_color)
Draws a rectangle based on the passed Rectangle object, using the specified LUT value.
Definition: bitmap.c:1608
bool Bitmap_FillMemory(Bitmap *the_bitmap, uint8_t the_color)
Definition: bitmap.c:1091
bool Bitmap_DrawLine(Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color)
Draws a line between 2 passed coordinates.
Definition: bitmap.c:1490
int16_t Bitmap_GetY(Bitmap *the_bitmap)
Get the current Y position of the pen.
Definition: bitmap.c:1298
bool Bitmap_DrawBox(Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color, bool do_fill)
Draws a rectangle based on start coords and width/height, and optionally fills the rectangle.
Definition: bitmap.c:1686
Definition: bitmap.h:97
bool in_vram_
a way to know if this bitmap is pointing to VRAM or standard RAM space.
Definition: bitmap.h:107
uint32_t addr_int_
address of the start of the bitmap, as an unsigned long int. For use with plotting locations on 65816...
Definition: bitmap.h:106
int16_t width_
width of the bitmap in pixels
Definition: bitmap.h:98
uint8_t color_
color value to use for next "pen" based operation in this bitmap
Definition: bitmap.h:102
int16_t y_
V position within this bitmap, of the "pen", for functions that draw from that point.
Definition: bitmap.h:101
Font * font_
the currently selected font. All text drawing activities will use this font face.
Definition: bitmap.h:104
uint8_t reserved_
future use
Definition: bitmap.h:103
int16_t x_
H position within this bitmap, of the "pen", for functions that draw from that point.
Definition: bitmap.h:100
unsigned char * addr_
address of the start of the bitmap, within the machine's global address space. This is not the VICKY'...
Definition: bitmap.h:105
int16_t height_
height of the bitmap in pixels
Definition: bitmap.h:99
This Font object is essentially the Mac "fontRecord" struct, with added pointers for the data tables.
Definition: font.h:71
Definition: a2560k.h:1369