annotate gFont.c @ 96:0b65ca27f113

compile on Mac OS X 2
author Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
date Thu, 02 Jun 2011 14:56:11 +0900
parents 8edae89a3877
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; // スプライトロードフラグ
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
26
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
30 gFont_Init_Png(char *texname)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
31 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
32 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
33 fprintf(stderr,
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
34 "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
35 fflush(stderr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
36 exit(EXIT_FAILURE);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
37 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
38
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
39 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
40 fprintf(stderr,
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
41 "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
42 fflush(stderr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
43 exit(EXIT_FAILURE);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
44 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
45 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
46
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
47 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
48 gFont_Create()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
49 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
50 int i;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
51 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
52 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
53 fprintf(stderr,
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
54 "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
55 fflush(stderr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
56 exit(EXIT_FAILURE);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
57 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
58 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
59 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
60
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
61
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
62 flag_spriteInited = true;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
64
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
65 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
66 gFont_DefSprite(int number, int x, int y, int w, int h)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
68 sptable[number].tx = x;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
69 sptable[number].ty = y;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
70 sptable[number].tw = w;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
71 sptable[number].th = h;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
72 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
73
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
74 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
75 gFont_Init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
76 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
77 int i, j;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
78 int number = 0;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
79
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
80 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
81 gFont_Create(); // スプライト生成
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
82
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
83 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
84 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
85 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
86 number++;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
87 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
88 }
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
93 gFont_PutSprite(int number, int x, int y)
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 ps2utilSprite *p = &sp[sp_counter];
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
96
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
97 // ushortってなんですか?:miya
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
98 /*
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
99 ps2util_sprite_Set_basicAttribute(
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
100 p,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
101 (ushort)x, (ushort)y,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
102 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 (ushort)sptable[number].tx, (ushort)sptable[number].ty,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
104 (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
105 SPRITE_PRIO_FOREGROUND);
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
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
108 ps2util_sprite_Request(p);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109 sp_counter++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
111
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
112
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
113 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
114 gFont_Clear()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
115 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
116 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
117
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118 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
119 sprite_disappear(&sp[i].attribute);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
121 sp_counter = 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
122 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
123
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
124 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
125 gFont_Draw_Reset()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
126 {
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
127 if (flag_spriteInited == true) {
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
128 gFont_Clear();
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
132 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133 get_number_char(char a)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
135 return (int)a-32;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
136 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
137
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
139 * str をスプライド表示
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 gFont_SetString(char *str, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
143 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
144 int number;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
145
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
146 while (*str != '\0') {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
147 number = get_number_char(*str);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
148 gFont_PutSprite(number, x, y);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
149 str++;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
150 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
151 }
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 * numを文字列に変換してSetStringに渡す
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
157 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
158 gFont_SetStringInt(int num, int x, int y)
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 char bufp[256];
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 snprintf(bufp, 256, "%d", num);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
163 gFont_SetString(bufp, x, y);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
164 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
165
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
166 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
167 gFont_SetFont_OP()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
168 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
169 }