annotate gFont.cc @ 134:42337585fb7c

fix merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 22 Jul 2011 18:32:39 +0900
parents 4f50f5a3b363
children
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; // スプライトロードフラグ
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
26 //static TEXTURE *font_tex;
130
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
27 extern SceneGraphPtr root;
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 */
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
66 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
68 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
69 gFont_DefSprite(int number, int x, int y, int w, int h)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
70 {
116
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
71 sptable[number].mx = x;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
72 sptable[number].my = y;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
73 sptable[number].w = w;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
74 sptable[number].h = h;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
75 }
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
76
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
77 void
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
78 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
79 {
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
80 SpriteTable *m = &sptable[number];
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
81 m->w = w;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
82 m->h = h;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
83 m->color = (color & 32);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
84 m->mx = w / 2;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
85 m->my = h / 2;
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
86 m->tex_w = power_of_two(m->w);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
87 m->tex_h = power_of_two(m->h);
ed702e49cc6c conpile
e085768
parents: 100
diff changeset
88 m->texture = (int *)name;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
89 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
90
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
91 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 gFont_Init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
93 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
94 int i, j;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
95 int number = 0;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
96 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
97 gFont_Create(); // スプライト生成
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
98
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
99 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
100 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
101 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
102 number++;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
104 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
105 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
106
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
107
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
108 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109 gFont_PutSprite(int number, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
111 ps2utilSprite *p = &sp[sp_counter];
0
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 // ushortってなんですか?:miya
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
114 /*
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
115 ps2util_sprite_Set_basicAttribute(
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
116 p,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
117 (ushort)x, (ushort)y,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
119 (ushort)sptable[number].tx, (ushort)sptable[number].ty,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 (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
121 SPRITE_PRIO_FOREGROUND);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
122 */
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
123
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
124 ps2util_sprite_Request(p);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
125 sp_counter++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
126 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
127
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
128
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130 gFont_Clear()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 {
119
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
132 int i;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133
119
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
134 for (i=0; i<DEFOBJ; i++) {
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
135 sprite_disappear(&sp[i].attribute);
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
136 }
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
137 sp_counter = 0;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
139
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141 gFont_Draw_Reset()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 {
119
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
143 if (flag_spriteInited == true) {
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
144 gFont_Clear();
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
145 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
146 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
147
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
148 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149 get_number_char(char a)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
150 {
119
f2e2460b4011 draw_title
e085768
parents: 116
diff changeset
151 return (int)a-32;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
152 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
153
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
155 * str をスプライド表示
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
157 void
100
e5f2eb98b575 change cc
e085768
parents: 99
diff changeset
158 gFont_SetString(const char *str, int x, int y)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
159 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
160 int number;
130
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
161 char *ch_str = (char *)str;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
162
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
163 while (*str != '\0') {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
164 number = get_number_char(*str);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
165 gFont_PutSprite(number, x, y);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
166 str++;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
167 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
168 }
130
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
169
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
170 //SceneGraphPtr font = droot->createSceneGraph();
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
171 droot->createStringFont(root,ch_str,50,/*640*/x,/*480*/y,0x00ff00ff);
4f50f5a3b363 new repository
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 119
diff changeset
172 //droot->setSceneData(font);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
173 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
174
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
175 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
176 * numを文字列に変換してSetStringに渡す
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
177 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
178 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
179 gFont_SetStringInt(int num, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
180 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
181 char bufp[256];
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
182
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
183 snprintf(bufp, 256, "%d", num);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
184 gFont_SetString(bufp, x, y);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
185 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
186
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
187 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
188 gFont_SetFont_OP()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
189 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
190 }