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