Panel now holds data on how it should be rendered and render just uses that instead of calculating it.

main
Zed A. Shaw 1 month ago
parent 1a3bbaedda
commit f79e7638c0
  1. 2
      panel.cpp
  2. 16
      panel.hpp
  3. 16
      render.cpp
  4. 3
      render.hpp
  5. 7
      status.txt

@ -16,7 +16,7 @@ void Panel::add(Component child) {
void Panel::render() {
$dirty = true;
if($must_clear) $screen.Clear();
if(must_clear) $screen.Clear();
Render($screen, $component->Render());
}

@ -6,9 +6,12 @@
#include <ftxui/dom/canvas.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/dom/canvas.hpp>
#include <SFML/Graphics/Color.hpp>
#include <locale>
#include <codecvt>
const int UI_PANEL_BORDER_PX=5;
using ftxui::Renderer, ftxui::Component, ftxui::Element, ftxui::Screen;
struct Panel {
@ -16,20 +19,25 @@ struct Panel {
int y;
int width;
int height;
std::wstring $screenout;
bool has_border = false;
bool must_clear = true;
sf::Color default_bg = sf::Color(0,0,0);
sf::Color border_color = sf::Color::Red;
int border_px = UI_PANEL_BORDER_PX;
bool $dirty = true;
Component $component;
Screen $screen;
bool $must_clear = true;
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) :
x(x),
y(y),
width(width),
height(height),
$screen(Screen(width, height)),
$must_clear(must_clear)
must_clear(must_clear),
$screen(Screen(width, height))
{
};

@ -216,18 +216,16 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star
}
}
void SFMLRender::draw_text(Panel &panel, bool with_border) {
int border_px = with_border ? UI_PANEL_BORDER_PX : 0;
void SFMLRender::draw_text(Panel &panel) {
sf::RectangleShape backing(
sf::Vector2f($ui_bounds.width * panel.width + border_px,
$ui_bounds.height * panel.height + border_px));
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
$ui_bounds.height * panel.height + panel.border_px));
backing.setFillColor(sf::Color(0, 0, 0));
backing.setFillColor(panel.default_bg);
if(with_border) {
backing.setOutlineColor(color(Value::MID));
backing.setOutlineThickness(border_px);
if(panel.has_border) {
backing.setOutlineColor(panel.border_color);
backing.setOutlineThickness(panel.border_px);
}
backing.setPosition(panel.x, panel.y);

@ -23,7 +23,6 @@ const int BASE_MAP_FONT_SIZE=90;
const wchar_t BG_TILE = L'';
const wchar_t UI_BASE_CHAR = L'';
const int BG_BOX_OFFSET=5;
const int UI_PANEL_BORDER_PX=5;
enum class Value {
BLACK=0, DARK_DARK, DARK_MID,
@ -59,7 +58,7 @@ 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, bool with_border=false);
void draw_text(Panel &panel);
void draw_grid(Panel &panel, float map_off_x=0.0f, float map_off_y=0.0f);
bool poll_event(sf::Event &event) {

@ -1,8 +1,13 @@
TODAY'S GOAL:
TODO:
* 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.
TODO:
* Keep panel unified by implementing border and backing on grids too.
* Can std::any be defaulted to a noop in the events?
* Save file isn't saving gold.
* Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold.

Loading…
Cancel
Save