rev |
line source |
paulo@0
|
1 /*
|
paulo@0
|
2 Variable width font drawing library for DS (and GBA)
|
paulo@0
|
3
|
paulo@0
|
4 Copyright 2007 Damian Yerrick <pinoandchester@pineight.com>
|
paulo@0
|
5
|
paulo@0
|
6 This work is provided 'as-is', without any express or implied
|
paulo@0
|
7 warranty. In no event will the authors be held liable for any
|
paulo@0
|
8 damages arising from the use of this work.
|
paulo@0
|
9
|
paulo@0
|
10 Permission is granted to anyone to use this work for any purpose,
|
paulo@0
|
11 including commercial applications, and to alter it and redistribute
|
paulo@0
|
12 it freely, subject to the following restrictions:
|
paulo@0
|
13
|
paulo@0
|
14 1. The origin of this work must not be misrepresented; you must
|
paulo@0
|
15 not claim that you wrote the original work. If you use
|
paulo@0
|
16 this work in a product, an acknowledgment in the product
|
paulo@0
|
17 documentation would be appreciated but is not required.
|
paulo@0
|
18 2. Altered source versions must be plainly marked as such, and must
|
paulo@0
|
19 not be misrepresented as being the original work.
|
paulo@0
|
20 3. This notice may not be removed or altered from any source
|
paulo@0
|
21 distribution.
|
paulo@0
|
22
|
paulo@0
|
23 "Source" is the preferred form of a work for making changes to it.
|
paulo@0
|
24
|
paulo@0
|
25 */
|
paulo@0
|
26
|
paulo@0
|
27 #ifndef FONTDRAW_H
|
paulo@0
|
28 #define FONTDRAW_H
|
paulo@0
|
29 #include <sys/types.h>
|
paulo@0
|
30
|
paulo@0
|
31 #ifdef ARM9
|
paulo@0
|
32 // DS specific macros
|
paulo@0
|
33 #include <nds.h>
|
paulo@0
|
34 #ifndef BG_OFFSET_SUB
|
paulo@0
|
35 #define BG_OFFSET_SUB ((bg_scroll *)(0x04001010))
|
paulo@0
|
36 #endif
|
paulo@0
|
37
|
paulo@0
|
38 // macros from libgba that didn't make it to libnds
|
paulo@0
|
39 #ifndef MAP
|
paulo@0
|
40 typedef u16 NAMETABLE[32][32];
|
paulo@0
|
41 #define MAP ((NAMETABLE *)BG_MAP_RAM(0))
|
paulo@0
|
42 #define MAP_SUB ((NAMETABLE *)BG_MAP_RAM_SUB(0))
|
paulo@0
|
43 #endif
|
paulo@0
|
44
|
paulo@0
|
45 #else
|
paulo@0
|
46 // GBA specific macros
|
paulo@0
|
47 #include <gba_video.h>
|
paulo@0
|
48
|
paulo@0
|
49 #endif
|
paulo@0
|
50
|
paulo@0
|
51 unsigned int fontdraw_charWidth(int glyph);
|
paulo@0
|
52 unsigned int fontdraw_strWidth(const char *s);
|
paulo@0
|
53
|
paulo@0
|
54 /**
|
paulo@0
|
55 * Returns the number of characters in s that fit within targetWidth pixels.
|
paulo@0
|
56 */
|
paulo@0
|
57 size_t fontdraw_cutStr(const char *s, int targetWidth);
|
paulo@0
|
58
|
paulo@0
|
59 void fontdraw_setupVRAM(int sub);
|
paulo@0
|
60
|
paulo@0
|
61 // New API
|
paulo@0
|
62
|
paulo@0
|
63 typedef struct VWFWindow {
|
paulo@0
|
64 u8 left; // in 8 pixel units on nametable
|
paulo@0
|
65 u8 top; // in 8 pixel units on nametable
|
paulo@0
|
66 u8 width; // in 8 pixel units on nametable
|
paulo@0
|
67 u8 height; // in 8 pixel units on nametable
|
paulo@0
|
68 u32 *chrBase;
|
paulo@0
|
69 u8 map; // in 2 KiB units on VRAM
|
paulo@0
|
70 u8 core; // 0: main; 1: sub
|
paulo@0
|
71 u16 mapTileBase;
|
paulo@0
|
72 } VWFWindow;
|
paulo@0
|
73
|
paulo@0
|
74 void vwfWinInit(const VWFWindow *vwf);
|
paulo@0
|
75 void vwfWinClear(const VWFWindow *vwf);
|
paulo@0
|
76 /**
|
paulo@0
|
77 * Sets up a portion of a window.
|
paulo@0
|
78 * @param vwf the window
|
paulo@0
|
79 * @param l distance in tiles from the left side of the window to the
|
paulo@0
|
80 * left side of the area to be updated
|
paulo@0
|
81 * @param t distance in tiles from the top of the window to the
|
paulo@0
|
82 * top of the area to be updated
|
paulo@0
|
83 * @param r distance in tiles from the left side of the window to the
|
paulo@0
|
84 * right side of the area to be updated
|
paulo@0
|
85 * @param b distance in tiles from the top of the window to the
|
paulo@0
|
86 * bottom of the area to be updated
|
paulo@0
|
87 * @param orMask the data to be OR'd with each map space, typically
|
paulo@0
|
88 * containing a palette number in bits 12 to 15
|
paulo@0
|
89 */
|
paulo@0
|
90 void vwfPutMap(const VWFWindow *vwf,
|
paulo@0
|
91 int l, int t, int r, int b,
|
paulo@0
|
92 unsigned int orMask);
|
paulo@0
|
93
|
paulo@0
|
94 unsigned int vwfPutc(const VWFWindow *w,
|
paulo@0
|
95 int c,
|
paulo@0
|
96 int x, int y);
|
paulo@0
|
97 unsigned int vwfPuts(const VWFWindow *src,
|
paulo@0
|
98 const char *str,
|
paulo@0
|
99 int x, int y);
|
paulo@0
|
100 void vwfRectfill(const VWFWindow *v,
|
paulo@0
|
101 int l, int t, int r, int b,
|
paulo@0
|
102 int c);
|
paulo@0
|
103 void vwfHline(const VWFWindow *v, int l, int t, int r, int c);
|
paulo@0
|
104 void vwfVline(const VWFWindow *v, int l, int t, int b, int c);
|
paulo@0
|
105 void vwfRect(const VWFWindow *v, int l, int t, int r, int b, int c);
|
paulo@0
|
106
|
paulo@0
|
107 /**
|
paulo@0
|
108 * Replaces a rectangle of pixels in dst with pixels from src.
|
paulo@0
|
109 * @param src the bitmap to copy from
|
paulo@0
|
110 * @param dst the bitmap to copy to
|
paulo@0
|
111 * @param srcX the left side of the part of src to copy,
|
paulo@0
|
112 * in 8-pixel units
|
paulo@0
|
113 * @param srcY the top of the part of src to copy,
|
paulo@0
|
114 * in pixels
|
paulo@0
|
115 * @param dstX the left side of the part of dst to be replaced,
|
paulo@0
|
116 * in 8-pixel units
|
paulo@0
|
117 * @param dstY the top of the part of src dst to be replaced,
|
paulo@0
|
118 * in pixels
|
paulo@0
|
119 */
|
paulo@0
|
120 void vwfBlitAligned(const VWFWindow *src, const VWFWindow *dst,
|
paulo@0
|
121 int srcX, int srcY, int dstX, int dstY,
|
paulo@0
|
122 int w, int h);
|
paulo@0
|
123
|
paulo@0
|
124 extern const VWFWindow vwfTop, vwfTouch;
|
paulo@0
|
125
|
paulo@0
|
126
|
paulo@0
|
127 #endif
|