| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
. |
| 6 |
|
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
#include <string.h> |
| 10 |
|
| 11 |
#include "apple2draw.h" |
| 12 |
#include "glk.h" |
| 13 |
#include "saga.h" |
| 14 |
#include "sagagraphics.h" |
| 15 |
#include "scott.h" |
| 16 |
|
| 17 |
#ifdef SPATTERLIGHT |
| 18 |
#include "glkimp.h" |
| 19 |
#endif |
| 20 |
|
| 21 |
#include "titleimage.h" |
| 22 |
|
| 23 |
glui32 OptimalPictureSize(glui32 *width, glui32 *height); |
| 24 |
|
| 25 |
void ResizeTitleImage(void) |
| 26 |
{ |
| 27 |
glui32 graphwidth, graphheight, optimal_width, optimal_height; |
| 28 |
#ifdef SPATTERLIGHT |
| 29 |
glk_window_set_background_color(Graphics, gbgcol); |
| 30 |
glk_window_clear(Graphics); |
| 31 |
#endif |
| 32 |
glk_window_get_size(Graphics, &graphwidth, &graphheight); |
| 33 |
pixel_size = OptimalPictureSize(&optimal_width, &optimal_height); |
| 34 |
x_offset = ((int)graphwidth - (int)optimal_width) / 2; |
| 35 |
right_margin = optimal_width + x_offset; |
| 36 |
y_offset = ((int)graphheight - (int)optimal_height) / 3; |
| 37 |
} |
| 38 |
|
| 39 |
void DrawTitleImage(void) |
| 40 |
{ |
| 41 |
int storedwidth = ImageWidth; |
| 42 |
int storedheight = ImageHeight; |
| 43 |
#ifdef SPATTERLIGHT |
| 44 |
if (!gli_enable_graphics) |
| 45 |
return; |
| 46 |
#endif |
| 47 |
Top = FindGlkWindowWithRock(GLK_STATUS_ROCK); |
| 48 |
if (Top) { |
| 49 |
glk_window_close(Top, NULL); |
| 50 |
Top = NULL; |
| 51 |
} |
| 52 |
|
| 53 |
glui32 background_color = -1; |
| 54 |
|
| 55 |
Bottom = FindGlkWindowWithRock(GLK_BUFFER_ROCK); |
| 56 |
if (Bottom) { |
| 57 |
glk_style_measure(Bottom, style_Normal, stylehint_BackColor, |
| 58 |
&background_color); |
| 59 |
glk_window_close(Bottom, NULL); |
| 60 |
} |
| 61 |
|
| 62 |
Graphics = glk_window_open(0, 0, 0, wintype_Graphics, GLK_GRAPHICS_ROCK); |
| 63 |
|
| 64 |
if (glk_gestalt_ext(gestalt_GraphicsCharInput, 0, NULL, 0)) { |
| 65 |
glk_request_char_event(Graphics); |
| 66 |
} else { |
| 67 |
Bottom = glk_window_open(Graphics, winmethod_Below | winmethod_Fixed, |
| 68 |
2, wintype_TextBuffer, GLK_BUFFER_ROCK); |
| 69 |
glk_request_char_event(Bottom); |
| 70 |
} |
| 71 |
|
| 72 |
if (background_color != -1) { |
| 73 |
glk_window_set_background_color(Graphics, background_color); |
| 74 |
glk_window_clear(Graphics); |
| 75 |
} |
| 76 |
|
| 77 |
ResizeTitleImage(); |
| 78 |
|
| 79 |
if (DrawUSRoom(99)) { |
| 80 |
ResizeTitleImage(); |
| 81 |
glk_window_clear(Graphics); |
| 82 |
DrawUSRoom(99); |
| 83 |
if (CurrentSys == SYS_APPLE2) |
| 84 |
DrawApple2ImageFromVideoMem(); |
| 85 |
event_t ev; |
| 86 |
do { |
| 87 |
glk_select(&ev); |
| 88 |
if (ev.type == evtype_Arrange) { |
| 89 |
#ifdef SPATTERLIGHT |
| 90 |
if (!gli_enable_graphics) |
| 91 |
break; |
| 92 |
#endif |
| 93 |
ResizeTitleImage(); |
| 94 |
glk_window_clear(Graphics); |
| 95 |
DrawUSRoom(99); |
| 96 |
if (CurrentSys == SYS_APPLE2) |
| 97 |
DrawApple2ImageFromVideoMem(); |
| 98 |
} |
| 99 |
} while (ev.type != evtype_CharInput); |
| 100 |
} |
| 101 |
|
| 102 |
glk_window_close(Graphics, NULL); |
| 103 |
Graphics = NULL; |
| 104 |
Bottom = FindGlkWindowWithRock(GLK_BUFFER_ROCK); |
| 105 |
if (Bottom != NULL) |
| 106 |
glk_window_close(Bottom, NULL); |
| 107 |
Bottom = glk_window_open(0, 0, 0, wintype_TextBuffer, GLK_BUFFER_ROCK); |
| 108 |
if (Bottom == NULL) |
| 109 |
glk_exit(); |
| 110 |
glk_set_window(Bottom); |
| 111 |
OpenTopWindow(); |
| 112 |
OpenGraphicsWindow(); |
| 113 |
ResizeTitleImage(); |
| 114 |
ImageWidth = storedwidth; |
| 115 |
ImageHeight = storedheight; |
| 116 |
CloseGraphicsWindow(); |
| 117 |
} |
| 118 |
|
| 119 |
void PrintTitleScreenBuffer(void) |
| 120 |
{ |
| 121 |
glk_stream_set_current(glk_window_get_stream(Bottom)); |
| 122 |
glk_set_style(style_User1); |
| 123 |
glk_window_clear(Graphics); |
| 124 |
Output(title_screen); |
| 125 |
free((void *)title_screen); |
| 126 |
glk_set_style(style_Normal); |
| 127 |
HitEnter(); |
| 128 |
glk_window_clear(Graphics); |
| 129 |
} |
| 130 |
|
| 131 |
void PrintTitleScreenGrid(void) |
| 132 |
{ |
| 133 |
int title_length = strlen(title_screen); |
| 134 |
int rows = 0; |
| 135 |
for (int i = 0; i < title_length; i++) |
| 136 |
if (title_screen[i] == '\n') |
| 137 |
rows++; |
| 138 |
winid_t titlewin = glk_window_open(Bottom, winmethod_Above | winmethod_Fixed, rows + 2, |
| 139 |
wintype_TextGrid, 0); |
| 140 |
glui32 width, height; |
| 141 |
glk_window_get_size(titlewin, &width, &height); |
| 142 |
if (width < 40 || height < rows + 2) { |
| 143 |
glk_window_close(titlewin, NULL); |
| 144 |
PrintTitleScreenBuffer(); |
| 145 |
return; |
| 146 |
} |
| 147 |
int offset = (width - 40) / 2; |
| 148 |
int pos = 0; |
| 149 |
char row[40]; |
| 150 |
row[39] = 0; |
| 151 |
for (int i = 1; i <= rows; i++) { |
| 152 |
glk_window_move_cursor(titlewin, offset, i); |
| 153 |
while (title_screen[pos] != '\n' && pos < title_length) |
| 154 |
Display(titlewin, "%c", title_screen[pos++]); |
| 155 |
pos++; |
| 156 |
} |
| 157 |
free((void *)title_screen); |
| 158 |
HitEnter(); |
| 159 |
glk_window_close(titlewin, NULL); |
| 160 |
} |