Add CMakeLists.txt

Fix warnings related to -Weffc++.

Format with clang-format.
This commit is contained in:
Stephen Seo 2023-12-14 20:16:09 +09:00
parent c4f9a01b7f
commit a43f83d7d5
5 changed files with 309 additions and 218 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/objects/
/.cache/
/compile_commands.json
/build*/

39
CMakeLists.txt Normal file
View file

@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.22.1)
project(DvorakTypingPractice)
set(DvorakTypingPractice_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/screen.cc"
)
set(DvorakTypingPractice_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/screen.h"
)
add_executable(DvorakTypingPractice ${DvorakTypingPractice_SOURCES})
find_package(raylib REQUIRED)
target_include_directories(DvorakTypingPractice PUBLIC ${raylib_INCLUDE_DIRS})
target_link_libraries(DvorakTypingPractice PUBLIC ${raylib_LIBRARIES})
target_compile_options(DvorakTypingPractice PUBLIC
-Wall -Wextra -Wpedantic
$<$<COMPILE_LANGUAGE:CXX>:-Weffc++>
$<$<CONFIG:DEBUG>:-Og>
)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug', none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
if(EXISTS /usr/bin/clang-format)
add_custom_target(
ClangFormatTarget
COMMAND clang-format -i --style=google ${DvorakTypingPractice_SOURCES} ${DvorakTypingPractice_HEADERS}
)
add_dependencies(DvorakTypingPractice ClangFormatTarget)
message(STATUS "Enabled clang-format formatting.")
endif()

View file

@ -1,7 +1,7 @@
// Standard library includes
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
// Third party includes
#include <raylib.h>
@ -10,58 +10,59 @@
#include "screen.h"
std::string get_next_word(std::istream *i) {
std::string word;
while (i->good()) {
int in = i->get();
if (in != std::char_traits<char>::eof() && in != ' ' && in != '\n' && in != '\r') {
word.push_back((char)in);
} else if (in == ' '|| in == '\n' || in == '\r' || in == '\t') {
if (!word.empty()) {
break;
} else {
continue;
}
}
std::string word;
while (i->good()) {
int in = i->get();
if (in != std::char_traits<char>::eof() && in != ' ' && in != '\n' &&
in != '\r') {
word.push_back((char)in);
} else if (in == ' ' || in == '\n' || in == '\r' || in == '\t') {
if (!word.empty()) {
break;
} else {
continue;
}
}
}
return word;
return word;
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Expected 1 arg input filename!\n";
return 1;
}
if (argc != 2) {
std::cout << "Expected 1 arg input filename!\n";
return 1;
}
std::ifstream ifs(argv[1]);
std::ifstream ifs(argv[1]);
if (!ifs.good()) {
std::cout << "ERROR: Failed to open file \"" << argv[1] << "\"!\n";
return 2;
}
if (!ifs.good()) {
std::cout << "ERROR: Failed to open file \"" << argv[1] << "\"!\n";
return 2;
}
InitWindow(900, 400, "Dvorak Typing Practice");
SetTargetFPS(15);
InitWindow(900, 400, "Dvorak Typing Practice");
SetTargetFPS(15);
{
Screen screen{};
{
Screen screen{};
std::string word;
std::string word;
do {
word = get_next_word(&ifs);
if (!word.empty()) {
screen.set_word(word);
while (!screen.update() && !WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
screen.draw();
EndDrawing();
}
}
} while (!ifs.eof() && !WindowShouldClose());
}
do {
word = get_next_word(&ifs);
if (!word.empty()) {
screen.set_word(word);
while (!screen.update() && !WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
screen.draw();
EndDrawing();
}
}
} while (!ifs.eof() && !WindowShouldClose());
}
CloseWindow();
return 0;
CloseWindow();
return 0;
}

View file

@ -1,275 +1,326 @@
#include "screen.h"
#include <raylib.h>
Screen::Screen() :
prev(),
word(),
word_center{0, 0},
keyboard(LoadTexture("dvorak_keyboard.png")),
idx(0)
{
flags.set(0);
Screen::Screen()
: prev(),
word(),
word_pre(),
word_post(),
word_center{0, 0},
keyboard(LoadTexture("dvorak_keyboard.png")),
idx(0),
flags() {
flags.set(0);
}
Screen::~Screen() {
UnloadTexture(keyboard);
}
Screen::~Screen() { UnloadTexture(keyboard); }
void Screen::set_word(std::string s) {
prev = word;
word = s;
idx = 0;
word_pre.clear();
word_post.clear();
word_center[0] = s.at(0);
flags.set(0);
prev = word;
word = s;
idx = 0;
word_pre.clear();
word_post.clear();
word_center[0] = s.at(0);
flags.set(0);
}
bool Screen::update() {
int input = GetCharPressed();
if (input == word_center[0]) {
++idx;
flags.set(0);
if (idx >= word.size()) {
return true;
}
int input = GetCharPressed();
if (input == word_center[0]) {
++idx;
flags.set(0);
if (idx >= word.size()) {
return true;
}
}
return false;
return false;
}
void Screen::draw() {
DrawTexture(keyboard, 0, 0, WHITE);
if (flags.test(0)) {
flags.reset(0);
DrawTexture(keyboard, 0, 0, WHITE);
if (flags.test(0)) {
flags.reset(0);
if (idx > 0) {
word_pre = word.substr(0, idx);
} else {
word_pre.clear();
}
if (idx < word.size()) {
word_post = word.substr(idx + 1, word.size() - idx - 1);
} else {
word_post.clear();
}
word_center[0] = word.at(idx);
if (idx > 0) {
word_pre = word.substr(0, idx);
} else {
word_pre.clear();
}
int offset = 0;
if (!prev.empty()) {
DrawText(prev.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, GRAY);
offset += MeasureText(prev.c_str(), FONT_SIZE) + PREV_OFFSET;
if (idx < word.size()) {
word_post = word.substr(idx + 1, word.size() - idx - 1);
} else {
word_post.clear();
}
if (!word_pre.empty()) {
DrawText(word_pre.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, WHITE);
offset += MeasureText(word_pre.c_str(), FONT_SIZE) + CENTER_X_OFFSET;
}
word_center[0] = word.at(idx);
}
DrawText(word_center.data(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, GREEN);
offset += MeasureText(word_center.data(), FONT_SIZE) + CENTER_X_OFFSET;
int offset = 0;
if (!prev.empty()) {
DrawText(prev.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, GRAY);
offset += MeasureText(prev.c_str(), FONT_SIZE) + PREV_OFFSET;
}
if (!word_post.empty()) {
DrawText(word_post.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, WHITE);
}
if (!word_pre.empty()) {
DrawText(word_pre.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE,
WHITE);
offset += MeasureText(word_pre.c_str(), FONT_SIZE) + CENTER_X_OFFSET;
}
draw_overlay(word_center[0]);
DrawText(word_center.data(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE,
GREEN);
offset += MeasureText(word_center.data(), FONT_SIZE) + CENTER_X_OFFSET;
if (!word_post.empty()) {
DrawText(word_post.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE,
WHITE);
}
draw_overlay(word_center[0]);
}
void Screen::draw_overlay(char c) {
switch (c) {
switch (c) {
case '`':
case '~':
DrawCircle(1 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(1 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '1':
case '!':
DrawCircle(61 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(61 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '2':
case '@':
DrawCircle(121 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(121 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '3':
case '#':
DrawCircle(181 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(181 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '4':
case '$':
DrawCircle(241 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(241 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '5':
case '%':
DrawCircle(301 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(301 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '6':
case '^':
DrawCircle(361 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(361 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '7':
case '&':
DrawCircle(421 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(421 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '8':
case '*':
DrawCircle(481 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(481 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '9':
case '(':
DrawCircle(541 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(541 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '0':
case ')':
DrawCircle(601 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(601 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '{':
case '[':
DrawCircle(661 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(661 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '}':
case ']':
DrawCircle(721 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(721 + KEY_HALF_SIZE, 1 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '\'':
case '"':
DrawCircle(91 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(91 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '<':
case ',':
DrawCircle(151 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(151 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '>':
case '.':
DrawCircle(211 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(211 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'P':
case 'p':
DrawCircle(271 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(271 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'Y':
case 'y':
DrawCircle(331 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(331 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'F':
case 'f':
DrawCircle(391 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(391 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'G':
case 'g':
DrawCircle(451 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(451 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'C':
case 'c':
DrawCircle(511 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(511 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'R':
case 'r':
DrawCircle(571 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(571 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'L':
case 'l':
DrawCircle(631 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(631 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '?':
case '/':
DrawCircle(691 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(691 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '+':
case '=':
DrawCircle(751 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(751 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '|':
case '\\':
DrawCircle(811 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(811 + KEY_HALF_SIZE, 61 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'A':
case 'a':
DrawCircle(106 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(106 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'O':
case 'o':
DrawCircle(166 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(166 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'E':
case 'e':
DrawCircle(226 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(226 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'U':
case 'u':
DrawCircle(286 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(286 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'I':
case 'i':
DrawCircle(346 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(346 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'D':
case 'd':
DrawCircle(406 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(406 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'H':
case 'h':
DrawCircle(466 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(466 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'T':
case 't':
DrawCircle(526 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(526 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'N':
case 'n':
DrawCircle(586 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(586 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'S':
case 's':
DrawCircle(646 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(646 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case '_':
case '-':
DrawCircle(706 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(706 + KEY_HALF_SIZE, 121 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case ':':
case ';':
DrawCircle(136 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(136 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'Q':
case 'q':
DrawCircle(196 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(196 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'J':
case 'j':
DrawCircle(256 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(256 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'K':
case 'k':
DrawCircle(316 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(316 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'X':
case 'x':
DrawCircle(376 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(376 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'B':
case 'b':
DrawCircle(436 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(436 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'M':
case 'm':
DrawCircle(496 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(496 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'W':
case 'w':
DrawCircle(556 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(556 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'V':
case 'v':
DrawCircle(616 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(616 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
case 'Z':
case 'z':
DrawCircle(676 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
break;
DrawCircle(676 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE,
KEY_HIGHLIGHT_COLOR);
break;
default:
break;
}
break;
}
}

View file

@ -20,31 +20,30 @@ constexpr int KEY_HALF_SIZE = 29;
constexpr Color KEY_HIGHLIGHT_COLOR = Color{255, 255, 0, 127};
class Screen {
public:
Screen();
~Screen();
public:
Screen();
~Screen();
void set_word(std::string s);
void set_word(std::string s);
// True if finished with word.
bool update();
void draw();
// True if finished with word.
bool update();
void draw();
private:
std::string prev;
std::string word;
std::string word_pre;
std::string word_post;
std::array<char, 2> word_center;
Texture2D keyboard;
unsigned int idx;
/*
* 0 - cached word data is dirty
*/
std::bitset<32> flags;
void draw_overlay(char c);
private:
std::string prev;
std::string word;
std::string word_pre;
std::string word_post;
std::array<char, 2> word_center;
Texture2D keyboard;
unsigned int idx;
/*
* 0 - cached word data is dirty
*/
std::bitset<32> flags;
void draw_overlay(char c);
};
#endif