enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget) { struct EDIT pEdt; struct UniChar ___last; struct UniChar *pInputChain_TMP = NULL; enum Edit_Return_Codes ret; void *backup = pEdit_Widget->data.ptr; pEdt.pWidget = pEdit_Widget; pEdt.ChainLen = 0; pEdt.Truelength = 0; pEdt.Start_X = adj_size(5); pEdt.InputChain_X = 0; pEdit_Widget->data.ptr = (void *)&pEdt; SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); pEdt.pBg = create_bcgnd_surf(pEdit_Widget->theme, 2, pEdit_Widget->size.w, pEdit_Widget->size.h); /* Creating Chain */ pEdt.pBeginTextChain = text2chain(pEdit_Widget->string16->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; /* set font style (if any ) */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, (pEdit_Widget->string16->style & 0x0F)); } pEdt.pEndTextChain->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pEdt.pEndTextChain->chr, pEdit_Widget->string16->fgcol); /* create surface for each font in chain and find chain length */ if (pEdt.pBeginTextChain) { pInputChain_TMP = pEdt.pBeginTextChain; while (TRUE) { pEdt.ChainLen++; pInputChain_TMP->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pInputChain_TMP->chr, pEdit_Widget->string16->fgcol); pEdt.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 = NULL; } else { pEdt.pBeginTextChain = pEdt.pInputChain; } redraw_edit_chain(&pEdt); set_wstate(pEdit_Widget, FC_WS_PRESSED); { /* local loop */ Uint16 rety = gui_event_loop((void *)&pEdt, NULL, edit_key_down, NULL, edit_mouse_button_down, NULL, NULL); if (pEdt.pBeginTextChain == pEdt.pEndTextChain) { pEdt.pBeginTextChain = NULL; } if (rety == MAX_ID) { ret = ED_FORCE_EXIT; } else { ret = (enum Edit_Return_Codes) rety; /* this is here becouse we have no knowladge that pEdit_Widget exist or nor in force exit mode from gui loop */ /* reset font settings */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, TTF_STYLE_NORMAL); } if(ret != ED_ESC) { FC_FREE(pEdit_Widget->string16->text); pEdit_Widget->string16->text = chain2text(pEdt.pBeginTextChain, pEdt.ChainLen); pEdit_Widget->string16->n_alloc = (pEdt.ChainLen + 1) * sizeof(Uint16); } pEdit_Widget->data.ptr = backup; set_wstate(pEdit_Widget, FC_WS_NORMAL); } } FREESURFACE(pEdt.pEndTextChain->pTsurf); del_chain(pEdt.pBeginTextChain); FREESURFACE(pEdt.pBg); /* disable repeate key */ SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); /* disable Unicode */ SDL_EnableUNICODE(0); return ret; }
/************************************************************************** The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ void ui_main(int argc, char *argv[]) { SDL_Event __Net_User_Event; SDL_Event __GGZ_User_Event; SDL_Event __Anim_User_Event; SDL_Event __Info_User_Event; SDL_Event __Flush_User_Event; SDL_Event __pMap_Scroll_User_Event; parse_options(argc, argv); __Net_User_Event.type = SDL_USEREVENT; __Net_User_Event.user.code = NET; __Net_User_Event.user.data1 = NULL; __Net_User_Event.user.data2 = NULL; pNet_User_Event = &__Net_User_Event; __GGZ_User_Event.type = SDL_USEREVENT; __GGZ_User_Event.user.code = GGZ; __GGZ_User_Event.user.data1 = NULL; __GGZ_User_Event.user.data2 = NULL; pGGZ_User_Event = &__GGZ_User_Event; __Anim_User_Event.type = SDL_USEREVENT; __Anim_User_Event.user.code = EVENT_ERROR; __Anim_User_Event.user.data1 = NULL; __Anim_User_Event.user.data2 = NULL; pAnim_User_Event = &__Anim_User_Event; __Info_User_Event.type = SDL_USEREVENT; __Info_User_Event.user.code = SHOW_WIDGET_INFO_LABBEL; __Info_User_Event.user.data1 = NULL; __Info_User_Event.user.data2 = NULL; pInfo_User_Event = &__Info_User_Event; __Flush_User_Event.type = SDL_USEREVENT; __Flush_User_Event.user.code = FLUSH; __Flush_User_Event.user.data1 = NULL; __Flush_User_Event.user.data2 = NULL; pFlush_User_Event = &__Flush_User_Event; __pMap_Scroll_User_Event.type = SDL_USEREVENT; __pMap_Scroll_User_Event.user.code = MAP_SCROLL; __pMap_Scroll_User_Event.user.data1 = NULL; __pMap_Scroll_User_Event.user.data2 = NULL; pMap_Scroll_User_Event = &__pMap_Scroll_User_Event; is_unit_move_blocked = FALSE; SDL_Client_Flags |= (CF_DRAW_PLAYERS_NEUTRAL_STATUS| CF_DRAW_PLAYERS_WAR_STATUS| CF_DRAW_PLAYERS_CEASEFIRE_STATUS| CF_DRAW_PLAYERS_PEACE_STATUS| CF_DRAW_PLAYERS_ALLIANCE_STATUS); tileset_init(tileset); tileset_load_tiles(tileset); tileset_use_prefered_theme(tileset); load_cursors(); callbacks = callback_list_new(); diplomacy_dialog_init(); intel_dialog_init(); clear_double_messages_call(); setup_auxiliary_tech_icons(); if (gui_sdl_fullscreen) { #ifdef SMALL_SCREEN #ifdef UNDER_CE /* set 320x240 fullscreen */ set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT | SDL_FULLSCREEN); #else /* UNDER_CE */ /* small screen on desktop -> don't set 320x240 fullscreen mode */ set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* UNDER_CE */ #else /* SMALL_SCREEN */ set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT | SDL_FULLSCREEN); #endif /* SMALL_SCREEN */ } else { #ifdef SMALL_SCREEN #ifdef UNDER_CE set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT); #else /* UNDER_CE */ set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* UNDER_CE */ #else /* SMALL_SCREEN */ set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* SMALL_SCREEN */ #if 0 /* * call this for other that X enviroments - currently not supported. */ center_main_window_on_screen(); #endif /* 0 */ } /* SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); */ /* this need correct Main.screen size */ init_mapcanvas_and_overview(); set_client_state(C_S_DISCONNECTED); /* Main game loop */ gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler, main_mouse_button_down_handler, main_mouse_button_up_handler, main_mouse_motion_handler); }