annotate gFont.cc @ 116:ed702e49cc6c

conpile
author e085768
date Thu, 16 Jun 2011 04:05:33 +0900
parents e5f2eb98b575
children f2e2460b4011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 /*
18
3780d1b2943e *** empty log message ***
gongo
parents: 2
diff changeset
2 * $Id$
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
3 *
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
4 * フォント表示。といっても結局スプライトです。
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
5 * gSprite.c と一緒にしてもよかったんだけど
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
6 * 文字は文字でいろいろあるので分けてみる
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13 #include "gSprite.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15 #define DEFOBJ 120
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 #define SPRITE_COL 0x4f
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17 #define SCREEN_HALF_W 320
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
18 #define SCREEN_HALF_H 240
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19 #define CHAR_W_SIZE 17
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20 #define CHAR_H_SIZE 34
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
26
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
27 //static TEXTURE *font_tex;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
28
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
29 static void
100
e5f2eb98b575 change cc
e085768
parents: 99
diff changeset
30 gFont_Init_Png(const char *texname)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
31 {
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
46 */
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
47 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
48
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
49 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
50 gFont_Create()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
51 {
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
64 flag_spriteInited = true;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
65 */
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
66
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
68
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
69 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
70 gFont_DefSprite(int number, int x, int y, int w, int h)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
71 {
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
72 sptable[number].mx = x;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
73 sptable[number].my = y;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
74 sptable[number].w = w;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
75 sptable[number].h = h;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
76 }
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
77
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
78 void
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
79 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
80 {
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
81 SpriteTable *m = &sptable[number];
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
82 m->w = w;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
83 m->h = h;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
84 m->color = (color & 32);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
85 m->mx = w / 2;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
86 m->my = h / 2;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
87 m->tex_w = power_of_two(m->w);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
88 m->tex_h = power_of_two(m->h);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
89 m->texture = (int *)name;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
90 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
91
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
93 gFont_Init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
105 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
106 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
107 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
108
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
111 gFont_PutSprite(int number, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118 p,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
119 (ushort)x, (ushort)y,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
121 (ushort)sptable[number].tx, (ushort)sptable[number].ty,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
127 sp_counter++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
128 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
132 gFont_Clear()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
135
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
139 sp_counter = 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
143 gFont_Draw_Reset()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
147 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
148 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
150 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
151 get_number_char(char a)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
152 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
153 return (int)a-32;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
155
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
157 * str をスプライド表示
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
158 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
159 void
100
e5f2eb98b575 change cc
e085768
parents: 99
diff changeset
160 gFont_SetString(const char *str, int x, int y)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
170 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
171
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
172 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
173 * numを文字列に変換してSetStringに渡す
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
174 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
175 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
176 gFont_SetStringInt(int num, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
182 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
183
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
184 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
185 gFont_SetFont_OP()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
186 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
187 }