| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
. |
| 6 |
|
| 7 |
|
| 8 |
#include <ctype.h> |
| 9 |
#include <string.h> |
| 10 |
|
| 11 |
#include "glk.h" |
| 12 |
#include "scott.h" |
| 13 |
|
| 14 |
#include "sagagraphics.h" |
| 15 |
|
| 16 |
int pixel_size; |
| 17 |
int x_offset = 0; |
| 18 |
int y_offset = 0; |
| 19 |
int right_margin; |
| 20 |
int left_margin = 0; |
| 21 |
|
| 22 |
PALETTE pal; |
| 23 |
|
| 24 |
struct USImage *USImages = NULL; |
| 25 |
|
| 26 |
int has_graphics(void) |
| 27 |
{ |
| 28 |
return (USImages != NULL); |
| 29 |
} |
| 30 |
|
| 31 |
USImage *new_image(void) |
| 32 |
{ |
| 33 |
struct USImage *new = MemAlloc(sizeof(USImage)); |
| 34 |
new->index = -1; |
| 35 |
new->datasize = 0; |
| 36 |
new->imagedata = NULL; |
| 37 |
new->systype = 0; |
| 38 |
new->usage = 0; |
| 39 |
new->cropleft = 0; |
| 40 |
new->cropright = 0; |
| 41 |
new->previous = NULL; |
| 42 |
new->next = NULL; |
| 43 |
return new; |
| 44 |
} |
| 45 |
|
| 46 |
void SetColor(int32_t index, const RGB *color) |
| 47 |
{ |
| 48 |
pal[index][0] = (*color)[0]; |
| 49 |
pal[index][1] = (*color)[1]; |
| 50 |
pal[index][2] = (*color)[2]; |
| 51 |
} |
| 52 |
|
| 53 |
void SetRGB(int32_t index, int red, int green, int blue) |
| 54 |
{ |
| 55 |
red = red * 35.7; |
| 56 |
green = green * 35.7; |
| 57 |
blue = blue * 35.7; |
| 58 |
|
| 59 |
pal[index][0] = red; |
| 60 |
pal[index][1] = green; |
| 61 |
pal[index][2] = blue; |
| 62 |
} |
| 63 |
|
| 64 |
void PutPixel(glsi32 xpos, glsi32 ypos, int32_t color) |
| 65 |
{ |
| 66 |
if (xpos < 0 || xpos > right_margin || xpos < left_margin) { |
| 67 |
return; |
| 68 |
} |
| 69 |
glui32 glk_color = ((pal[color][0] << 16)) | ((pal[color][1] << 8)) | (pal[color][2]); |
| 70 |
|
| 71 |
glk_window_fill_rect(Graphics, glk_color, xpos * pixel_size + x_offset, |
| 72 |
ypos * pixel_size + y_offset, pixel_size, pixel_size); |
| 73 |
} |
| 74 |
|
| 75 |
void PutDoublePixel(glsi32 xpos, glsi32 ypos, int32_t color) |
| 76 |
{ |
| 77 |
if (xpos < 0 || xpos > right_margin || xpos < left_margin) { |
| 78 |
return; |
| 79 |
} |
| 80 |
glui32 glk_color = ((pal[color][0] << 16)) | ((pal[color][1] << 8)) | (pal[color][2]); |
| 81 |
|
| 82 |
glk_window_fill_rect(Graphics, glk_color, xpos * pixel_size + x_offset, |
| 83 |
ypos * pixel_size + y_offset, pixel_size * 2, pixel_size); |
| 84 |
} |
| 85 |
|
| 86 |
int issagaimg(const char *name) |
| 87 |
{ |
| 88 |
if (name == NULL) |
| 89 |
return 0; |
| 90 |
size_t len = strlen(name); |
| 91 |
if (len < 4) |
| 92 |
return 0; |
| 93 |
char c = name[0]; |
| 94 |
if (c == 'R' || c == 'B' || c == 'S') { |
| 95 |
for (int i = 1; i < 4; i++) |
| 96 |
if (!isdigit(name[i])) |
| 97 |
return 0; |
| 98 |
return 1; |
| 99 |
} |
| 100 |
return 0; |
| 101 |
} |