paulo@0: /* paulo@0: Variable width font drawing library for DS (and GBA) paulo@0: paulo@0: Copyright 2007 Damian Yerrick paulo@0: paulo@0: This work is provided 'as-is', without any express or implied paulo@0: warranty. In no event will the authors be held liable for any paulo@0: damages arising from the use of this work. paulo@0: paulo@0: Permission is granted to anyone to use this work for any purpose, paulo@0: including commercial applications, and to alter it and redistribute paulo@0: it freely, subject to the following restrictions: paulo@0: paulo@0: 1. The origin of this work must not be misrepresented; you must paulo@0: not claim that you wrote the original work. If you use paulo@0: this work in a product, an acknowledgment in the product paulo@0: documentation would be appreciated but is not required. paulo@0: 2. Altered source versions must be plainly marked as such, and must paulo@0: not be misrepresented as being the original work. paulo@0: 3. This notice may not be removed or altered from any source paulo@0: distribution. paulo@0: paulo@0: "Source" is the preferred form of a work for making changes to it. paulo@0: paulo@0: */ paulo@0: paulo@0: #ifndef FONTDRAW_H paulo@0: #define FONTDRAW_H paulo@0: #include paulo@0: paulo@0: #ifdef ARM9 paulo@0: // DS specific macros paulo@0: #include paulo@0: #ifndef BG_OFFSET_SUB paulo@0: #define BG_OFFSET_SUB ((bg_scroll *)(0x04001010)) paulo@0: #endif paulo@0: paulo@0: // macros from libgba that didn't make it to libnds paulo@0: #ifndef MAP paulo@0: typedef u16 NAMETABLE[32][32]; paulo@0: #define MAP ((NAMETABLE *)BG_MAP_RAM(0)) paulo@0: #define MAP_SUB ((NAMETABLE *)BG_MAP_RAM_SUB(0)) paulo@0: #endif paulo@0: paulo@0: #else paulo@0: // GBA specific macros paulo@0: #include paulo@0: paulo@0: #endif paulo@0: paulo@0: unsigned int fontdraw_charWidth(int glyph); paulo@0: unsigned int fontdraw_strWidth(const char *s); paulo@0: paulo@0: /** paulo@0: * Returns the number of characters in s that fit within targetWidth pixels. paulo@0: */ paulo@0: size_t fontdraw_cutStr(const char *s, int targetWidth); paulo@0: paulo@0: void fontdraw_setupVRAM(int sub); paulo@0: paulo@0: // New API paulo@0: paulo@0: typedef struct VWFWindow { paulo@0: u8 left; // in 8 pixel units on nametable paulo@0: u8 top; // in 8 pixel units on nametable paulo@0: u8 width; // in 8 pixel units on nametable paulo@0: u8 height; // in 8 pixel units on nametable paulo@0: u32 *chrBase; paulo@0: u8 map; // in 2 KiB units on VRAM paulo@0: u8 core; // 0: main; 1: sub paulo@0: u16 mapTileBase; paulo@0: } VWFWindow; paulo@0: paulo@0: void vwfWinInit(const VWFWindow *vwf); paulo@0: void vwfWinClear(const VWFWindow *vwf); paulo@0: /** paulo@0: * Sets up a portion of a window. paulo@0: * @param vwf the window paulo@0: * @param l distance in tiles from the left side of the window to the paulo@0: * left side of the area to be updated paulo@0: * @param t distance in tiles from the top of the window to the paulo@0: * top of the area to be updated paulo@0: * @param r distance in tiles from the left side of the window to the paulo@0: * right side of the area to be updated paulo@0: * @param b distance in tiles from the top of the window to the paulo@0: * bottom of the area to be updated paulo@0: * @param orMask the data to be OR'd with each map space, typically paulo@0: * containing a palette number in bits 12 to 15 paulo@0: */ paulo@0: void vwfPutMap(const VWFWindow *vwf, paulo@0: int l, int t, int r, int b, paulo@0: unsigned int orMask); paulo@0: paulo@0: unsigned int vwfPutc(const VWFWindow *w, paulo@0: int c, paulo@0: int x, int y); paulo@0: unsigned int vwfPuts(const VWFWindow *src, paulo@0: const char *str, paulo@0: int x, int y); paulo@0: void vwfRectfill(const VWFWindow *v, paulo@0: int l, int t, int r, int b, paulo@0: int c); paulo@0: void vwfHline(const VWFWindow *v, int l, int t, int r, int c); paulo@0: void vwfVline(const VWFWindow *v, int l, int t, int b, int c); paulo@0: void vwfRect(const VWFWindow *v, int l, int t, int r, int b, int c); paulo@0: paulo@0: /** paulo@0: * Replaces a rectangle of pixels in dst with pixels from src. paulo@0: * @param src the bitmap to copy from paulo@0: * @param dst the bitmap to copy to paulo@0: * @param srcX the left side of the part of src to copy, paulo@0: * in 8-pixel units paulo@0: * @param srcY the top of the part of src to copy, paulo@0: * in pixels paulo@0: * @param dstX the left side of the part of dst to be replaced, paulo@0: * in 8-pixel units paulo@0: * @param dstY the top of the part of src dst to be replaced, paulo@0: * in pixels paulo@0: */ paulo@0: void vwfBlitAligned(const VWFWindow *src, const VWFWindow *dst, paulo@0: int srcX, int srcY, int dstX, int dstY, paulo@0: int w, int h); paulo@0: paulo@0: extern const VWFWindow vwfTop, vwfTouch; paulo@0: paulo@0: paulo@0: #endif