Skip to content

Commit

Permalink
Clean up input popup window interface and setting position.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbroad committed Oct 7, 2017
1 parent 70882b8 commit a0bf7f3
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 54 deletions.
5 changes: 2 additions & 3 deletions command_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ namespace CommandQueue
//
Queue::Queue(void) : last_time(0)
{
init_ipu(&ipu, -1, 300, 100, MAX_TEXT_MESSAGE_LENGTH, 3, cancel_handler, input_handler);
ipu.x = (window_width - ipu.popup_x_len) / 2;
ipu.y = (window_height - ipu.popup_y_len) / 2;
init_ipu(&ipu, -1, MAX_TEXT_MESSAGE_LENGTH, 3, 30, cancel_handler, input_handler);
ipu.data = static_cast<void *>(this);
}

Expand Down Expand Up @@ -178,6 +176,7 @@ namespace CommandQueue
return;
// open the input window and continue waiting for input
display_popup_win(&ipu, commands.front().get_prompts()[params.size()].c_str());
centre_popup_window(&ipu);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions encyclopedia.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ static int cm_encycl_handler(window_info *win, int widget_id, int mx, int my, in
break;
case CM_ENCYCL_SEARCH:
close_ipu(&ipu_encycl);
init_ipu(&ipu_encycl, win->window_id, DEFAULT_FONT_X_LEN * 20, -1, 40, 1, NULL, find_page_callback);
init_ipu(&ipu_encycl, win->window_id, 21, 1, 22, NULL, find_page_callback);
ipu_encycl.x = mx; ipu_encycl.y = my;
display_popup_win(&ipu_encycl, encycl_search_prompt_str);
if (ipu_encycl.popup_win >=0 && ipu_encycl.popup_win<windows_list.num_windows)
Expand Down Expand Up @@ -1249,7 +1249,7 @@ void fill_encyclopedia_win (int window_id)
cm_encycl = cm_create(cm_encycl_base_str, cm_encycl_handler);
cm_set_pre_show_handler(cm_encycl, cm_encycl_pre_show_handler);
cm_add_window(cm_encycl, window_id);
init_ipu(&ipu_encycl, -1, -1, -1, 1, 1, NULL, NULL);
init_ipu(&ipu_encycl, -1, 1, 1, 1, NULL, NULL);
find_base_pages();
process_encycl_links();
}
Expand Down
10 changes: 7 additions & 3 deletions hud_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "context_menu.h"
#include "elconfig.h"
#include "font.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_timer.h"
#include "notepad.h"
Expand Down Expand Up @@ -165,10 +166,13 @@ int Hud_Timer::cm_handler(window_info *win, int option)
input = new INPUT_POPUP;
else
close_ipu(input);
init_ipu(input, win->window_id, 220, -1, 4, 1, 0, set_timer_time);
input->x = -230;
input->y = last_base_y_start;
init_ipu(input, -1, 4, 1, 5, 0, set_timer_time);
display_popup_win(input, hud_timer_popup_title_str);
if (input->popup_win >= 0 && input->popup_win < windows_list.num_windows)
{
window_info *win = &windows_list.window[input->popup_win];
move_window(win->window_id, win->pos_id, win->pos_loc, window_width - hud_x - win->len_x - 10, window_height - hud_y - win->len_y - 10);
}
}
break;
case CMHT_RESET: reset(); break;
Expand Down
10 changes: 4 additions & 6 deletions item_lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace ItemLists
class Quantity_Input
{
public:
Quantity_Input(void) { init_ipu(&ipu, -1, 200, -1, 10, 1, NULL, quantity_input_handler); }
Quantity_Input(void) { init_ipu(&ipu, -1, 10, 1, 11, NULL, quantity_input_handler); }
size_t get_list(void) const { return list; };
size_t get_item(void) const { return item; };
void open(int parent_id, int mx, int my, size_t list, size_t item);
Expand Down Expand Up @@ -907,7 +907,7 @@ namespace ItemLists
names_scroll_id = vscrollbar_add_extended(win_id, 1, NULL, 0, 0, 0, 0, 0,
1.0, 0.77f, 0.57f, 0.39f, 0, 1, Vars::lists()->size()-num_show_names_list);

init_ipu(&ipu_item_list_name, -1, -1, -1, 1, 1, NULL, NULL);
init_ipu(&ipu_item_list_name, -1, 1, 1, 1, NULL, NULL);
}
else
{
Expand Down Expand Up @@ -1103,12 +1103,10 @@ CHECK_GL_ERRORS();
{
if ((win_id < 0) || (win_id >= windows_list.num_windows))
return;
window_info *win = &windows_list.window[win_id];
close_ipu(&ipu_item_list_name);
init_ipu(&ipu_item_list_name, win_id, -1, -1, 41, 1, NULL, (is_new) ?new_list_handler :rename_list_handler);
ipu_item_list_name.x = (win->len_x - ipu_item_list_name.popup_x_len) / 2;
ipu_item_list_name.y = (get_grid_size()*num_grid_rows - ipu_item_list_name.popup_y_len) / 2;
init_ipu(&ipu_item_list_name, win_id, 41, 1, 42, NULL, (is_new) ?new_list_handler :rename_list_handler);
display_popup_win(&ipu_item_list_name, (is_new) ?item_list_name_str : item_list_rename_str );
centre_popup_window(&ipu_item_list_name);
if (!is_new && Vars::lists()->valid_active_list())
set_text_message_data(&ipu_item_list_name.popup_text, Vars::lists()->get_active_name().c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions knowledge.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static int cm_knowledge_handler(window_info *win, int widget_id, int mx, int my,
{
case 0:
close_ipu(&ipu_know);
init_ipu(&ipu_know, win->window_id, DEFAULT_FONT_X_LEN * 20, -1, 40, 1, NULL, set_hightlight_callback);
init_ipu(&ipu_know, win->window_id, 21, 1, 22, NULL, set_hightlight_callback);
ipu_know.x = mx; ipu_know.y = my;
display_popup_win(&ipu_know, know_highlight_prompt_str);
if (ipu_know.popup_win >=0 && ipu_know.popup_win<windows_list.num_windows)
Expand Down Expand Up @@ -502,7 +502,7 @@ void fill_knowledge_win (int window_id)
{
cm_know_id = cm_create(know_highlight_cm_str, cm_knowledge_handler);
cm_add_window(cm_know_id, window_id);
init_ipu(&ipu_know, -1, -1, -1, 1, 1, NULL, NULL);
init_ipu(&ipu_know, -1, 1, 1, 1, NULL, NULL);
}
}

Expand Down
53 changes: 31 additions & 22 deletions notepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "elwindows.h"
#include "errors.h"
#include "gamewin.h"
#include "gl_init.h"
#include "init.h"
#include "hud.h"
#include "notepad.h"
Expand All @@ -26,24 +27,13 @@
* Popup Section *
******************************************/

void init_ipu (INPUT_POPUP *ipu, int parent, int x_len, int y_len, int maxlen, int rows, void cancel(void *), void input(const char *, void *))
void init_ipu (INPUT_POPUP *ipu, int parent, int maxlen, int rows, int cols, void cancel(void *), void input(const char *, void *))
{
ipu->text_flags = TEXT_FIELD_BORDER|TEXT_FIELD_EDITABLE|TEXT_FIELD_NO_KEYPRESS|TEXT_FIELD_MOUSE_EDITABLE;
ipu->text_flags |= (rows>1) ?TEXT_FIELD_SCROLLBAR :0;

ipu->popup_win = ipu->popup_field = ipu->popup_label = ipu->popup_ok =
ipu->popup_no = ipu->x = ipu->y = -1;

if (x_len == -1)
ipu->popup_x_len = DEFAULT_FONT_X_LEN * maxlen + 20;
else
ipu->popup_x_len = x_len;

if (y_len == -1)
ipu->popup_y_len = 100;
else
ipu->popup_y_len = y_len;
ipu->popup_y_len += ((rows>1) ?(rows-1)*28 :0);
ipu->popup_win = ipu->popup_field = ipu->popup_label = ipu->popup_ok = ipu->popup_no = -1;
ipu->x = ipu->y = 0;

ipu->popup_cancel = cancel;
ipu->popup_input = input;
Expand All @@ -52,6 +42,7 @@ void init_ipu (INPUT_POPUP *ipu, int parent, int x_len, int y_len, int maxlen, i
ipu->parent = parent;
ipu->maxlen = maxlen;
ipu->rows = rows;
ipu->cols = cols;
ipu->accept_do_not_close = ipu->allow_nonprint_chars = 0;
}

Expand All @@ -68,7 +59,7 @@ void close_ipu (INPUT_POPUP *ipu)
destroy_window(ipu->popup_win);
clear_text_message_data (&ipu->popup_text);
free_text_message_data (&ipu->popup_text);
init_ipu(ipu, -1, 200, 100, 10, 1, NULL, NULL);
init_ipu(ipu, -1, 1, 1, 1, NULL, NULL);
}
}

Expand Down Expand Up @@ -207,7 +198,7 @@ static int popup_keypress_handler(window_info *win,

static int popup_ui_scale_handler(window_info *win)
{
int seperator = (int)(0.5 + win->current_scale * 5);
int seperator = (int)(0.5 + win->current_scale * 10);
int y_len = seperator;
int max_x = 0;
int ok_w = 0;
Expand All @@ -221,9 +212,9 @@ static int popup_ui_scale_handler(window_info *win)
max_x = 2 * seperator + widget_get_width(win->window_id, ipu->popup_label);

widget_set_size(win->window_id, ipu->popup_field, win->current_scale);
widget_resize(win->window_id, ipu->popup_field, ipu->popup_x_len * win->current_scale - 2 * seperator, 1 + ipu->rows * win->default_font_len_y + 2 * 5 );
widget_resize(win->window_id, ipu->popup_field, ipu->cols * win->default_font_len_x + 2 * seperator + 2 * 5, 1 + ipu->rows * win->default_font_len_y + 2 * 5 );
// hack - the text feld scrollbar does not function correct until the next resize, so do it twice for now
widget_resize(win->window_id, ipu->popup_field, ipu->popup_x_len * win->current_scale - 2 * seperator, 1 + ipu->rows * win->default_font_len_y + 2 * 5 );
widget_resize(win->window_id, ipu->popup_field, ipu->cols * win->default_font_len_x + 2 * seperator + 2 * 5, 1 + ipu->rows * win->default_font_len_y + 2 * 5 );
max_x = (2 * seperator + widget_get_width(win->window_id, ipu->popup_field) > max_x) ?2 * seperator + widget_get_width(win->window_id, ipu->popup_field) :max_x;

button_resize(win->window_id, ipu->popup_ok, 0, 0, win->current_scale);
Expand All @@ -249,6 +240,25 @@ static int popup_ui_scale_handler(window_info *win)
return 1;
}

void centre_popup_window(INPUT_POPUP *ipu)
{
window_info *win = NULL;
if (ipu == NULL) return;
if (ipu->popup_win < 0 || ipu->popup_win >= windows_list.num_windows) return;

win = &windows_list.window[ipu->popup_win];

if ((ipu->parent > -1) && (ipu->parent < windows_list.num_windows))
{
window_info *pwin = &windows_list.window[ipu->parent];
move_window(win->window_id, win->pos_id,win->pos_loc, win->pos_x + (pwin->len_x - win->len_x) / 2, win->pos_y + (pwin->len_y - win->len_y) / 2);
}
else
{
move_window(win->window_id, win->pos_id,win->pos_loc, (window_width - win->len_x) / 2, (window_height - win->len_y) / 2);
}
}


void display_popup_win (INPUT_POPUP *ipu, const char* label)
{
Expand All @@ -258,7 +268,7 @@ void display_popup_win (INPUT_POPUP *ipu, const char* label)
int widget_id = 100;

Uint32 flags = (ELW_USE_UISCALE|ELW_WIN_DEFAULT) & ~ELW_CLOSE_BOX;
ipu->popup_win = create_window (win_prompt, ipu->parent, 0, ipu->x, ipu->y, ipu->popup_x_len, ipu->popup_y_len, flags);
ipu->popup_win = create_window (win_prompt, ipu->parent, 0, ipu->x, ipu->y, 0, 0, flags);

if (ipu->popup_win >= 0 && ipu->popup_win < windows_list.num_windows)
win = &windows_list.window[ipu->popup_win];
Expand Down Expand Up @@ -778,6 +788,7 @@ static int notepad_add_category(widget_list* UNUSED(w),
increase_note_storage();

display_popup_win (&popup_str, label_note_name);
centre_popup_window (&popup_str);
return 1;
}

Expand Down Expand Up @@ -878,9 +889,7 @@ static int resize_notepad_handler(window_info *win, int new_width, int new_heigh
tab_collection_move(w, win->pos_x, win->pos_y + tab_tag_height);

close_ipu(&popup_str);
init_ipu (&popup_str, main_note_tab_id, NOTE_NAME_LEN*DEFAULT_FONT_X_LEN, 100, NOTE_NAME_LEN, 1, NULL, notepad_add_continued);
popup_str.x = (win->len_x - popup_str.popup_x_len) / 2;
popup_str.y = (win->len_y - popup_str.popup_y_len) / 2;
init_ipu (&popup_str, main_note_tab_id, NOTE_NAME_LEN+1, 1, NOTE_NAME_LEN+2, NULL, notepad_add_continued);

update_note_button_scrollbar (0);

Expand Down
22 changes: 16 additions & 6 deletions notepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extern float note_zoom; /*!< Size of the text in the note pad */
/* state structure for an input popup window */
typedef struct
{
int popup_win, popup_field, popup_label, popup_ok, popup_no;
int popup_x_len, popup_y_len, parent, x, y;
int maxlen, rows, accept_do_not_close, allow_nonprint_chars;
int popup_win, parent, popup_field, popup_label, popup_ok, popup_no;
int maxlen, cols, rows, x, y;
int accept_do_not_close, allow_nonprint_chars;
void (*popup_cancel)(void *);
void (*popup_input)(const char *, void *);
Uint32 text_flags;
Expand All @@ -37,15 +37,14 @@ typedef struct
*
* \param ipu pointer to the input popup window state structure
* \param parent id of the parent window
* \param x_len width of the window in pixels
* \param y_len base height of the window if rows is 1
* \param maxlen the maximum length of the popup window text.
* \param rows number of rows for the text widget
* \param cols number of chars columns for the text widget
* \param cancel callback function if the window is cancelled (or NULL)
* \param input callback function to pass entered text (or (unusefully) NULL)
* \callgraph
*/
void init_ipu (INPUT_POPUP *ipu, int parent, int x_len, int y_len, int maxlen, int rows, void cancel(void *), void input(const char *, void *));
void init_ipu (INPUT_POPUP *ipu, int parent, int maxlen, int rows, int cols, void cancel(void *), void input(const char *, void *));

/*!
* \ingroup notepad_window
Expand Down Expand Up @@ -81,6 +80,17 @@ void close_ipu (INPUT_POPUP *ipu);
*/
void display_popup_win (INPUT_POPUP *ipu, const char* label);

/*!
* \ingroup notepad_window
* \brief Centres the popup window to parent window
*
* Centres the popup window to parent window.
*
* \param ipu pointer to the input popup window state structure
* \callgraph
*/
void centre_popup_window (INPUT_POPUP *ipu);

/*!
* \ingroup notepad_window
* \brief Displays the in-game notepad.
Expand Down
17 changes: 7 additions & 10 deletions quest_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,9 @@ static void add_entry(window_info *win, size_t entry)
current_action = CMQL_ADD;
adding_insert_pos = (entry < active_entries.size()) ?active_entries[entry] :quest_entries.size();
close_ipu(&ipu_questlog);
init_ipu(&ipu_questlog, questlog_win, -1, -1, MAX_USERNAME_LENGTH, 1, questlog_input_cancel_handler, questlog_add_npc_input_handler);
ipu_questlog.x = (win->len_x - ipu_questlog.popup_x_len) / 2;
ipu_questlog.y = (win->len_y - ipu_questlog.popup_y_len) / 2;
init_ipu(&ipu_questlog, questlog_win, MAX_USERNAME_LENGTH, 1, MAX_USERNAME_LENGTH + 1, questlog_input_cancel_handler, questlog_add_npc_input_handler);
display_popup_win(&ipu_questlog, questlog_add_npc_prompt_str);
centre_popup_window(&ipu_questlog);
}

// Continue inputting a new entry, part 2 have npc so queue the input
Expand All @@ -1416,11 +1415,10 @@ static void questlog_add_text_input(window_info *win)
{
prompt_for_add_text = false;
close_ipu(&ipu_questlog);
init_ipu(&ipu_questlog, questlog_win, 400, -1, 1024, 5, questlog_input_cancel_handler, questlog_add_text_input_handler);
ipu_questlog.x = (win->len_x - ipu_questlog.popup_x_len) / 2;
ipu_questlog.y = (win->len_y - ipu_questlog.popup_y_len) / 2;
init_ipu(&ipu_questlog, questlog_win, 1024, 5, 40, questlog_input_cancel_handler, questlog_add_text_input_handler);
ipu_questlog.allow_nonprint_chars = 1;
display_popup_win(&ipu_questlog, questlog_add_text_prompt_str);
centre_popup_window(&ipu_questlog);
}

// Continue inputting a new entry, part 4 insert the entry.
Expand Down Expand Up @@ -1466,11 +1464,10 @@ static void find_in_entry(window_info *win)
return;
current_action = CMQL_FIND;
close_ipu(&ipu_questlog);
init_ipu(&ipu_questlog, questlog_win, -1, -1, 21, 1, questlog_input_cancel_handler, questlog_find_input_handler);
ipu_questlog.x = (win->len_x - ipu_questlog.popup_x_len) / 2;
ipu_questlog.y = win->len_y + 20;
init_ipu(&ipu_questlog, questlog_win, 21, 1, 22, questlog_input_cancel_handler, questlog_find_input_handler);
ipu_questlog.accept_do_not_close = 1;
display_popup_win(&ipu_questlog, questlog_find_prompt_str);
centre_popup_window(&ipu_questlog);
}


Expand Down Expand Up @@ -1957,7 +1954,7 @@ extern "C" void display_questlog()
cm_questlog_id = cm_create(cm_questlog_menu_str, cm_quest_handler);
cm_add_window(cm_questlog_id, questlog_win);
cm_set_pre_show_handler(cm_questlog_id, cm_questlog_pre_show_handler);
init_ipu(&ipu_questlog, -1, -1, -1, 1, 1, NULL, NULL);
init_ipu(&ipu_questlog, -1, 1, 1, 1, NULL, NULL);
}
}
else
Expand Down

0 comments on commit a0bf7f3

Please sign in to comment.