Mercurial > hg > index.fcgi > lj > lj046-2players
diff src/fontdraw.h @ 0:c84446dfb3f5
initial add
author | paulo@localhost |
---|---|
date | Fri, 13 Mar 2009 00:39:12 -0700 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/fontdraw.h Fri Mar 13 00:39:12 2009 -0700 1.3 @@ -0,0 +1,127 @@ 1.4 +/* 1.5 +Variable width font drawing library for DS (and GBA) 1.6 + 1.7 +Copyright 2007 Damian Yerrick <pinoandchester@pineight.com> 1.8 + 1.9 +This work is provided 'as-is', without any express or implied 1.10 +warranty. In no event will the authors be held liable for any 1.11 +damages arising from the use of this work. 1.12 + 1.13 +Permission is granted to anyone to use this work for any purpose, 1.14 +including commercial applications, and to alter it and redistribute 1.15 +it freely, subject to the following restrictions: 1.16 + 1.17 +1. The origin of this work must not be misrepresented; you must 1.18 + not claim that you wrote the original work. If you use 1.19 + this work in a product, an acknowledgment in the product 1.20 + documentation would be appreciated but is not required. 1.21 +2. Altered source versions must be plainly marked as such, and must 1.22 + not be misrepresented as being the original work. 1.23 +3. This notice may not be removed or altered from any source 1.24 + distribution. 1.25 + 1.26 +"Source" is the preferred form of a work for making changes to it. 1.27 + 1.28 +*/ 1.29 + 1.30 +#ifndef FONTDRAW_H 1.31 +#define FONTDRAW_H 1.32 +#include <sys/types.h> 1.33 + 1.34 +#ifdef ARM9 1.35 +// DS specific macros 1.36 +#include <nds.h> 1.37 +#ifndef BG_OFFSET_SUB 1.38 +#define BG_OFFSET_SUB ((bg_scroll *)(0x04001010)) 1.39 +#endif 1.40 + 1.41 +// macros from libgba that didn't make it to libnds 1.42 +#ifndef MAP 1.43 +typedef u16 NAMETABLE[32][32]; 1.44 +#define MAP ((NAMETABLE *)BG_MAP_RAM(0)) 1.45 +#define MAP_SUB ((NAMETABLE *)BG_MAP_RAM_SUB(0)) 1.46 +#endif 1.47 + 1.48 +#else 1.49 +// GBA specific macros 1.50 +#include <gba_video.h> 1.51 + 1.52 +#endif 1.53 + 1.54 +unsigned int fontdraw_charWidth(int glyph); 1.55 +unsigned int fontdraw_strWidth(const char *s); 1.56 + 1.57 +/** 1.58 + * Returns the number of characters in s that fit within targetWidth pixels. 1.59 + */ 1.60 +size_t fontdraw_cutStr(const char *s, int targetWidth); 1.61 + 1.62 +void fontdraw_setupVRAM(int sub); 1.63 + 1.64 +// New API 1.65 + 1.66 +typedef struct VWFWindow { 1.67 + u8 left; // in 8 pixel units on nametable 1.68 + u8 top; // in 8 pixel units on nametable 1.69 + u8 width; // in 8 pixel units on nametable 1.70 + u8 height; // in 8 pixel units on nametable 1.71 + u32 *chrBase; 1.72 + u8 map; // in 2 KiB units on VRAM 1.73 + u8 core; // 0: main; 1: sub 1.74 + u16 mapTileBase; 1.75 +} VWFWindow; 1.76 + 1.77 +void vwfWinInit(const VWFWindow *vwf); 1.78 +void vwfWinClear(const VWFWindow *vwf); 1.79 +/** 1.80 + * Sets up a portion of a window. 1.81 + * @param vwf the window 1.82 + * @param l distance in tiles from the left side of the window to the 1.83 + * left side of the area to be updated 1.84 + * @param t distance in tiles from the top of the window to the 1.85 + * top of the area to be updated 1.86 + * @param r distance in tiles from the left side of the window to the 1.87 + * right side of the area to be updated 1.88 + * @param b distance in tiles from the top of the window to the 1.89 + * bottom of the area to be updated 1.90 + * @param orMask the data to be OR'd with each map space, typically 1.91 + * containing a palette number in bits 12 to 15 1.92 + */ 1.93 +void vwfPutMap(const VWFWindow *vwf, 1.94 + int l, int t, int r, int b, 1.95 + unsigned int orMask); 1.96 + 1.97 +unsigned int vwfPutc(const VWFWindow *w, 1.98 + int c, 1.99 + int x, int y); 1.100 +unsigned int vwfPuts(const VWFWindow *src, 1.101 + const char *str, 1.102 + int x, int y); 1.103 +void vwfRectfill(const VWFWindow *v, 1.104 + int l, int t, int r, int b, 1.105 + int c); 1.106 +void vwfHline(const VWFWindow *v, int l, int t, int r, int c); 1.107 +void vwfVline(const VWFWindow *v, int l, int t, int b, int c); 1.108 +void vwfRect(const VWFWindow *v, int l, int t, int r, int b, int c); 1.109 + 1.110 +/** 1.111 + * Replaces a rectangle of pixels in dst with pixels from src. 1.112 + * @param src the bitmap to copy from 1.113 + * @param dst the bitmap to copy to 1.114 + * @param srcX the left side of the part of src to copy, 1.115 + * in 8-pixel units 1.116 + * @param srcY the top of the part of src to copy, 1.117 + * in pixels 1.118 + * @param dstX the left side of the part of dst to be replaced, 1.119 + * in 8-pixel units 1.120 + * @param dstY the top of the part of src dst to be replaced, 1.121 + * in pixels 1.122 + */ 1.123 +void vwfBlitAligned(const VWFWindow *src, const VWFWindow *dst, 1.124 + int srcX, int srcY, int dstX, int dstY, 1.125 + int w, int h); 1.126 + 1.127 +extern const VWFWindow vwfTop, vwfTouch; 1.128 + 1.129 + 1.130 +#endif