summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:25 +0100
committerBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:25 +0100
commit05f7bb2fae2db44837f26e766597371c286679fe (patch)
tree6ba50845638c0c8dbc4f08a589c7ecbc0750699e /src
parentaf23ba10a91dbc29f97c37217e82a9178ad4d532 (diff)
Change term_init to a constructor-like function
This will leak the instances, but it should be tolerable for now since there's only a small fixed number of instances.
Diffstat (limited to 'src')
-rw-r--r--src/main-gcu.c20
-rw-r--r--src/main-gtk2.c17
-rw-r--r--src/main-sdl.c17
-rw-r--r--src/main-win.c26
-rw-r--r--src/main-x11.c20
-rw-r--r--src/z-term.c30
-rw-r--r--src/z-term.h3
7 files changed, 67 insertions, 66 deletions
diff --git a/src/main-gcu.c b/src/main-gcu.c
index 8f9f393b..7fd04aa7 100644
--- a/src/main-gcu.c
+++ b/src/main-gcu.c
@@ -189,7 +189,7 @@ typedef struct term_data term_data;
struct term_data
{
- term t; /* All term info */
+ term *term_ptr; /* All term info */
WINDOW *win; /* Pointer to the curses window */
};
@@ -724,8 +724,6 @@ static void Term_text_gcu(void *data, int x, int y, int n, byte a, const char *s
*/
static errr term_data_init_gcu(term_data *td, int rows, int cols, int y, int x)
{
- term *t = &td->t;
-
/* Create new window */
td->win = newwin(rows, cols, y, x);
@@ -746,12 +744,12 @@ static errr term_data_init_gcu(term_data *td, int rows, int cols, int y, int x)
};
/* Initialize the term */
- term_init(t, td, cols, rows, 256);
- term_init_icky_corner(t);
- term_init_ui_hooks(t, ui_hooks);
+ td->term_ptr = term_init(td, cols, rows, 256);
+ term_init_icky_corner(td->term_ptr);
+ term_init_ui_hooks(td->term_ptr, ui_hooks);
/* Activate it */
- Term_activate(t);
+ Term_activate(td->term_ptr);
/* Success */
return (0);
@@ -912,7 +910,7 @@ int init_gcu(int argc, char **argv)
term_data_init_gcu(&data[0], LINES, COLS, 0, 0);
/* Remember the term */
- angband_term[0] = &data[0].t;
+ angband_term[0] = data[0].term_ptr;
}
/* No big screen -- create as many term windows as possible */
@@ -980,7 +978,7 @@ int init_gcu(int argc, char **argv)
term_data_init_gcu(&data[next_win], rows, cols, y, x);
/* Remember the term */
- angband_term[next_win] = &data[next_win].t;
+ angband_term[next_win] = data[next_win].term_ptr;
/* One more window */
next_win++;
@@ -988,10 +986,10 @@ int init_gcu(int argc, char **argv)
}
/* Activate the "Angband" window screen */
- Term_activate(&data[0].t);
+ Term_activate(data[0].term_ptr);
/* Remember the active screen */
- term_screen = &data[0].t;
+ term_screen = data[0].term_ptr;
/* Success */
return (0);
diff --git a/src/main-gtk2.c b/src/main-gtk2.c
index 5711c8d7..d8ac84e5 100644
--- a/src/main-gtk2.c
+++ b/src/main-gtk2.c
@@ -80,7 +80,7 @@ typedef struct term_data term_data;
struct term_data
{
- term t;
+ term *term_ptr;
GtkWidget *window;
GtkWidget *drawing_area;
@@ -1107,7 +1107,7 @@ static void size_allocate_event_handler(
allocation->height);
/* And in the term package */
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
/* Resize if necessary */
if ((td->cols != old_cols) || (td->rows != old_rows))
@@ -1168,7 +1168,7 @@ static gboolean expose_event_handler(
{
/* Activate the relevant term */
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
# ifdef NO_REDRAW_SECTION
@@ -1222,7 +1222,6 @@ static gboolean expose_event_handler(
*/
static errr term_data_init(term_data *td, int i)
{
- term *t = &td->t;
char *p;
td->cols = 80;
@@ -1238,9 +1237,9 @@ static errr term_data_init(term_data *td, int i)
};
/* Initialize the term */
- term_init(t, td, td->cols, td->rows, 1024);
- term_init_soft_cursor(t);
- term_init_ui_hooks(t, ui_hooks);
+ td->term_ptr = term_init(td, td->cols, td->rows, 1024);
+ term_init_soft_cursor(td->term_ptr);
+ term_init_ui_hooks(td->term_ptr, ui_hooks);
/* Store the name of the term */
assert(angband_term_name[i] != NULL);
@@ -1250,7 +1249,7 @@ static errr term_data_init(term_data *td, int i)
for (p = (char *)td->name; *p; p++) *p = tolower(*p);
/* Activate (important) */
- Term_activate(t);
+ Term_activate(td->term_ptr);
/* Success */
return (0);
@@ -1931,7 +1930,7 @@ int init_gtk2(int argc, char **argv)
}
/* Activate the "Angband" window screen */
- Term_activate(&data[0].t);
+ Term_activate(data[0].term_ptr);
/* Activate more hook */
plog_aux = hook_plog;
diff --git a/src/main-sdl.c b/src/main-sdl.c
index 859ea960..5ede853a 100644
--- a/src/main-sdl.c
+++ b/src/main-sdl.c
@@ -181,7 +181,7 @@ typedef struct _term_data term_data;
/* A structure for each "term" */
struct _term_data
{
- term t; /* the term structure, defined in z-term.h */
+ term *term_ptr; /* the term structure, defined in z-term.h */
const char *name; /* name of this term sub-window */
unsigned int rows, cols; /* row/column count */
@@ -1189,7 +1189,7 @@ void resizeTerminal(term_data *td, int width, int height)
/* Reactivate, since Term_resize seems to activate the
main window again...*/
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
/* It might not have resized completely to the new
size we wanted (some windows have size limits it seems,
@@ -1319,7 +1319,7 @@ int cycleTerminal(int current)
/* now do a little modulo cycle action and
activate the next term! */
current %= arg_console_count;
- Term_activate(&(data[current].t));
+ Term_activate(data[current].term_ptr);
/* before redrawing, set the border color to purple to
indicate that this terminal is being manipulated*/
@@ -1381,7 +1381,7 @@ void redrawAllTerminals(void)
while (i--)
{
/* Activate this terminal */
- Term_activate(&(data[i].t));
+ Term_activate(data[i].term_ptr);
/* Make its border white since manipulation mode is over */
data[i].border_color = data[i].white;
@@ -1612,7 +1612,6 @@ void manipulationMode(void)
static errr term_data_init(term_data *td, int i)
{
- term *t = &(td->t);
char env_var[80];
const char *val;
@@ -1726,12 +1725,12 @@ static errr term_data_init(term_data *td, int i)
};
/* Initialize the term */
- term_init(t, td, cols, rows, 24);
- term_init_soft_cursor(t);
- term_init_ui_hooks(t, ui_hooks);
+ td->term_ptr = term_init(td, cols, rows, 24);
+ term_init_soft_cursor(td->term_ptr);
+ term_init_ui_hooks(td->term_ptr, ui_hooks);
/* Activate (important) */
- Term_activate(t);
+ Term_activate(td->term_ptr);
/************* finish term_data intializing */
diff --git a/src/main-win.c b/src/main-win.c
index 5eb85dbf..543cea9e 100644
--- a/src/main-win.c
+++ b/src/main-win.c
@@ -316,7 +316,7 @@ typedef struct _term_data term_data;
*/
struct _term_data
{
- term t;
+ term *term_ptr;
const char *s;
@@ -1226,7 +1226,7 @@ static void term_change_font(term_data *td)
static void term_data_redraw(term_data *td)
{
/* Activate the term */
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
/* Redraw the contents */
Term_redraw();
@@ -1308,11 +1308,15 @@ static void Term_xtra_win_react(void)
term_data *td = &data[i];
+ int wid;
+ int hgt;
+ term_get_size(td->term_ptr, &wid, &hgt);
+
/* Update resized windows */
- if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
+ if ((td->cols != wid) || (td->rows != hgt))
{
/* Activate */
- Term_activate(&td->t);
+ Term_activate(&td->term_ptr);
/* Hack -- Resize the term */
Term_resize(td->cols, td->rows);
@@ -1642,8 +1646,6 @@ static void Term_text_win(void *data, int x, int y, int n, byte a, const char *s
*/
static void term_data_link(term_data *td)
{
- term *t = &td->t;
-
/* Hooks */
struct term_ui_hooks_t ui_hooks = {
NULL /* init */,
@@ -1654,9 +1656,9 @@ static void term_data_link(term_data *td)
};
/* Initialize the term */
- term_init(t, td, td->cols, td->rows, td->keys);
- term_init_soft_cursor(t);
- term_init_ui_hooks(t, ui_hooks);
+ td->term_ptr = term_init(td, td->cols, td->rows, td->keys);
+ term_init_soft_cursor(td->term_ptr);
+ term_init_ui_hooks(td->term_ptr, ui_hooks);
}
@@ -1788,7 +1790,7 @@ static void init_windows(void)
}
term_data_link(td);
- angband_term[i] = &td->t;
+ angband_term[i] = td->term_ptr;
if (td->visible)
{
@@ -1815,7 +1817,7 @@ static void init_windows(void)
if (!td->w) quit("Failed to create Angband window");
term_data_link(td);
- angband_term[0] = &td->t;
+ angband_term[0] = td->term_ptr;
/* Activate the main window */
SetActiveWindow(td->w);
@@ -2615,7 +2617,7 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
td->rows = rows;
/* Activate */
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
/* Resize the term */
Term_resize(td->cols, td->rows);
diff --git a/src/main-x11.c b/src/main-x11.c
index b83f7b86..33c30374 100644
--- a/src/main-x11.c
+++ b/src/main-x11.c
@@ -1206,7 +1206,7 @@ typedef struct term_data term_data;
*/
struct term_data
{
- term t;
+ term *term_ptr;
infofnt *fnt;
@@ -1395,7 +1395,7 @@ static errr CheckEvent(term_data *old_td, bool_ wait)
/* Hack -- activate the Term */
- Term_activate(&td->t);
+ Term_activate(td->term_ptr);
/* Hack -- activate the window */
Infowin_set(iwin);
@@ -1423,7 +1423,7 @@ static errr CheckEvent(term_data *old_td, bool_ wait)
case KeyPress:
{
/* Hack -- use "old" term */
- Term_activate(&old_td->t);
+ Term_activate(old_td->term_ptr);
/* Process the key */
react_keypress(&(xev->xkey));
@@ -1502,7 +1502,7 @@ static errr CheckEvent(term_data *old_td, bool_ wait)
/* Hack -- Activate the old term */
- Term_activate(&old_td->t);
+ Term_activate(old_td->term_ptr);
/* Hack -- Activate the proper window */
Infowin_set(old_td->win);
@@ -1664,8 +1664,6 @@ static void Term_text_x11(void *data, int x, int y, int n, byte a, const char *s
*/
static errr term_data_init(term_data *td, int i)
{
- term *t = &td->t;
-
const char *name = angband_term_name[i];
const char *font;
@@ -1902,12 +1900,12 @@ static errr term_data_init(term_data *td, int i)
};
/* Initialize the term */
- term_init(t, td, cols, rows, num);
- term_init_soft_cursor(t);
- term_init_ui_hooks(t, ui_hooks);
+ td->term_ptr = term_init(td, cols, rows, num);
+ term_init_soft_cursor(td->term_ptr);
+ term_init_ui_hooks(td->term_ptr, ui_hooks);
/* Activate (important) */
- Term_activate(t);
+ Term_activate(td->term_ptr);
/* Success */
return (0);
@@ -2016,7 +2014,7 @@ errr init_x11(int argc, char *argv[])
Infowin_raise();
/* Activate the "Angband" window screen */
- Term_activate(&data[0].t);
+ Term_activate(data[0].term_ptr);
diff --git a/src/z-term.c b/src/z-term.c
index ee275148..04fec998 100644
--- a/src/z-term.c
+++ b/src/z-term.c
@@ -1281,16 +1281,7 @@ errr Term_get_cursor(int *v)
*/
errr Term_get_size(int *w, int *h)
{
- /* Access the cursor */
- if (w)
- {
- (*w) = Term->wid;
- }
-
- if (h)
- {
- (*h) = Term->hgt;
- }
+ term_get_size(Term, w, h);
/* Success */
return (0);
@@ -1903,14 +1894,14 @@ errr term_nuke(term *t)
* By default, the cursor starts out "invisible"
* By default, we "erase" using "black spaces"
*/
-errr term_init(term *t, void *data, int w, int h, int k)
+term *term_init(void *data, int w, int h, int k)
{
int y;
/* Wipe it */
+ term *t = safe_calloc(1, sizeof(term));
memset(t, 0, sizeof(term));
-
/* Prepare the input queue */
t->key_head = t->key_tail = 0;
@@ -1963,7 +1954,7 @@ errr term_init(term *t, void *data, int w, int h, int k)
t->data = data;
/* Success */
- return (0);
+ return t;
}
void term_init_icky_corner(term *t)
@@ -1989,3 +1980,16 @@ void term_set_resize_hook(term *t, resize_hook_t *hook)
{
t->resize_hook = hook;
}
+
+void term_get_size(term *t, int *w, int *h)
+{
+ if (w)
+ {
+ (*w) = t->wid;
+ }
+
+ if (h)
+ {
+ (*h) = t->hgt;
+ }
+}
diff --git a/src/z-term.h b/src/z-term.h
index 7d0933cf..139f3fe4 100644
--- a/src/z-term.h
+++ b/src/z-term.h
@@ -265,11 +265,12 @@ void Term_mapped();
void Term_unmapped();
errr term_nuke(term *t);
-errr term_init(term *t, void *data, int w, int h, int k);
+term *term_init(void *data, int w, int h, int k);
void term_init_icky_corner(term *t);
void term_init_soft_cursor(term *t);
void term_init_ui_hooks(term *t, term_ui_hooks_t hooks);
void term_set_resize_hook(term *t, resize_hook_t *hook);
+void term_get_size(term *t, int *w, int *h);
#ifdef __cplusplus
} /* extern "C" */