From 8b88fbd2166388611430cf0036e988b3e24adbd4 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Fri, 18 Jan 2008 17:47:21 +0000 Subject: Making mouse-over region larger on Linux. Reformatting mouse-over messages to be consistent. More tile code cleanup and dead code removal. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3299 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libgui.cc | 56 ++++++++++------------ crawl-ref/source/libx11.cc | 115 +++++++++++++++++++++++---------------------- crawl-ref/source/tile2.cc | 111 ++++++++++--------------------------------- crawl-ref/source/tiles.h | 49 ++++++++++--------- 4 files changed, 135 insertions(+), 196 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/libgui.cc b/crawl-ref/source/libgui.cc index b8c5ab4881..6817a9db38 100644 --- a/crawl-ref/source/libgui.cc +++ b/crawl-ref/source/libgui.cc @@ -9,9 +9,6 @@ * */ -#define deblog(x) {FILE *ddfp=fopen("log.txt","a");fprintf(ddfp,x);fprintf(ddfp,"\n");fclose(ddfp);} -#define deblog2(x,y) {FILE *ddfp=fopen("log.txt","a");fprintf(ddfp,"%s %d\n",x,y);fclose(ddfp);} - #include #include #include @@ -78,9 +75,6 @@ img_type TileImg, TileIsoImg; img_type PlayerImg; img_type WallImg; -extern bool force_redraw_tile; -extern bool force_redraw_inv; - // for item use gui #define MAX_ITEMLIST 60 extern int itemlist[MAX_ITEMLIST]; @@ -620,7 +614,8 @@ void libgui_init() } #elif defined(USE_X11) - region_tip = new TextRegionClass(region_stat->mx, 1, 0, 0); + const unsigned int region_tip_height = 3; + region_tip = new TextRegionClass(region_stat->mx, region_tip_height, 0, 0); region_tip->id = REGION_TIP; region_crt->init_font(font_name); @@ -996,14 +991,14 @@ void edit_prefs() if (upd_dngn) { region_tile -> resize_backbuf(); - force_redraw_tile = true; + tile_set_force_redraw_tiles(true); TileResizeScreen(dngn_x, dngn_y); } if (region_item) region_item->resize_backbuf(); if (region_item2) region_item2->resize_backbuf(); - force_redraw_inv = true; + tile_set_force_redraw_inv(true); tile_draw_inv(-1, REGION_INV1); region_map->force_redraw = true; @@ -1237,7 +1232,7 @@ static int handle_mouse_motion(int mouse_x, int mouse_y, bool init) } desc += mitm[ix].name(DESC_NOCAP_A); if (display_actions) - desc += EOL "[L-Click] *Pickup(g)"; + desc += EOL "[L-Click] Pick up (g)"; } else { @@ -1278,69 +1273,69 @@ static int handle_mouse_motion(int mouse_x, int mouse_y, bool init) case OBJ_WEAPONS: case OBJ_STAVES: case OBJ_MISCELLANY: - desc += "*(w)ield"; + desc += "Wield (w)"; break; case OBJ_WEAPONS + 18: - desc += "unwield"; + desc += "Unwield"; break; case OBJ_MISCELLANY + 18: if (you.inv[ix].sub_type >= MISC_DECK_OF_ESCAPE && you.inv[ix].sub_type <= MISC_DECK_OF_DEFENSE) { - desc += "draw a card"; + desc += "Draw a card (E)"; break; } // else fall-through case OBJ_STAVES + 18: // rods - other staves handled above - desc += "*(E)voke"; + desc += "Evoke (E)"; break; case OBJ_ARMOUR: - desc += "*(W)ear"; + desc += "Wear (W)"; break; case OBJ_ARMOUR + 18: - desc += "*(T)ake off"; + desc += "Take off (T)"; break; case OBJ_JEWELLERY: - desc += "*(P)ut on"; + desc += "Put on (P)"; break; case OBJ_JEWELLERY + 18: - desc += "*(R)emove"; + desc += "Remove (R)"; break; case OBJ_MISSILES: - desc += "*(t)hrow"; + desc += "Throw (t)"; break; case OBJ_WANDS: - desc += "*(z)ap"; + desc += "Zap (z)"; break; case OBJ_BOOKS: if (item_type_known(you.inv[ix]) && you.inv[ix].sub_type != BOOK_MANUAL && you.inv[ix].sub_type != BOOK_DESTRUCTION) { - desc += "*(M)emorize"; + desc += "Memorize (M)"; break; } // else fall-through case OBJ_SCROLLS: - desc += "*(r)ead"; + desc += "Read (r)"; break; case OBJ_POTIONS: - desc += "*(q)uaff"; + desc += "Quaff (q)"; break; case OBJ_FOOD: - desc += "*(e)at"; + desc += "Eat (e)"; break; case OBJ_CORPSES: if (you.species == SP_VAMPIRE) - desc += "drink blood"; + desc += "Drink blood (e)"; break; default: - desc += "*Use it"; + desc += "Use"; } } desc += EOL "[R-Click] Info"; - desc += EOL "[Shift-L-Click] *(d)rop"; + desc += EOL "[Shift-L-Click] Drop (d)"; } } update_tip_text(desc.c_str()); @@ -1402,13 +1397,13 @@ static int handle_mouse_motion(int mouse_x, int mouse_y, bool init) desc += get_class_abbrev(you.char_class); desc += ")" EOL; - desc += EOL "[L-Click] *Search 1 turn(s)"; + desc += EOL "[L-Click] Search 1 turn"; if (grid_stair_direction( grd[gx][gy] ) != CMD_NO_CMD) desc += EOL "[Shift-L-Click] use stairs ()"; // character overview - desc += EOL "[R-Click] Overview(%)"; + desc += EOL "[R-Click] Overview (%)"; // Religion if (you.religion != GOD_NO_GOD) @@ -1451,7 +1446,7 @@ static int handle_mouse_motion(int mouse_x, int mouse_y, bool init) if (mode == REGION_STAT && mouse_mode == MOUSE_MODE_COMMAND) { if (oldmode != REGION_STAT) - update_tip_text("[L-Click] Rest/Search for a while"); + update_tip_text("[L-Click] Rest / Search for a while"); oldmode = mode; oldcx = cx; oldcy = cy; @@ -1460,6 +1455,7 @@ static int handle_mouse_motion(int mouse_x, int mouse_y, bool init) return 0; } + static int handle_mouse_button(int mx, int my, int button, bool shift, bool ctrl) { diff --git a/crawl-ref/source/libx11.cc b/crawl-ref/source/libx11.cc index cf291db862..2bc75e3ac6 100644 --- a/crawl-ref/source/libx11.cc +++ b/crawl-ref/source/libx11.cc @@ -116,90 +116,91 @@ int my_getenv_int(const char *envname, int def) return atoi(rstr); } -#if 0 -void libgui_load_prefs(struct pref_data *pref, int nprefs) -{ - int i; - strcpy(font_name, my_getenv("CRAWL_X11_FONT", - "-alias-fixed-bold-r-normal--16-*")); - strcpy(font_name, my_getenv("CRAWL_X11_FONT", "9x15")); - *crt_x = my_getenv_int("CRAWL_X11_CRTX",80); - *crt_y = my_getenv_int("CRAWL_X11_CRTY",25); - *msg_x = my_getenv_int("CRAWL_X11_MSGX",80); - *msg_y = my_getenv_int("CRAWL_X11_MSGY",8); - *map_x = my_getenv_int("CRAWL_X11_MAPX",3); - *map_y = my_getenv_int("CRAWL_X11_MAPY",3); - *dngn_x = my_getenv_int("CRAWL_X11_DNGNX",17); - *dngn_y = my_getenv_int("CRAWL_X11_DNGNY",17); -} - -void libgui_save_prefs() -{ -} -#endif - extern WinClass *win_main; extern TextRegionClass *region_tip; +extern TextRegionClass *region_crt; void update_tip_text(const char *tip) { - static char newtip[512]; - static char oldtip[512]; - char tbuf[35]; + const unsigned int tip_size = 512; + static char old_tip[tip_size]; + char new_tip[tip_size]; - strncpy(newtip, tip, 500); - char* pc = strchr(newtip, '\n'); - if (pc) - *pc = 0; - - if (strncmp(oldtip, newtip, 500)==0) + if (strncmp(old_tip, tip, tip_size) == 0) return; - strncpy(oldtip, newtip, 500); - strncpy(tbuf,tip,34); - tbuf[34]=0; + const bool is_main_screen = (win_main->active_layer == 0); + const unsigned int height = is_main_screen ? region_tip->my : 1; + const unsigned int width = is_main_screen ? region_tip->mx : region_crt->mx; + + strncpy(new_tip, tip, tip_size); + strncpy(old_tip, new_tip, tip_size); + + if (is_main_screen) + { + region_tip->clear(); + } - if (win_main->active_layer == 0) + char *next_tip = new_tip; + for (unsigned int i = 0; next_tip && i < height; i++) { - // avoid overruns... - if ((int)strlen(newtip) > region_tip->mx) + char *this_tip = next_tip; + + // find end of line + char *pc = strchr(next_tip, '\n'); + if (pc) + { + *pc = 0; + next_tip = pc + 1; + } + else + { + next_tip = 0; + } + + if (strlen(this_tip) > width) { // try to remove inscriptions - char *ins = strchr(newtip, '{'); - if (ins && ins[-1] == ' ') ins--; - if (ins && (ins - newtip <= region_tip->mx)) + char *ins = strchr(this_tip, '{'); + if (ins && ins[-1] == ' ') + ins--; + if (ins && (ins - this_tip <= (int)width)) { *ins = 0; } else { // try to remove state, e.g. "(worn)" - char *state = strchr(newtip, '('); - if (state && state[-1] == ' ') state--; - if (state && (state - newtip <= region_tip->mx)) + char *state = strchr(this_tip, '('); + if (state && state[-1] == ' ') + state--; + if (state && (state - this_tip <= (int)width)) { *state = 0; } else { // if nothing else... - newtip[region_tip->mx] = 0; - newtip[region_tip->mx-1] = '.'; - newtip[region_tip->mx-2] = '.'; + this_tip[width] = 0; + this_tip[width-1] = '.'; + this_tip[width-2] = '.'; } } } - region_tip->clear(); - region_tip->gotoxy(1,1); - region_tip->addstr(newtip); - region_tip->make_active(); - } - else - { - textattr( WHITE ); - gotoxy(1, get_number_of_lines() + 1); - cprintf("%s", oldtip); - clear_to_end_of_line(); + if (is_main_screen) + { + region_tip->gotoxy(1, 1 + i); + region_tip->addstr(this_tip); + region_tip->make_active(); + } + else + { + ASSERT(i == 0); + textattr(WHITE); + gotoxy(1, get_number_of_lines() + 1); + cprintf("%s", this_tip); + clear_to_end_of_line(); + } } } diff --git a/crawl-ref/source/tile2.cc b/crawl-ref/source/tile2.cc index ac2f808421..e5b9ebd716 100644 --- a/crawl-ref/source/tile2.cc +++ b/crawl-ref/source/tile2.cc @@ -54,7 +54,6 @@ static img_type DollCacheImg; static void tile_draw_grid(int kind, int xx, int yy); static void clear_tcache(); static void init_tcache(); -static void init_tileflag(); static void register_tile_mask(int tile, int region, int *cp, char *ms, bool smalltile = false); static void tcache_compose_normal(int ix, int *fg, int *bg); @@ -63,8 +62,19 @@ static void mcache_init(); //Internal variables -bool force_redraw_tile; -bool force_redraw_inv = false; +static bool force_redraw_tile = false; +static bool force_redraw_inv = false; + +void tile_set_force_redraw_tiles(bool redraw) +{ + force_redraw_tile = redraw; +} + +void tile_set_force_redraw_inv(bool redraw) +{ + force_redraw_inv = redraw; +} + static unsigned short int t1buf[TILE_DAT_XMAX+2][TILE_DAT_YMAX+2], t2buf[TILE_DAT_XMAX+2][TILE_DAT_YMAX+2]; static short unsigned int tb_bk[TILE_DAT_YMAX*TILE_DAT_XMAX*2]; @@ -154,19 +164,6 @@ const int tcache_ox_normal[TCACHE_KIND_NORMAL] = {0}; const int tcache_oy_normal[TCACHE_KIND_NORMAL] = {0}; const int tcache_nlayer_normal[TCACHE_KIND_NORMAL] = {1}; -unsigned char tile_flag[TILE_TOTAL2]; -#define TFLAG_A 0x80 -#define TFLAG_B 0x40 -#define TFLAG_C 0x20 -#define TFLAG_D 0x10 -#define TFLAG_F 0x08 -#define TFLAG_G 0x04 -#define TFLAG_H 0x02 -#define TFLAG_I 0x01 - -#define tile_check_blank(tile,region) \ - if( (tile_flag[tile & TILE_FLAG_MASK]&(region))==0) (tile) &= ~TILE_FLAG_MASK; - #define TREGION_0_NORMAL 0 const int region_sx_normal[1]={0}; const int region_sy_normal[1]={0}; @@ -176,11 +173,6 @@ const int region_wy_normal[1]={TILE_Y}; // ISO mode sink mask static char *sink_mask; -/* BG tile priority */ -static unsigned char tile_prio[TILE_TOTAL2]; -#define PRIO_WALL 10 -#define tile_is_wall(tile) (tile_prio[(tile)&TILE_FLAG_MASK]==PRIO_WALL) - /********* Image manipulation subroutines ****************/ img_type ImgLoadFileSimple(const char *name) { @@ -315,7 +307,6 @@ void TileInit() sink_mask = (char *)malloc(TILE_X*TILE_Y); - init_tileflag(); init_tcache(); DollCacheImg = ImgCreateSimple(TILE_X, TILE_Y); @@ -323,7 +314,7 @@ void TileInit() for(x=0;x= simple_iso_tile(TILE_DNGN_LAVA) && - bg0 <= simple_iso_tile(TILE_DNGN_LAVA)+3) - return TILE_MASK_LAVA; -*/ - if ( bg0 >= simple_iso_tile(TILE_DNGN_LAVA) && - bg0 <= simple_iso_tile(TILE_DNGN_SHALLOW_WATER) + 3) - { - int result = TILE_SINK_MASK;//simple_iso_tile(TILE_SINK_MASK); - if ((fg & TILE_FLAG_MASK) >= TILE_NORMAL) - result = simple_iso_tile(TILE_SINK_MASK); - //if ((fg & TILE_FLAG_MASK) >= TILE_NORMAL) result++; - return result; + if (fg == 0 || (fg & TILE_FLAG_FLYING) != 0) + return 0; + + if ( bg0 >= TILE_DNGN_LAVA && + bg0 <= TILE_DNGN_SHALLOW_WATER + 3) + { + return TILE_SINK_MASK; } return 0; @@ -876,7 +817,8 @@ void LoadDungeonView(short unsigned int *tileb) void TileDrawDungeon(short unsigned int *tileb) { int x, y, kind; - if(!TileImg)return; + if(!TileImg) + return; LoadDungeonView(tileb); @@ -2061,7 +2003,7 @@ void TilePlayerEdit() for(x=0;x