2020-12-11 21:47:11 -05:00
|
|
|
#include <ultra64.h>
|
|
|
|
|
#include <PR/gs2dex.h>
|
2020-12-12 16:20:37 -05:00
|
|
|
#include <PR/gu.h>
|
2020-12-15 22:57:04 -05:00
|
|
|
#include <stdarg.h>
|
2020-12-11 21:47:11 -05:00
|
|
|
|
2020-12-15 17:46:07 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2020-12-11 21:47:11 -05:00
|
|
|
#include "s2d_draw.h"
|
2020-12-11 22:51:58 -05:00
|
|
|
#include "s2d_print.h"
|
2020-12-15 17:46:07 -05:00
|
|
|
#include "s2d_ustdlib.h"
|
2020-12-11 21:47:11 -05:00
|
|
|
|
2020-12-15 23:10:28 -05:00
|
|
|
void s2d_snprint(int x, int y, const char *str, uObjMtx *buf, int len) {
|
2020-12-11 21:47:11 -05:00
|
|
|
char *p = str;
|
2020-12-12 18:50:26 -05:00
|
|
|
int tx = 0, ty = 0;
|
2020-12-15 22:57:04 -05:00
|
|
|
int tmp_len = 0;
|
2020-12-15 23:06:09 -05:00
|
|
|
int orig_x = x;
|
|
|
|
|
int orig_y = y;
|
2020-12-15 23:36:40 -05:00
|
|
|
|
2020-12-16 18:06:46 -05:00
|
|
|
if (*p == '\0') return;
|
|
|
|
|
|
2020-12-18 18:38:27 -05:00
|
|
|
// resets parameters
|
2020-12-15 23:36:40 -05:00
|
|
|
s2d_red = s2d_green = s2d_blue = 255;
|
|
|
|
|
s2d_alpha = 255;
|
2020-12-18 18:38:27 -05:00
|
|
|
drop_shadow = FALSE;
|
2020-12-11 22:51:58 -05:00
|
|
|
do {
|
2020-12-16 18:06:46 -05:00
|
|
|
char current_char = *p;
|
2020-12-15 22:57:04 -05:00
|
|
|
|
2020-12-16 18:06:46 -05:00
|
|
|
switch (current_char) {
|
2020-12-11 22:51:58 -05:00
|
|
|
case CH_SCALE:
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p);
|
2020-12-16 18:06:46 -05:00
|
|
|
myScale = s2d_atoi(p, &p);
|
2020-12-11 21:47:11 -05:00
|
|
|
break;
|
2020-12-11 22:51:58 -05:00
|
|
|
case CH_ROT:
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p);
|
2020-12-16 18:06:46 -05:00
|
|
|
myDegrees = s2d_atoi(p, &p);
|
2020-12-11 21:47:11 -05:00
|
|
|
break;
|
2020-12-11 22:51:58 -05:00
|
|
|
case CH_TRANSLATE:
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p);
|
2020-12-12 20:28:07 -05:00
|
|
|
x = s2d_atoi(p, &p);
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p);
|
|
|
|
|
CH_SKIP(p);
|
2020-12-12 20:28:07 -05:00
|
|
|
y = s2d_atoi(p, &p);
|
2020-12-12 15:33:14 -05:00
|
|
|
break;
|
2020-12-12 19:45:53 -05:00
|
|
|
case CH_COLOR:
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p);
|
2020-12-12 19:45:53 -05:00
|
|
|
s2d_red = s2d_atoi(p, &p);
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p); CH_SKIP(p);
|
2020-12-12 21:56:36 -05:00
|
|
|
|
2020-12-12 19:45:53 -05:00
|
|
|
s2d_green = s2d_atoi(p, &p);
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p); CH_SKIP(p);
|
2020-12-12 21:56:36 -05:00
|
|
|
|
2020-12-12 19:45:53 -05:00
|
|
|
s2d_blue = s2d_atoi(p, &p);
|
2020-12-13 18:31:42 -05:00
|
|
|
CH_SKIP(p); CH_SKIP(p);
|
2020-12-12 21:56:36 -05:00
|
|
|
|
2020-12-12 19:45:53 -05:00
|
|
|
s2d_alpha = s2d_atoi(p, &p);
|
|
|
|
|
break;
|
2020-12-18 18:38:27 -05:00
|
|
|
case CH_DROPSHADOW:
|
|
|
|
|
drop_shadow ^= 1;
|
|
|
|
|
// CH_SKIP(p);
|
|
|
|
|
break;
|
2020-12-15 23:06:09 -05:00
|
|
|
case '\n':
|
|
|
|
|
x = orig_x;
|
|
|
|
|
y += TEX_HEIGHT;
|
2020-12-15 23:36:40 -05:00
|
|
|
break;
|
|
|
|
|
case '\t':
|
|
|
|
|
x += TAB_WIDTH_H;
|
|
|
|
|
break;
|
|
|
|
|
case '\v':
|
|
|
|
|
x += TAB_WIDTH_V;
|
|
|
|
|
y += TEX_HEIGHT;
|
2020-12-15 23:06:09 -05:00
|
|
|
break;
|
2020-12-11 21:47:11 -05:00
|
|
|
default:
|
2020-12-16 18:06:46 -05:00
|
|
|
if (current_char != '\0') {
|
2020-12-15 22:57:04 -05:00
|
|
|
if (myDegrees == 0)
|
2020-12-16 18:06:46 -05:00
|
|
|
draw_s2d_glyph(current_char, (x += (8 * myScale)) + tx, y + ty, (buf++));
|
2020-12-15 22:57:04 -05:00
|
|
|
else
|
2020-12-16 18:06:46 -05:00
|
|
|
draw_s2d_glyph(current_char, (x += ((8 * myScale))) + tx, y + ty, (buf++));
|
2020-12-15 22:57:04 -05:00
|
|
|
}
|
2020-12-11 21:47:11 -05:00
|
|
|
}
|
2020-12-15 17:46:07 -05:00
|
|
|
if (*p == '\0') break;
|
2020-12-13 22:24:18 -05:00
|
|
|
p++;
|
2020-12-15 22:57:04 -05:00
|
|
|
tmp_len++;
|
|
|
|
|
} while (tmp_len < len);
|
2020-12-11 22:51:58 -05:00
|
|
|
myScale = 1;
|
2020-12-12 15:33:14 -05:00
|
|
|
myDegrees = 0;
|
2020-12-12 18:50:26 -05:00
|
|
|
tx = 0;
|
|
|
|
|
ty = 0;
|
2020-12-11 21:47:11 -05:00
|
|
|
}
|
2020-12-11 22:51:58 -05:00
|
|
|
|
2020-12-15 22:57:04 -05:00
|
|
|
void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
|
|
|
|
|
s2d_snprint(x, y, str, buf, s2d_strlen(str));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 23:10:28 -05:00
|
|
|
void s2d_type_print(int x, int y, const char *str, uObjMtx *buf, int *pos) {
|
2020-12-15 17:46:07 -05:00
|
|
|
int len = s2d_strlen(str);
|
|
|
|
|
|
2020-12-15 22:57:04 -05:00
|
|
|
s2d_snprint(x, y, str, buf, *pos);
|
2020-12-15 17:46:07 -05:00
|
|
|
if (s2d_timer % 2 == 0) {
|
2020-12-15 22:57:04 -05:00
|
|
|
if (*pos < len) {
|
|
|
|
|
(*pos)++;
|
|
|
|
|
}
|
2020-12-15 17:46:07 -05:00
|
|
|
}
|
2020-12-13 22:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-16 01:12:08 -05:00
|
|
|
// void s2d_vsprint(int x, int y, uObjMtx *buf, const char *str, ...) {
|
|
|
|
|
// int last_chr;
|
|
|
|
|
// va_list args;
|
|
|
|
|
// char *dst = alloc(s2d_strlen(str) * 2);
|
|
|
|
|
// va_start(args, str);
|
|
|
|
|
// last_chr = vsprintf(dst, str, str, args);
|
|
|
|
|
// if (last_chr >= 0) {
|
|
|
|
|
// dst[last_chr] = '\0';
|
|
|
|
|
// }
|
|
|
|
|
// s2d_print(x, y, dst, buf);
|
|
|
|
|
// }
|
2020-12-15 22:57:04 -05:00
|
|
|
|
|
|
|
|
|