Renderer now knows how to render panels as grid/text based on how the panel is configured.

main
Zed A. Shaw 2 weeks ago
parent f79e7638c0
commit 7cb03594a3
  1. 8
      gui.cpp
  2. 6
      panel.hpp
  3. 40
      render.cpp
  4. 4
      render.hpp
  5. 1
      status.txt

@ -33,7 +33,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
$game_map(game_map),
$log({{"Welcome to the game!"}}),
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
$map_view(0, 0, GAME_MAP_POS, 0, false),
$map_view(0, 0, GAME_MAP_POS, 0, true),
$view_port{0,0},
$world(world),
$sounds("./assets"),
@ -231,7 +231,7 @@ void GUI::shake() {
int x = Random::uniform<int>(-20,20);
int y = Random::uniform<int>(-20,20);
// add x/y back to draw screen
$renderer.draw_grid($map_view, x, y);
$renderer.draw($map_view, x, y);
$renderer.display();
std::this_thread::sleep_for(1ms);
}
@ -240,8 +240,8 @@ void GUI::shake() {
void GUI::render_scene() {
$renderer.clear();
$renderer.draw_text($status_ui);
$renderer.draw_grid($map_view);
$renderer.draw($status_ui);
$renderer.draw($map_view);
$renderer.display();
}

@ -21,6 +21,7 @@ struct Panel {
int height;
bool has_border = false;
bool must_clear = true;
bool grid = false;
sf::Color default_bg = sf::Color(0,0,0);
sf::Color border_color = sf::Color::Red;
int border_px = UI_PANEL_BORDER_PX;
@ -31,14 +32,15 @@ struct Panel {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
std::wstring $screenout;
Panel(int width, int height, int x, int y, bool must_clear=true) :
Panel(int width, int height, int x, int y, bool is_grid=false) :
x(x),
y(y),
width(width),
height(height),
must_clear(must_clear),
grid(is_grid),
$screen(Screen(width, height))
{
must_clear = !is_grid;
};
void resize(int width, int height);

@ -180,7 +180,7 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star
$ui_text.setFillColor($default_fg);
$ansi.parse(text,
[&](sf::Color fg, sf::Color bg){
[&](sf::Color fg, sf::Color bg) {
if(out.size() > 0 ) {
auto bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out);
x += bounds.width;
@ -216,28 +216,26 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star
}
}
void SFMLRender::draw_text(Panel &panel) {
sf::RectangleShape backing(
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
$ui_bounds.height * panel.height + panel.border_px));
backing.setFillColor(panel.default_bg);
void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
panel.render();
const std::wstring &panelout = panel.to_string();
if(panel.has_border) {
backing.setOutlineColor(panel.border_color);
backing.setOutlineThickness(panel.border_px);
}
if(panel.grid) {
render_grid(panelout, panel.x + x_offset, panel.y + y_offset);
} else {
sf::RectangleShape backing(
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
$ui_bounds.height * panel.height + panel.border_px));
backing.setPosition(panel.x, panel.y);
$window.draw(backing);
backing.setFillColor(panel.default_bg);
panel.render();
const std::wstring &panelout = panel.to_string();
render_text(panelout, panel.x, panel.y);
}
if(panel.has_border) {
backing.setOutlineColor(panel.border_color);
backing.setOutlineThickness(panel.border_px);
}
void SFMLRender::draw_grid(Panel &panel, float x, float y) {
panel.render();
const std::wstring &panelout = panel.to_string();
render_grid(panelout, panel.x + x, panel.y + y);
backing.setPosition(panel.x + x_offset, panel.y + y_offset);
$window.draw(backing);
render_text(panelout, panel.x, panel.y);
}
}

@ -58,8 +58,8 @@ struct SFMLRender {
bool resize_map(int new_size, Point &view_port);
void render_grid(const std::wstring &text, float x, float y);
void render_text(const std::wstring &text, float x, float y);
void draw_text(Panel &panel);
void draw_grid(Panel &panel, float map_off_x=0.0f, float map_off_y=0.0f);
void draw(Panel &panel, float x_offset=0.0f, float y_offset=0.0f);
bool poll_event(sf::Event &event) {
return $window.pollEvent(event);

@ -2,7 +2,6 @@ TODAY'S GOAL:
* Clean up renderer.
* panels and everything except renderer should use character coodinates
* panels should know if they're text vs. grid rendered
* Image -> Text converter.

Loading…
Cancel
Save