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

main
Zed A. Shaw 6 days 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() { void Panel::render() {
$dirty = true; $dirty = true;
if($must_clear) $screen.Clear(); if(must_clear) $screen.Clear();
Render($screen, $component->Render()); Render($screen, $component->Render());
} }

@ -6,9 +6,12 @@
#include <ftxui/dom/canvas.hpp> #include <ftxui/dom/canvas.hpp>
#include <ftxui/screen/screen.hpp> #include <ftxui/screen/screen.hpp>
#include <ftxui/dom/canvas.hpp> #include <ftxui/dom/canvas.hpp>
#include <SFML/Graphics/Color.hpp>
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
const int UI_PANEL_BORDER_PX=5;
using ftxui::Renderer, ftxui::Component, ftxui::Element, ftxui::Screen; using ftxui::Renderer, ftxui::Component, ftxui::Element, ftxui::Screen;
struct Panel { struct Panel {
@ -16,20 +19,25 @@ struct Panel {
int y; int y;
int width; int width;
int height; 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; bool $dirty = true;
Component $component; Component $component;
Screen $screen; Screen $screen;
bool $must_clear = true;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter; 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 must_clear=true) :
x(x), x(x),
y(y), y(y),
width(width), width(width),
height(height), 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) { void SFMLRender::draw_text(Panel &panel) {
int border_px = with_border ? UI_PANEL_BORDER_PX : 0;
sf::RectangleShape backing( sf::RectangleShape backing(
sf::Vector2f($ui_bounds.width * panel.width + border_px, sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
$ui_bounds.height * panel.height + 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) { if(panel.has_border) {
backing.setOutlineColor(color(Value::MID)); backing.setOutlineColor(panel.border_color);
backing.setOutlineThickness(border_px); backing.setOutlineThickness(panel.border_px);
} }
backing.setPosition(panel.x, panel.y); 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 BG_TILE = L'';
const wchar_t UI_BASE_CHAR = L''; const wchar_t UI_BASE_CHAR = L'';
const int BG_BOX_OFFSET=5; const int BG_BOX_OFFSET=5;
const int UI_PANEL_BORDER_PX=5;
enum class Value { enum class Value {
BLACK=0, DARK_DARK, DARK_MID, BLACK=0, DARK_DARK, DARK_MID,
@ -59,7 +58,7 @@ struct SFMLRender {
bool resize_map(int new_size, Point &view_port); bool resize_map(int new_size, Point &view_port);
void render_grid(const std::wstring &text, float x, float y); void render_grid(const std::wstring &text, float x, float y);
void render_text(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); void draw_grid(Panel &panel, float map_off_x=0.0f, float map_off_y=0.0f);
bool poll_event(sf::Event &event) { bool poll_event(sf::Event &event) {

@ -1,8 +1,13 @@
TODAY'S GOAL: TODAY'S GOAL:
TODO: * Clean up renderer.
* panels and everything except renderer should use character coodinates * panels and everything except renderer should use character coodinates
* panels should know if they're text vs. grid rendered * 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? * Can std::any be defaulted to a noop in the events?
* Save file isn't saving gold. * 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. * Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold.

Loading…
Cancel
Save