Skip to content

Commit

Permalink
Merge pull request #3 from softmoth/menu_forced_right
Browse files Browse the repository at this point in the history
renderer: Don't recenter viewport when sidebar changes sizes
  • Loading branch information
thurin authored May 12, 2022
2 parents 21b6c48 + be588af commit 850c1f1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
17 changes: 10 additions & 7 deletions commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ command_result multilevel_cmd (color_ostream &out, std::vector <std::string> & p

else if (param0 == "fogcolor" && pcnt >= 4)
{
float c[3];
float c[4];
bool ok = parse_float(parameters[1], c[0]) &&
parse_float(parameters[2], c[1]) &&
parse_float(parameters[3], c[2]);

if (ok)
{
c[3] = 0;
memcpy(fogcolor, c, sizeof(fogcolor));
}
else
return CR_WRONG_USAGE;
}
Expand Down Expand Up @@ -158,7 +161,7 @@ command_result twbt_cmd (color_ostream &out, std::vector <std::string> & paramet
r->gdispx++;
r->gdispy++;

r->needs_reshape = true;
r->needs_reshape = reshape_all;
}
else if (parameters[1] == "smaller")
{
Expand All @@ -167,7 +170,7 @@ command_result twbt_cmd (color_ostream &out, std::vector <std::string> & paramet
r->gdispx--;
r->gdispy--;

r->needs_reshape = true;
r->needs_reshape = reshape_all;
}
}

Expand All @@ -176,7 +179,7 @@ command_result twbt_cmd (color_ostream &out, std::vector <std::string> & paramet
r->gdispx = enabler->fullscreen ? small_map_dispx : large_map_dispx;
r->gdispy = enabler->fullscreen ? small_map_dispy : large_map_dispy;

r->needs_reshape = true;
r->needs_reshape = reshape_all;
}

else if (parameters[1][0] == '+' || parameters[1][0] == '-')
Expand All @@ -188,7 +191,7 @@ command_result twbt_cmd (color_ostream &out, std::vector <std::string> & paramet
r->gdispx += delta;
r->gdispy += delta;

r->needs_reshape = true;
r->needs_reshape = reshape_all;
}

else if (pcnt >= 3)
Expand All @@ -201,7 +204,7 @@ command_result twbt_cmd (color_ostream &out, std::vector <std::string> & paramet
{
r->gdispx = w;
r->gdispy = h;
r->needs_reshape = true;
r->needs_reshape = reshape_all;
}
else
return CR_WRONG_USAGE;
Expand Down Expand Up @@ -330,4 +333,4 @@ command_result colormap_cmd (color_ostream &out, std::vector <std::string> & par
}

return CR_OK;
}
}
2 changes: 1 addition & 1 deletion config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static bool load_overrides()
int idx = tilesets.size() - 1;
string n = (tokens.size() == 4) ?
tokens[3] :
static_cast<std::ostringstream*>(&(std::ostringstream() << idx))->str();
int_to_string(idx);
tilesetnames[n] = idx;
}

Expand Down
4 changes: 2 additions & 2 deletions dwarfmode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct dwarfmode_hook : public df::viewscreen_dwarfmodest
if (gmenu_w != menu_w_new)
{
gmenu_w = menu_w_new;
r->needs_reshape = true;
r->needs_reshape = reshape_sidebar;
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ struct dwarfmode_hook : public df::viewscreen_dwarfmodest
if (gmenu_w < 0)
{
gmenu_w = get_menu_width();
r->needs_reshape = true;
r->needs_reshape = reshape_sidebar;
}

r->reshape_zoom_swap();
Expand Down
22 changes: 13 additions & 9 deletions renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ static void write_tile_vertexes(GLfloat x, GLfloat y, GLfloat *vertex, float d)

renderer_cool::renderer_cool()
{
dummy = 'TWBT';
dummy = TWBT_MAGIC_IDENT;
gvertexes = 0, gfg = 0, gtex = 0;
gdimx = 0, gdimy = 0, gdimxfull = 0, gdimyfull = 0;
gdispx = 0, gdispy = 0;
goff_x = 0, goff_y = 0, gsize_x = 0, gsize_y = 0;
needs_reshape = needs_zoom = 0;
needs_reshape = reshape_none;
needs_zoom = 0;
map_cache = 0;
}

Expand Down Expand Up @@ -171,12 +172,16 @@ void renderer_cool::reshape_graphics()
if (df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws))
goff_y_gl = goff_y - (gdimy == gdimyfull ? 0 : roundf(gdispy - (gsize_y - gdispy * gdimyfull)));

*df::global::window_x = std::max(0, cx - gdimx / 2);
*df::global::window_y = std::max(0, cy - gdimy / 2);
if (needs_reshape == reshape_all)
{
*df::global::window_x = std::max(0, cx - gdimx / 2);
*df::global::window_y = std::max(0, cy - gdimy / 2);
}

int tiles = gdimx * gdimy;
init_buffers_and_coords(tiles, gdimy + 1);

needs_reshape = reshape_none;
needs_full_update = true;
}

Expand Down Expand Up @@ -685,11 +690,11 @@ void renderer_cool::reshape_zoom_swap()
static int game_mode = 3;
if (game_mode != *df::global::gamemode)
{
needs_reshape = true;
needs_reshape = reshape_all;
game_mode = *df::global::gamemode;
}

if (needs_reshape)
if (needs_reshape != reshape_none)
{
if (needs_zoom)
{
Expand All @@ -709,7 +714,6 @@ void renderer_cool::reshape_zoom_swap()
needs_zoom = 0;
}

needs_reshape = false;
reshape_graphics();
gps->force_full_display_count = 1;
DFHack::Gui::getCurViewscreen()->resize(gps->dimx, gps->dimy);
Expand Down Expand Up @@ -752,7 +756,7 @@ void renderer_cool::zoom(df::zoom_commands cmd)
return;
}

needs_reshape = true;
needs_reshape = reshape_all;
}

extern "C" {
Expand Down Expand Up @@ -780,4 +784,4 @@ bool renderer_cool::get_mouse_coords(int32_t *x, int32_t *y)
*y = _y;

return true;
}
}
13 changes: 11 additions & 2 deletions renderer_twbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ struct _renderer_opengl : public df::renderer
};
typedef _renderer_opengl renderer_opengl; // This is to make Linux happy

const uint32_t TWBT_MAGIC_IDENT = 0x54574254;

enum reshape_status
{
reshape_none,
reshape_sidebar,
reshape_all,
};

struct renderer_cool : renderer_opengl
{
uint32_t dummy;
Expand All @@ -30,7 +39,7 @@ struct renderer_cool : renderer_opengl
int gdimx, gdimy, gdimxfull, gdimyfull;
int gdispx, gdispy;
float goff_x, goff_y, gsize_x, gsize_y;
bool needs_reshape;
reshape_status needs_reshape;
int needs_zoom;
bool needs_full_update;
unsigned char *gscreen;
Expand Down Expand Up @@ -66,7 +75,7 @@ struct renderer_cool : renderer_opengl
virtual void _last_vmethod() {};

bool is_twbt() {
return (this->dummy == 'TWBT');
return (this->dummy == TWBT_MAGIC_IDENT);
};

void output_string(int8_t color, int x, int y, std::string str)
Expand Down
7 changes: 7 additions & 0 deletions twbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ struct tile_overrides {
bool has_material_overrides = false;
};

inline string int_to_string(const int n)
{
std::ostringstream ss;
ss << n;
return ss.str();
}

static struct tile_overrides *overrides[256];

long *text_texpos, *map_texpos;
Expand Down

0 comments on commit 850c1f1

Please sign in to comment.