| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
#include "angband.h" |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
#define MAX_MOUSE_BUTTONS 20 |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
#define MAX_MOUSE_LABEL 10 |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
typedef struct |
|---|
| 40 |
{ |
|---|
| 41 |
char label[MAX_MOUSE_LABEL]; |
|---|
| 42 |
int left; |
|---|
| 43 |
int right; |
|---|
| 44 |
unsigned char key; |
|---|
| 45 |
} button_mouse; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
static button_mouse *button_mse; |
|---|
| 52 |
static button_mouse *button_backup; |
|---|
| 53 |
|
|---|
| 54 |
static int button_start; |
|---|
| 55 |
static int button_length; |
|---|
| 56 |
static int button_num; |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
button_add_f button_add_hook; |
|---|
| 63 |
button_kill_f button_kill_hook; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
int button_add_text(const char *label, unsigned char keypress) |
|---|
| 84 |
{ |
|---|
| 85 |
int i; |
|---|
| 86 |
int length = strlen(label); |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
if (length > MAX_MOUSE_LABEL) |
|---|
| 90 |
{ |
|---|
| 91 |
bell("Label too long - button abandoned!"); |
|---|
| 92 |
return 0; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
for (i = 0; i < button_num; i++) |
|---|
| 97 |
if (button_mse[i].key == keypress) |
|---|
| 98 |
return 0; |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
button_length += length; |
|---|
| 102 |
my_strcpy(button_mse[button_num].label, label, MAX_MOUSE_LABEL); |
|---|
| 103 |
button_mse[button_num].left = button_length - length + 1; |
|---|
| 104 |
button_mse[button_num].right = button_length; |
|---|
| 105 |
button_mse[button_num++].key = keypress; |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
p_ptr->redraw |= (PR_BUTTONS); |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
return (length); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
int button_add(char *label, unsigned char keypress) |
|---|
| 118 |
{ |
|---|
| 119 |
if (!button_add_hook) |
|---|
| 120 |
return 0; |
|---|
| 121 |
else |
|---|
| 122 |
return (*button_add_hook) (label, keypress); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
void button_backup_all(void) |
|---|
| 129 |
{ |
|---|
| 130 |
|
|---|
| 131 |
if (button_backup[0].key) return; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
(void)C_COPY(button_backup, button_mse, MAX_MOUSE_BUTTONS, button_mouse); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
void button_restore(void) |
|---|
| 142 |
{ |
|---|
| 143 |
int i = 0; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
button_kill_all(); |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
while (button_backup[i].key) |
|---|
| 150 |
{ |
|---|
| 151 |
|
|---|
| 152 |
button_add(button_backup[i].label, button_backup[i].key); |
|---|
| 153 |
button_backup[i].key = '\0'; |
|---|
| 154 |
i++; |
|---|
| 155 |
} |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
int button_kill_text(unsigned char keypress) |
|---|
| 163 |
{ |
|---|
| 164 |
int i, j, length; |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
for (i = 0; i < button_num; i++) |
|---|
| 168 |
if (button_mse[i].key == keypress) break; |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
if (i == button_num) |
|---|
| 172 |
{ |
|---|
| 173 |
return 0; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
length = button_mse[i].right - button_mse[i].left + 1; |
|---|
| 178 |
button_length -= length; |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
for (j = i; j < button_num - 1; j++) |
|---|
| 182 |
{ |
|---|
| 183 |
button_mse[j] = button_mse[j + 1]; |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
button_mse[j].left -= length; |
|---|
| 187 |
button_mse[j].right -= length; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
button_mse[button_num].label[0] = '\0'; |
|---|
| 192 |
button_mse[button_num].left = 0; |
|---|
| 193 |
button_mse[button_num].right = 0; |
|---|
| 194 |
button_mse[button_num--].key = 0; |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
p_ptr->redraw |= (PR_BUTTONS); |
|---|
| 198 |
redraw_stuff(); |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
return (length); |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
int button_kill(unsigned char keypress) |
|---|
| 208 |
{ |
|---|
| 209 |
if (!button_kill_hook) return 0; |
|---|
| 210 |
else |
|---|
| 211 |
return (*button_kill_hook) (keypress); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
void button_kill_all(void) |
|---|
| 218 |
{ |
|---|
| 219 |
int i; |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
if (!button_kill_hook) return; |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
for (i = button_num - 1; i >= 0; i--) |
|---|
| 226 |
(void)(*button_kill_hook) (button_mse[i].key); |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
void button_init(button_add_f add, button_kill_f kill) |
|---|
| 234 |
{ |
|---|
| 235 |
|
|---|
| 236 |
button_mse = C_ZNEW(MAX_MOUSE_BUTTONS, button_mouse); |
|---|
| 237 |
button_backup = C_ZNEW(MAX_MOUSE_BUTTONS, button_mouse); |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
button_add_hook = add; |
|---|
| 241 |
button_kill_hook = kill; |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
char button_get_key(int x, int y) |
|---|
| 250 |
{ |
|---|
| 251 |
int i; |
|---|
| 252 |
|
|---|
| 253 |
for (i = 0; i < button_num; i++) |
|---|
| 254 |
{ |
|---|
| 255 |
if ((y == Term->hgt - 1) && |
|---|
| 256 |
(x >= button_start + button_mse[i].left) && |
|---|
| 257 |
(x <= button_start + button_mse[i].right)) |
|---|
| 258 |
{ |
|---|
| 259 |
return button_mse[i].key; |
|---|
| 260 |
} |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
return 0; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
size_t button_print(int row, int col) |
|---|
| 270 |
{ |
|---|
| 271 |
int j; |
|---|
| 272 |
|
|---|
| 273 |
button_start = col; |
|---|
| 274 |
|
|---|
| 275 |
for (j = 0; j < button_num; j++) |
|---|
| 276 |
c_put_str(TERM_SLATE, button_mse[j].label, row, col + button_mse[j].left); |
|---|
| 277 |
|
|---|
| 278 |
return button_length; |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|