Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #899680 ยป 0036-sdl2-Rename-pEdit-and-friends-to-adhere-with-coding-.patch

Marko Lindqvist, 2020-11-25 03:17 AM

View differences:

client/gui-sdl2/chatline.c
struct widget *pLoadGameButton;
struct widget *pConfigure;
struct widget *pBackButton;
struct widget *pEdit;
struct widget *pedit;
int text_width;
int active;
} *pConnDlg = NULL;
......
**************************************************************************/
void popup_input_line(void)
{
struct widget *pInput_Edit;
struct widget *input_edit;
pInput_Edit = create_edit_from_chars(NULL, main_data.gui, "", adj_font(12),
input_edit = create_edit_from_chars(NULL, main_data.gui, "", adj_font(12),
adj_size(400), 0);
pInput_Edit->size.x = (main_window_width() - pInput_Edit->size.w) / 2;
pInput_Edit->size.y = (main_window_height() - pInput_Edit->size.h) / 2;
input_edit->size.x = (main_window_width() - input_edit->size.w) / 2;
input_edit->size.y = (main_window_height() - input_edit->size.h) / 2;
if (edit(pInput_Edit) != ED_ESC) {
inputline_return_callback(pInput_Edit);
if (edit(input_edit) != ED_ESC) {
inputline_return_callback(input_edit);
}
widget_undraw(pInput_Edit);
widget_mark_dirty(pInput_Edit);
FREEWIDGET(pInput_Edit);
widget_undraw(input_edit);
widget_mark_dirty(input_edit);
FREEWIDGET(input_edit);
flush_dirty();
}
......
buf->size.y = pwindow->size.h - adj_size(40) - adj_size(5) - buf->size.h;
buf->action = input_edit_conn_callback;
set_wstate(buf, FC_WS_NORMAL);
pConnDlg->pEdit = buf;
pConnDlg->pedit = buf;
add_to_gui_list(ID_EDIT, buf);
/* buttons */
......
bool popdown_conn_list_dialog(void)
{
if (pConnDlg) {
if (get_wstate(pConnDlg->pEdit) == FC_WS_PRESSED) {
if (get_wstate(pConnDlg->pedit) == FC_WS_PRESSED) {
force_exit_from_event_loop();
}
client/gui-sdl2/citydlg.c
/**********************************************************************//**
Rename city name:
**************************************************************************/
static int new_name_city_dlg_callback(struct widget *pEdit)
static int new_name_city_dlg_callback(struct widget *pedit)
{
if (PRESSED_EVENT(main_data.event)) {
if (pEdit->string_utf8->text != NULL) {
if (strcmp(pEdit->string_utf8->text, city_name_get(pcity_dlg->pcity))) {
if (pedit->string_utf8->text != NULL) {
if (strcmp(pedit->string_utf8->text, city_name_get(pcity_dlg->pcity))) {
sdl2_client_flags |= CF_CHANGED_CITY_NAME;
city_rename(pcity_dlg->pcity, pEdit->string_utf8->text);
city_rename(pcity_dlg->pcity, pedit->string_utf8->text);
}
} else {
/* empty input -> restore previous content */
copy_chars_to_utf8_str(pEdit->string_utf8, city_name_get(pcity_dlg->pcity));
widget_redraw(pEdit);
widget_mark_dirty(pEdit);
copy_chars_to_utf8_str(pedit->string_utf8, city_name_get(pcity_dlg->pcity));
widget_redraw(pedit);
widget_mark_dirty(pedit);
flush_dirty();
}
}
client/gui-sdl2/cma_fe.c
{
if (PRESSED_EVENT(main_data.event)) {
if (pwidget && pCma && pCma->pAdv) {
struct widget *pEdit = (struct widget *)pwidget->data.ptr;
struct widget *pedit = (struct widget *)pwidget->data.ptr;
if (pEdit->string_utf8->text != NULL) {
cmafec_preset_add(pEdit->string_utf8->text, &pCma->edited_cm_parm);
if (pedit->string_utf8->text != NULL) {
cmafec_preset_add(pedit->string_utf8->text, &pCma->edited_cm_parm);
} else {
cmafec_preset_add(_("new preset"), &pCma->edited_cm_parm);
}
client/gui-sdl2/dialogs.c
bool leader_sex; /* selected leader sex */
struct nation_set *set;
struct widget *pChange_Sex;
struct widget *pName_Edit;
struct widget *name_edit;
struct widget *pName_Next;
struct widget *pName_Prev;
struct widget *pset_name;
......
{
if (PRESSED_EVENT(main_data.event)) {
struct NAT *pSetup = (struct NAT *)(pNationDlg->end_widget_list->data.ptr);
char *pstr = pSetup->pName_Edit->string_utf8->text;
char *pstr = pSetup->name_edit->string_utf8->text;
/* perform a minimum of sanity test on the name */
if (strlen(pstr) == 0) {
......
}
/* change leader name */
copy_chars_to_utf8_str(pSetup->pName_Edit->string_utf8,
copy_chars_to_utf8_str(pSetup->name_edit->string_utf8,
nation_leader_name(pleader));
FC_FREE(pLeaderName);
......
set_wstate(pSetup->pName_Next, FC_WS_SELECTED);
}
widget_redraw(pSetup->pName_Edit);
widget_redraw(pSetup->name_edit);
widget_redraw(pSetup->pName_Prev);
widget_redraw(pSetup->pName_Next);
widget_mark_dirty(pSetup->pName_Edit);
widget_mark_dirty(pSetup->name_edit);
widget_mark_dirty(pSetup->pName_Prev);
widget_mark_dirty(pSetup->pName_Next);
......
}
/* change leader name */
copy_chars_to_utf8_str(pSetup->pName_Edit->string_utf8,
copy_chars_to_utf8_str(pSetup->name_edit->string_utf8,
nation_leader_name(pleader));
FC_FREE(pLeaderName);
......
set_wstate(pSetup->pName_Prev, FC_WS_SELECTED);
}
widget_redraw(pSetup->pName_Edit);
widget_redraw(pSetup->name_edit);
widget_redraw(pSetup->pName_Prev);
widget_redraw(pSetup->pName_Next);
widget_mark_dirty(pSetup->pName_Edit);
widget_mark_dirty(pSetup->name_edit);
widget_mark_dirty(pSetup->pName_Prev);
widget_mark_dirty(pSetup->pName_Next);
......
/**********************************************************************//**
User interacted with leader name edit widget.
**************************************************************************/
static int leader_name_edit_callback(struct widget *pEdit)
static int leader_name_edit_callback(struct widget *pedit)
{
if (PRESSED_EVENT(main_data.event)) {
if (pEdit->string_utf8->text != NULL) {
if (pedit->string_utf8->text != NULL) {
/* empty input -> restore previous content */
copy_chars_to_utf8_str(pEdit->string_utf8, pLeaderName);
widget_redraw(pEdit);
widget_mark_dirty(pEdit);
copy_chars_to_utf8_str(pedit->string_utf8, pLeaderName);
widget_redraw(pedit);
widget_mark_dirty(pedit);
flush_dirty();
}
}
......
SDL_Surface *pTmp_Surf, *pTmp_Surf_zoomed;
struct widget *pwindow = pNationDlg->end_widget_list;
struct NAT *pSetup = (struct NAT *)(pwindow->data.ptr);
struct widget *pLabel = pSetup->pName_Edit->next;
struct widget *pLabel = pSetup->name_edit->next;
struct nation_type *pNation = nation_by_number(pSetup->nation);
pTmp_Surf = get_nation_flag_surface(pNation);
......
pSetup->selected_leader = fc_rand(nation_leader_list_size(leaders));
pleader = nation_leader_list_get(leaders, pSetup->selected_leader);
copy_chars_to_utf8_str(pSetup->pName_Edit->string_utf8,
copy_chars_to_utf8_str(pSetup->name_edit->string_utf8,
nation_leader_name(pleader));
FC_FREE(pLeaderName);
......
set_wstate(pwidget, FC_WS_NORMAL);
pwidget->action = leader_name_edit_callback;
add_to_gui_list(ID_NATION_WIZARD_LEADER_NAME_EDIT, pwidget);
pSetup->pName_Edit = pwidget;
pSetup->name_edit = pwidget;
/* create next leader name button */
pwidget = create_themeicon_button(current_theme->R_ARROW_Icon,
......
pNat = get_widget_pointer_form_main_list(MAX_ID - pSetup->nation);
} while (get_wstate(pNat) == FC_WS_DISABLED);
if (get_wstate(pSetup->pName_Edit) == FC_WS_PRESSED) {
if (get_wstate(pSetup->name_edit) == FC_WS_PRESSED) {
force_exit_from_event_loop();
set_wstate(pSetup->pName_Edit, FC_WS_NORMAL);
set_wstate(pSetup->name_edit, FC_WS_NORMAL);
}
change_nation_label();
enable(MAX_ID - 1000 - pSetup->nation_style);
client/gui-sdl2/mapctrl.c
/**********************************************************************//**
User interacted with the edit button of the new city dialog.
**************************************************************************/
static int newcity_name_edit_callback(struct widget *pEdit)
static int newcity_name_edit_callback(struct widget *pedit)
{
if (PRESSED_EVENT(main_data.event)) {
if (pNewCity_Dlg->begin_widget_list->string_utf8->text == NULL) {
/* empty input -> restore previous content */
copy_chars_to_utf8_str(pEdit->string_utf8, pSuggestedCityName);
widget_redraw(pEdit);
widget_mark_dirty(pEdit);
copy_chars_to_utf8_str(pedit->string_utf8, pSuggestedCityName);
widget_redraw(pedit);
widget_mark_dirty(pedit);
flush_dirty();
}
}
......
struct widget *pwindow = NULL;
struct widget *cancel_button = NULL;
struct widget *ok_button;
struct widget *pEdit;
struct widget *pedit;
SDL_Rect area;
int suggestlen;
......
area.h += pLabel->size.h;
pEdit = create_edit(NULL, pwindow->dst, create_utf8_from_char(pSuggestname, adj_font(12)),
pedit = create_edit(NULL, pwindow->dst, create_utf8_from_char(pSuggestname, adj_font(12)),
(ok_button->size.w + cancel_button->size.w + adj_size(15)), WF_RESTORE_BACKGROUND);
pEdit->action = newcity_name_edit_callback;
pedit->action = newcity_name_edit_callback;
area.w = MAX(area.w, pEdit->size.w + adj_size(20));
area.h += pEdit->size.h + adj_size(25);
area.w = MAX(area.w, pedit->size.w + adj_size(20));
area.h += pedit->size.h + adj_size(25);
/* I make this hack to center label on window */
if (pLabel->size.w < area.w) {
......
area.w = MAX(pwindow->area.w, pLabel->size.w + adj_size(10));
}
pEdit->size.w = area.w - adj_size(20);
pedit->size.w = area.w - adj_size(20);
/* create window background */
background = theme_get_background(theme, BACKGROUND_NEWCITYDLG);
......
cancel_button->size.y = ok_button->size.y;
cancel_button->size.x = area.x + area.w - cancel_button->size.w - adj_size(10);
pEdit->size.x = area.x + adj_size(10);
pEdit->size.y = area.y + adj_size(4) + pLabel->size.h + adj_size(3);
pedit->size.x = area.x + adj_size(10);
pedit->size.y = area.y + adj_size(4) + pLabel->size.h + adj_size(3);
pLabel->size.x = area.x + adj_size(3);
pLabel->size.y = area.y + adj_size(4);
......
/* enable widgets */
set_wstate(cancel_button, FC_WS_NORMAL);
set_wstate(ok_button, FC_WS_NORMAL);
set_wstate(pEdit, FC_WS_NORMAL);
set_wstate(pedit, FC_WS_NORMAL);
set_wstate(pwindow, FC_WS_NORMAL);
/* add widgets to main list */
......
add_to_gui_list(ID_NEWCITY_NAME_LABEL, pLabel);
add_to_gui_list(ID_NEWCITY_NAME_CANCEL_BUTTON, cancel_button);
add_to_gui_list(ID_NEWCITY_NAME_OK_BUTTON, ok_button);
add_to_gui_list(ID_NEWCITY_NAME_EDIT, pEdit);
pNewCity_Dlg->begin_widget_list = pEdit;
add_to_gui_list(ID_NEWCITY_NAME_EDIT, pedit);
pNewCity_Dlg->begin_widget_list = pedit;
/* redraw */
redraw_group(pEdit, pwindow, 0);
redraw_group(pedit, pwindow, 0);
widget_flush(pwindow);
}
client/gui-sdl2/widget.c
{
if (PRESSED_EVENT(main_data.event)) {
bool ret, loop = (get_wflags(pwidget) & WF_EDIT_LOOP);
enum Edit_Return_Codes change;
enum edit_return_codes change;
do {
ret = FALSE;
client/gui-sdl2/widget_edit.c
SDL_Surface *pTsurf;
};
struct EDIT {
struct text_edit {
struct Utf8Char *pBeginTextChain;
struct Utf8Char *pEndTextChain;
struct Utf8Char *pInputChain;
......
/**********************************************************************//**
Draw the text being edited.
**************************************************************************/
static int redraw_edit_chain(struct EDIT *pEdt)
static int redraw_edit_chain(struct text_edit *edt)
{
struct Utf8Char *pInputChain_TMP;
SDL_Rect Dest, Dest_Copy = {0, 0, 0, 0};
int iStart_Mod_X;
int ret;
Dest_Copy.x = pEdt->pwidget->size.x;
Dest_Copy.y = pEdt->pwidget->size.y;
Dest_Copy.x = edt->pwidget->size.x;
Dest_Copy.y = edt->pwidget->size.y;
ret = (*baseclass_redraw)(pEdt->pwidget);
ret = (*baseclass_redraw)(edt->pwidget);
if (ret != 0) {
return ret;
}
......
/* blit theme */
Dest = Dest_Copy;
alphablit(pEdt->pBg, NULL, pEdt->pwidget->dst->surface, &Dest, 255);
alphablit(edt->pBg, NULL, edt->pwidget->dst->surface, &Dest, 255);
/* set start parameters */
pInputChain_TMP = pEdt->pBeginTextChain;
pInputChain_TMP = edt->pBeginTextChain;
iStart_Mod_X = 0;
Dest_Copy.y += (pEdt->pBg->h - pInputChain_TMP->pTsurf->h) / 2;
Dest_Copy.x += pEdt->Start_X;
Dest_Copy.y += (edt->pBg->h - pInputChain_TMP->pTsurf->h) / 2;
Dest_Copy.x += edt->Start_X;
/* draw loop */
while (pInputChain_TMP) {
Dest_Copy.x += iStart_Mod_X;
/* chech if we draw inside of edit rect */
if (Dest_Copy.x > pEdt->pwidget->size.x + pEdt->pBg->w - 4) {
if (Dest_Copy.x > edt->pwidget->size.x + edt->pBg->w - 4) {
break;
}
if (Dest_Copy.x > pEdt->pwidget->size.x) {
if (Dest_Copy.x > edt->pwidget->size.x) {
Dest = Dest_Copy;
alphablit(pInputChain_TMP->pTsurf, NULL, pEdt->pwidget->dst->surface, &Dest,
alphablit(pInputChain_TMP->pTsurf, NULL, edt->pwidget->dst->surface, &Dest,
255);
}
iStart_Mod_X = pInputChain_TMP->pTsurf->w;
/* draw cursor */
if (pInputChain_TMP == pEdt->pInputChain) {
if (pInputChain_TMP == edt->pInputChain) {
Dest = Dest_Copy;
create_line(pEdt->pwidget->dst->surface,
Dest.x - 1, Dest.y + (pEdt->pBg->h / 8),
Dest.x - 1, Dest.y + pEdt->pBg->h - (pEdt->pBg->h / 4),
create_line(edt->pwidget->dst->surface,
Dest.x - 1, Dest.y + (edt->pBg->h / 8),
Dest.x - 1, Dest.y + edt->pBg->h - (edt->pBg->h / 4),
get_theme_color(COLOR_THEME_EDITFIELD_CARET));
/* save active element position */
pEdt->InputChain_X = Dest_Copy.x;
edt->InputChain_X = Dest_Copy.x;
}
pInputChain_TMP = pInputChain_TMP->next;
} /* while - draw loop */
widget_flush(pEdt->pwidget);
widget_flush(edt->pwidget);
return 0;
}
/**********************************************************************//**
Create Edit Field surface ( with Text) and blit them to Main.screen,
on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'
on position 'edit_widget->size.x , edit_widget->size.y'
Graphic is taken from 'pEdit_Widget->theme'
Text is taken from 'pEdit_Widget->string_utf8'
Graphic is taken from 'edit_widget->theme'
Text is taken from 'edit_widget->string_utf8'
if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
transparent ( Alpha = 128 )
......
function return Hight of created surfaces or (-1) if theme surface can't
be created.
**************************************************************************/
static int redraw_edit(struct widget *pEdit_Widget)
static int redraw_edit(struct widget *edit_widget)
{
int ret;
if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) {
return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr);
if (get_wstate(edit_widget) == FC_WS_PRESSED) {
return redraw_edit_chain((struct text_edit *)edit_widget->data.ptr);
} else {
int iRet = 0;
SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0};
SDL_Surface *pEdit = NULL;
SDL_Rect rDest = {edit_widget->size.x, edit_widget->size.y, 0, 0};
SDL_Surface *pedit = NULL;
SDL_Surface *pText;
ret = (*baseclass_redraw)(pEdit_Widget);
ret = (*baseclass_redraw)(edit_widget);
if (ret != 0) {
return ret;
}
if (pEdit_Widget->string_utf8->text != NULL
&& get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) {
char *backup = pEdit_Widget->string_utf8->text;
if (edit_widget->string_utf8->text != NULL
&& get_wflags(edit_widget) & WF_PASSWD_EDIT) {
char *backup = edit_widget->string_utf8->text;
size_t len = strlen(backup) + 1;
char *cbuf = fc_calloc(1, len);
memset(cbuf, '*', len - 1);
cbuf[len - 1] = '\0';
pEdit_Widget->string_utf8->text = cbuf;
pText = create_text_surf_from_utf8(pEdit_Widget->string_utf8);
edit_widget->string_utf8->text = cbuf;
pText = create_text_surf_from_utf8(edit_widget->string_utf8);
FC_FREE(cbuf);
pEdit_Widget->string_utf8->text = backup;
edit_widget->string_utf8->text = backup;
} else {
pText = create_text_surf_from_utf8(pEdit_Widget->string_utf8);
pText = create_text_surf_from_utf8(edit_widget->string_utf8);
}
pEdit = create_bcgnd_surf(pEdit_Widget->theme, get_wstate(pEdit_Widget),
pEdit_Widget->size.w, pEdit_Widget->size.h);
pedit = create_bcgnd_surf(edit_widget->theme, get_wstate(edit_widget),
edit_widget->size.w, edit_widget->size.h);
if (!pEdit) {
if (!pedit) {
return -1;
}
/* blit theme */
alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest, 255);
alphablit(pedit, NULL, edit_widget->dst->surface, &rDest, 255);
/* set position and blit text */
if (pText) {
rDest.y += (pEdit->h - pText->h) / 2;
rDest.y += (pedit->h - pText->h) / 2;
/* blit centred text to botton */
if (pEdit_Widget->string_utf8->style & SF_CENTER) {
rDest.x += (pEdit->w - pText->w) / 2;
if (edit_widget->string_utf8->style & SF_CENTER) {
rDest.x += (pedit->w - pText->w) / 2;
} else {
if (pEdit_Widget->string_utf8->style & SF_CENTER_RIGHT) {
rDest.x += pEdit->w - pText->w - adj_size(5);
if (edit_widget->string_utf8->style & SF_CENTER_RIGHT) {
rDest.x += pedit->w - pText->w - adj_size(5);
} else {
rDest.x += adj_size(5); /* center left */
}
}
alphablit(pText, NULL, pEdit_Widget->dst->surface, &rDest, 255);
alphablit(pText, NULL, edit_widget->dst->surface, &rDest, 255);
}
/* pText */
iRet = pEdit->h;
iRet = pedit->h;
/* Free memory */
FREESURFACE(pText);
FREESURFACE(pEdit);
FREESURFACE(pedit);
return iRet;
}
......
utf8_str *pstr, int length, Uint32 flags)
{
SDL_Rect buf = {0, 0, 0, 0};
struct widget *pEdit = widget_new();
struct widget *pedit = widget_new();
pEdit->theme = current_theme->Edit;
pEdit->theme2 = background; /* FIXME: make somewhere use of it */
pEdit->string_utf8 = pstr;
set_wflag(pEdit, (WF_FREE_STRING | WF_FREE_GFX | flags));
set_wstate(pEdit, FC_WS_DISABLED);
set_wtype(pEdit, WT_EDIT);
pEdit->mod = KMOD_NONE;
pedit->theme = current_theme->Edit;
pedit->theme2 = background; /* FIXME: make somewhere use of it */
pedit->string_utf8 = pstr;
set_wflag(pedit, (WF_FREE_STRING | WF_FREE_GFX | flags));
set_wstate(pedit, FC_WS_DISABLED);
set_wtype(pedit, WT_EDIT);
pedit->mod = KMOD_NONE;
baseclass_redraw = pEdit->redraw;
pEdit->redraw = redraw_edit;
baseclass_redraw = pedit->redraw;
pedit->redraw = redraw_edit;
if (pstr != NULL) {
pEdit->string_utf8->style |= SF_CENTER;
pedit->string_utf8->style |= SF_CENTER;
utf8_str_size(pstr, &buf);
buf.h += adj_size(4);
}
......
correct_size_bcgnd_surf(current_theme->Edit, &length, &buf.h);
pEdit->size.w = length;
pEdit->size.h = buf.h;
pedit->size.w = length;
pedit->size.h = buf.h;
if (pdest) {
pEdit->dst = pdest;
pedit->dst = pdest;
} else {
pEdit->dst = add_gui_layer(pEdit->size.w, pEdit->size.h);
pedit->dst = add_gui_layer(pedit->size.w, pedit->size.h);
}
return pEdit;
return pedit;
}
/**********************************************************************//**
set new x, y position and redraw edit.
**************************************************************************/
int draw_edit(struct widget *pEdit, Sint16 start_x, Sint16 start_y)
int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
{
pEdit->size.x = start_x;
pEdit->size.y = start_y;
pedit->size.x = start_x;
pedit->size.y = start_y;
if (get_wflags(pEdit) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(pEdit);
if (get_wflags(pedit) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(pedit);
}
return redraw_edit(pEdit);
return redraw_edit(pedit);
}
/**********************************************************************//**
This functions are pure madness :)
Create Edit Field surface ( with Text) and blit them to Main.screen,
on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'
on position 'edit_widget->size.x , edit_widget->size.y'
Main role of this functions are been text input to GUI.
This code allow you to add, del unichar from unistring.
Graphic is taken from 'pEdit_Widget->theme'
OldText is taken from 'pEdit_Widget->string_utf8'
Graphic is taken from 'edit_widget->theme'
OldText is taken from 'edit_widget->string_utf8'
NewText is returned to 'pEdit_Widget->string_utf8' ( after free OldText )
NewText is returned to 'edit_widget->string_utf8' ( after free OldText )
if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
transparent ( Alpha = 128 )
NOTE: This functions can return NULL in 'pEdit_Widget->string_utf8->text' but
never free 'pEdit_Widget->string_utf8' struct.
NOTE: This functions can return NULL in 'edit_widget->string_utf8->text' but
never free 'edit_widget->string_utf8' struct.
**************************************************************************/
static Uint16 edit_key_down(SDL_Keysym key, void *pData)
{
struct EDIT *pEdt = (struct EDIT *)pData;
struct text_edit *edt = (struct text_edit *)pData;
struct Utf8Char *pInputChain_TMP;
bool Redraw = FALSE;
......
case SDLK_RIGHT:
{
/* move cursor right */
if (pEdt->pInputChain->next) {
if (pEdt->InputChain_X >= (pEdt->pwidget->size.x + pEdt->pBg->w - adj_size(10))) {
pEdt->Start_X -= pEdt->pInputChain->pTsurf->w -
(pEdt->pwidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X);
if (edt->pInputChain->next) {
if (edt->InputChain_X >= (edt->pwidget->size.x + edt->pBg->w - adj_size(10))) {
edt->Start_X -= edt->pInputChain->pTsurf->w -
(edt->pwidget->size.x + edt->pBg->w - adj_size(5) - edt->InputChain_X);
}
pEdt->pInputChain = pEdt->pInputChain->next;
edt->pInputChain = edt->pInputChain->next;
Redraw = TRUE;
}
}
......
case SDLK_LEFT:
{
/* move cursor left */
if (pEdt->pInputChain->prev) {
pEdt->pInputChain = pEdt->pInputChain->prev;
if ((pEdt->InputChain_X <=
(pEdt->pwidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) {
if (pEdt->InputChain_X != (pEdt->pwidget->size.x + adj_size(5))) {
pEdt->Start_X += (pEdt->pwidget->size.x - pEdt->InputChain_X + adj_size(5));
if (edt->pInputChain->prev) {
edt->pInputChain = edt->pInputChain->prev;
if ((edt->InputChain_X <=
(edt->pwidget->size.x + adj_size(9))) && (edt->Start_X != adj_size(5))) {
if (edt->InputChain_X != (edt->pwidget->size.x + adj_size(5))) {
edt->Start_X += (edt->pwidget->size.x - edt->InputChain_X + adj_size(5));
}
pEdt->Start_X += (pEdt->pInputChain->pTsurf->w);
edt->Start_X += (edt->pInputChain->pTsurf->w);
}
Redraw = TRUE;
}
......
case SDLK_HOME:
{
/* move cursor to begin of chain (and edit field) */
pEdt->pInputChain = pEdt->pBeginTextChain;
edt->pInputChain = edt->pBeginTextChain;
Redraw = TRUE;
pEdt->Start_X = adj_size(5);
edt->Start_X = adj_size(5);
}
break;
/*
......
case SDLK_END:
{
/* move cursor to end of chain (and edit field) */
pEdt->pInputChain = pEdt->pEndTextChain;
edt->pInputChain = edt->pEndTextChain;
Redraw = TRUE;
if (pEdt->pwidget->size.w - pEdt->Truelength < 0) {
pEdt->Start_X = pEdt->pwidget->size.w - pEdt->Truelength - adj_size(5);
if (edt->pwidget->size.w - edt->Truelength < 0) {
edt->Start_X = edt->pwidget->size.w - edt->Truelength - adj_size(5);
}
}
break;
case SDLK_BACKSPACE:
{
/* del element of chain (and move cursor left) */
if (pEdt->pInputChain->prev) {
if ((pEdt->InputChain_X <=
(pEdt->pwidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) {
if (pEdt->InputChain_X != (pEdt->pwidget->size.x + adj_size(5))) {
pEdt->Start_X += (pEdt->pwidget->size.x - pEdt->InputChain_X + adj_size(5));
if (edt->pInputChain->prev) {
if ((edt->InputChain_X <=
(edt->pwidget->size.x + adj_size(9))) && (edt->Start_X != adj_size(5))) {
if (edt->InputChain_X != (edt->pwidget->size.x + adj_size(5))) {
edt->Start_X += (edt->pwidget->size.x - edt->InputChain_X + adj_size(5));
}
pEdt->Start_X += (pEdt->pInputChain->prev->pTsurf->w);
edt->Start_X += (edt->pInputChain->prev->pTsurf->w);
}
if (pEdt->pInputChain->prev->prev) {
pEdt->pInputChain->prev->prev->next = pEdt->pInputChain;
pInputChain_TMP = pEdt->pInputChain->prev->prev;
pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
FREESURFACE(pEdt->pInputChain->prev->pTsurf);
FC_FREE(pEdt->pInputChain->prev);
pEdt->pInputChain->prev = pInputChain_TMP;
if (edt->pInputChain->prev->prev) {
edt->pInputChain->prev->prev->next = edt->pInputChain;
pInputChain_TMP = edt->pInputChain->prev->prev;
edt->Truelength -= edt->pInputChain->prev->pTsurf->w;
FREESURFACE(edt->pInputChain->prev->pTsurf);
FC_FREE(edt->pInputChain->prev);
edt->pInputChain->prev = pInputChain_TMP;
} else {
pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
FREESURFACE(pEdt->pInputChain->prev->pTsurf);
FC_FREE(pEdt->pInputChain->prev);
pEdt->pBeginTextChain = pEdt->pInputChain;
edt->Truelength -= edt->pInputChain->prev->pTsurf->w;
FREESURFACE(edt->pInputChain->prev->pTsurf);
FC_FREE(edt->pInputChain->prev);
edt->pBeginTextChain = edt->pInputChain;
}
pEdt->ChainLen--;
edt->ChainLen--;
Redraw = TRUE;
}
}
......
case SDLK_DELETE:
{
/* del element of chain */
if (pEdt->pInputChain->next && pEdt->pInputChain->prev) {
pEdt->pInputChain->prev->next = pEdt->pInputChain->next;
pEdt->pInputChain->next->prev = pEdt->pInputChain->prev;
pInputChain_TMP = pEdt->pInputChain->next;
pEdt->Truelength -= pEdt->pInputChain->pTsurf->w;
FREESURFACE(pEdt->pInputChain->pTsurf);
FC_FREE(pEdt->pInputChain);
pEdt->pInputChain = pInputChain_TMP;
pEdt->ChainLen--;
if (edt->pInputChain->next && edt->pInputChain->prev) {
edt->pInputChain->prev->next = edt->pInputChain->next;
edt->pInputChain->next->prev = edt->pInputChain->prev;
pInputChain_TMP = edt->pInputChain->next;
edt->Truelength -= edt->pInputChain->pTsurf->w;
FREESURFACE(edt->pInputChain->pTsurf);
FC_FREE(edt->pInputChain);
edt->pInputChain = pInputChain_TMP;
edt->ChainLen--;
Redraw = TRUE;
}
if (pEdt->pInputChain->next && !pEdt->pInputChain->prev) {
pEdt->pInputChain = pEdt->pInputChain->next;
pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
FREESURFACE(pEdt->pInputChain->prev->pTsurf);
FC_FREE(pEdt->pInputChain->prev);
pEdt->pBeginTextChain = pEdt->pInputChain;
pEdt->ChainLen--;
if (edt->pInputChain->next && !edt->pInputChain->prev) {
edt->pInputChain = edt->pInputChain->next;
edt->Truelength -= edt->pInputChain->prev->pTsurf->w;
FREESURFACE(edt->pInputChain->prev->pTsurf);
FC_FREE(edt->pInputChain->prev);
edt->pBeginTextChain = edt->pInputChain;
edt->ChainLen--;
Redraw = TRUE;
}
}
......
} /* key pressed switch */
if (Redraw) {
redraw_edit_chain(pEdt);
redraw_edit_chain(edt);
}
return ID_ERROR;
......
**************************************************************************/
static Uint16 edit_textinput(char *text, void *pData)
{
struct EDIT *pEdt = (struct EDIT *)pData;
struct text_edit *edt = (struct text_edit *)pData;
struct Utf8Char *pInputChain_TMP;
int i;
......
int addition = 32;
/* add new element of chain (and move cursor right) */
if (pEdt->pInputChain != pEdt->pBeginTextChain) {
pInputChain_TMP = pEdt->pInputChain->prev;
pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct Utf8Char));
pEdt->pInputChain->prev->next = pEdt->pInputChain;
pEdt->pInputChain->prev->prev = pInputChain_TMP;
pInputChain_TMP->next = pEdt->pInputChain->prev;
if (edt->pInputChain != edt->pBeginTextChain) {
pInputChain_TMP = edt->pInputChain->prev;
edt->pInputChain->prev = fc_calloc(1, sizeof(struct Utf8Char));
edt->pInputChain->prev->next = edt->pInputChain;
edt->pInputChain->prev->prev = pInputChain_TMP;
pInputChain_TMP->next = edt->pInputChain->prev;
} else {
pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct Utf8Char));
pEdt->pInputChain->prev->next = pEdt->pInputChain;
pEdt->pBeginTextChain = pEdt->pInputChain->prev;
edt->pInputChain->prev = fc_calloc(1, sizeof(struct Utf8Char));
edt->pInputChain->prev->next = edt->pInputChain;
edt->pBeginTextChain = edt->pInputChain->prev;
}
pEdt->pInputChain->prev->chr[0] = leading;
edt->pInputChain->prev->chr[0] = leading;
/* UTF-8 multibyte handling */
while (leading >= sum) {
pEdt->pInputChain->prev->chr[charlen++] = text[i++];
edt->pInputChain->prev->chr[charlen++] = text[i++];
sum += addition;
addition /= 2;
}
pEdt->pInputChain->prev->chr[charlen] = '\0';
pEdt->pInputChain->prev->bytes = charlen;
edt->pInputChain->prev->chr[charlen] = '\0';
edt->pInputChain->prev->bytes = charlen;
if (get_wflags(pEdt->pwidget) & WF_PASSWD_EDIT) {
if (get_wflags(edt->pwidget) & WF_PASSWD_EDIT) {
char passwd_chr[2] = {'*', '\0'};
pEdt->pInputChain->prev->pTsurf =
TTF_RenderUTF8_Blended(pEdt->pwidget->string_utf8->font,
edt->pInputChain->prev->pTsurf =
TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
passwd_chr,
pEdt->pwidget->string_utf8->fgcol);
edt->pwidget->string_utf8->fgcol);
} else {
pEdt->pInputChain->prev->pTsurf =
TTF_RenderUTF8_Blended(pEdt->pwidget->string_utf8->font,
pEdt->pInputChain->prev->chr,
pEdt->pwidget->string_utf8->fgcol);
edt->pInputChain->prev->pTsurf =
TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
edt->pInputChain->prev->chr,
edt->pwidget->string_utf8->fgcol);
}
pEdt->Truelength += pEdt->pInputChain->prev->pTsurf->w;
edt->Truelength += edt->pInputChain->prev->pTsurf->w;
if (pEdt->InputChain_X >= pEdt->pwidget->size.x + pEdt->pBg->w - adj_size(10)) {
if (pEdt->pInputChain == pEdt->pEndTextChain) {
pEdt->Start_X = pEdt->pBg->w - adj_size(5) - pEdt->Truelength;
if (edt->InputChain_X >= edt->pwidget->size.x + edt->pBg->w - adj_size(10)) {
if (edt->pInputChain == edt->pEndTextChain) {
edt->Start_X = edt->pBg->w - adj_size(5) - edt->Truelength;
} else {
pEdt->Start_X -= pEdt->pInputChain->prev->pTsurf->w -
(pEdt->pwidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X);
edt->Start_X -= edt->pInputChain->prev->pTsurf->w -
(edt->pwidget->size.x + edt->pBg->w - adj_size(5) - edt->InputChain_X);
}
}
pEdt->ChainLen++;
edt->ChainLen++;
}
redraw_edit_chain(pEdt);
redraw_edit_chain(edt);
return ID_ERROR;
}
......
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
void *pData)
{
struct EDIT *pEdt = (struct EDIT *)pData;
struct text_edit *edt = (struct text_edit *)pData;
if (button_event->button == SDL_BUTTON_LEFT) {
if (!(button_event->x >= pEdt->pwidget->size.x
&& button_event->x < pEdt->pwidget->size.x + pEdt->pBg->w
&& button_event->y >= pEdt->pwidget->size.y
&& button_event->y < pEdt->pwidget->size.y + pEdt->pBg->h)) {
if (!(button_event->x >= edt->pwidget->size.x
&& button_event->x < edt->pwidget->size.x + edt->pBg->w
&& button_event->y >= edt->pwidget->size.y
&& button_event->y < edt->pwidget->size.y + edt->pBg->h)) {
/* exit from loop */
return (Uint16)ED_MOUSE;
}
......
Handle active edit. Returns what should happen to the edit
next.
**************************************************************************/
enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget)
enum edit_return_codes edit_field(struct widget *edit_widget)
{
struct EDIT pEdt;
struct text_edit edt;
struct Utf8Char ___last;
struct Utf8Char *pInputChain_TMP = NULL;
enum Edit_Return_Codes ret;
void *backup = pEdit_Widget->data.ptr;
enum edit_return_codes ret;
void *backup = edit_widget->data.ptr;
pEdt.pwidget = pEdit_Widget;
pEdt.ChainLen = 0;
pEdt.Truelength = 0;
pEdt.Start_X = adj_size(5);
pEdt.InputChain_X = 0;
edt.pwidget = edit_widget;
edt.ChainLen = 0;
edt.Truelength = 0;
edt.Start_X = adj_size(5);
edt.InputChain_X = 0;
pEdit_Widget->data.ptr = (void *)&pEdt;
edit_widget->data.ptr = (void *)&edt;
#if 0
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#endif /* 0 */
pEdt.pBg = create_bcgnd_surf(pEdit_Widget->theme, 2,
pEdit_Widget->size.w, pEdit_Widget->size.h);
edt.pBg = create_bcgnd_surf(edit_widget->theme, 2,
edit_widget->size.w, edit_widget->size.h);
/* Creating Chain */
pEdt.pBeginTextChain = text2chain(pEdit_Widget->string_utf8->text);
edt.pBeginTextChain = text2chain(edit_widget->string_utf8->text);
/* Creating Empty (Last) pice of Chain */
pEdt.pInputChain = &___last;
pEdt.pEndTextChain = pEdt.pInputChain;
pEdt.pEndTextChain->chr[0] = 32; /* spacebar */
pEdt.pEndTextChain->chr[1] = 0; /* spacebar */
pEdt.pEndTextChain->next = NULL;
pEdt.pEndTextChain->prev = NULL;
edt.pInputChain = &___last;
edt.pEndTextChain = edt.pInputChain;
edt.pEndTextChain->chr[0] = 32; /* spacebar */
edt.pEndTextChain->chr[1] = 0; /* spacebar */
edt.pEndTextChain->next = NULL;
edt.pEndTextChain->prev = NULL;
/* set font style (if any ) */
if (!((pEdit_Widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(pEdit_Widget->string_utf8->font,
(pEdit_Widget->string_utf8->style & 0x0F));
if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(edit_widget->string_utf8->font,
(edit_widget->string_utf8->style & 0x0F));
}
pEdt.pEndTextChain->pTsurf =
TTF_RenderUTF8_Blended(pEdit_Widget->string_utf8->font,
pEdt.pEndTextChain->chr,
pEdit_Widget->string_utf8->fgcol);
edt.pEndTextChain->pTsurf =
TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
edt.pEndTextChain->chr,
edit_widget->string_utf8->fgcol);
/* create surface for each font in chain and find chain length */
if (pEdt.pBeginTextChain) {
pInputChain_TMP = pEdt.pBeginTextChain;
if (edt.pBeginTextChain) {
pInputChain_TMP = edt.pBeginTextChain;
while (TRUE) {
pEdt.ChainLen++;
edt.ChainLen++;
if (get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) {
if (get_wflags(edit_widget) & WF_PASSWD_EDIT) {
const char passwd_chr[2] = {'*', '\0'};
pInputChain_TMP->pTsurf =
TTF_RenderUTF8_Blended(pEdit_Widget->string_utf8->font,
TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
passwd_chr,
pEdit_Widget->string_utf8->fgcol);
edit_widget->string_utf8->fgcol);
} else {
pInputChain_TMP->pTsurf =
TTF_RenderUTF8_Blended(pEdit_Widget->string_utf8->font,
TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
pInputChain_TMP->chr,
pEdit_Widget->string_utf8->fgcol);
edit_widget->string_utf8->fgcol);
}
pEdt.Truelength += pInputChain_TMP->pTsurf->w;
edt.Truelength += pInputChain_TMP->pTsurf->w;
if (pInputChain_TMP->next == NULL) {
break;
......
pInputChain_TMP = pInputChain_TMP->next;
}
/* set terminator of list */
pInputChain_TMP->next = pEdt.pInputChain;
pEdt.pInputChain->prev = pInputChain_TMP;
pInputChain_TMP->next = edt.pInputChain;
edt.pInputChain->prev = pInputChain_TMP;
pInputChain_TMP = NULL;
} else {
pEdt.pBeginTextChain = pEdt.pInputChain;
edt.pBeginTextChain = edt.pInputChain;
}
redraw_edit_chain(&pEdt);
redraw_edit_chain(&edt);
set_wstate(pEdit_Widget, FC_WS_PRESSED);
set_wstate(edit_widget, FC_WS_PRESSED);
{
/* local loop */
Uint16 rety = gui_event_loop((void *)&pEdt, NULL,
Uint16 rety = gui_event_loop((void *)&edt, NULL,
edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
edit_mouse_button_down, NULL, NULL);
if (pEdt.pBeginTextChain == pEdt.pEndTextChain) {
pEdt.pBeginTextChain = NULL;
if (edt.pBeginTextChain == edt.pEndTextChain) {
edt.pBeginTextChain = NULL;
}
if (rety == MAX_ID) {
ret = ED_FORCE_EXIT;
} else {
ret = (enum Edit_Return_Codes) rety;
ret = (enum edit_return_codes) rety;
/* this is here because we have no knowledge that pEdit_Widget exist
/* this is here because we have no knowledge that edit_widget exist
or nor in force exit mode from gui loop */
/* reset font settings */
if (!((pEdit_Widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(pEdit_Widget->string_utf8->font, TTF_STYLE_NORMAL);
if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(edit_widget->string_utf8->font, TTF_STYLE_NORMAL);
}
if (ret != ED_ESC) {
size_t len = 0;
FC_FREE(pEdit_Widget->string_utf8->text);
pEdit_Widget->string_utf8->text =
chain2text(pEdt.pBeginTextChain, pEdt.ChainLen, &len);
pEdit_Widget->string_utf8->n_alloc = len + 1;
FC_FREE(edit_widget->string_utf8->text);
edit_widget->string_utf8->text =
chain2text(edt.pBeginTextChain, edt.ChainLen, &len);
edit_widget->string_utf8->n_alloc = len + 1;
}
pEdit_Widget->data.ptr = backup;
set_wstate(pEdit_Widget, FC_WS_NORMAL);
edit_widget->data.ptr = backup;
set_wstate(edit_widget, FC_WS_NORMAL);
}
}
FREESURFACE(pEdt.pEndTextChain->pTsurf);
FREESURFACE(edt.pEndTextChain->pTsurf);
del_chain(pEdt.pBeginTextChain);
del_chain(edt.pBeginTextChain);
FREESURFACE(pEdt.pBg);
FREESURFACE(edt.pBg);
/* disable repeat key */
client/gui-sdl2/widget_edit.h
#ifndef FC__WIDGET_EDIT_H
#define FC__WIDGET_EDIT_H
enum Edit_Return_Codes {
enum edit_return_codes {
ED_RETURN = 1,
ED_ESC = 2,
ED_MOUSE = 3,
......
create_utf8_from_char(pCharString, iPtsize), \
length, flags)
#define edit(pEdit) edit_field(pEdit)
#define edit(pedit) edit_field(pedit)
struct widget *create_edit(SDL_Surface *background, struct gui_layer *pdest,
utf8_str *pstr, int length,
Uint32 flags);
enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget);
int draw_edit(struct widget *pEdit, Sint16 start_x, Sint16 start_y);
enum edit_return_codes edit_field(struct widget *edit_widget);
int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y);
#endif /* FC__WIDGET_EDIT_H */
client/gui-sdl2/wldlg.c
#define TARGETS_COL 4
#define TARGETS_ROW 4
struct EDITOR {
struct wl_editor {
struct widget *begin_widget_list;
struct widget *end_widget_list; /* window */
......
int stock;
struct universal currently_building;
} *pEditor = NULL;
} *editor = NULL;
static int worklist_editor_item_callback(struct widget *pwidget);
......
{
if (PRESSED_EVENT(main_data.event)) {
int i, j;
struct city *pcity = pEditor->pcity;
struct city *pcity = editor->pcity;
/* remove duplicate entry of impv./wonder target from worklist */
for (i = 0; i < worklist_length(&pEditor->worklist_copy); i++) {
if (VUT_IMPROVEMENT == pEditor->worklist_copy.entries[i].kind) {
for (j = i + 1; j < worklist_length(&pEditor->worklist_copy); j++) {
if (VUT_IMPROVEMENT == pEditor->worklist_copy.entries[j].kind
&& pEditor->worklist_copy.entries[i].value.building ==
pEditor->worklist_copy.entries[j].value.building) {
worklist_remove(&pEditor->worklist_copy, j);
for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
if (VUT_IMPROVEMENT == editor->worklist_copy.entries[i].kind) {
for (j = i + 1; j < worklist_length(&editor->worklist_copy); j++) {
if (VUT_IMPROVEMENT == editor->worklist_copy.entries[j].kind
&& editor->worklist_copy.entries[i].value.building ==
editor->worklist_copy.entries[j].value.building) {
worklist_remove(&editor->worklist_copy, j);
}
}
}
......
if (pcity) {
/* remove duplicate entry of currently building impv./wonder from worklist */
if (VUT_IMPROVEMENT == pEditor->currently_building.kind) {
for (i = 0; i < worklist_length(&pEditor->worklist_copy); i++) {
if (VUT_IMPROVEMENT == pEditor->worklist_copy.entries[i].kind
&& pEditor->worklist_copy.entries[i].value.building ==
pEditor->currently_building.value.building) {
worklist_remove(&pEditor->worklist_copy, i);
if (VUT_IMPROVEMENT == editor->currently_building.kind) {
for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
if (VUT_IMPROVEMENT == editor->worklist_copy.entries[i].kind
&& editor->worklist_copy.entries[i].value.building ==
editor->currently_building.value.building) {
worklist_remove(&editor->worklist_copy, i);
}
}
}
/* change production */
if (!are_universals_equal(&pcity->production, &pEditor->currently_building)) {
city_change_production(pcity, &pEditor->currently_building);
if (!are_universals_equal(&pcity->production, &editor->currently_building)) {
city_change_production(pcity, &editor->currently_building);
}
/* commit new city worklist */
city_set_worklist(pcity, &pEditor->worklist_copy);
city_set_worklist(pcity, &editor->worklist_copy);
} else {
/* commit global worklist */
struct global_worklist *pGWL = global_worklist_by_id(pEditor->global_worklist_id);
struct global_worklist *pGWL = global_worklist_by_id(editor->global_worklist_id);
if (pGWL) {
global_worklist_set(pGWL, &pEditor->worklist_copy);
global_worklist_set_name(pGWL, pEditor->worklist_name);
global_worklist_set(pGWL, &editor->worklist_copy);
global_worklist_set_name(pGWL, editor->worklist_name);
update_worklist_report_dialog();
}
}
......
{
if (PRESSED_EVENT(main_data.event)) {
if (pwidget->string_utf8->text != NULL) {
fc_snprintf(pEditor->worklist_name, MAX_LEN_NAME, "%s",
fc_snprintf(editor->worklist_name, MAX_LEN_NAME, "%s",
pwidget->string_utf8->text);
} else {
/* empty input -> restore previous content */
copy_chars_to_utf8_str(pwidget->string_utf8, pEditor->worklist_name);
copy_chars_to_utf8_str(pwidget->string_utf8, editor->worklist_name);
widget_redraw(pwidget);
widget_mark_dirty(pwidget);
flush_dirty();
......
widget_flush(pTarget);
/* Deny adding currently building Impr/Wonder Target */
if (pEditor->pcity
if (editor->pcity
&& VUT_IMPROVEMENT == prod.kind
&& are_universals_equal(&prod, &pEditor->currently_building)) {
&& are_universals_equal(&prod, &editor->currently_building)) {
return;
}
if (worklist_length(&pEditor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
if (worklist_length(&editor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
return;
}
for (i = 0; i < worklist_length(&pEditor->worklist_copy); i++) {
for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
if (VUT_IMPROVEMENT == prod.kind
&& are_universals_equal(&prod, &pEditor->worklist_copy.entries[i])) {
&& are_universals_equal(&prod, &editor->worklist_copy.entries[i])) {
return;
}
}
worklist_append(&pEditor->worklist_copy, &prod);
worklist_append(&editor->worklist_copy, &prod);
/* create widget entry */
if (VUT_UTYPE == prod.kind) {
pstr = create_utf8_from_char(utype_name_translation(prod.value.utype), adj_font(10));
} else {
pstr = create_utf8_from_char(city_improvement_name_translation(pEditor->pcity,
pstr = create_utf8_from_char(city_improvement_name_translation(editor->pcity,
prod.value.building),
adj_font(10));
}
......
buf->action = worklist_editor_item_callback;
buf->data.ptr = fc_calloc(1, sizeof(int));
*((int *)buf->data.ptr) = worklist_length(&pEditor->worklist_copy) - 1;
*((int *)buf->data.ptr) = worklist_length(&editor->worklist_copy) - 1;
buf->ID = MAX_ID - cid_encode(prod);
if (pEditor->pWork->begin_active_widget_list) {
dock = pEditor->pWork->begin_active_widget_list;
if (editor->pWork->begin_active_widget_list) {
dock = editor->pWork->begin_active_widget_list;
} else {
dock = pEditor->dock;
dock = editor->dock;
}
/* FIXME */
#if 0
if (worklist_length(&pEditor->worklist_copy) > pEditor->pWork->scroll->active + 1) {
if (worklist_length(&editor->worklist_copy) > editor->pWork->scroll->active + 1) {
setup_vertical_widgets_position(1,
pEditor->end_widget_list->area.x + adj_size(2),
editor->end_widget_list->area.x + adj_size(2),
get_widget_pointer_form_main_list(ID_WINDOW)->area.y + adj_size(152) +
pEditor->pWork->scroll->up_left_button->size.h + 1,
adj_size(126), 0, pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list);
editor->pWork->scroll->up_left_button->size.h + 1,
adj_size(126), 0, editor->pWork->begin_widget_list,
editor->pWork->end_widget_list);
setup_vertical_scrollbar_area(pEditor->pWork->scroll,
pEditor->end_widget_list->area.x + adj_size(2),
setup_vertical_scrollbar_area(editor->pWork->scroll,
editor->end_widget_list->area.x + adj_size(2),
get_widget_pointer_form_main_list(ID_WINDOW)->area.y + adj_size(152),
adj_size(225), FALSE);
show_scrollbar(pEditor->pWork->scroll);
show_scrollbar(editor->pWork->scroll);
}
#endif /* 0 */
add_widget_to_vertical_scroll_widget_list(pEditor->pWork, buf,
add_widget_to_vertical_scroll_widget_list(editor->pWork, buf,
dock, FALSE,
pEditor->end_widget_list->area.x + adj_size(2),
pEditor->end_widget_list->area.y + adj_size(152));
editor->end_widget_list->area.x + adj_size(2),
editor->end_widget_list->area.y + adj_size(152));
buf->size.w = adj_size(126);
refresh_worklist_count_label();
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
......
**************************************************************************/
static void change_production(struct universal *prod)
{
if (!are_prods_same_class(&pEditor->currently_building, prod)) {
if (pEditor->stock != pEditor->pcity->shield_stock) {
if (are_prods_same_class(&pEditor->pcity->production, prod)) {
pEditor->stock = pEditor->pcity->shield_stock;
if (!are_prods_same_class(&editor->currently_building, prod)) {
if (editor->stock != editor->pcity->shield_stock) {
if (are_prods_same_class(&editor->pcity->production, prod)) {
editor->stock = editor->pcity->shield_stock;
}
} else {
pEditor->stock =
city_change_production_penalty(pEditor->pcity, prod);
editor->stock =
city_change_production_penalty(editor->pcity, prod);
}
}
pEditor->currently_building = *prod;
refresh_production_label(pEditor->stock);
editor->currently_building = *prod;
refresh_production_label(editor->stock);
}
/**********************************************************************//**
......
prod = cid_decode(MAX_ID - pTarget->ID);
/* check if we change to the same target */
if (are_universals_equal(&prod, &pEditor->currently_building)) {
if (are_universals_equal(&prod, &editor->currently_building)) {
/* comit changes and exit - double click detection */
ok_worklist_editor_callback(NULL);
return;
......
change_production(&prod);
/* change Production Text Label in Worklist Widget list */
copy_chars_to_utf8_str(pEditor->pWork->end_active_widget_list->string_utf8,
get_production_name(pEditor->pcity, prod, &dummy));
copy_chars_to_utf8_str(editor->pWork->end_active_widget_list->string_utf8,
get_production_name(editor->pcity, prod, &dummy));
pEditor->pWork->end_active_widget_list->ID = MAX_ID - cid_encode(prod);
editor->pWork->end_active_widget_list->ID = MAX_ID - cid_encode(prod);
widget_redraw(pEditor->pWork->end_active_widget_list);
widget_mark_dirty(pEditor->pWork->end_active_widget_list);
widget_redraw(editor->pWork->end_active_widget_list);
widget_mark_dirty(editor->pWork->end_active_widget_list);
flush_dirty();
}
......
if (main_data.event.type == SDL_MOUSEBUTTONDOWN) {
switch (main_data.event.button.button) {
case SDL_BUTTON_LEFT:
if (pEditor->pcity) {
if (editor->pcity) {
add_target_to_production(pwidget);
} else {
add_target_to_worklist(pwidget);
......
break;
}
} else if (PRESSED_EVENT(main_data.event)) {
if (pEditor->pcity) {
if (editor->pcity) {
add_target_to_production(pwidget);
} else {
add_target_to_worklist(pwidget);
......
static void remove_item_from_worklist(struct widget *pItem)
{
/* only one item (production) is left */
if (worklist_is_empty(&pEditor->worklist_copy)) {
if (worklist_is_empty(&editor->worklist_copy)) {
return;
}
......
/* correct "data" widget fiels */
struct widget *buf = pItem;
if (buf != pEditor->pWork->begin_active_widget_list) {
if (buf != editor->pWork->begin_active_widget_list) {
do {
buf = buf->prev;
*((int *)buf->data.ptr) = *((int *)buf->data.ptr) - 1;
} while (buf != pEditor->pWork->begin_active_widget_list);
} while (buf != editor->pWork->begin_active_widget_list);
}
/* remove element from worklist */
worklist_remove(&pEditor->worklist_copy, *((int *)pItem->data.ptr));
worklist_remove(&editor->worklist_copy, *((int *)pItem->data.ptr));
/* remove widget from widget list */
del_widget_from_vertical_scroll_widget_list(pEditor->pWork, pItem);
del_widget_from_vertical_scroll_widget_list(editor->pWork, pItem);
} else {
/* change productions to first worklist element */
struct widget *buf = pItem->prev;
change_production(&pEditor->worklist_copy.entries[0]);
worklist_advance(&pEditor->worklist_copy);
del_widget_from_vertical_scroll_widget_list(pEditor->pWork, pItem);
change_production(&editor->worklist_copy.entries[0]);
worklist_advance(&editor->worklist_copy);
del_widget_from_vertical_scroll_widget_list(editor->pWork, pItem);
FC_FREE(buf->data.ptr);
if (buf != pEditor->pWork->begin_active_widget_list) {
if (buf != editor->pWork->begin_active_widget_list) {
do {
buf = buf->prev;
*((int *)buf->data.ptr) = *((int *)buf->data.ptr) - 1;
} while (buf != pEditor->pWork->begin_active_widget_list);
} while (buf != editor->pWork->begin_active_widget_list);
}
}
/* FIXME: fix scrollbar code */
#if 0
/* worklist_length(&pEditor->worklist_copy): without production */
if (worklist_length(&pEditor->worklist_copy) <= pEditor->pWork->scroll->active + 1) {
/* worklist_length(&editor->worklist_copy): without production */
if (worklist_length(&editor->worklist_copy) <= editor->pWork->scroll->active + 1) {
setup_vertical_widgets_position(1,
pEditor->end_widget_list->area.x + adj_size(2),
editor->end_widget_list->area.x + adj_size(2),
get_widget_pointer_form_main_list(ID_WINDOW)->area.y + adj_size(152),
adj_size(126), 0, pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list);
adj_size(126), 0, editor->pWork->begin_widget_list,
editor->pWork->end_widget_list);
#if 0
setup_vertical_scrollbar_area(pEditor->pWork->scroll,
pEditor->end_widget_list->area.x + adj_size(2),
setup_vertical_scrollbar_area(editor->pWork->scroll,
editor->end_widget_list->area.x + adj_size(2),
get_widget_pointer_form_main_list(ID_WINDOW)->area.y + adj_size(152),
adj_size(225), FALSE);*/
#endif /* 0 */
hide_scrollbar(pEditor->pWork->scroll);
hide_scrollbar(editor->pWork->scroll);
}
#endif /* 0 */
refresh_worklist_count_label();
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
......
bool changed = FALSE;
struct universal tmp;
if (pItem == pEditor->pWork->begin_active_widget_list) {
if (pItem == editor->pWork->begin_active_widget_list) {
remove_item_from_worklist(pItem);
return;
}
......
/* worklist operations -> swap down */
int row = *((int *)pItem->data.ptr);
tmp = pEditor->worklist_copy.entries[row];
pEditor->worklist_copy.entries[row] = pEditor->worklist_copy.entries[row + 1];
pEditor->worklist_copy.entries[row + 1] = tmp;
tmp = editor->worklist_copy.entries[row];
editor->worklist_copy.entries[row] = editor->worklist_copy.entries[row + 1];
editor->worklist_copy.entries[row + 1] = tmp;
changed = TRUE;
} else {
/* first item was clicked -> change production */
change_production(&pEditor->worklist_copy.entries[0]);
pEditor->worklist_copy.entries[0] = cid_decode(MAX_ID - ID);
change_production(&editor->worklist_copy.entries[0]);
editor->worklist_copy.entries[0] = cid_decode(MAX_ID - ID);
changed = TRUE;
}
......
pItem->prev->string_utf8->text = text;
pItem->prev->ID = ID;
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
}
......
struct universal tmp;
/* first item was clicked -> remove */
if (pItem == pEditor->pWork->end_active_widget_list) {
if (pItem == editor->pWork->end_active_widget_list) {
remove_item_from_worklist(pItem);
return;
}
......
/* worklist operations -> swap up */
int row = *((int *)pItem->data.ptr);
tmp = pEditor->worklist_copy.entries[row];
pEditor->worklist_copy.entries[row] = pEditor->worklist_copy.entries[row - 1];
pEditor->worklist_copy.entries[row - 1] = tmp;
tmp = editor->worklist_copy.entries[row];
editor->worklist_copy.entries[row] = editor->worklist_copy.entries[row - 1];
editor->worklist_copy.entries[row - 1] = tmp;
changed = TRUE;
} else {
/* second item was clicked -> change production ... */
tmp = pEditor->currently_building;
change_production(&pEditor->worklist_copy.entries[0]);
pEditor->worklist_copy.entries[0] = tmp;
tmp = editor->currently_building;
change_production(&editor->worklist_copy.entries[0]);
editor->worklist_copy.entries[0] = tmp;
changed = TRUE;
}
......
pItem->next->string_utf8->text = text;
pItem->next->ID = ID;
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
}
......
static void add_global_worklist(struct widget *pwidget)
{
struct global_worklist *pGWL = global_worklist_by_id(MAX_ID - pwidget->ID);
struct widget *buf = pEditor->pWork->end_active_widget_list;
struct widget *buf = editor->pWork->end_active_widget_list;
const struct worklist *pWorkList;
int count, firstfree;
......
return;
}
if (worklist_length(&pEditor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
if (worklist_length(&editor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
/* worklist is full */
return;
}
firstfree = worklist_length(&pEditor->worklist_copy);
firstfree = worklist_length(&editor->worklist_copy);
/* copy global worklist to city worklist */
for (count = 0 ; count < worklist_length(pWorkList); count++) {
/* global worklist can have targets unavilable in current state of game
then we must remove those targets from new city worklist */
if (!can_city_build_later(pEditor->pcity, &pWorkList->entries[count])) {
if (!can_city_build_later(editor->pcity, &pWorkList->entries[count])) {
continue;
}
worklist_append(&pEditor->worklist_copy, &pWorkList->entries[count]);
worklist_append(&editor->worklist_copy, &pWorkList->entries[count]);
/* create widget */
if (VUT_UTYPE == pWorkList->entries[count].kind) {
......
} else {
buf = create_iconlabel(NULL, pwidget->dst,
create_utf8_from_char(
city_improvement_name_translation(pEditor->pcity,
city_improvement_name_translation(editor->pcity,
pWorkList->entries[count].value.building),
adj_font(10)),
(WF_RESTORE_BACKGROUND|WF_FREE_DATA));
......
buf->data.ptr = fc_calloc(1, sizeof(int));
*((int *)buf->data.ptr) = firstfree;
add_widget_to_vertical_scroll_widget_list(pEditor->pWork,
buf, pEditor->pWork->begin_active_widget_list,
add_widget_to_vertical_scroll_widget_list(editor->pWork,
buf, editor->pWork->begin_active_widget_list,
FALSE,
pEditor->end_widget_list->area.x + adj_size(2),
pEditor->end_widget_list->area.y + adj_size(152));
editor->end_widget_list->area.x + adj_size(2),
editor->end_widget_list->area.y + adj_size(152));
firstfree++;
if (firstfree == MAX_LEN_WORKLIST - 1) {
......
}
refresh_worklist_count_label();
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
......
static void set_global_worklist(struct widget *pwidget)
{
struct global_worklist *pGWL = global_worklist_by_id(MAX_ID - pwidget->ID);
struct widget *buf = pEditor->pWork->end_active_widget_list;
struct widget *buf = editor->pWork->end_active_widget_list;
const struct worklist *pWorkList;
struct worklist wl;
int count, wl_count;
......
for (count = 0; count < worklist_length(pWorkList); count++) {
/* global worklist can have targets unavilable in current state of game
then we must remove those targets from new city worklist */
if (!can_city_build_later(pEditor->pcity, &pWorkList->entries[count])) {
if (!can_city_build_later(editor->pcity, &pWorkList->entries[count])) {
continue;
}
......
if (!worklist_is_empty(&wl)) {
/* free old widget list */
if (buf != pEditor->pWork->begin_active_widget_list) {
if (buf != editor->pWork->begin_active_widget_list) {
buf = buf->prev;
if (buf != pEditor->pWork->begin_active_widget_list) {
if (buf != editor->pWork->begin_active_widget_list) {
do {
buf = buf->prev;
del_widget_from_vertical_scroll_widget_list(pEditor->pWork, buf->next);
} while (buf != pEditor->pWork->begin_active_widget_list);
del_widget_from_vertical_scroll_widget_list(editor->pWork, buf->next);
} while (buf != editor->pWork->begin_active_widget_list);
}
del_widget_from_vertical_scroll_widget_list(pEditor->pWork, buf);
del_widget_from_vertical_scroll_widget_list(editor->pWork, buf);
}
/* --------------------------------- */
worklist_copy(&pEditor->worklist_copy, &wl);
worklist_copy(&editor->worklist_copy, &wl);
/* --------------------------------- */
/* create new widget list */
for (count = 0; count < MAX_LEN_WORKLIST; count++) {
/* end of list */
if (!worklist_peek_ith(&pEditor->worklist_copy, &target, count)) {
if (!worklist_peek_ith(&editor->worklist_copy, &target, count)) {
break;
}
......
buf->ID = MAX_ID - B_LAST - utype_number(target.value.utype);
} else {
buf = create_iconlabel(NULL, pwidget->dst,
create_utf8_from_char(city_improvement_name_translation(pEditor->pcity,
create_utf8_from_char(city_improvement_name_translation(editor->pcity,
target.value.building),
adj_font(10)),
(WF_RESTORE_BACKGROUND|WF_FREE_DATA));
......
buf->data.ptr = fc_calloc(1, sizeof(int));
*((int *)buf->data.ptr) = count;
add_widget_to_vertical_scroll_widget_list(pEditor->pWork,
buf, pEditor->pWork->begin_active_widget_list, FALSE,
pEditor->end_widget_list->area.x + adj_size(2),
pEditor->end_widget_list->area.y + adj_size(152));
add_widget_to_vertical_scroll_widget_list(editor->pWork,
buf, editor->pWork->begin_active_widget_list, FALSE,
editor->end_widget_list->area.x + adj_size(2),
editor->end_widget_list->area.y + adj_size(152));
}
refresh_worklist_count_label();
redraw_group(pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list, TRUE);
redraw_group(editor->pWork->begin_widget_list,
editor->pWork->end_widget_list, TRUE);
flush_dirty();
}
......
int cost, turns;
char cBuf[64];
SDL_Rect area;
bool gold_prod = improvement_has_flag(pEditor->currently_building.value.building, IF_GOLD);
const char *name = get_production_name(pEditor->pcity,
pEditor->currently_building, &cost);
bool gold_prod = improvement_has_flag(editor->currently_building.value.building, IF_GOLD);
const char *name = get_production_name(editor->pcity,
editor->currently_building, &cost);
if (VUT_IMPROVEMENT == pEditor->currently_building.kind && gold_prod) {
int gold = MAX(0, pEditor->pcity->surplus[O_SHIELD]);
if (VUT_IMPROVEMENT == editor->currently_building.kind && gold_prod) {
int gold = MAX(0, editor->pcity->surplus[O_SHIELD]);
fc_snprintf(cBuf, sizeof(cBuf),
PL_("%s\n%d gold per turn",
......
name, gold);
} else {
if (stock < cost) {
turns = city_turns_to_build(pEditor->pcity,
&pEditor->currently_building, TRUE);
turns = city_turns_to_build(editor->pcity,
&editor->currently_building, TRUE);
if (turns == 999) {
fc_snprintf(cBuf, sizeof(cBuf), _("%s\nblocked!"), name);
} else {
......
fc_snprintf(cBuf, sizeof(cBuf), _("%s\nfinished!"), name);
}
}
copy_chars_to_utf8_str(pEditor->pProduction_Name->string_utf8, cBuf);
copy_chars_to_utf8_str(editor->pProduction_Name->string_utf8, cBuf);
widget_undraw(pEditor->pProduction_Name);
remake_label_size(pEditor->pProduction_Name);
widget_undraw(editor->pProduction_Name);
remake_label_size(editor->pProduction_Name);
pEditor->pProduction_Name->size.x = pEditor->end_widget_list->area.x +
(adj_size(130) - pEditor->pProduction_Name->size.w)/2;
editor->pProduction_Name->size.x = editor->end_widget_list->area.x +
(adj_size(130) - editor->pProduction_Name->size.w)/2;
/* Can't just widget_mark_dirty(), as it may have reduced in size */
area.x = pEditor->end_widget_list->area.x; /* left edge of client area */
area.y = pEditor->pProduction_Name->size.y;
area.x = editor->end_widget_list->area.x; /* left edge of client area */
area.y = editor->pProduction_Name->size.y;
area.w = adj_size(130);
area.h = pEditor->pProduction_Name->size.h;
layer_rect_to_screen_rect(pEditor->end_widget_list->dst, &area);
area.h = editor->pProduction_Name->size.h;
layer_rect_to_screen_rect(editor->end_widget_list->dst, &area);
if (get_wflags(pEditor->pProduction_Name) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(pEditor->pProduction_Name);
if (get_wflags(editor->pProduction_Name) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(editor->pProduction_Name);
}
widget_redraw(pEditor->pProduction_Name);
widget_redraw(editor->pProduction_Name);
dirty_sdl_rect(&area);
FREESURFACE(pEditor->pProduction_Progres->theme);
pEditor->pProduction_Progres->theme =
FREESURFACE(editor->pProduction_Progres->theme);
editor->pProduction_Progres->theme =
get_progress_icon(stock, cost, &cost);
if (!gold_prod) {
......
} else {
fc_snprintf(cBuf, sizeof(cBuf), "-");
}
copy_chars_to_utf8_str(pEditor->pProduction_Progres->string_utf8, cBuf);
widget_redraw(pEditor->pProduction_Progres);
widget_mark_dirty(pEditor->pProduction_Progres);
copy_chars_to_utf8_str(editor->pProduction_Progres->string_utf8, cBuf);
widget_redraw(editor->pProduction_Progres);
widget_mark_dirty(editor->pProduction_Progres);
}
/**********************************************************************//**
......
{
char cBuf[64];
SDL_Rect area;
int len = worklist_length(&pEditor->worklist_copy);
int len = worklist_length(&editor->worklist_copy);
if (pEditor->pcity != NULL) {
if (editor->pcity != NULL) {
len += 1; /* External entry from current production */
}
fc_snprintf(cBuf, sizeof(cBuf),
/* TRANS: length of worklist */
PL_("( %d entry )", "( %d entries )", len), len);
copy_chars_to_utf8_str(pEditor->pWorkList_Counter->string_utf8, cBuf);
copy_chars_to_utf8_str(editor->pWorkList_Counter->string_utf8, cBuf);
widget_undraw(pEditor->pWorkList_Counter);
remake_label_size(pEditor->pWorkList_Counter);
widget_undraw(editor->pWorkList_Counter);
remake_label_size(editor->pWorkList_Counter);
pEditor->pWorkList_Counter->size.x = pEditor->end_widget_list->area.x +
(adj_size(130) - pEditor->pWorkList_Counter->size.w)/2;
editor->pWorkList_Counter->size.x = editor->end_widget_list->area.x +
(adj_size(130) - editor->pWorkList_Counter->size.w)/2;
if (get_wflags(pEditor->pWorkList_Counter) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(pEditor->pWorkList_Counter);
if (get_wflags(editor->pWorkList_Counter) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(editor->pWorkList_Counter);
}
widget_redraw(pEditor->pWorkList_Counter);
widget_redraw(editor->pWorkList_Counter);
/* Can't just widget_mark_dirty(), as it may have reduced in size */
area.x = pEditor->end_widget_list->area.x; /* left edge of client area */
area.y = pEditor->pWorkList_Counter->size.y;
area.x = editor->end_widget_list->area.x; /* left edge of client area */
area.y = editor->pWorkList_Counter->size.y;
area.w = adj_size(130);
area.h = pEditor->pWorkList_Counter->size.h;
layer_rect_to_screen_rect(pEditor->end_widget_list->dst, &area);
area.h = editor->pWorkList_Counter->size.h;
layer_rect_to_screen_rect(editor->end_widget_list->dst, &area);
dirty_sdl_rect(&area);
}
......
SDL_Rect area;
int len;
if (pEditor) {
if (editor) {
return;
}
pEditor = fc_calloc(1, sizeof(struct EDITOR));
editor = fc_calloc(1, sizeof(struct wl_editor));
if (pcity) {
pEditor->pcity = pcity;
pEditor->global_worklist_id = -1;
pEditor->currently_building = pcity->production;
pEditor->stock = pcity->shield_stock;
worklist_copy(&pEditor->worklist_copy, &pcity->worklist);
fc_snprintf(pEditor->worklist_name, sizeof(pEditor->worklist_name),
editor->pcity = pcity;
editor->global_worklist_id = -1;
editor->currently_building = pcity->production;
editor->stock = pcity->shield_stock;
worklist_copy(&editor->worklist_copy, &pcity->worklist);
fc_snprintf(editor->worklist_name, sizeof(editor->worklist_name),
"%s worklist", city_name_get(pcity));
} else if (gwl != NULL) {
pEditor->pcity = NULL;
pEditor->global_worklist_id = global_worklist_id(gwl);
worklist_copy(&pEditor->worklist_copy, global_worklist_get(gwl));
sz_strlcpy(pEditor->worklist_name, global_worklist_name(gwl));
editor->pcity = NULL;
editor->global_worklist_id = global_worklist_id(gwl);
worklist_copy(&editor->worklist_copy, global_worklist_get(gwl));
sz_strlcpy(editor->worklist_name, global_worklist_name(gwl));
} else {
/* Not valid variant! */
return;
}
len = worklist_length(&pEditor->worklist_copy);
len = worklist_length(&editor->worklist_copy);
advanced_tech = (pcity == NULL);
/* --------------- */
......
set_wstate(pwindow, FC_WS_NORMAL);
add_to_gui_list(ID_WINDOW, pwindow);
pEditor->end_widget_list = pwindow;
editor->end_widget_list = pwindow;
area = pwindow->area;
......
pstr = create_utf8_from_char(cbuf, adj_font(10));
pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
buf = create_iconlabel(NULL, pwindow->dst, pstr, WF_RESTORE_BACKGROUND);
pEditor->pWorkList_Counter = buf;
editor->pWorkList_Counter = buf;
add_to_gui_list(ID_LABEL, buf);
/* --------------------------- */
......
pstr->style |= SF_CENTER;
buf = create_iconlabel(NULL, pwindow->dst, pstr, WF_RESTORE_BACKGROUND);
pEditor->pProduction_Name = buf;
editor->pProduction_Name = buf;
add_to_gui_list(ID_LABEL, buf);
icon = get_progress_icon(pcity->shield_stock, count, &turns);
......
icon = NULL;
turns = 0;
pEditor->pProduction_Progres = buf;
editor->pProduction_Progres = buf;
add_to_gui_list(ID_LABEL, buf);
} else {
buf = create_edit_from_chars(NULL, pwindow->dst,
......
will have this field NULL
*/
pEditor->pWork = fc_calloc(1, sizeof(struct advanced_dialog));
editor->pWork = fc_calloc(1, sizeof(struct advanced_dialog));
pEditor->pWork->scroll = fc_calloc(1, sizeof(struct scroll_bar));
pEditor->pWork->scroll->count = 0;
pEditor->pWork->scroll->active = MAX_LEN_WORKLIST;
pEditor->pWork->scroll->step = 1;
editor->pWork->scroll = fc_calloc(1, sizeof(struct scroll_bar));
editor->pWork->scroll->count = 0;
editor->pWork->scroll->active = MAX_LEN_WORKLIST;
editor->pWork->scroll->step = 1;
/* FIXME: this should replace the 4 lines above, but
* pEditor->pWork->end_widget_list is not set yet */
* editor->pWork->end_widget_list is not set yet */
#if 0
create_vertical_scrollbar(pEditor->pWork, 1, MAX_LEN_WORKLIST, TRUE, TRUE);
create_vertical_scrollbar(editor->pWork, 1, MAX_LEN_WORKLIST, TRUE, TRUE);
#endif /* 0 */
if (pcity) {
......
add_to_gui_list(MAX_ID - cid_encode(pcity->production), buf);
pEditor->pWork->end_widget_list = buf;
pEditor->pWork->begin_widget_list = buf;
pEditor->pWork->end_active_widget_list = pEditor->pWork->end_widget_list;
pEditor->pWork->begin_active_widget_list = pEditor->pWork->begin_widget_list;
pEditor->pWork->scroll->count++;
editor->pWork->end_widget_list = buf;
editor->pWork->begin_widget_list = buf;
editor->pWork->end_active_widget_list = editor->pWork->end_widget_list;
editor->pWork->begin_active_widget_list = editor->pWork->begin_widget_list;
editor->pWork->scroll->count++;
}
pLast = buf;
pEditor->dock = buf;
editor->dock = buf;
/* create Widget Labels of worklist entries */
count = 0;
worklist_iterate(&pEditor->worklist_copy, prod) {
worklist_iterate(&editor->worklist_copy, prod) {
if (VUT_UTYPE == prod.kind) {
pstr = create_utf8_from_char(utype_name_translation(prod.value.utype),
adj_font(10));
......
count++;
if (count > pEditor->pWork->scroll->active - 1) {
if (count > editor->pWork->scroll->active - 1) {
set_wflag(buf, WF_HIDDEN);
}
......
if (count) {
if (!pcity) {
pEditor->pWork->end_widget_list = pLast->prev;
pEditor->pWork->end_active_widget_list = pEditor->pWork->end_widget_list;
editor->pWork->end_widget_list = pLast->prev;
editor->pWork->end_active_widget_list = editor->pWork->end_widget_list;
}
pEditor->pWork->begin_widget_list = buf;
pEditor->pWork->begin_active_widget_list = pEditor->pWork->begin_widget_list;
editor->pWork->begin_widget_list = buf;
editor->pWork->begin_active_widget_list = editor->pWork->begin_widget_list;
} else {
if (!pcity) {
pEditor->pWork->end_widget_list = pLast;
editor->pWork->end_widget_list = pLast;
}
pEditor->pWork->begin_widget_list = pLast;
editor->pWork->begin_widget_list = pLast;
}
/* FIXME */
#if 0
pEditor->pWork->active_widget_list = pEditor->pWork->end_active_widget_list;
create_vertical_scrollbar(pEditor->pWork, 1,
pEditor->pWork->scroll->active, FALSE, TRUE);
pEditor->pWork->scroll->up_left_button->size.w = adj_size(122);
pEditor->pWork->scroll->down_right_button->size.w = adj_size(122);
editor->pWork->active_widget_list = editor->pWork->end_active_widget_list;
create_vertical_scrollbar(editor->pWork, 1,
editor->pWork->scroll->active, FALSE, TRUE);
editor->pWork->scroll->up_left_button->size.w = adj_size(122);
editor->pWork->scroll->down_right_button->size.w = adj_size(122);
/* count: without production */
if (count <= pEditor->pWork->scroll->active + 1) {
if (count <= editor->pWork->scroll->active + 1) {
if (count > 0) {
struct widget *pTmp = pLast;
......
clear_wflag(pTmp, WF_HIDDEN);
} while (pTmp != buf);
}
hide_scrollbar(pEditor->pWork->scroll);
hide_scrollbar(editor->pWork->scroll);
}
#endif /* 0 */
pEditor->pWork->scroll->count += count;
pLast = pEditor->pWork->begin_widget_list;
editor->pWork->scroll->count += count;
pLast = editor->pWork->begin_widget_list;
/* --------------------------- */
/* global worklists */
......
} global_worklists_iterate_end;
if (count) {
pEditor->pGlobal = fc_calloc(1, sizeof(struct advanced_dialog));
pEditor->pGlobal->end_widget_list = pLast->prev;
pEditor->pGlobal->end_active_widget_list = pEditor->pGlobal->end_widget_list;
pEditor->pGlobal->begin_widget_list = buf;
pEditor->pGlobal->begin_active_widget_list = pEditor->pGlobal->begin_widget_list;
editor->pGlobal = fc_calloc(1, sizeof(struct advanced_dialog));
editor->pGlobal->end_widget_list = pLast->prev;
editor->pGlobal->end_active_widget_list = editor->pGlobal->end_widget_list;
editor->pGlobal->begin_widget_list = buf;
editor->pGlobal->begin_active_widget_list = editor->pGlobal->begin_widget_list;
if (count > 6) {
pEditor->pGlobal->active_widget_list = pEditor->pGlobal->end_active_widget_list;
editor->pGlobal->active_widget_list = editor->pGlobal->end_active_widget_list;
create_vertical_scrollbar(pEditor->pGlobal, 1, 4, FALSE, TRUE);
pEditor->pGlobal->scroll->up_left_button->size.w = adj_size(122);
pEditor->pGlobal->scroll->down_right_button->size.w = adj_size(122);
create_vertical_scrollbar(editor->pGlobal, 1, 4, FALSE, TRUE);
editor->pGlobal->scroll->up_left_button->size.w = adj_size(122);
editor->pGlobal->scroll->down_right_button->size.w = adj_size(122);
} else {
struct widget *pTmp = pLast;
......
} while (pTmp != buf);
}
pLast = pEditor->pGlobal->begin_widget_list;
pLast = editor->pGlobal->begin_widget_list;
}
}
/* ----------------------------- */
......
}
} unit_type_iterate_end;
pEditor->pTargets = fc_calloc(1, sizeof(struct advanced_dialog));
editor->pTargets = fc_calloc(1, sizeof(struct advanced_dialog));
pEditor->pTargets->end_widget_list = pLast->prev;
pEditor->pTargets->begin_widget_list = buf;
pEditor->pTargets->end_active_widget_list = pEditor->pTargets->end_widget_list;
pEditor->pTargets->begin_active_widget_list = pEditor->pTargets->begin_widget_list;
pEditor->pTargets->active_widget_list = pEditor->pTargets->end_active_widget_list;
editor->pTargets->end_widget_list = pLast->prev;
editor->pTargets->begin_widget_list = buf;
editor->pTargets->end_active_widget_list = editor->pTargets->end_widget_list;
editor->pTargets->begin_active_widget_list = editor->pTargets->begin_widget_list;
editor->pTargets->active_widget_list = editor->pTargets->end_active_widget_list;
/* --------------- */
if (count > (TARGETS_ROW * TARGETS_COL - 1)) {
count = create_vertical_scrollbar(pEditor->pTargets,
count = create_vertical_scrollbar(editor->pTargets,
TARGETS_COL, TARGETS_ROW, TRUE, TRUE);
} else {
count = 0;
}
/* --------------- */
pEditor->begin_widget_list = pEditor->pTargets->begin_widget_list;
editor->begin_widget_list = editor->pTargets->begin_widget_list;
/* Window */
area.w = MAX(area.w, widget_w * TARGETS_COL + count + adj_size(130));
......
dst.x, dst.y, dst.w - 1, dst.h - 1,
get_theme_color(COLOR_THEME_WLDLG_FRAME));
if (pEditor->pGlobal) {
if (editor->pGlobal) {
dst.x = area.x;
dst.y += dst.h + adj_size(2);
dst.w = adj_size(130);
......
buf->size.y = area.y + adj_size(135) - buf->size.h;
/* worklist */
/* pEditor->pWork->scroll->count: including production */
/* editor->pWork->scroll->count: including production */
if (len > 0) {
/* FIXME */
setup_vertical_widgets_position(1,
area.x + adj_size(2), area.y + adj_size(152)
/* + ((pEditor->pWork->scroll->count > pEditor->pWork->scroll->active + 2) ?
pEditor->pWork->scroll->up_left_button->size.h + 1 : 0)*/,
adj_size(126), 0, pEditor->pWork->begin_widget_list,
pEditor->pWork->end_widget_list);
/* + ((editor->pWork->scroll->count > editor->pWork->scroll->active + 2) ?
editor->pWork->scroll->up_left_button->size.h + 1 : 0)*/,
adj_size(126), 0, editor->pWork->begin_widget_list,
editor->pWork->end_widget_list);
setup_vertical_scrollbar_area(pEditor->pWork->scroll,
setup_vertical_scrollbar_area(editor->pWork->scroll,
area.x + adj_size(2),
area.y + adj_size(152),
adj_size(225), FALSE);
}
/* global worklists */
if (pEditor->pGlobal) {
if (editor->pGlobal) {
setup_vertical_widgets_position(1,
area.x + adj_size(4),
area.y + adj_size(384) +
(pEditor->pGlobal->scroll ?
pEditor->pGlobal->scroll->up_left_button->size.h + 1 : 0),
adj_size(122), 0, pEditor->pGlobal->begin_widget_list,
pEditor->pGlobal->end_widget_list);
(editor->pGlobal->scroll ?
editor->pGlobal->scroll->up_left_button->size.h + 1 : 0),
adj_size(122), 0, editor->pGlobal->begin_widget_list,
editor->pGlobal->end_widget_list);
if (pEditor->pGlobal->scroll) {
setup_vertical_scrollbar_area(pEditor->pGlobal->scroll,
if (editor->pGlobal->scroll) {
setup_vertical_scrollbar_area(editor->pGlobal->scroll,
area.x + adj_size(4),
area.y + adj_size(384),
adj_size(93), FALSE);
......
/* Targets */
setup_vertical_widgets_position(TARGETS_COL,
area.x + adj_size(130), area.y,
0, 0, pEditor->pTargets->begin_widget_list,
pEditor->pTargets->end_widget_list);
0, 0, editor->pTargets->begin_widget_list,
editor->pTargets->end_widget_list);
if (pEditor->pTargets->scroll) {
setup_vertical_scrollbar_area(pEditor->pTargets->scroll,
if (editor->pTargets->scroll) {
setup_vertical_scrollbar_area(editor->pTargets->scroll,
area.x + area.w,
area.y + 1,
area.h - 1, TRUE);
......
FREEUTF8STR(pstr);
FREESURFACE(pMain);
redraw_group(pEditor->begin_widget_list, pwindow, 0);
redraw_group(editor->begin_widget_list, pwindow, 0);
widget_flush(pwindow);
}
......
**************************************************************************/
void popdown_worklist_editor(void)
{
if (pEditor) {
popdown_window_group_dialog(pEditor->begin_widget_list,
pEditor->end_widget_list);
FC_FREE(pEditor->pTargets->scroll);
FC_FREE(pEditor->pTargets);
FC_FREE(pEditor->pWork->scroll);
FC_FREE(pEditor->pWork);
if (pEditor->pGlobal) {
FC_FREE(pEditor->pGlobal->scroll);
FC_FREE(pEditor->pGlobal);
if (editor) {
popdown_window_group_dialog(editor->begin_widget_list,
editor->end_widget_list);
FC_FREE(editor->pTargets->scroll);
FC_FREE(editor->pTargets);
FC_FREE(editor->pWork->scroll);
FC_FREE(editor->pWork);
if (editor->pGlobal) {
FC_FREE(editor->pGlobal->scroll);
FC_FREE(editor->pGlobal);
}
if (city_dialog_is_open(pEditor->pcity)) {
if (city_dialog_is_open(editor->pcity)) {
enable_city_dlg_widgets();
}
FC_FREE(pEditor);
FC_FREE(editor);
flush_dirty();
}
    (1-1/1)