Mercurial > hg > old > magoroku_racing
annotate gFont.cc @ 116:ed702e49cc6c
conpile
author | e085768 |
---|---|
date | Thu, 16 Jun 2011 04:05:33 +0900 |
parents | e5f2eb98b575 |
children | f2e2460b4011 |
rev | line source |
---|---|
0 | 1 /* |
18 | 2 * $Id$ |
0 | 3 * |
88 | 4 * フォント表示。といっても結局スプライトです。 |
5 * gSprite.c と一緒にしてもよかったんだけど | |
6 * 文字は文字でいろいろあるので分けてみる | |
0 | 7 */ |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
10 #include <stdbool.h> |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
11 #include "libps2.h" |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
12 #include "ps2util.h" |
0 | 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]; | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
23 static ps2utilSprite sp[DEFOBJ*2]; // 表示スプライト用スタック |
0 | 24 static unsigned int sp_counter; |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
25 static bool flag_spriteInited = false; // スプライトロードフラグ |
0 | 26 |
116 | 27 //static TEXTURE *font_tex; |
0 | 28 |
29 static void | |
100 | 30 gFont_Init_Png(const char *texname) |
0 | 31 { |
116 | 32 /* |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
33 if (!(font_tex = read_png_file(texname))) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
34 fprintf(stderr, |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
35 "cannot creat texture - gFont_Init_Png().\n"); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
36 fflush(stderr); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
37 exit(EXIT_FAILURE); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
38 } |
0 | 39 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
40 if (ps2util_tex_Set(font_tex) == -1) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
41 fprintf(stderr, |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
42 "cannot set texture - gFont_Init_Png().\n"); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
43 fflush(stderr); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
44 exit(EXIT_FAILURE); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
45 } |
116 | 46 */ |
0 | 47 } |
48 | |
49 static void | |
50 gFont_Create() | |
51 { | |
116 | 52 /* |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
53 int i; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
54 for (i=0; i<DEFOBJ; i++) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
55 if (ps2util_sprite_Create(&sp[i], font_tex) == -1) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
56 fprintf(stderr, |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
57 "cannot create sprite - gFont_Create()\n"); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
58 fflush(stderr); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
59 exit(EXIT_FAILURE); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
60 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
61 ps2util_sprite_Unuse_alpha(&sp[i]); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
62 } |
0 | 63 |
116 | 64 flag_spriteInited = true; |
65 */ | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
66 |
0 | 67 } |
68 | |
69 static void | |
70 gFont_DefSprite(int number, int x, int y, int w, int h) | |
71 { | |
116 | 72 sptable[number].mx = x; |
73 sptable[number].my = y; | |
74 sptable[number].w = w; | |
75 sptable[number].h = h; | |
76 } | |
77 | |
78 void | |
79 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
80 { | |
81 SpriteTable *m = &sptable[number]; | |
82 m->w = w; | |
83 m->h = h; | |
84 m->color = (color & 32); | |
85 m->mx = w / 2; | |
86 m->my = h / 2; | |
87 m->tex_w = power_of_two(m->w); | |
88 m->tex_h = power_of_two(m->h); | |
89 m->texture = (int *)name; | |
0 | 90 } |
91 | |
92 void | |
93 gFont_Init() | |
94 { | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
95 int i, j; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
96 int number = 0; |
0 | 97 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
98 gFont_Init_Png("img/font.png"); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
99 gFont_Create(); // スプライト生成 |
0 | 100 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
101 for (i=0; i<7; i++) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
102 for (j=0; j<15; j++) { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
103 gFont_DefSprite(number, j*17, i*34, 17, 34); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
104 number++; |
0 | 105 } |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
106 } |
0 | 107 } |
108 | |
109 | |
110 static void | |
111 gFont_PutSprite(int number, int x, int y) | |
112 { | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
113 ps2utilSprite *p = &sp[sp_counter]; |
0 | 114 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
115 // ushortってなんですか?:miya |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
116 /* |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
117 ps2util_sprite_Set_basicAttribute( |
0 | 118 p, |
119 (ushort)x, (ushort)y, | |
120 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5, | |
121 (ushort)sptable[number].tx, (ushort)sptable[number].ty, | |
122 (ushort)sptable[number].tw, (ushort)sptable[number].th, | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
123 SPRITE_PRIO_FOREGROUND); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
124 */ |
0 | 125 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
126 ps2util_sprite_Request(p); |
0 | 127 sp_counter++; |
128 } | |
129 | |
130 | |
131 static void | |
132 gFont_Clear() | |
133 { | |
134 int i; | |
135 | |
136 for (i=0; i<DEFOBJ; i++) { | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
137 sprite_disappear(&sp[i].attribute); |
0 | 138 } |
139 sp_counter = 0; | |
140 } | |
141 | |
142 void | |
143 gFont_Draw_Reset() | |
144 { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
145 if (flag_spriteInited == true) { |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
146 gFont_Clear(); |
0 | 147 } |
148 } | |
149 | |
150 static int | |
151 get_number_char(char a) | |
152 { | |
153 return (int)a-32; | |
154 } | |
155 | |
156 /* | |
88 | 157 * str をスプライド表示 |
0 | 158 */ |
159 void | |
100 | 160 gFont_SetString(const char *str, int x, int y) |
0 | 161 { |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
162 int number; |
0 | 163 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
164 while (*str != '\0') { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
165 number = get_number_char(*str); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
166 gFont_PutSprite(number, x, y); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
167 str++; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
168 x += (int)CHAR_W_SIZE*1.5; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
169 } |
0 | 170 } |
171 | |
172 /* | |
88 | 173 * numを文字列に変換してSetStringに渡す |
0 | 174 */ |
175 void | |
176 gFont_SetStringInt(int num, int x, int y) | |
177 { | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
178 char bufp[256]; |
0 | 179 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
180 snprintf(bufp, 256, "%d", num); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
181 gFont_SetString(bufp, x, y); |
0 | 182 } |
183 | |
184 void | |
185 gFont_SetFont_OP() | |
186 { | |
187 } |