Impl highlighting of keys, fixes
This commit is contained in:
parent
51c167bbb4
commit
e4850ca3e1
4 changed files with 207 additions and 3 deletions
4
Makefile
4
Makefile
|
@ -6,6 +6,8 @@ endif
|
||||||
|
|
||||||
OBJDIR = objects
|
OBJDIR = objects
|
||||||
|
|
||||||
|
HEADERS = src/screen.h
|
||||||
|
|
||||||
SOURCES = src/main.cc \
|
SOURCES = src/main.cc \
|
||||||
src/screen.cc
|
src/screen.cc
|
||||||
|
|
||||||
|
@ -16,7 +18,7 @@ all: dvorak_typing_practice
|
||||||
dvorak_typing_practice: ${OBJECTS}
|
dvorak_typing_practice: ${OBJECTS}
|
||||||
${CXX} ${CXX_FLAGS} -o dvorak_typing_practice $^ -lraylib
|
${CXX} ${CXX_FLAGS} -o dvorak_typing_practice $^ -lraylib
|
||||||
|
|
||||||
${OBJDIR}/%.o: %.cc
|
${OBJDIR}/%.o: %.cc ${HEADERS}
|
||||||
@mkdir -p $$(dirname $@)
|
@mkdir -p $$(dirname $@)
|
||||||
${CXX} ${CXX_FLAGS} -c -o $@ $<
|
${CXX} ${CXX_FLAGS} -c -o $@ $<
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ int main(int argc, char **argv) {
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!std::cin.eof() && !WindowShouldClose());
|
} while (!ifs.eof() && !WindowShouldClose());
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
199
src/screen.cc
199
src/screen.cc
|
@ -60,7 +60,7 @@ void Screen::draw() {
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
if (!prev.empty()) {
|
if (!prev.empty()) {
|
||||||
DrawText(prev.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, Color{127, 127, 127, 255});
|
DrawText(prev.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, GRAY);
|
||||||
offset += MeasureText(prev.c_str(), FONT_SIZE) + PREV_OFFSET;
|
offset += MeasureText(prev.c_str(), FONT_SIZE) + PREV_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,4 +75,201 @@ void Screen::draw() {
|
||||||
if (!word_post.empty()) {
|
if (!word_post.empty()) {
|
||||||
DrawText(word_post.c_str(), LEFT_OFFSET + offset, TOP_OFFSET, FONT_SIZE, WHITE);
|
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) {
|
||||||
|
case '`':
|
||||||
|
case '~':
|
||||||
|
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;
|
||||||
|
case '2':
|
||||||
|
case '@':
|
||||||
|
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;
|
||||||
|
case '4':
|
||||||
|
case '$':
|
||||||
|
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;
|
||||||
|
case '6':
|
||||||
|
case '^':
|
||||||
|
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;
|
||||||
|
case '8':
|
||||||
|
case '*':
|
||||||
|
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;
|
||||||
|
case '0':
|
||||||
|
case ')':
|
||||||
|
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;
|
||||||
|
case '}':
|
||||||
|
case ']':
|
||||||
|
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;
|
||||||
|
case '<':
|
||||||
|
case ',':
|
||||||
|
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;
|
||||||
|
case 'P':
|
||||||
|
case 'p':
|
||||||
|
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;
|
||||||
|
case 'F':
|
||||||
|
case 'f':
|
||||||
|
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;
|
||||||
|
case 'C':
|
||||||
|
case 'c':
|
||||||
|
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;
|
||||||
|
case 'L':
|
||||||
|
case 'l':
|
||||||
|
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;
|
||||||
|
case '+':
|
||||||
|
case '=':
|
||||||
|
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;
|
||||||
|
case 'A':
|
||||||
|
case 'a':
|
||||||
|
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;
|
||||||
|
case 'E':
|
||||||
|
case 'e':
|
||||||
|
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;
|
||||||
|
case 'I':
|
||||||
|
case 'i':
|
||||||
|
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;
|
||||||
|
case 'H':
|
||||||
|
case 'h':
|
||||||
|
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;
|
||||||
|
case 'N':
|
||||||
|
case 'n':
|
||||||
|
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;
|
||||||
|
case '_':
|
||||||
|
case '-':
|
||||||
|
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;
|
||||||
|
case 'Q':
|
||||||
|
case 'q':
|
||||||
|
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;
|
||||||
|
case 'K':
|
||||||
|
case 'k':
|
||||||
|
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;
|
||||||
|
case 'B':
|
||||||
|
case 'b':
|
||||||
|
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;
|
||||||
|
case 'W':
|
||||||
|
case 'w':
|
||||||
|
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;
|
||||||
|
case 'Z':
|
||||||
|
case 'z':
|
||||||
|
DrawCircle(676 + KEY_HALF_SIZE, 181 + KEY_HALF_SIZE, KEY_HALF_SIZE, KEY_HIGHLIGHT_COLOR);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ constexpr int FONT_SIZE = 40;
|
||||||
constexpr int CENTER_X_OFFSET = FONT_SIZE / 2;
|
constexpr int CENTER_X_OFFSET = FONT_SIZE / 2;
|
||||||
constexpr int PREV_OFFSET = FONT_SIZE * 2;
|
constexpr int PREV_OFFSET = FONT_SIZE * 2;
|
||||||
|
|
||||||
|
constexpr int KEY_HALF_SIZE = 29;
|
||||||
|
constexpr Color KEY_HIGHLIGHT_COLOR = Color{255, 255, 0, 127};
|
||||||
|
|
||||||
class Screen {
|
class Screen {
|
||||||
public:
|
public:
|
||||||
Screen();
|
Screen();
|
||||||
|
@ -40,6 +43,8 @@ private:
|
||||||
*/
|
*/
|
||||||
std::bitset<32> flags;
|
std::bitset<32> flags;
|
||||||
|
|
||||||
|
void draw_overlay(char c);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue