aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-05-27 19:07:57 -0400
committerJon Santmyer <jon@jonsantmyer.com>2021-05-27 19:07:57 -0400
commitd3602d5cccf7f6c4a7f975694db2b16db28cdd60 (patch)
tree8640f324adea00102d039378c3a46bb9331cf266 /include
downloadpostmodern-d3602d5cccf7f6c4a7f975694db2b16db28cdd60.tar.gz
postmodern-d3602d5cccf7f6c4a7f975694db2b16db28cdd60.tar.bz2
postmodern-d3602d5cccf7f6c4a7f975694db2b16db28cdd60.zip
working screens / windows system. title screen and escape menu
Diffstat (limited to 'include')
-rw-r--r--include/canvaswindow.h20
-rw-r--r--include/game.h47
-rw-r--r--include/input.h48
-rw-r--r--include/pausescreen.h28
-rw-r--r--include/screen.h29
-rw-r--r--include/testscreen.h4
-rw-r--r--include/textwindow.h25
-rw-r--r--include/titlescreen.h32
-rw-r--r--include/window.h51
9 files changed, 284 insertions, 0 deletions
diff --git a/include/canvaswindow.h b/include/canvaswindow.h
new file mode 100644
index 0000000..a44056f
--- /dev/null
+++ b/include/canvaswindow.h
@@ -0,0 +1,20 @@
+#ifndef POSTMODERN_CANVAS_WINDOW_H
+#define POSTMODERN_CANVAS_WINDOW_H 1
+
+#include "window.h"
+
+class CanvasWindow : public Window
+{
+protected:
+
+private:
+
+public:
+ CanvasWindow(int x, int y, int width, int height, bool bordered);
+ ~CanvasWindow();
+
+ void plot(int x, int y, char c);
+
+};
+
+#endif
diff --git a/include/game.h b/include/game.h
new file mode 100644
index 0000000..66a4eb4
--- /dev/null
+++ b/include/game.h
@@ -0,0 +1,47 @@
+#ifndef POSTMODERN_GAME_H
+#define POSTMODERN_GAME_H 1
+
+#include <string>
+#include <memory>
+#include <unordered_map>
+#include <deque>
+#include <termios.h>
+
+#include "screen.h"
+
+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:
+public:
+ static void init();
+ static void loop();
+
+ static void addScreen(const std::string &key, std::shared_ptr<Screen> value);
+ static bool pushScreen(const std::string &key);
+ static bool popScreen();
+ 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
new file mode 100644
index 0000000..f3943d5
--- /dev/null
+++ b/include/input.h
@@ -0,0 +1,48 @@
+#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
new file mode 100644
index 0000000..02d3c4d
--- /dev/null
+++ b/include/pausescreen.h
@@ -0,0 +1,28 @@
+#ifndef POSTMODERN_PAUSESCREEN_H
+#define POSTMODERN_PAUSESCREEN_H 1
+
+#include "textwindow.h"
+#include "screen.h"
+
+class PauseScreen : public Screen {
+private:
+ enum class Selection {
+ RESUME = 0,
+ SETTINGS,
+ ABORT,
+ SELECTION_COUNT
+ };
+
+ std::shared_ptr<TextWindow> m_menuWindow;
+
+ int m_selection;
+ void parseSelection();
+protected:
+public:
+ PauseScreen();
+ ~PauseScreen();
+
+ void update() override;
+};
+
+#endif
diff --git a/include/screen.h b/include/screen.h
new file mode 100644
index 0000000..d7de4bb
--- /dev/null
+++ b/include/screen.h
@@ -0,0 +1,29 @@
+#ifndef POSTMODERN_SCREEN_H
+#define POSTMODERN_SCREEN_H 1
+
+#include "window.h"
+
+#include <unordered_map>
+#include <deque>
+#include <string>
+#include <memory>
+
+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;
+public:
+ Screen() {}
+ virtual ~Screen() {}
+
+ void addWindow(const std::string &key, std::shared_ptr<Window> value);
+
+ virtual void update() {}
+ void render();
+
+ void setRedraw() { m_redraw = true; }
+};
+
+#endif
diff --git a/include/testscreen.h b/include/testscreen.h
new file mode 100644
index 0000000..6d17760
--- /dev/null
+++ b/include/testscreen.h
@@ -0,0 +1,4 @@
+#ifndef POSTMODERN_TESTSCREEN_H
+#define POSTMODERN_TESTSCREEN_H 1
+
+#endif
diff --git a/include/textwindow.h b/include/textwindow.h
new file mode 100644
index 0000000..00ac3ed
--- /dev/null
+++ b/include/textwindow.h
@@ -0,0 +1,25 @@
+#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
new file mode 100644
index 0000000..7d8088a
--- /dev/null
+++ b/include/titlescreen.h
@@ -0,0 +1,32 @@
+#ifndef POSTMODERN_SCREEN_TITLE_H
+#define POSTMODERN_SCREEN_TITLE_H 1
+
+#include "textwindow.h"
+#include "screen.h"
+
+class TitleScreen : public Screen{
+private:
+ enum class Selection {
+ PLAY = 0,
+ WORLDS,
+ SETTINGS,
+ TESTGEN,
+ QUIT,
+ SELECTION_COUNT
+ };
+
+ std::shared_ptr<Window> m_graphicWindow;
+ std::shared_ptr<TextWindow> m_selectionWindow;
+
+ int m_selection;
+
+ void parseSelection();
+protected:
+public:
+ TitleScreen();
+ ~TitleScreen();
+
+ void update() override;
+};
+
+#endif
diff --git a/include/window.h b/include/window.h
new file mode 100644
index 0000000..425da0f
--- /dev/null
+++ b/include/window.h
@@ -0,0 +1,51 @@
+#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