Designer is working great now, and this fixes a bunch of things about the mouse.
This commit is contained in:
parent
f05f652c26
commit
ffc787df64
10 changed files with 4958 additions and 91 deletions
100
ansi_parser.cpp
100
ansi_parser.cpp
|
@ -20,85 +20,87 @@ static const char _ansi_parser_actions[] = {
|
|||
5, 1, 6, 1, 7, 1, 8, 1,
|
||||
9, 1, 10, 1, 11, 1, 15, 1,
|
||||
16, 2, 1, 12, 2, 1, 13, 2,
|
||||
16, 5, 3, 1, 14, 2
|
||||
6, 7, 2, 16, 5, 3, 1, 14,
|
||||
2
|
||||
};
|
||||
|
||||
static const char _ansi_parser_key_offsets[] = {
|
||||
0, 0, 1, 2, 10, 11, 13, 16,
|
||||
20, 21, 25, 26, 27, 28, 29, 31,
|
||||
34, 36, 39, 41, 44, 45, 48, 49,
|
||||
50, 51, 52, 53
|
||||
0, 0, 1, 2, 11, 12, 14, 17,
|
||||
18, 22, 23, 27, 28, 29, 30, 31,
|
||||
33, 36, 38, 41, 43, 46, 47, 50,
|
||||
51, 52, 53, 54, 55
|
||||
};
|
||||
|
||||
static const int _ansi_parser_trans_keys[] = {
|
||||
27, 91, 49, 50, 51, 52, 55, 57,
|
||||
48, 54, 109, 48, 109, 34, 48, 55,
|
||||
50, 52, 55, 109, 109, 49, 56, 57,
|
||||
109, 109, 59, 50, 59, 48, 57, 59,
|
||||
48, 57, 48, 57, 59, 48, 57, 48,
|
||||
57, 109, 48, 57, 109, 56, 57, 109,
|
||||
59, 50, 109, 109, 27, 27, 0
|
||||
27, 91, 48, 49, 50, 51, 52, 55,
|
||||
57, 53, 54, 109, 48, 109, 34, 48,
|
||||
55, 109, 50, 52, 55, 109, 109, 49,
|
||||
56, 57, 109, 109, 59, 50, 59, 48,
|
||||
57, 59, 48, 57, 48, 57, 59, 48,
|
||||
57, 48, 57, 109, 48, 57, 109, 56,
|
||||
57, 109, 59, 50, 109, 109, 27, 27,
|
||||
0
|
||||
};
|
||||
|
||||
static const char _ansi_parser_single_lengths[] = {
|
||||
0, 1, 1, 6, 1, 2, 3, 4,
|
||||
1, 4, 1, 1, 1, 1, 0, 1,
|
||||
0, 1, 0, 1, 1, 3, 1, 1,
|
||||
1, 1, 1, 1
|
||||
0, 1, 1, 7, 1, 2, 3, 1,
|
||||
4, 1, 4, 1, 1, 1, 1, 0,
|
||||
1, 0, 1, 0, 1, 1, 3, 1,
|
||||
1, 1, 1, 1, 1
|
||||
};
|
||||
|
||||
static const char _ansi_parser_range_lengths[] = {
|
||||
0, 0, 0, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1,
|
||||
1, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
0, 0, 0, 0, 0, 0, 0, 1,
|
||||
1, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static const char _ansi_parser_index_offsets[] = {
|
||||
0, 0, 2, 4, 12, 14, 17, 21,
|
||||
26, 28, 33, 35, 37, 39, 41, 43,
|
||||
46, 48, 51, 53, 56, 58, 62, 64,
|
||||
66, 68, 70, 72
|
||||
0, 0, 2, 4, 13, 15, 18, 22,
|
||||
24, 29, 31, 36, 38, 40, 42, 44,
|
||||
46, 49, 51, 54, 56, 59, 61, 65,
|
||||
67, 69, 71, 73, 75
|
||||
};
|
||||
|
||||
static const char _ansi_parser_trans_targs[] = {
|
||||
2, 1, 3, 0, 5, 7, 9, 21,
|
||||
25, 6, 4, 0, 27, 0, 6, 27,
|
||||
0, 4, 4, 4, 0, 4, 4, 8,
|
||||
27, 0, 27, 0, 10, 11, 20, 27,
|
||||
0, 27, 0, 12, 0, 13, 0, 14,
|
||||
0, 15, 0, 16, 15, 0, 17, 0,
|
||||
18, 17, 0, 19, 0, 27, 19, 0,
|
||||
27, 0, 22, 24, 27, 0, 23, 0,
|
||||
13, 0, 27, 0, 27, 0, 2, 1,
|
||||
2, 1, 0
|
||||
2, 1, 3, 0, 4, 5, 8, 10,
|
||||
22, 26, 6, 7, 0, 28, 0, 6,
|
||||
28, 0, 7, 7, 7, 0, 28, 0,
|
||||
7, 7, 9, 28, 0, 28, 0, 11,
|
||||
12, 21, 28, 0, 28, 0, 13, 0,
|
||||
14, 0, 15, 0, 16, 0, 17, 16,
|
||||
0, 18, 0, 19, 18, 0, 20, 0,
|
||||
28, 20, 0, 28, 0, 23, 25, 28,
|
||||
0, 24, 0, 14, 0, 28, 0, 28,
|
||||
0, 2, 1, 2, 1, 0
|
||||
};
|
||||
|
||||
static const char _ansi_parser_trans_actions[] = {
|
||||
0, 7, 0, 0, 21, 21, 21, 21,
|
||||
21, 21, 21, 0, 0, 0, 0, 0,
|
||||
21, 21, 21, 21, 0, 31, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
17, 0, 15, 0, 0, 0, 0, 0,
|
||||
0, 19, 0, 0, 0, 3, 0, 0,
|
||||
0, 1, 0, 25, 0, 0, 1, 0,
|
||||
28, 0, 0, 1, 0, 34, 0, 0,
|
||||
9, 0, 0, 0, 0, 0, 0, 0,
|
||||
5, 0, 11, 0, 13, 0, 0, 7,
|
||||
23, 31, 0
|
||||
0, 0, 0, 17, 0, 15, 0, 0,
|
||||
0, 0, 0, 0, 19, 0, 0, 0,
|
||||
3, 0, 0, 0, 1, 0, 25, 0,
|
||||
0, 1, 0, 28, 0, 0, 1, 0,
|
||||
37, 0, 0, 9, 0, 0, 0, 0,
|
||||
0, 0, 0, 5, 0, 11, 0, 13,
|
||||
0, 0, 7, 23, 34, 0
|
||||
};
|
||||
|
||||
static const char _ansi_parser_eof_actions[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 23
|
||||
0, 0, 0, 0, 23
|
||||
};
|
||||
|
||||
static const int ansi_parser_start = 26;
|
||||
static const int ansi_parser_first_final = 26;
|
||||
static const int ansi_parser_start = 27;
|
||||
static const int ansi_parser_first_final = 27;
|
||||
static const int ansi_parser_error = 0;
|
||||
|
||||
static const int ansi_parser_en_main = 26;
|
||||
static const int ansi_parser_en_main = 27;
|
||||
|
||||
|
||||
#line 125 "ansi_parser.rl"
|
||||
|
@ -123,14 +125,14 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
|||
sf::Color* target = &color;
|
||||
|
||||
|
||||
#line 118 "ansi_parser.cpp"
|
||||
#line 120 "ansi_parser.cpp"
|
||||
{
|
||||
cs = ansi_parser_start;
|
||||
}
|
||||
|
||||
#line 146 "ansi_parser.rl"
|
||||
|
||||
#line 121 "ansi_parser.cpp"
|
||||
#line 123 "ansi_parser.cpp"
|
||||
{
|
||||
int _klen;
|
||||
unsigned int _trans;
|
||||
|
@ -321,7 +323,7 @@ _match:
|
|||
#line 85 "ansi_parser.rl"
|
||||
{}
|
||||
break;
|
||||
#line 294 "ansi_parser.cpp"
|
||||
#line 296 "ansi_parser.cpp"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,7 +343,7 @@ _again:
|
|||
#line 85 "ansi_parser.rl"
|
||||
{}
|
||||
break;
|
||||
#line 312 "ansi_parser.cpp"
|
||||
#line 314 "ansi_parser.cpp"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ using namespace fmt;
|
|||
start %start
|
||||
(
|
||||
reset |
|
||||
"0" |
|
||||
"0" %reset_fg %reset_bg |
|
||||
"1" |
|
||||
"2" %half_bright |
|
||||
"3" |
|
||||
|
|
4830
assets/fontlist.json
Normal file
4830
assets/fontlist.json
Normal file
File diff suppressed because it is too large
Load diff
12
gui.cpp
12
gui.cpp
|
@ -178,6 +178,7 @@ bool GUI::handle_ui_events() {
|
|||
auto player = $world.get_the<Player>();
|
||||
int map_font_size = $renderer.font_size();
|
||||
auto& player_motion = $world.get<Motion>(player.entity);
|
||||
Point pos;
|
||||
|
||||
while($renderer.poll_event(event)) {
|
||||
if(event.type == sf::Event::Closed) {
|
||||
|
@ -203,15 +204,16 @@ bool GUI::handle_ui_events() {
|
|||
} else if(KB::isKeyPressed(KB::S)) {
|
||||
save_world();
|
||||
} else if(KB::isKeyPressed(KB::Tab)) {
|
||||
$status_ui.$component->OnEvent(Event::Tab);
|
||||
$status_ui.key_press(Event::Tab);
|
||||
} else if(KB::isKeyPressed(KB::Enter)) {
|
||||
$status_ui.$component->OnEvent(Event::Return);
|
||||
$status_ui.key_press(Event::Return);
|
||||
}
|
||||
} else if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
||||
Point pos;
|
||||
if($renderer.mouse_position($status_ui, pos)) {
|
||||
} else if($renderer.mouse_position($status_ui, pos)) {
|
||||
if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
||||
$status_ui.mouse_click(Mouse::Button::Left, pos);
|
||||
event_happened = true;
|
||||
} else {
|
||||
$status_ui.mouse_release(Mouse::Button::Left, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
16
panel.cpp
16
panel.cpp
|
@ -38,13 +38,27 @@ const std::wstring& Panel::to_string() {
|
|||
void Panel::mouse_click(ftxui::Mouse::Button btn, Point pos) {
|
||||
ftxui::Mouse mev{
|
||||
.button=btn,
|
||||
.motion=ftxui::Mouse::Motion::Pressed,
|
||||
.x=int(pos.x), .y=int(pos.y)
|
||||
};
|
||||
|
||||
$component->OnEvent(ftxui::Event::Mouse("", mev));
|
||||
}
|
||||
|
||||
void Panel::mouse_release(ftxui::Mouse::Button btn, Point pos) {
|
||||
ftxui::Mouse mev{
|
||||
.button=btn,
|
||||
.motion=ftxui::Mouse::Motion::Released,
|
||||
.x=int(pos.x), .y=int(pos.y)
|
||||
};
|
||||
|
||||
const Screen &Panel::screen() {
|
||||
$component->OnEvent(ftxui::Event::Mouse("", mev));
|
||||
}
|
||||
|
||||
const Screen& Panel::screen() {
|
||||
return $screen;
|
||||
}
|
||||
|
||||
void Panel::key_press(ftxui::Event event) {
|
||||
$component->OnEvent(event);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ struct Panel {
|
|||
void add(Component child);
|
||||
void render();
|
||||
void mouse_click(ftxui::Mouse::Button btn, Point pos);
|
||||
void mouse_release(ftxui::Mouse::Button btn, Point pos);
|
||||
void key_press(ftxui::Event event);
|
||||
const std::wstring &to_string();
|
||||
const Screen &screen();
|
||||
};
|
||||
|
|
|
@ -239,9 +239,6 @@ bool SFMLRender::mouse_position(Panel &panel, Point &out) {
|
|||
|
||||
auto bounds = panel.grid ? $grid_bounds : $text_bounds;
|
||||
|
||||
println("mouse position pos={},{} panel.pos={},{} panel.size={},{}",
|
||||
pos.x, pos.y, panel.x, panel.y, panel.width, panel.height);
|
||||
|
||||
if(pos.x >= panel.x && pos.y >= panel.y
|
||||
&& pos.x <= (panel.x + panel.width * bounds.width)
|
||||
&& pos.y <= (panel.y + panel.height * bounds.height))
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
TODAY'S GOAL:
|
||||
|
||||
0. \ua3fd causes the character immediately after to vanish.
|
||||
-1. Learn std::initializer_list by using it.
|
||||
0. \ua3fd causes the character immediately after to vanish. Make a test and solve it.
|
||||
1. Why do Sliders only have to be kept around forever and can't go in containers like everything else?
|
||||
2. Why are sliders not selected when I click on them? Is it a hover?
|
||||
3. Why do fonts render blank? Also when I scroll they slowly disappear until there's a column.
|
||||
* \u2738 is missing on the row when in grid but works when clicked.
|
||||
|
||||
|
||||
* A designer tool to help find characters for foreground, background, and figure out their colors.
|
||||
|
||||
* renderer's mouse coordinates are totally wrong. Need to put glyph bounds into the panel and then you can ask if a mouse click is on a panel, and what the _panel's_ coordinates are.
|
||||
|
@ -14,7 +16,9 @@ TODAY'S GOAL:
|
|||
|
||||
TODO:
|
||||
|
||||
* Make a unicode helper.
|
||||
* Refine the event handling to pass most of them to the gui panels and then I can intercept them.
|
||||
|
||||
* Resolve fmt::format vs std::format.
|
||||
|
||||
* Fix " room should always be found"
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace fmt;
|
||||
|
@ -39,19 +40,23 @@ struct FontGrid {
|
|||
size_t width;
|
||||
size_t height;
|
||||
vector<vector<FontGridCell>> $grid;
|
||||
string $font_list;
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
vector<wstring> $wcharmap;
|
||||
vector<string> $charmap;
|
||||
|
||||
FontGrid(size_t width, size_t height) :
|
||||
FontGrid(string font_list, size_t width, size_t height) :
|
||||
width(width), height(height),
|
||||
$grid(height, vector<FontGridCell>(width, {0, "", L""}))
|
||||
$grid(height, vector<FontGridCell>(width, {0, "", L""})),
|
||||
$font_list(font_list)
|
||||
{
|
||||
configure_font();
|
||||
}
|
||||
|
||||
void configure_font() {
|
||||
std::ifstream in_file("./fontlist.json");
|
||||
dbc::check(fs::exists($font_list), format("font listing {} does not exist", $font_list));
|
||||
|
||||
std::ifstream in_file($font_list);
|
||||
json input = json::parse(in_file);
|
||||
|
||||
for(auto inchar : input) {
|
||||
|
@ -120,7 +125,6 @@ struct WhatTheColor {
|
|||
|
||||
class GUI {
|
||||
public:
|
||||
DinkyECS::World& $world;
|
||||
Panel $font_view;
|
||||
Panel $status_ui;
|
||||
Canvas $canvas;
|
||||
|
@ -133,11 +137,10 @@ class GUI {
|
|||
Component $fg_settings;
|
||||
Component $bg_settings;
|
||||
|
||||
GUI(DinkyECS::World &world) :
|
||||
$world(world),
|
||||
GUI(string font_list) :
|
||||
$font_view(GAME_MAP_POS, 0, GRID_SIZE.x, GRID_SIZE.y, true),
|
||||
$status_ui(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
|
||||
$font_grid(GRID_SIZE.x, GRID_SIZE.y),
|
||||
$font_grid(font_list, GRID_SIZE.x, GRID_SIZE.y),
|
||||
$fg_color{.h=20, .s=50, .v=20},
|
||||
$bg_color{.h=100, .s=100, .v=100}
|
||||
{
|
||||
|
@ -157,12 +160,11 @@ class GUI {
|
|||
}
|
||||
|
||||
void draw_font_grid() {
|
||||
int flip_it = 0;
|
||||
for(size_t y = 0; y < $font_grid.height; y++) {
|
||||
for(size_t x = 0; x < $font_grid.width; x++, flip_it++) {
|
||||
for(size_t x = 0; x < $font_grid.width; x++) {
|
||||
$canvas.DrawText(x * 2, y * 4, $font_grid.as_string(x, y), [&](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV($fg_color.h, $fg_color.s, $fg_color.v / (flip_it % 2 + 1));
|
||||
pixel.background_color = Color::HSV($bg_color.h, $bg_color.s, $bg_color.v / (flip_it % 2 + 1));
|
||||
pixel.foreground_color = Color::HSV($fg_color.h, $fg_color.s, $fg_color.v);
|
||||
pixel.background_color = Color::HSV($bg_color.h, $bg_color.s, $bg_color.v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -238,6 +240,7 @@ class GUI {
|
|||
bool event_happened;
|
||||
using KB = sf::Keyboard;
|
||||
sf::Event event;
|
||||
Point pos;
|
||||
int font_size = $renderer.font_size();
|
||||
int page_size = $font_grid.page_size();
|
||||
|
||||
|
@ -255,23 +258,30 @@ class GUI {
|
|||
$start_char = std::min($font_grid.max_chars() - page_size, $start_char + page_size);
|
||||
render_grid($start_char, false);
|
||||
$renderer.clear_cache();
|
||||
} else if(KB::isKeyPressed(KB::Tab)) {
|
||||
$status_ui.key_press(Event::Tab);
|
||||
} else if(KB::isKeyPressed(KB::Tab)) {
|
||||
$status_ui.key_press(Event::Return);
|
||||
} else if(KB::isKeyPressed(KB::Equal)) {
|
||||
resize_fonts(font_size + 10);
|
||||
} else if(KB::isKeyPressed(KB::Hyphen)) {
|
||||
resize_fonts(font_size - 10);
|
||||
event_happened = true;
|
||||
}
|
||||
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||
Point pos;
|
||||
if($renderer.mouse_position($font_view, pos)) {
|
||||
} else if($renderer.mouse_position($font_view, pos)) {
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||
select_cell(pos);
|
||||
event_happened = true;
|
||||
} else if($renderer.mouse_position($status_ui, pos)) {
|
||||
$status_ui.mouse_click(Mouse::Button::Left, pos);
|
||||
}
|
||||
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
||||
deselect_cell();
|
||||
}
|
||||
} else if($renderer.mouse_position($status_ui, pos)) {
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||
$status_ui.mouse_click(Mouse::Button::Left, pos);
|
||||
} else if(event.type == sf::Event::MouseMoved) {
|
||||
$status_ui.mouse_release(Mouse::Button::Left, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event_happened;
|
||||
|
@ -291,9 +301,12 @@ class GUI {
|
|||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
DinkyECS::World world;
|
||||
try {
|
||||
dbc::check(argc == 2, "USAGE: designer fontlist.json");
|
||||
|
||||
GUI gui(world);
|
||||
string font_list{argv[1]};
|
||||
|
||||
GUI gui(font_list);
|
||||
|
||||
gui.create_renderer();
|
||||
|
||||
|
@ -307,4 +320,7 @@ int main(int argc, char *argv[]) {
|
|||
} while(gui.$renderer.is_open());
|
||||
|
||||
return 0;
|
||||
} catch(const dbc::Error &e) {
|
||||
println("ERROR: {}", e.message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#include <iostream>
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <thread> // for sleep_for
|
||||
#include "dbc.hpp"
|
||||
#include <filesystem>
|
||||
#include <fcntl.h>
|
||||
#include "constants.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
@ -16,6 +14,8 @@
|
|||
#include FT_FREETYPE_H
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
#include FT_TRUETYPE_IDS_H
|
||||
#include "dbc.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace fmt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue