Skip to content

Commit

Permalink
Merge pull request #40055 from Qrox/remove-view-offset-xy
Browse files Browse the repository at this point in the history
Remove VIEW_OFFSET_X/Y
  • Loading branch information
ifreund authored May 1, 2020
2 parents 61bbbe8 + f082362 commit 2b565c6
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ editmap::editmap()
{
width = 45;
height = TERMY;
offsetX = VIEW_OFFSET_X;
offsetX = 0;
infoHeight = 0;
sel_field = -1;
sel_field_intensity = -1;
Expand Down
98 changes: 41 additions & 57 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,35 +507,19 @@ void game::init_ui( const bool resized )
* You usually don't have to use it, expect for positioning of windows,
* because the window positions use the standard font dimension.
*
* VIEW_OFFSET_X/VIEW_OFFSET_Y is the position of w_terrain on screen,
* it is (as every window position) in standard font dimension.
* As the sidebar is located right of w_terrain it also controls its position.
* It was used to move everything into the center of the screen,
* when the screen was larger than what the game required. They are currently
* set to zero to prevent the other game windows from being truncated if
* w_terrain is too small for the current window.
*
* The code here calculates size available for w_terrain, caps it at
* max_view_size (the maximal view range than any character can have at
* any time).
* It is stored in TERRAIN_WINDOW_*.
* If w_terrain does not occupy the whole available area, VIEW_OFFSET_*
* are set to move everything into the middle of the screen.
*/
to_map_font_dimension( TERRAIN_WINDOW_WIDTH, TERRAIN_WINDOW_HEIGHT );

VIEW_OFFSET_X = 0;
VIEW_OFFSET_Y = 0;

// VIEW_OFFSET_* are in standard font dimension.
from_map_font_dimension( VIEW_OFFSET_X, VIEW_OFFSET_Y );

// Position of the player in the terrain window, it is always in the center
POSX = TERRAIN_WINDOW_WIDTH / 2;
POSY = TERRAIN_WINDOW_HEIGHT / 2;

w_terrain = w_terrain_ptr = catacurses::newwin( TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_WIDTH,
point( VIEW_OFFSET_X + sidebar_left, VIEW_OFFSET_Y ) );
point( sidebar_left, 0 ) );
werase( w_terrain );

/**
Expand All @@ -551,8 +535,8 @@ void game::init_ui( const bool resized )
reinitialize_framebuffer();

// minimap is always MINIMAP_WIDTH x MINIMAP_HEIGHT in size
int _y = VIEW_OFFSET_Y;
int _x = VIEW_OFFSET_X;
int _y = 0;
int _x = 0;

w_minimap = w_minimap_ptr = catacurses::newwin( MINIMAP_HEIGHT, MINIMAP_WIDTH, point( _x, _y ) );
werase( w_minimap );
Expand Down Expand Up @@ -2144,8 +2128,8 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
// TODO: Ideally the setup of uilist would be split into calculate variables (size, width...),
// and actual window creation. This would allow us to let uilist calculate the width, we can
// use that to adjust its location afterwards.
action_menu.w_y = VIEW_OFFSET_Y;
action_menu.w_x = popup_x + VIEW_OFFSET_X;
action_menu.w_y = 0;
action_menu.w_x = popup_x;
action_menu.w_width = popup_width;
// Filtering isn't needed, the number of entries is manageable.
action_menu.filtering = false;
Expand All @@ -2158,10 +2142,10 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
do {
item_info_data data( oThisItem.tname(), oThisItem.type_name(), vThisItem, vDummy, iScrollPos );
data.without_getch = true;
const int iHeight = TERMY - VIEW_OFFSET_Y * 2;
const int iHeight = TERMY;
const int iScrollHeight = iHeight - 2;

draw_item_info( iStartX, iWidth, VIEW_OFFSET_X, iHeight, data );
draw_item_info( iStartX, iWidth, 0, iHeight, data );
const int prev_selected = action_menu.selected;
action_menu.query( false );
if( action_menu.ret >= 0 ) {
Expand Down Expand Up @@ -6120,11 +6104,11 @@ static void zones_manager_draw_borders( const catacurses::window &w_border,
for( int i = 1; i < TERMX; ++i ) {
if( i < width ) {
mvwputch( w_border, point( i, 0 ), c_light_gray, LINE_OXOX ); // -
mvwputch( w_border, point( i, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( w_border, point( i, TERMY - iInfoHeight - 1 ), c_light_gray,
LINE_OXOX ); // -
}

if( i < TERMY - iInfoHeight - VIEW_OFFSET_Y * 2 ) {
if( i < TERMY - iInfoHeight ) {
mvwputch( w_border, point( 0, i ), c_light_gray, LINE_XOXO ); // |
mvwputch( w_border, point( width - 1, i ), c_light_gray, LINE_XOXO ); // |
}
Expand All @@ -6133,9 +6117,9 @@ static void zones_manager_draw_borders( const catacurses::window &w_border,
mvwputch( w_border, point_zero, c_light_gray, LINE_OXXO ); // |^
mvwputch( w_border, point( width - 1, 0 ), c_light_gray, LINE_OOXX ); // ^|

mvwputch( w_border, point( 0, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( w_border, point( 0, TERMY - iInfoHeight - 1 ), c_light_gray,
LINE_XXXO ); // |-
mvwputch( w_border, point( width - 1, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( w_border, point( width - 1, TERMY - iInfoHeight - 1 ), c_light_gray,
LINE_XOXX ); // -|

mvwprintz( w_border, point( 2, 0 ), c_white, _( "Zones manager" ) );
Expand Down Expand Up @@ -6178,21 +6162,21 @@ void game::zones_manager()
ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
offsetX = get_option<std::string>( "SIDEBAR_POSITION" ) == "left" ?
TERMX + VIEW_OFFSET_X - width : VIEW_OFFSET_X;
const int w_zone_height = TERMY - zone_ui_height - VIEW_OFFSET_Y * 2;
TERMX - width : 0;
const int w_zone_height = TERMY - zone_ui_height;
max_rows = w_zone_height - 2;
w_zones = catacurses::newwin( w_zone_height - 2, width - 2,
point( offsetX + 1, VIEW_OFFSET_Y + 1 ) );
point( offsetX + 1, 1 ) );
w_zones_border = catacurses::newwin( w_zone_height, width,
point( offsetX, VIEW_OFFSET_Y ) );
point( offsetX, 0 ) );
w_zones_info = catacurses::newwin( zone_ui_height - zone_options_height - 1,
width - 2, point( offsetX + 1, w_zone_height + VIEW_OFFSET_Y ) );
width - 2, point( offsetX + 1, w_zone_height ) );
w_zones_info_border = catacurses::newwin( zone_ui_height, width,
point( offsetX, w_zone_height + VIEW_OFFSET_Y ) );
point( offsetX, w_zone_height ) );
w_zones_options = catacurses::newwin( zone_options_height - 1, width - 2,
point( offsetX + 1, TERMY - zone_options_height - VIEW_OFFSET_Y ) );
point( offsetX + 1, TERMY - zone_options_height ) );

ui.position( point( offsetX, VIEW_OFFSET_Y ), point( width, TERMY - VIEW_OFFSET_Y * 2 ) );
ui.position( point( offsetX, 0 ), point( width, TERMY ) );
} );
ui.mark_resize();

Expand Down Expand Up @@ -7059,11 +7043,11 @@ void game::reset_item_list_state( const catacurses::window &window, int height,
for( int i = 1; i < TERMX; i++ ) {
if( i < width ) {
mvwputch( window, point( i, 0 ), c_light_gray, LINE_OXOX ); // -
mvwputch( window, point( i, TERMY - height - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( window, point( i, TERMY - height - 1 ), c_light_gray,
LINE_OXOX ); // -
}

if( i < TERMY - height - VIEW_OFFSET_Y * 2 ) {
if( i < TERMY - height ) {
mvwputch( window, point( 0, i ), c_light_gray, LINE_XOXO ); // |
mvwputch( window, point( width - 1, i ), c_light_gray, LINE_XOXO ); // |
}
Expand All @@ -7072,9 +7056,9 @@ void game::reset_item_list_state( const catacurses::window &window, int height,
mvwputch( window, point_zero, c_light_gray, LINE_OXXO ); // |^
mvwputch( window, point( width - 1, 0 ), c_light_gray, LINE_OOXX ); // ^|

mvwputch( window, point( 0, TERMY - height - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( window, point( 0, TERMY - height - 1 ), c_light_gray,
LINE_XXXO ); // |-
mvwputch( window, point( width - 1, TERMY - height - 1 - VIEW_OFFSET_Y * 2 ), c_light_gray,
mvwputch( window, point( width - 1, TERMY - height - 1 ), c_light_gray,
LINE_XOXX ); // -|

mvwprintz( window, point( 2, 0 ), c_light_green, "<Tab> " );
Expand Down Expand Up @@ -7114,7 +7098,7 @@ void game::reset_item_list_state( const catacurses::window &window, int height,
const int gap_spaces = ( width - usedwidth ) / gaps;
usedwidth += gap_spaces * gaps;
int xpos = gap_spaces + ( width - usedwidth ) / 2;
const int ypos = TERMY - height - 1 - VIEW_OFFSET_Y * 2;
const int ypos = TERMY - height - 1;

for( int i = 0; i < n; i++ ) {
xpos += shortcut_print( window, point( xpos, ypos ), c_white, c_light_green,
Expand Down Expand Up @@ -7193,24 +7177,24 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
iInfoHeight = std::min( 25, TERMY / 2 );
iMaxRows = TERMY - iInfoHeight - 2 - VIEW_OFFSET_Y * 2;
iMaxRows = TERMY - iInfoHeight - 2;

width = clamp( max_name_width, 45, ( TERMX - VIEW_OFFSET_X ) / 3 );
width = clamp( max_name_width, 45, TERMX / 3 );

const int offsetX = TERMX - VIEW_OFFSET_X - width;
const int offsetX = TERMX - width;

w_items = catacurses::newwin( TERMY - 2 - iInfoHeight - VIEW_OFFSET_Y * 2,
width - 2, point( offsetX + 1, VIEW_OFFSET_Y + 1 ) );
w_items_border = catacurses::newwin( TERMY - iInfoHeight - VIEW_OFFSET_Y * 2,
width, point( offsetX, VIEW_OFFSET_Y ) );
w_items = catacurses::newwin( TERMY - 2 - iInfoHeight,
width - 2, point( offsetX + 1, 1 ) );
w_items_border = catacurses::newwin( TERMY - iInfoHeight,
width, point( offsetX, 0 ) );
w_item_info = catacurses::newwin( iInfoHeight, width,
point( offsetX, TERMY - iInfoHeight - VIEW_OFFSET_Y ) );
point( offsetX, TERMY - iInfoHeight ) );

if( activeItem ) {
centerlistview( active_pos, width );
}

ui.position( point( offsetX, VIEW_OFFSET_Y ), point( width, TERMY - VIEW_OFFSET_Y * 2 ) );
ui.position( point( offsetX, 0 ), point( width, TERMY ) );
} );
ui.mark_resize();

Expand Down Expand Up @@ -7427,7 +7411,7 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
info_data.handle_scrolling = true;

draw_item_info( [&]() -> catacurses::window {
return catacurses::newwin( TERMY - VIEW_OFFSET_Y * 2, width - 5, point_zero );
return catacurses::newwin( TERMY, width - 5, point_zero );
}, info_data );
} else if( action == "PRIORITY_INCREASE" ) {
filter_type = item_filter_type::HIGH_PRIORITY;
Expand Down Expand Up @@ -7629,23 +7613,23 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
if( hide_ui ) {
ui.position( point_zero, point_zero );
} else {
offsetX = TERMX - VIEW_OFFSET_X - width;
iMaxRows = TERMY - iInfoHeight - VIEW_OFFSET_Y * 2 - 1;
offsetX = TERMX - width;
iMaxRows = TERMY - iInfoHeight - 1;

w_monsters = catacurses::newwin( iMaxRows, width - 2, point( offsetX + 1,
VIEW_OFFSET_Y + 1 ) );
1 ) );
w_monsters_border = catacurses::newwin( iMaxRows + 1, width, point( offsetX,
VIEW_OFFSET_Y ) );
0 ) );
w_monster_info = catacurses::newwin( iInfoHeight - 2, width - 2,
point( offsetX + 1, TERMY - iInfoHeight - VIEW_OFFSET_Y + 1 ) );
point( offsetX + 1, TERMY - iInfoHeight + 1 ) );
w_monster_info_border = catacurses::newwin( iInfoHeight, width, point( offsetX,
TERMY - iInfoHeight - VIEW_OFFSET_Y ) );
TERMY - iInfoHeight ) );

if( cCurMon ) {
centerlistview( iActivePos, width );
}

ui.position( point( offsetX, VIEW_OFFSET_Y ), point( width, TERMY - VIEW_OFFSET_Y * 2 ) );
ui.position( point( offsetX, 0 ), point( width, TERMY ) );
}
} );
ui.mark_resize();
Expand Down
4 changes: 2 additions & 2 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,8 @@ void game_menus::inv::compare( player &p, const cata::optional<tripoint> &offset
catacurses::window w_cur_item_info;
ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
const int half_width = ( TERMX - VIEW_OFFSET_X * 2 ) / 2;
const int height = TERMY - VIEW_OFFSET_Y * 2;
const int half_width = TERMX / 2;
const int height = TERMY;
w_last_item_info = catacurses::newwin( height, half_width, point_zero );
w_cur_item_info = catacurses::newwin( height, half_width, point( half_width, 0 ) );
ui.position( point_zero, point( half_width * 2, height ) );
Expand Down
4 changes: 2 additions & 2 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,8 +1338,8 @@ cata::optional<tripoint> input_context::get_coordinates( const catacurses::windo
return cata::nullopt;
}
const point view_size( getmaxx( capture_win ), getmaxy( capture_win ) );
const point win_min( getbegx( capture_win ) - VIEW_OFFSET_X,
getbegy( capture_win ) - VIEW_OFFSET_Y );
const point win_min( getbegx( capture_win ),
getbegy( capture_win ) );
const rectangle win_bounds( win_min, win_min + view_size );
if( !win_bounds.contains_half_open( coordinate ) ) {
return cata::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ void inventory_selector::resize_window( int width, int height )
{
if( !w_inv || width != getmaxx( w_inv ) || height != getmaxy( w_inv ) ) {
w_inv = catacurses::newwin( height, width,
point( VIEW_OFFSET_X + ( TERMX - width ) / 2, VIEW_OFFSET_Y + ( TERMY - height ) / 2 ) );
point( ( TERMX - width ) / 2, ( TERMY - height ) / 2 ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ncurses_def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ input_event input_manager::get_input_event()
MEVENT event;
if( getmouse( &event ) == OK ) {
rval.type = CATA_INPUT_MOUSE;
rval.mouse_pos = point( event.x, event.y ) - point( VIEW_OFFSET_X, VIEW_OFFSET_Y );
rval.mouse_pos = point( event.x, event.y );
if( event.bstate & BUTTON1_CLICKED ) {
rval.add_input( MOUSE_BUTTON_LEFT );
} else if( event.bstate & BUTTON3_CLICKED ) {
Expand Down
11 changes: 2 additions & 9 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ int TERMX;
int TERMY;
int POSX;
int POSY;
int VIEW_OFFSET_X;
int VIEW_OFFSET_Y;
int TERRAIN_WINDOW_WIDTH;
int TERRAIN_WINDOW_HEIGHT;
int TERRAIN_WINDOW_TERM_WIDTH;
Expand Down Expand Up @@ -681,7 +679,7 @@ input_event draw_item_info( const int iLeft, const int iWidth, const int iTop, c
{
catacurses::window win =
catacurses::newwin( iHeight, iWidth,
point( iLeft + VIEW_OFFSET_X, iTop + VIEW_OFFSET_Y ) );
point( iLeft, iTop ) );

#if defined(TILES)
clear_window_area( win );
Expand Down Expand Up @@ -1468,13 +1466,8 @@ void calcStartPos( int &iStartPos, const int iCurrentLine, const int iContentHei
catacurses::window w_hit_animation;
void hit_animation( const point &p, nc_color cColor, const std::string &cTile )
{
/*
chtype chtOld = mvwinch(w, iY + VIEW_OFFSET_Y, iX + VIEW_OFFSET_X);
mvwputch(w, iY + VIEW_OFFSET_Y, iX + VIEW_OFFSET_X, cColor, cTile);
*/

catacurses::window w_hit =
catacurses::newwin( 1, 1, p + point( VIEW_OFFSET_X, VIEW_OFFSET_Y ) );
catacurses::newwin( 1, 1, p );
if( !w_hit ) {
return; //we passed in negative values (semi-expected), so let's not segfault
}
Expand Down
2 changes: 0 additions & 2 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ extern int TERMX; // width available for display
extern int TERMY; // height available for display
extern int POSX; // X position of '@' inside terrain window
extern int POSY; // Y position of '@' inside terrain window
extern int VIEW_OFFSET_X; // X position of terrain window
extern int VIEW_OFFSET_Y; // Y position of terrain window
extern int TERRAIN_WINDOW_WIDTH; // width of terrain window
extern int TERRAIN_WINDOW_HEIGHT; // height of terrain window
extern int TERRAIN_WINDOW_TERM_WIDTH; // width of terrain window in terminal characters
Expand Down
Loading

0 comments on commit 2b565c6

Please sign in to comment.