|
|
|
@ -52,12 +52,20 @@ struct FontGrid { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string from_unicode(wstring input) { |
|
|
|
|
try { |
|
|
|
|
return $converter.to_bytes(input); |
|
|
|
|
} catch(...) { |
|
|
|
|
return "?"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wchar_t to_unicode_char(size_t x, size_t y) { |
|
|
|
|
string input = $chars[y][x]; |
|
|
|
|
try { |
|
|
|
|
string input = $chars[y][x]; // BUG: bounds check this instead
|
|
|
|
|
return $converter.from_bytes(input)[0]; |
|
|
|
|
} catch(...) { |
|
|
|
|
return L'?'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string at(size_t x, size_t y) { |
|
|
|
@ -87,7 +95,7 @@ class GUI { |
|
|
|
|
Canvas $canvas; |
|
|
|
|
SFMLRender $renderer; |
|
|
|
|
FontGrid $font_grid; |
|
|
|
|
wchar_t $start_char = L'\ua66b'; |
|
|
|
|
wchar_t $start_char = L'\u28cc'; |
|
|
|
|
wchar_t $fill_char = WCHAR_MIN; |
|
|
|
|
WhatTheColor $fg_color; |
|
|
|
|
WhatTheColor $bg_color; |
|
|
|
@ -143,7 +151,7 @@ class GUI { |
|
|
|
|
return hbox({ |
|
|
|
|
hflow( |
|
|
|
|
vbox( |
|
|
|
|
text(format("\\u{:x}", int($fill_char))) | border, |
|
|
|
|
text(format("\\u{:x} {} MIN: {}, MAX: {}", int($fill_char), int($fill_char), WCHAR_MIN, WCHAR_MAX)) | border, |
|
|
|
|
separator(), |
|
|
|
|
text(format("FG H: {}, S: {}, V: {}", |
|
|
|
|
$fg_color.h, $fg_color.s, $fg_color.v)) | border, |
|
|
|
@ -191,7 +199,6 @@ class GUI { |
|
|
|
|
bool handle_ui_events() { |
|
|
|
|
bool event_happened; |
|
|
|
|
using KB = sf::Keyboard; |
|
|
|
|
using MOUSE = sf::Mouse; |
|
|
|
|
sf::Event event; |
|
|
|
|
int font_size = $renderer.font_size(); |
|
|
|
|
|
|
|
|
@ -200,21 +207,22 @@ class GUI { |
|
|
|
|
shutdown(); |
|
|
|
|
return true; |
|
|
|
|
} else if(event.type == sf::Event::KeyPressed) { |
|
|
|
|
println("KEY PRESSED"); |
|
|
|
|
if(KB::isKeyPressed(KB::Up)) { |
|
|
|
|
$start_char = std::min(WCHAR_MAX, $start_char + $font_grid.page_size()); |
|
|
|
|
$start_char = std::max(WCHAR_MIN+1, $start_char - $font_grid.page_size()); |
|
|
|
|
$font_grid.render($start_char, false); |
|
|
|
|
event_happened = true; |
|
|
|
|
$renderer.clear_cache(); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Down)) { |
|
|
|
|
$start_char = std::max(WCHAR_MIN+1, $start_char - $font_grid.page_size()); |
|
|
|
|
$start_char = std::min(WCHAR_MAX, $start_char + $font_grid.page_size()); |
|
|
|
|
$font_grid.render($start_char, false); |
|
|
|
|
$renderer.clear_cache(); |
|
|
|
|
} 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(MOUSE::isButtonPressed(MOUSE::Left)) { |
|
|
|
|
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { |
|
|
|
|
Point pos; |
|
|
|
|
if($renderer.mouse_position($font_view, pos)) { |
|
|
|
|
select_cell(pos); |
|
|
|
@ -222,6 +230,8 @@ class GUI { |
|
|
|
|
} 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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|