aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-05-28 11:07:52 -0400
committerJon Santmyer <jon@jonsantmyer.com>2021-05-28 11:07:52 -0400
commita0af2c0be21cbba9c9c5d9ea9ffcd7e9d7b74905 (patch)
treebad7b23d96597a167f829b749165b2e352eacff3
parentd3602d5cccf7f6c4a7f975694db2b16db28cdd60 (diff)
downloadpostmodern-a0af2c0be21cbba9c9c5d9ea9ffcd7e9d7b74905.tar.gz
postmodern-a0af2c0be21cbba9c9c5d9ea9ffcd7e9d7b74905.tar.bz2
postmodern-a0af2c0be21cbba9c9c5d9ea9ffcd7e9d7b74905.zip
seperate rendering from game logic, new library boxii
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
-rw-r--r--Makefile18
-rw-r--r--bin/assets/title.txt2
-rwxr-xr-xbin/libboxii.sobin0 -> 90256 bytes
-rwxr-xr-xbin/run.sh4
m---------boxii0
-rw-r--r--include/game.h11
-rw-r--r--include/input.h48
-rw-r--r--include/pausescreen.h4
-rw-r--r--include/screen.h8
-rw-r--r--include/testscreen.h12
-rw-r--r--include/textwindow.h25
-rw-r--r--include/titlescreen.h6
-rw-r--r--include/window.h51
-rw-r--r--src/game.cpp54
-rw-r--r--src/input.cpp85
-rw-r--r--src/main.cpp3
-rw-r--r--src/pausescreen.cpp22
-rw-r--r--src/screen.cpp4
-rw-r--r--src/testscreen.cpp17
-rw-r--r--src/textwindow.cpp56
-rw-r--r--src/titlescreen.cpp28
-rw-r--r--src/window.cpp94
24 files changed, 97 insertions, 459 deletions
diff --git a/.gitignore b/.gitignore
index 5bdc739..d28cdfc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.o
postmodern
+include/boxii
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..ed20854
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "boxii"]
+ path = boxii
+ url = git@git.jonsantmyer.com:boxii
diff --git a/Makefile b/Makefile
index f4825bd..88b8d2a 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ WARNINGS := -Wall \
CPP := g++
CPPFLAGS := -std=gnu++20 $(WARNINGS) -I$(INCDIR) -g
-LIBS :=
+LIBS := -L$(TARGET_PREFIX) -l:libboxii.so
ifeq ($(TRUECOLOR), 1)
CPPFLAGS += -DTRUECOLOR
@@ -43,17 +43,27 @@ else
endif
.PHONY: all
-all: $(OBJFILES)
+all: $(OBJFILES) $(TARGET_PREFIX)/libboxii.so
$(CPP) $(CPPFLAGS) $(LIBS) $(OBJFILES) -o $(TARGET)
run:
- cd $(TARGET_PREFIX); ./$(TARGET_NAME)
+ cd $(TARGET_PREFIX); ./run.sh
clean:
rm $(OBJFILES)
rm $(TARGET)
+ rm $(TARGET_PREFIX)/libboxii.so
+ $(MAKE) -C $(PWD)/boxii clean
-%.o:%.cpp
+%.o:%.cpp $(INCDIR)/boxii
$(CPP) $(CPPFLAGS) -c $< -o $@
+$(INCDIR)/boxii:
+ ln -s $(PWD)/boxii/include $(INCDIR)/boxii
+
+.PHONY: $(TARGET_PREFIX)/libboxii.so
+$(TARGET_PREFIX)/libboxii.so:
+ $(MAKE) -C $(PWD)/boxii
+ mv $(PWD)/boxii/bin/libboxii.so $(TARGET_PREFIX)
+
# vim: set ts=4 sw=0 tw=0 noet :
diff --git a/bin/assets/title.txt b/bin/assets/title.txt
index f027939..8d04dd1 100644
--- a/bin/assets/title.txt
+++ b/bin/assets/title.txt
@@ -3,4 +3,4 @@
| |_) | | | \___ \ | | | |\/| | | | | | | | _| | |_) | \| |
| __/| |_| |___) || | | | | | |_| | |_| | |___| _ <| |\ |
|_| \___/|____/ |_| |_| |_|\___/|____/|_____|_| \_\_| \_|
-
+Powered by Boxii!
diff --git a/bin/libboxii.so b/bin/libboxii.so
new file mode 100755
index 0000000..6d20a19
--- /dev/null
+++ b/bin/libboxii.so
Binary files differ
diff --git a/bin/run.sh b/bin/run.sh
new file mode 100755
index 0000000..270bb63
--- /dev/null
+++ b/bin/run.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/bash
+
+export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
+./postmodern
diff --git a/boxii b/boxii
new file mode 160000
+Subproject a5ef0ae876df2b767cf03c2b42a253dd1e0cf07
diff --git a/include/game.h b/include/game.h
index 66a4eb4..4e00bb8 100644
--- a/include/game.h
+++ b/include/game.h
@@ -11,17 +11,12 @@
class Game {
private:
- static int m_width;
- static int m_height;
static bool m_running;
static std::unordered_map<std::string, std::shared_ptr<Screen>> m_screens;
static std::deque<std::weak_ptr<Screen>> m_order;
static bool m_dirty;
- static bool m_rawmode;
- static struct termios m_tosOriginal;
-
static void update();
static void render();
protected:
@@ -35,13 +30,7 @@ public:
static bool popUpto(const std::string &key);
static bool popUptoIncluding(const std::string &key);
- static void enableRawmode();
- static void disableRawmode();
-
static void stop() { m_running = false; }
-
- static int getWidth() { return m_width; }
- static int getHeight() { return m_height; }
};
#endif
diff --git a/include/input.h b/include/input.h
deleted file mode 100644
index f3943d5..0000000
--- a/include/input.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef POSTMODERN_INPUT_H
-#define POSTMODERN_INPUT_H 1
-
-enum class Keycode {
- TERMINATE = 128,
- F1,
- F2,
- F3,
- F4,
- F5,
- F6,
- F7,
- F8,
- F9,
- F10,
- F11,
- F12,
- NUMPAD_HOME,
- NUMPAD_UP,
- NUMPAD_PGUP,
- NUMPAD_LEFT,
- NUMPAD_5,
- NUMPAD_RIGHT,
- NUMPAD_END,
- NUMPAD_DOWN,
- NUMPAD_PGDN,
- HOME,
- UP,
- PGUP,
- LEFT,
- RIGHT,
- END ,
- DOWN,
- PGDOWN,
- INSERT,
- DELETE,
- CTRL_MOD,
- ALT_MOD,
-};
-
-class Input {
-private:
-protected:
-public:
- static int getch();
-};
-
-#endif
diff --git a/include/pausescreen.h b/include/pausescreen.h
index 02d3c4d..c3c1a43 100644
--- a/include/pausescreen.h
+++ b/include/pausescreen.h
@@ -1,7 +1,7 @@
#ifndef POSTMODERN_PAUSESCREEN_H
#define POSTMODERN_PAUSESCREEN_H 1
-#include "textwindow.h"
+#include "boxii/textwindow.h"
#include "screen.h"
class PauseScreen : public Screen {
@@ -13,7 +13,7 @@ private:
SELECTION_COUNT
};
- std::shared_ptr<TextWindow> m_menuWindow;
+ std::shared_ptr<Boxii::TextWindow> m_menuWindow;
int m_selection;
void parseSelection();
diff --git a/include/screen.h b/include/screen.h
index d7de4bb..6896b72 100644
--- a/include/screen.h
+++ b/include/screen.h
@@ -1,7 +1,7 @@
#ifndef POSTMODERN_SCREEN_H
#define POSTMODERN_SCREEN_H 1
-#include "window.h"
+#include "boxii/window.h"
#include <unordered_map>
#include <deque>
@@ -12,13 +12,13 @@ class Screen {
private:
bool m_redraw;
protected:
- std::unordered_map<std::string, std::shared_ptr<Window>> m_windows;
- std::deque<std::weak_ptr<Window>> m_order;
+ std::unordered_map<std::string, std::shared_ptr<Boxii::Window>> m_windows;
+ std::deque<std::weak_ptr<Boxii::Window>> m_order;
public:
Screen() {}
virtual ~Screen() {}
- void addWindow(const std::string &key, std::shared_ptr<Window> value);
+ void addWindow(const std::string &key, std::shared_ptr<Boxii::Window> value);
virtual void update() {}
void render();
diff --git a/include/testscreen.h b/include/testscreen.h
index 6d17760..67d98dc 100644
--- a/include/testscreen.h
+++ b/include/testscreen.h
@@ -1,4 +1,16 @@
#ifndef POSTMODERN_TESTSCREEN_H
#define POSTMODERN_TESTSCREEN_H 1
+#include "screen.h"
+
+class TestScreen : public Screen {
+private:
+protected:
+public:
+ TestScreen();
+ ~TestScreen();
+
+ void update() override;
+};
+
#endif
diff --git a/include/textwindow.h b/include/textwindow.h
deleted file mode 100644
index 00ac3ed..0000000
--- a/include/textwindow.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef POSTMODERN_TEXT_WINDOW_H
-#define POSTMODERN_TEXT_WINDOW_H 1
-
-#include <cstdarg>
-
-#include "window.h"
-
-class TextWindow : public Window
-{
-private:
-protected:
- int m_colorfg;
- int m_colorbg;
-public:
- TextWindow(int x, int y, int width, int height, bool bordered);
- ~TextWindow();
-
- void setfg(int fg) { m_colorfg = fg; }
- void setbg(int bg) { m_colorbg = bg; }
-
- int vprint(const char *fmt, va_list ap);
- int print(const char *fmt, ...);
-};
-
-#endif
diff --git a/include/titlescreen.h b/include/titlescreen.h
index 7d8088a..509ea11 100644
--- a/include/titlescreen.h
+++ b/include/titlescreen.h
@@ -1,7 +1,7 @@
#ifndef POSTMODERN_SCREEN_TITLE_H
#define POSTMODERN_SCREEN_TITLE_H 1
-#include "textwindow.h"
+#include "boxii/textwindow.h"
#include "screen.h"
class TitleScreen : public Screen{
@@ -15,8 +15,8 @@ private:
SELECTION_COUNT
};
- std::shared_ptr<Window> m_graphicWindow;
- std::shared_ptr<TextWindow> m_selectionWindow;
+ std::shared_ptr<Boxii::Window> m_graphicWindow;
+ std::shared_ptr<Boxii::TextWindow> m_selectionWindow;
int m_selection;
diff --git a/include/window.h b/include/window.h
deleted file mode 100644
index 425da0f..0000000
--- a/include/window.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef POSTMODERN_WINDOW_H
-#define POSTMODERN_WINDOW_H 1
-
-struct Cell {
- Cell() : chr(0), fg(0), bg(0) {}
-
- char chr;
- unsigned int fg;
- unsigned int bg;
-
- bool operator==(const Cell &a)
- {
- return a.chr == chr && a.fg == fg && a.bg == bg;
- }
-};
-
-class Window {
-private:
- Cell *m_foreplane;
- Cell *m_backplane;
-protected:
- int m_x;
- int m_y;
- int m_width;
- int m_height;
-
- int m_cursorx;
- int m_cursory;
-
- bool m_bordered;
- bool m_redraw;
-public:
- Window(int x, int y, int width, int height, bool bordered);
- ~Window();
-
- void refresh();
-
- void clear(int fg, int bg);
- void plot(int x, int y, char c, int fg, int bg);
-
- void setRedraw() { m_redraw = true; }
-
- void moveCursor(int x, int y);
- void move(int x, int y);
-
- int getWidth() { return m_width; }
- int getHeight() { return m_height; }
- bool getCenter(int &x, int &y); //Returns if has true center
-};
-
-#endif
diff --git a/src/game.cpp b/src/game.cpp
index b47f0c7..0177bd7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1,16 +1,12 @@
#include "game.h"
+#include "boxii/boxii.h"
#include <cstdio>
#include <cstring>
#include <sys/ioctl.h>
-int Game::m_width;
-int Game::m_height;
bool Game::m_running;
-bool Game::m_rawmode;
-struct termios Game::m_tosOriginal;
-
std::unordered_map<std::string, std::shared_ptr<Screen>> Game::m_screens;
std::deque<std::weak_ptr<Screen>> Game::m_order;
bool Game::m_dirty;
@@ -18,51 +14,13 @@ bool Game::m_dirty;
void
Game::init()
{
- //Get terminal width/length
- struct winsize w;
- ioctl(0, TIOCGWINSZ, &w);
-
- m_width = w.ws_col;
- m_height = w.ws_row;
-
- //Disable stdout buffer, Clear terminal
- setbuf(stdout, NULL);
- puts("\033[40;97m\033[2J");
-
m_running = true;
- m_rawmode = false;
m_dirty = false;
-}
-
-void
-Game::enableRawmode()
-{
- if(m_rawmode) return;
- tcgetattr(STDIN_FILENO, &m_tosOriginal);
- struct termios tos;
- memcpy(&tos, &m_tosOriginal, sizeof(struct termios));
-
- tos.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
- tos.c_iflag &= ~(ICRNL | IXON | INPCK | ISTRIP);
- tos.c_oflag &= ~(OPOST);
- tos.c_cflag |= (CS8);
-
- tos.c_cc[VMIN] = 0;
- tos.c_cc[VTIME] = 1;
-
- puts("\033[?25l");
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &tos);
- m_rawmode = true;
-}
-
-void
-Game::disableRawmode()
-{
- if(!m_rawmode) return;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &m_tosOriginal);
- puts("\033[?25h");
- m_rawmode = false;
+ Boxii::cursor(false);
+ Boxii::echo(false);
+ Boxii::canon(false);
+ Boxii::sig(true);
}
void
@@ -73,8 +31,6 @@ Game::loop()
render();
update();
}
- disableRawmode();
- puts("\033[0m\033[2J");
}
void
diff --git a/src/input.cpp b/src/input.cpp
deleted file mode 100644
index 46ba0d7..0000000
--- a/src/input.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-#include "input.h"
-#include "game.h"
-#include <cstdio>
-
-static int
-waitforch()
-{
- int c = 0;
- for(; c == 0; read(STDIN_FILENO, &c, 1));
- return c;
-}
-
-int
-Input::getch()
-{
- int c = waitforch();
- if(c == '\033'){
- char eseq[4];
- if(read(STDIN_FILENO, eseq, 1) != 1) return c;
- if(read(STDIN_FILENO, eseq + 1, 1) != 1) return c;
-
- if(eseq[0] == '\033') return c;
- if(eseq[0] == '['){
- if(eseq[1] >= '0' && eseq[1] <= '9'){
- if(read(STDIN_FILENO, eseq + 2, 1) != 1) return c;
- if(eseq[2] == '~'){
- switch(eseq[1]){
- case '1': return static_cast<int>(Keycode::HOME);
- case '3': return static_cast<int>(Keycode::DELETE);
- case '4': return static_cast<int>(Keycode::END);
- case '5': return static_cast<int>(Keycode::PGUP);
- case '6': return static_cast<int>(Keycode::PGDOWN);
- case '7': return static_cast<int>(Keycode::NUMPAD_HOME);
- case '8': return static_cast<int>(Keycode::NUMPAD_END);
- }
- }else if(eseq[2] == 'h'){
- switch(eseq[1]){
- case '4': return static_cast<int>(Keycode::INSERT);
- }
- }else if(eseq[2] >= '0' && eseq[2] <= '9'){
- if(read(STDIN_FILENO, eseq + 3, 1) != 1) return c;
- switch(eseq[1]){
- case '1': {
- switch(eseq[2]) {
- case '5': return static_cast<int>(Keycode::F5);
- case '7': return static_cast<int>(Keycode::F6);
- case '8': return static_cast<int>(Keycode::F7);
- case '9': return static_cast<int>(Keycode::F8);
- }
- }
- break;
- case '2': {
- switch(eseq[2]) {
- case '0': return static_cast<int>(Keycode::F9);
- case '1': return static_cast<int>(Keycode::F10);
- case '3': return static_cast<int>(Keycode::F11);
- case '4': return static_cast<int>(Keycode::F12);
- }
- }
- break;
- }
- }
- }
- switch(eseq[1]){
- case 'A': return static_cast<int>(Keycode::UP);
- case 'B': return static_cast<int>(Keycode::DOWN);
- case 'C': return static_cast<int>(Keycode::RIGHT);
- case 'D': return static_cast<int>(Keycode::LEFT);
- case 'E': return static_cast<int>(Keycode::NUMPAD_5);
- case 'H': return static_cast<int>(Keycode::HOME);
- case 'F': return static_cast<int>(Keycode::END);
- case 'P': return static_cast<int>(Keycode::DELETE);
- }
- }
- if(eseq[0] == 'O'){
- switch(eseq[1]){
- case 'P': return static_cast<int>(Keycode::F1);
- case 'Q': return static_cast<int>(Keycode::F2);
- case 'R': return static_cast<int>(Keycode::F3);
- case 'S': return static_cast<int>(Keycode::F4);
- }
- }
- }
- return c;
-}
diff --git a/src/main.cpp b/src/main.cpp
index b38a9e0..d8cb026 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,12 +2,15 @@
#include "titlescreen.h"
#include "pausescreen.h"
+#include "boxii/boxii.h"
+
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
+ Boxii::setup();
Game::init();
Game::addScreen("title", std::make_shared<TitleScreen>());
diff --git a/src/pausescreen.cpp b/src/pausescreen.cpp
index bbed192..17a82d5 100644
--- a/src/pausescreen.cpp
+++ b/src/pausescreen.cpp
@@ -1,6 +1,8 @@
#include "pausescreen.h"
#include "game.h"
-#include "input.h"
+
+#include "boxii/boxii.h"
+#include "boxii/input.h"
static const int selectionCount = 3;
static const std::string selectionText[selectionCount] =
@@ -11,7 +13,7 @@ static const std::string selectionText[selectionCount] =
};
static void
-printSelections(std::shared_ptr<TextWindow> menuWindow, int selection)
+printSelections(std::shared_ptr<Boxii::TextWindow> menuWindow, int selection)
{
int optx = 1;
int opty = 1;
@@ -43,15 +45,15 @@ PauseScreen::PauseScreen() :
m_menuWindow(nullptr),
m_selection(0)
{
- int sw = Game::getWidth();
- int sh = Game::getHeight();
+ int sw = Boxii::getTerminalWidth();
+ int sh = Boxii::getTerminalHeight();
int menuWidth = 20;
int menuHeight = 10;
int menuX = (sw / 2) - (menuWidth / 2);
int menuY = (sh / 2) - (menuHeight / 2);
- m_menuWindow = std::make_shared<TextWindow>(menuX, menuY / 2, menuWidth, menuHeight, false);
+ m_menuWindow = std::make_shared<Boxii::TextWindow>(menuX, menuY / 2, menuWidth, menuHeight, false);
addWindow("main", m_menuWindow);
printSelections(m_menuWindow, m_selection);
@@ -65,23 +67,23 @@ PauseScreen::~PauseScreen()
void
PauseScreen::update()
{
- int c = Input::getch();
- if(c == '\033'){
+ int c = Boxii::Input::getch(true);
+ if(c == Boxii::KEY_ESCAPE){
Game::popScreen();
return;
}
- if(c == static_cast<int>(Keycode::UP)){
+ if(c == Boxii::KEY_UP){
m_selection--;
if(m_selection < 0) m_selection = 0;
}
- if(c == static_cast<int>(Keycode::DOWN)){
+ if(c == Boxii::KEY_DOWN){
m_selection++;
if(m_selection >= selectionCount) m_selection = selectionCount - 1;
}
- if(c == 13){
+ if(c == Boxii::KEY_RETURN){
parseSelection();
}
diff --git a/src/screen.cpp b/src/screen.cpp
index 4925c31..fbefc5e 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -3,10 +3,10 @@
#include <ncurses.h>
void
-Screen::addWindow(const std::string &key, std::shared_ptr<Window> value)
+Screen::addWindow(const std::string &key, std::shared_ptr<Boxii::Window> value)
{
m_windows.emplace(key, value);
- m_order.push_back(std::weak_ptr<Window>(value));
+ m_order.push_back(std::weak_ptr<Boxii::Window>(value));
}
void
diff --git a/src/testscreen.cpp b/src/testscreen.cpp
new file mode 100644
index 0000000..43dcd3f
--- /dev/null
+++ b/src/testscreen.cpp
@@ -0,0 +1,17 @@
+#include "testscreen.h"
+
+TestScreen::TestScreen()
+{
+
+}
+
+TestScreen::~TestScreen()
+{
+
+}
+
+void
+TestScreen::update()
+{
+
+}
diff --git a/src/textwindow.cpp b/src/textwindow.cpp
deleted file mode 100644
index 37ec2f0..0000000
--- a/src/textwindow.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "textwindow.h"
-#include <cstdio>
-
-TextWindow::TextWindow(int x, int y, int width, int height, bool bordered) :
- m_colorfg(0xFFFFFF), m_colorbg(0x0),
- Window(x, y, width, height, bordered)
-{
-
-}
-TextWindow::~TextWindow()
-{
-
-}
-
-int
-TextWindow::vprint(const char *fmt, va_list ap)
-{
- //TODO
- char buffer[2048];
- vsnprintf(buffer, 2048, fmt, ap);
-
- for(char *c = buffer; *c; c++){
- switch(*c){
- case '\n':
- m_cursory++;
- m_cursorx = 0;
- break;
- default:
- plot(m_cursorx++, m_cursory, *c, m_colorfg, m_colorbg);
- break;
- }
- if(m_cursorx >= m_width){
- m_cursorx = 0;
- m_cursory++;
- }
- if(m_cursory >= m_height){
- //TODO: Scroll the screen
- m_cursory = m_height - 1;
- }
- }
-
- return 0;
-}
-
-int
-TextWindow::print(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
-
- int r = vprint(fmt, ap);
- va_end(ap);
-
- //TODO
- return r;
-}
diff --git a/src/titlescreen.cpp b/src/titlescreen.cpp
index 6fda23e..b2f6c02 100644
--- a/src/titlescreen.cpp
+++ b/src/titlescreen.cpp
@@ -1,11 +1,13 @@
#include "titlescreen.h"
#include "game.h"
-#include "input.h"
+
+#include "boxii/boxii.h"
+#include "boxii/input.h"
#include <fstream>
static void
-printTitle(std::shared_ptr<Window> graphicWindow)
+printTitle(std::shared_ptr<Boxii::Window> graphicWindow)
{
std::fstream titlefile;
std::string tmp;
@@ -45,7 +47,7 @@ static const std::string selectionTexts[selectionsTotal] =
};
static void
-printSelections(std::shared_ptr<TextWindow> selectionWindow, int selection)
+printSelections(std::shared_ptr<Boxii::TextWindow> selectionWindow, int selection)
{
int selwidth = selectionWindow->getWidth() / selectionsTotal;
int selcenter = selwidth / 2;
@@ -71,22 +73,20 @@ TitleScreen::TitleScreen() :
m_selectionWindow(nullptr),
m_selection(0)
{
- int sw = Game::getWidth();
- int sh = Game::getHeight();
+ int sw = Boxii::getTerminalWidth();
+ int sh = Boxii::getTerminalHeight();
int graphicHeight = (sh / 4) * 3;
int selectionHeight = (sh / 4);
- m_graphicWindow = std::make_shared<Window>(0, 0, sw, graphicHeight + 1, false);
- m_selectionWindow = std::make_shared<TextWindow>(0, graphicHeight + 1, sw, selectionHeight + 1, false);
+ m_graphicWindow = std::make_shared<Boxii::Window>(0, 0, sw, graphicHeight + 1, false);
+ m_selectionWindow = std::make_shared<Boxii::TextWindow>(0, graphicHeight + 1, sw, selectionHeight + 1, false);
addWindow("graphic", m_graphicWindow);
addWindow("selection", m_selectionWindow);
printTitle(m_graphicWindow);
printSelections(m_selectionWindow, m_selection);
-
- Game::enableRawmode();
}
TitleScreen::~TitleScreen()
@@ -103,20 +103,20 @@ TitleScreen::parseSelection()
void
TitleScreen::update()
{
- int c = Input::getch();
- if(c == '\033') {
+ int c = Boxii::Input::getch(false);
+ if(c == Boxii::KEY_ESCAPE) {
Game::pushScreen("pause");
}
- if(c == static_cast<int>(Keycode::LEFT)){
+ if(c == Boxii::KEY_LEFT){
m_selection--;
if(m_selection < 0) m_selection = selectionsTotal - 1;
}
- if(c == static_cast<int>(Keycode::RIGHT)){
+ if(c == Boxii::KEY_RIGHT){
m_selection++;
if(m_selection >= selectionsTotal) m_selection = 0;
}
- if(c == 13){
+ if(c == Boxii::KEY_RETURN){
parseSelection();
}
diff --git a/src/window.cpp b/src/window.cpp
deleted file mode 100644
index 0c06c30..0000000
--- a/src/window.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-#include "window.h"
-#include <cstdio>
-
-Window::Window(int x, int y, int width, int height, bool bordered) :
- m_x(x), m_y(y), m_width(width), m_height(height),
- m_cursorx(0), m_cursory(0),
- m_bordered(bordered), m_redraw(true)
-{
- m_foreplane = new Cell[width * height];
- m_backplane = new Cell[width * height];
-
- for(int i = 0; i < width * height; i++){
- m_foreplane[i].chr = ' ';
- m_foreplane[i].fg = 0xFFFFFF;
- }
-}
-
-Window::~Window()
-{
- delete[] m_foreplane;
- delete[] m_backplane;
-}
-
-static void
-replot(int x, int y, char c, int fg, int bg)
-{
-#if defined(TRUECOLOR)
- printf("\033[%i;%iH", y, x);
- printf("\033[38;2;%i;%i;%im", (fg & 0xFF0000) >> 16, (fg & 0x00FF00) >> 8, (fg & 0x0000FF));
- printf("\033[48;2;%i;%i;%im", (bg & 0xFF0000) >> 16, (bg & 0x00FF00) >> 8, (bg & 0x0000FF));
- printf("%c", c);
-#endif
-}
-
-void
-Window::refresh()
-{
- for(int y = 0; y < m_height; y++)
- for(int x = 0; x < m_width; x++)
- {
- int index = x + (y * m_width);
- if(m_foreplane[index] == m_backplane[index] && !m_redraw) continue;
- replot(x + m_x + 1, y + m_y + 1, m_foreplane[index].chr, m_foreplane[index].fg, m_foreplane[index].bg);
- m_backplane[index] = m_foreplane[index];
- }
- if(m_redraw) puts("\033[1;1H");
- m_redraw = false;
-}
-
-void
-Window::clear(int fg, int bg)
-{
- for(int i = 0; i < m_width * m_height; i++){
- m_foreplane[i].chr = ' ';
- m_foreplane[i].fg = fg;
- m_foreplane[i].bg = bg;
- }
-}
-
-void
-Window::plot(int x, int y, char c, int fg, int bg)
-{
- int index = x + (y * m_width);
- m_foreplane[index].chr = c;
- m_foreplane[index].fg = fg;
- m_foreplane[index].bg = bg;
-}
-
-void
-Window::moveCursor(int x, int y)
-{
- m_cursorx = x;
- m_cursory = y;
-
- if(m_cursorx >= m_width) m_cursorx = m_width - 1;
- if(m_cursory >= m_height) m_cursory = m_height - 1;
-}
-
-void
-Window::move(int x, int y)
-{
- m_x = x;
- m_y = y;
- m_redraw = true;
-}
-
-bool
-Window::getCenter(int &x, int &y)
-{
- x = (m_width / 2) + 1;
- y = (m_height / 2) + 1;
-
- return ((x * 2) - 1 == m_width) && ((y * 2) - 1 == m_height);
-}