-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtext.c
More file actions
92 lines (74 loc) · 1.94 KB
/
text.c
File metadata and controls
92 lines (74 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <psx.h>
#include "include/text.h"
#include "include/fontspace.h"
#include "include/font.h"
void InitText(){
GsImage FontImage;
/*Load a custom font and upload it to VRAM*/
GsImageFromTim(&FontImage, FontTimData);
GsUploadImage(&FontImage);
}
int GetPrintedStringWidth(char monospace, char *string)
{
int StringWidth = 0;
char CharOffset;
while(*string)
{
/*Check if this is a printable character*/
if(*string >= 0x20 && *string <= 0x7F)
{
/*Get char offset*/
CharOffset = *string - 0x20;
if(monospace) StringWidth += 8;
else StringWidth += (FontSpace[CharOffset] + 1);
}
/*Check if this is a newline character*/
if(*string == '\n') return StringWidth;
/*Point to the next character*/
string++;
}
return StringWidth;
}
void GsPrintString(int x, int y, char Red, char Green, char Blue, char monospace, char *string)
{
GsSprite CharSprite;
char CharOffset;
/*Set up character sprite*/
if(x < 0)CharSprite.x = 160 - (GetPrintedStringWidth(monospace, string)/2);
else CharSprite.x = x;
CharSprite.y = y;
CharSprite.w = 8;
CharSprite.h = 8;
CharSprite.r = Red;
CharSprite.g = Green;
CharSprite.b = Blue;
CharSprite.cx = 320;
CharSprite.cy = 240;
CharSprite.tpage = 5;
CharSprite.attribute = COLORMODE(COLORMODE_8BPP);
while(*string)
{
/*Check if this is a printable character*/
if(*string >= 0x20 && *string <= 0x7F)
{
/*Get char offset*/
CharOffset = *string - 0x20;
CharSprite.u = (CharOffset%0x20) * 8;
CharSprite.v = (CharOffset/0x20) * 8;
/*Place sprite in the drawing list*/
GsSortSimpleSprite(&CharSprite);
/*Increase X offset*/
if(monospace) CharSprite.x += 8;
else CharSprite.x += (FontSpace[CharOffset] + 1);
}
/*Check if this is a newline character*/
if(*string == '\n')
{
string++;
if(x < 0)CharSprite.x = 160 - (GetPrintedStringWidth(monospace, string)/2);
else CharSprite.x = x;
CharSprite.y += 10;
}
else string++;
}
}