#include "draw_wins.h"
#include <ncurses.h> /* attri_t, chtype */
+#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, int16_t */
#include <stdio.h> /* for sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* strlen(), strtok() */
-#include "../common/try_malloc.h" /* for try_malloc() */
-#include "command_db.h" /* for get_command_longdsc */
-#include "keybindings.h" /* struct KeyBinding, get_name_to_keycode() */
-#include "wincontrol.h" /* struct WinConf, get_winconf_by_win() */
-#include "windows.h" /* struct Win */
+#include "../common/try_malloc.h" /* try_malloc() */
+#include "keybindings.h" /* struct KeyBinding, get_keyname_to_keycode() */
+#include "windows.h" /* struct Win, get_win_by_id() */
#include "world.h" /* global world */
static char * get_kb_line_and_iterate(struct KeyBinding ** kb_pp);
/* Draw from line "start" on config view for keybindings defined at "kb". */
-static void draw_kb_view(struct Win * w, struct KeyBindingDB * kb,
- uint8_t start);
+static void draw_keybinding_config(struct Win * w, struct KeyBindingDB * kb,
+ uint8_t start);
/* Draw into window "w" from line "start" on a "title" followed by an empty
* line followed by a list of all keybindings starting at kb_p.
static void try_resize_winmap(struct Win * w, int new_size_y, int new_size_x)
{
char * f_name = "try_resize_winmap()";
- if (w->winmapsize.y >= new_size_y && w->winmapsize.x >= new_size_x)
+ if (w->winmap_size.y >= new_size_y && w->winmap_size.x >= new_size_x)
{
return;
}
- if (w->winmapsize.y > new_size_y)
+ if (w->winmap_size.y > new_size_y)
{
- new_size_y = w->winmapsize.y;
+ new_size_y = w->winmap_size.y;
}
- else if (w->winmapsize.x > new_size_x)
+ else if (w->winmap_size.x > new_size_x)
{
- new_size_x = w->winmapsize.x;
+ new_size_x = w->winmap_size.x;
}
chtype * old_winmap = w->winmap;
uint32_t new_size = sizeof(chtype) * new_size_y * new_size_x;
uint16_t y, x;
for (y = 0; y < new_size_y; y++)
{
- for (x = 0; y < w->winmapsize.y && x < w->winmapsize.x; x++)
+ for (x = 0; y < w->winmap_size.y && x < w->winmap_size.x; x++)
{
- chtype ch = old_winmap[(y * w->winmapsize.x) + x];
+ chtype ch = old_winmap[(y * w->winmap_size.x) + x];
w->winmap[(y * new_size_x) + x] = ch;
}
for (; x < new_size_x; x++)
}
}
free(old_winmap);
- w->winmapsize.y = new_size_y;
- w->winmapsize.x = new_size_x;
+ w->winmap_size.y = new_size_y;
+ w->winmap_size.x = new_size_x;
}
static void set_ch_on_yx(struct Win * w, int y, int x, chtype ch)
{
- w->winmap[(y * w->winmapsize.x) + x] = ch;
+ w->winmap[(y * w->winmap_size.x) + x] = ch;
}
{
uint16_t x, y;
int16_t z = -1;
- for (y = win->winmapsize.y; ; y++)
+ for (y = win->winmap_size.y; ; y++)
{
- try_resize_winmap(win, y + 1, win->framesize.x);
- for (x = 0; x < win->framesize.x; x++)
+ try_resize_winmap(win, y + 1, win->frame_size.x);
+ for (x = 0; x < win->frame_size.x; x++)
{
z++;
if ('\n' == text[z])
static void add_line(struct Win * w, char * line, attr_t attri)
{
- uint16_t y = w->winmapsize.y;
+ uint16_t y = w->winmap_size.y;
uint16_t len_line = strlen(line);
if (attri
- && w->winmapsize.x < w->framesize.x && w->framesize.x > len_line)
+ && w->winmap_size.x < w->frame_size.x && w->frame_size.x > len_line)
{
- try_resize_winmap(w, y + 1, w->framesize.x);
+ try_resize_winmap(w, y + 1, w->frame_size.x);
}
else
{
}
if (attri)
{
- for (; x < w->framesize.x; x++)
+ for (; x < w->frame_size.x; x++)
{
set_ch_on_yx(w, y, x, ' ' | attri);
}
int16_t z = -1;
for (y = 0; 0 == toggle; y++)
{
- for (x = 0; x < win->framesize.x; x++)
+ for (x = 0; x < win->frame_size.x; x++)
{
z++;
if ('\n' == text[z])
/* Depending on what's bigger, determine start point in window or text. */
uint16_t start_y = 0;
- if (y < win->framesize.y)
+ if (y < win->frame_size.y)
{
- start_y = win->framesize.y - y;
+ start_y = win->frame_size.y - y;
}
- else if (y > win->framesize.y)
+ else if (y > win->frame_size.y)
{
- uint16_t offset = y - win->framesize.y;
+ uint16_t offset = y - win->frame_size.y;
for (y = 0; y < offset; y++)
{
- for (x = 0; x < win->framesize.x; x++)
+ for (x = 0; x < win->frame_size.x; x++)
{
z++;
if ('\n' == text[z])
{
char * f_name = "get_kb_line_and_iterate()";
struct KeyBinding * kb_p = * kb_pp;
- char * keyname = get_name_to_keycode(kb_p->key);
- char * cmd_dsc = get_command_longdsc(kb_p->name);
- uint16_t size = 9 + 1 + strlen(cmd_dsc) + 1;
+ char * keyname = get_keyname_to_keycode(kb_p->key);
+ struct Command * command = get_command_to_keycode(kb_p, kb_p->key);
+ uint16_t size = 9 + 1 + strlen(command->dsc_long) + 1;
char * line = try_malloc(size, f_name);
- sprintf(line, "%-9s %s", keyname, cmd_dsc);
+ sprintf(line, "%-9s %s", keyname, command->dsc_long);
free(keyname);
* kb_pp = kb_p->next;
return line;
-static void draw_kb_view(struct Win * w, struct KeyBindingDB * kb,
- uint8_t start)
+static void draw_keybinding_config(struct Win * w, struct KeyBindingDB * kb,
+ uint8_t start)
{
if (0 == kb->kbs)
{
{
char * dsc_turn = "Turn: ";
char * dsc_hitpoints = "\nHitpoints: ";
- char * dsc_score = "\nScore: ";
- uint16_t maxl = strlen(dsc_turn) + strlen(dsc_hitpoints) + strlen(dsc_score)
- + 5 + 3 + 5; /* Max strlens of strings of numbers to use. */
+ uint16_t maxl = strlen(dsc_turn) + 5 + strlen(dsc_hitpoints) + 3;
char text[maxl + 1];
- sprintf(text, "%s%d%s%d%s%d",
- dsc_turn, world.turn,
- dsc_hitpoints, world.player_lifepoints,
- dsc_score, world.score);
+ sprintf(text, "%s%d%s%d",
+ dsc_turn, world.turn, dsc_hitpoints, world.player_lifepoints);
add_text_with_linebreaks(win, text);
}
win->center.y = world.player_inventory_select;
char inventory_copy[strlen(world.player_inventory) + 1];
sprintf(inventory_copy, "%s", world.player_inventory);
- char * foo = inventory_copy;
+ char * strtok_target = inventory_copy;
uint8_t i = 0;
while (1)
{
- char * object = strtok(foo, "\n");
- foo = NULL;
+ char * object = strtok(strtok_target, "\n");
+ strtok_target = NULL;
if (NULL == object)
{
return;
{
char * title = "Active window's keybindings:";
struct KeyBinding * kb_p;
- struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
- if (0 == wc->view)
+ struct Win * w = get_win_by_id(world.winDB.active);
+ if (0 == w->view)
{
- kb_p = wc->kb.kbs;
+ kb_p = w->kb.kbs;
}
- else if (1 == wc->view)
+ else if (1 == w->view)
{
kb_p = world.kb_wingeom.kbs;
}
- else if (2 == wc->view)
+ else if (2 == w->view)
{
kb_p = world.kb_winkeys.kbs;
}
extern void draw_win_keybindings_global(struct Win * win)
{
win->center.y = world.kb_global.select;
- draw_kb_view(win, &world.kb_global, 0);
+ draw_keybinding_config(win, &world.kb_global, 0);
}
extern void draw_win_keybindings_winconf_geometry(struct Win * win)
{
win->center.y = world.kb_wingeom.select;
- draw_kb_view(win, &world.kb_wingeom, 0);
+ draw_keybinding_config(win, &world.kb_wingeom, 0);
}
extern void draw_win_keybindings_winconf_keybindings(struct Win * win)
{
win->center.y = world.kb_winkeys.select;
- draw_kb_view(win, &world.kb_winkeys, 0);
+ draw_keybinding_config(win, &world.kb_winkeys, 0);
}
extern void draw_winconf_keybindings(struct Win * win)
{
- struct WinConf * wc = get_winconf_by_win(win);
char * title = "Window's keybindings:";
add_line(win, title, 0);
add_line(win, " ", 0);
- draw_kb_view(win, &wc->kb, 2);
- win->center.y = wc->kb.select + 2;
+ draw_keybinding_config(win, &win->kb, 2);
+ win->center.y = win->kb.select + 2;
}
extern void draw_winconf_geometry(struct Win * win)
{
- struct WinConf * wcp = get_winconf_by_win(win);
char * title = "Window's geometry:\n";
char * h_d = "\nHeight to save: ";
char * h_pos = " (width in cells)";
char * w_neg = " (negative diff: cells to screen height)";
char * h_t = h_pos;
char * w_t = w_pos;
- if (1 == wcp->height_type)
+ if (1 == win->target_height_type)
{
h_t = h_neg;
}
- if (1 == wcp->width_type)
+ if (1 == win->target_width_type)
{
w_t = w_neg;
}
+ strlen(h_t) + strlen(h_d) + 6 /* 6 = n of chars to */
+ strlen(w_t) + strlen(w_d) + 6 + 1; /* write max int16_t */
char text[maxl + 1];
- sprintf(text, "%s%s%d%s%s%d%s", title, h_d, wcp->height, h_t,
- w_d, wcp->width, w_t);
+ sprintf(text, "%s%s%d%s%s%d%s", title, h_d, win->target_height, h_t,
+ w_d, win->target_width, w_t);
add_text_with_linebreaks(win, text);
}