From 29dac2230fbae3a9c1f7cacf544c795cc38f3b78 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 23 Oct 2019 17:12:04 +0200 Subject: [PATCH] + public header fully documented. + internal header --- CHANGELOG.md | 2 +- README.md | 6 +- src/Color.h | 20 ++++ src/EventType.h | 19 ++++ src/Font.h | 17 +++ src/GraphicMode.h | 11 ++ src/KeyCode.h | 17 +++ src/LayoutVersion.h | 8 ++ src/internal.h | 37 +++++++ src/notes.txt | 12 +++ src/vkvm.h | 249 +++++++++++++++++++++++++++++++++----------- 11 files changed, 334 insertions(+), 64 deletions(-) create mode 100644 src/Color.h create mode 100644 src/EventType.h create mode 100644 src/Font.h create mode 100644 src/GraphicMode.h create mode 100644 src/KeyCode.h create mode 100644 src/LayoutVersion.h create mode 100644 src/internal.h create mode 100644 src/notes.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 101bcbe..9214fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Continuous Integration -## [0.0.1] - 2019-10-24 +## [0.1.0] - 2019-10-24 ### Added diff --git a/README.md b/README.md index 086aedc..b3ad77e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ # vKVM Library -# Installation + + +## Installation Use the installation script provided in the Scripts repository to install the full package. Installing a single component is currently not supported. -# Usage +## Usage Include this library with diff --git a/src/Color.h b/src/Color.h new file mode 100644 index 0000000..54b6e88 --- /dev/null +++ b/src/Color.h @@ -0,0 +1,20 @@ +#ifndef LIBRARY_COLOR_H +#define LIBRARY_COLOR_H + +static const Color black = Color(0, 0, 0); +static const Color white = Color(255, 255, 255); + +class Color { + +private: + unsigned char red; + unsigned char green; + unsigned char blue; + +public: + Color(red, green, blue); + +}; + + +#endif diff --git a/src/EventType.h b/src/EventType.h new file mode 100644 index 0000000..52e07e0 --- /dev/null +++ b/src/EventType.h @@ -0,0 +1,19 @@ +#ifndef LIBRARY_EVENTTYPE_H +#define LIBRARY_EVENTTYPE_H + +/** + * @since 0.1.0 + * @uthor Johannes Theiner + */ +enum EventType { + Timer = 1, + MouseMove = 2, + MouseButton = 3, + KeyDown = 4, + KeyUp = 5, + UpdateControlRegisters = 6, + Redraw = 7, + RenderText = 8 +}; + +#endif diff --git a/src/Font.h b/src/Font.h new file mode 100644 index 0000000..308dbc8 --- /dev/null +++ b/src/Font.h @@ -0,0 +1,17 @@ +#ifndef LIBRARY_FONT_H +#define LIBRARY_FONT_H + + +class Font { +private: + Font(); + +public: + std::string getName(); + int getHeight(); + int getWidth(); + +}; + + +#endif diff --git a/src/GraphicMode.h b/src/GraphicMode.h new file mode 100644 index 0000000..77f82c1 --- /dev/null +++ b/src/GraphicMode.h @@ -0,0 +1,11 @@ +#ifndef LIBRARY_GRAPHICMODE_H +#define LIBRARY_GRAPHICMODE_H + +enum GraphicMode { + Text = 1, + TwoColors = 2, + Gray_256 = 3, + TrueColor = 4, +}; + +#endif diff --git a/src/KeyCode.h b/src/KeyCode.h new file mode 100644 index 0000000..cb9d2a5 --- /dev/null +++ b/src/KeyCode.h @@ -0,0 +1,17 @@ +#ifndef LIBRARY_KEYCODE_H +#define LIBRARY_KEYCODE_H + + +const KeyCode Backspace = KeyCode(8); +const KeyCode tabulator = KeyCode(9); + +class KeyCode { + +private: + KeyCode(int value); +public: + int getValue(); +}; + + +#endif diff --git a/src/LayoutVersion.h b/src/LayoutVersion.h new file mode 100644 index 0000000..3d0dd54 --- /dev/null +++ b/src/LayoutVersion.h @@ -0,0 +1,8 @@ +#ifndef LIBRARY_LAYOUTVERSION_H +#define LIBRARY_LAYOUTVERSION_H + +enum LayoutVersion { + V1 = 1; +}; + +#endif diff --git a/src/internal.h b/src/internal.h new file mode 100644 index 0000000..5e3b072 --- /dev/null +++ b/src/internal.h @@ -0,0 +1,37 @@ +#ifndef LIBRARY_INTERNAL_H +#define LIBRARY_INTERNAL_H + +#include "EventType.h" +#include "KeyCode.h" +#include "LayoutVersion.h" + +//TODO: documentation + +void setLayoutVersion(LayoutVersion newValue); + +void setTriggerReset(int newValue); + +void setCharactersPerLine(int newValue); + +void setCharactersPerRow(int newValue); + +/** + * call a specific event. + * @param type + * @return true if there is a handler registere + */ +bool callEvent(EventType type); + +void setMousePosition(int x, int y); + +void buttonPressed(KeyCode keyCode); + +// Shared Memory Layout +// -------------------------------------------------------------------- +// struct ControlRegisters +// char reserved[1024] +// Interrupt Vector Table [64] +// text area [max_textMode_width * max_textMode_height] +// pixel area [max_height_pixels * max_height_pixels * sizeof(uint_32)] + +#endif \ No newline at end of file diff --git a/src/notes.txt b/src/notes.txt new file mode 100644 index 0000000..355056c --- /dev/null +++ b/src/notes.txt @@ -0,0 +1,12 @@ +//enum config file defaults { +const int max_width_pixels = 800; +const int max_height_pixels = 600; +const int max_textMode_width = 800; +const int max_textMode_height = 600; +//}; + + +struct interruptVector { + int pid; + int signal; +}; diff --git a/src/vkvm.h b/src/vkvm.h index a7b9788..1a6e959 100644 --- a/src/vkvm.h +++ b/src/vkvm.h @@ -1,74 +1,201 @@ #ifndef LIBRARY_VKVM_H #define LIBRARY_VKVM_H -typedef int type_todo; +#include +#include +#include "Color.h" +#include "EventType.h" +#include "GraphicMode.h" +#include "Font.h" +#include "KeyCode.h" +#include "LayoutVersion.h" -private struct interruptVector { - int pid; - int signal; -}; +/** + * @since 0.1.0 + * @author Johannes Theiner + */ -//enum config file defaults { -const int max_width_pixels = 800; -const int max_height_pixels = 600; -const int max_textMode_width; -const int max_textMode_height; -// TODO: add ControlRegisters members here -//TODO: add get/set methods -//}; +//TODO: better documentation +/** + * initialize the connection with the shared-memory application + * @param pid pip of shared-memory application + */ +void initialize(int pid); -enum GraphicMode { - Text, - BlackWhite, - Gray_256, - TrueColor; -}; +/** + * set pixel at a x,y position to a certain color. + * @param x x coordinate of pixel + * @param y y coordinate of pixel + * @param color color of pixel + * @return true if operation succeeded, false if it failed. + */ +bool setPixel(int x, int y, Color color); -private struct controlRegisters { - int layout_version - int trigger_reset; - int width_pixels; - int height_pixels; - GraphicMode graphicMode; - int autoRedrawInterval; - int timerInterruptInterval; - type_todo bw_background_color; - type_todo bw_foreground_color; - int textMode_width; - int textMode_height; - int textMode_font; - int textMode_font_width; - int textMode_font_height; - int mouse_pos_x; - int mouse_pos_y; - char keyboardBuffer[16]; - int keyboardBuffer_index_w; - int keyboardBuffer_index_r; -}; +/** + * get color of pixel at x,y position + * @param x x coordinate of pixel + * @param y y coordinate of pixel + * @return color of pixel + */ +Color getPixel(int x, int y); -//TODO: add init -//TODO: add methods for a event handling approach -//TODO: add methods for a pooling approach +/** + * register handler for event. + * @param type type of event. + * @param handler function to call. + * @return true if handler could be registered, false if it failed. + */ +bool registerEvent(EventType type, std::function handler); -// interrupts -/* -1 timer -2 mouse move - mouse button - key down - key up - reread ControlRegisters - redraw GUI // opposite direction (i.e. client to GUI)! - render Text // text mode client -> text rendering process -> redraw GUI - */ +/** + * set displayed text in Text mode + * @param text text to display + * @return if text could be set, false if it could not be set. + */ +bool setText(std::string text); -// Shared Memory Layout -// -------------------------------------------------------------------- -// struct ControlRegisters -// char reserved[1024] -// Interrupt Vector Table [64] -// text area [max_textMode_width * max_textMode_height] -// pixel area [max_height_pixels * max_height_pixels * sizeof(uint_32)] +/** + * get currently saved/displayed text. + */ +std::string getText(); + +//Control registers start here + +//all modes + +/** + * get version of the used layout + * @return layout version + */ +LayoutVersion getLayoutVersion(); + +/** + * reset all values to default. + */ +void reset(); + +/** + * get width of window. + * @return width of window. + */ +int getWidth(); + +/** + * set width of window. + * @param newValue new width for window. + */ +void setWidth(int newValue); + +/** + * get height for window. + * @return height of window. + */ +int getHeight(); + +/** + * set height of window. + * @param newValue new height for window. + */ +void setHeight(int newValue); + +/** + * get graphics display mode. + * @return GraphicMode. + */ +GraphicMode getMode(); + +/** + * set new graphics display mode. + * @param newValue new graphics display mode. + */ +void setMode(GraphicMode newValue); + +/** + * get interval between redraws in milliseconds. + */ +int getRedrawInterval(); + +/** + * set interval between redraws. + * @param newValue new interval in milliseconds. + */ +void setRedrawInterval(int newValue); + +/** + * get time between timer interrupts. + * @return time between interrupts in milliseconds. + */ +int getTimerInterruptInterval(); + +/** + * set time between timer interrupts. + * @param newValue new time between interrupts in milliseconds. + */ +void setTimerInterruptInterval(int newValue); + +//black/white mode + +/** + * get background color in two color mode. + * @return background color. + */ +Color getBackgroundColor(); + +/** + * set background color in two color mode. + * @param newValue new background color. + */ +void setBackgroundColor(Color newValue); + +/** + * get foreground color in two color mode. + * @return foreground color. + */ +Color getForegroundColor(); + +/** + * set foreground color in two color mode. + * @param newValue new foreground color. + */ +void setForegroundColor(Color newValue); + +//text mode + +/** + * get characters per line in text mode. + * @return characters per line. + */ +int getCharactersPerLine(); + +/** + * get characters per row in text mode. + * @return characters per row. + */ +int getCharactersPerRow(); + +/** + * get currently used font in text mode. + * @return currently used font. + */ +Font getFont(); + +/** + * set text mode font. + * @param newValue new text mode font. + */ +void setFont(Font newValue); + +/** + * get current mouse position + * @return mouse position as x,y pair + */ +std::pair getMousePosition(); + +/** + * get key code of last key press. + * @return KeyCode of last key press. + */ +KeyCode getLastPressedKey(); #endif \ No newline at end of file