Mercurial > hg > old > magoroku_racing
comparison gFont.c @ 0:0fae5658fb0b
Initial revision
author | gongo |
---|---|
date | Thu, 02 Nov 2006 08:55:19 +0000 |
parents | |
children | b6a1385f19be |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0fae5658fb0b |
---|---|
1 /* | |
2 * 2006/07/24 16:46:19 sugiyama | |
3 * | |
4 * フォント表示。といっても結局スプライトです。 | |
5 * gSprite.c と一緒にしてもよかったんだけど | |
6 * 文字は文字でいろいろあるので分けてみる | |
7 */ | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include "libps2.h" | |
11 #include "ps2util.h" | |
12 #include "gSprite.h" | |
13 | |
14 #define DEFOBJ 120 | |
15 #define SPRITE_COL 0x4f | |
16 #define SCREEN_HALF_W 320 | |
17 #define SCREEN_HALF_H 240 | |
18 #define CHAR_W_SIZE 17 | |
19 #define CHAR_H_SIZE 34 | |
20 | |
21 static SpriteTable sptable[DEFOBJ]; | |
22 static ps2utilSprite sp[DEFOBJ*2]; // 表示スプライト用スタック | |
23 static unsigned int sp_counter; | |
24 static Bool flag_spriteInited = FALSE; // スプライトロードフラグ | |
25 | |
26 static TEXTURE *font_tex; | |
27 | |
28 static void | |
29 gFont_Init_Png(char *texname) | |
30 { | |
31 if (!(font_tex = read_png_file(texname))) { | |
32 fprintf(stderr, | |
33 "cannot creat texture - gFont_Init_Png().\n"); | |
34 fflush(stderr); | |
35 exit(EXIT_FAILURE); | |
36 } | |
37 | |
38 if (ps2util_tex_Set(font_tex) == -1) { | |
39 fprintf(stderr, | |
40 "cannot set texture - gFont_Init_Png().\n"); | |
41 fflush(stderr); | |
42 exit(EXIT_FAILURE); | |
43 } | |
44 } | |
45 | |
46 static void | |
47 gFont_Create() | |
48 { | |
49 int i; | |
50 | |
51 for (i=0; i<DEFOBJ; i++) { | |
52 if (ps2util_sprite_Create(&sp[i], font_tex) == -1) { | |
53 fprintf(stderr, | |
54 "cannot create sprite - gFont_Create()\n"); | |
55 fflush(stderr); | |
56 exit(EXIT_FAILURE); | |
57 } | |
58 ps2util_sprite_Unuse_alpha(&sp[i]); | |
59 } | |
60 flag_spriteInited = TRUE; | |
61 } | |
62 | |
63 static void | |
64 gFont_DefSprite(int number, int x, int y, int w, int h) | |
65 { | |
66 sptable[number].tx = x; | |
67 sptable[number].ty = y; | |
68 sptable[number].tw = w; | |
69 sptable[number].th = h; | |
70 } | |
71 | |
72 void | |
73 gFont_Init() | |
74 { | |
75 int i, j; | |
76 int number = 0; | |
77 | |
78 gFont_Init_Png("img/font.png"); | |
79 gFont_Create(); // スプライト生成 | |
80 | |
81 for (i=0; i<7; i++) { | |
82 for (j=0; j<15; j++) { | |
83 gFont_DefSprite(number, j*17, i*34, 17, 34); | |
84 number++; | |
85 } | |
86 } | |
87 } | |
88 | |
89 | |
90 static void | |
91 gFont_PutSprite(int number, int x, int y) | |
92 { | |
93 ps2utilSprite *p = &sp[sp_counter]; | |
94 | |
95 ps2util_sprite_Set_basicAttribute( | |
96 p, | |
97 (ushort)x, (ushort)y, | |
98 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5, | |
99 (ushort)sptable[number].tx, (ushort)sptable[number].ty, | |
100 (ushort)sptable[number].tw, (ushort)sptable[number].th, | |
101 SPRITE_PRIO_FOREGROUND); | |
102 | |
103 ps2util_sprite_Request(p); | |
104 sp_counter++; | |
105 } | |
106 | |
107 | |
108 static void | |
109 gFont_Clear() | |
110 { | |
111 int i; | |
112 | |
113 for (i=0; i<DEFOBJ; i++) { | |
114 sprite_disappear(&sp[i].attribute); | |
115 } | |
116 sp_counter = 0; | |
117 } | |
118 | |
119 void | |
120 gFont_Draw_Reset() | |
121 { | |
122 if (flag_spriteInited == TRUE) { | |
123 gFont_Clear(); | |
124 } | |
125 } | |
126 | |
127 static int | |
128 get_number_char(char a) | |
129 { | |
130 return (int)a-32; | |
131 } | |
132 | |
133 /* | |
134 * str をスプライド表示 | |
135 */ | |
136 void | |
137 gFont_SetString(char *str, int x, int y) | |
138 { | |
139 int number; | |
140 | |
141 while (*str != '\0') { | |
142 number = get_number_char(*str); | |
143 gFont_PutSprite(number, x, y); | |
144 str++; | |
145 x += (int)CHAR_W_SIZE*1.5; | |
146 } | |
147 } | |
148 | |
149 /* | |
150 * numを文字列に変換してSetStringに渡す | |
151 */ | |
152 void | |
153 gFont_SetStringInt(int num, int x, int y) | |
154 { | |
155 char bufp[256]; | |
156 | |
157 snprintf(bufp, 256, "%d", num); | |
158 gFont_SetString(bufp, x, y); | |
159 } | |
160 | |
161 void | |
162 gFont_SetFont_OP() | |
163 { | |
164 } | |
165 | |
166 | |
167 | |
168 | |
169 |