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..6124b42 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,47 @@ # vKVM Library -# Installation +This library allows for easy interaction with the graphical user interface of the vKVM project. + + +## Features + +- set pixel color +- respond to keyboard/mouse events +- get/set text to be drawn + +## Installation Use the installation script provided in the Scripts repository to install the full package. Installing a single component is currently not supported. -# Usage +## Include Include this library with ``` -set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") +set(LIB_PATH "${CMAKE_SOURCE_DIR}/../relative_path_to_library_folder") include_directories(${LIB_PATH}/include) add_executable(your_client ${SOURCES} ${HEADERS}) target_link_libraries(your_client ${LIB_PATH}/lib/liblibrary.a) ``` -in your CMakeLists. +in your CMakeList. -More documentation coming soon. +## Usage + +```cpp +#include + +int main(int argc, char* argv[]) { + if(argc != 1) return -1; + int pid = std::stoi(argv[0]); + initialize(pid); + + setPixel(10, 10, Color::black); + setPixel(10, 20, Color::red); +} + +``` \ No newline at end of file diff --git a/src/Color.cpp b/src/Color.cpp new file mode 100644 index 0000000..3daac50 --- /dev/null +++ b/src/Color.cpp @@ -0,0 +1,8 @@ + +#include "Color.h" + +Color::Color(unsigned char red, unsigned char green, unsigned char blue) + : red(red), green(green), blue(blue){ + +} + diff --git a/src/Color.h b/src/Color.h new file mode 100644 index 0000000..3d75e99 --- /dev/null +++ b/src/Color.h @@ -0,0 +1,25 @@ +#ifndef LIBRARY_COLOR_H +#define LIBRARY_COLOR_H + + +/** + * color values represented as rgb values. + * @author Johannes Theiner + * @since 0.1.0 + */ +class Color { + +private: + unsigned char red; + unsigned char green; + unsigned char blue; + +public: + Color(unsigned char red, unsigned char green, unsigned char blue); + +}; + +const Color black = Color(0, 0, 0); +const Color white = Color(255, 255, 255); + +#endif diff --git a/src/EventType.h b/src/EventType.h new file mode 100644 index 0000000..6daa1ea --- /dev/null +++ b/src/EventType.h @@ -0,0 +1,20 @@ +#ifndef LIBRARY_EVENTTYPE_H +#define LIBRARY_EVENTTYPE_H + +/** + * types of events. + * @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..d447ee8 --- /dev/null +++ b/src/GraphicMode.h @@ -0,0 +1,16 @@ +#ifndef LIBRARY_GRAPHICMODE_H +#define LIBRARY_GRAPHICMODE_H + +/** + * all possible graphics modes. + * @author Johannes Theiner + * @since 0.1.0 + */ +enum GraphicMode { + Text = 1, + TwoColors = 2, + Gray_256 = 3, + TrueColor = 4, +}; + +#endif diff --git a/src/KeyCode.cpp b/src/KeyCode.cpp new file mode 100644 index 0000000..6e7e2c7 --- /dev/null +++ b/src/KeyCode.cpp @@ -0,0 +1,9 @@ + +#include "KeyCode.h" + +KeyCode::KeyCode(int value) : value(value) {} + +int KeyCode::getValue() { + return value; +} + diff --git a/src/KeyCode.h b/src/KeyCode.h new file mode 100644 index 0000000..65ab74d --- /dev/null +++ b/src/KeyCode.h @@ -0,0 +1,15 @@ +#ifndef LIBRARY_KEYCODE_H +#define LIBRARY_KEYCODE_H + +class KeyCode { +private: + int value; +public: + explicit KeyCode(int value); + int getValue(); +}; + +const KeyCode Backspace = KeyCode(8); +const KeyCode tabulator = KeyCode(9); + +#endif diff --git a/src/LayoutVersion.h b/src/LayoutVersion.h new file mode 100644 index 0000000..ce24e93 --- /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.cpp b/src/internal.cpp new file mode 100644 index 0000000..d9575d2 --- /dev/null +++ b/src/internal.cpp @@ -0,0 +1,5 @@ +#include "internal.h" + +Internal internal; + + diff --git a/src/internal.h b/src/internal.h new file mode 100644 index 0000000..65baee5 --- /dev/null +++ b/src/internal.h @@ -0,0 +1,97 @@ +#ifndef LIBRARY_INTERNAL_H +#define LIBRARY_INTERNAL_H + +#include "EventType.h" +#include "KeyCode.h" +#include "LayoutVersion.h" +#include "GraphicMode.h" +#include "Color.h" + +/** + * the Control Registers + * @author Julian Hinxlage + * @since 0.1.0 + */ +struct Registers{ + int layout_version; + int trigger_reset; + int width_pixels; + int height_pixels; + GraphicMode graphicMode; + int autoRedrawInterval; + int timerInterruptInterval; + Color background_color; + Color foreground_color; + int characters_per_row; + int characters_per_column; + 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; +}; + +struct InterruptEntry{ + int pid; + int signum; +}; + +/** + * internal values for the library. + */ +struct Internal{ + int sharedMemoryPid; +}; +extern Internal internal; + +/** + * set layout version. + * @param newValue new layout version number. + */ +void setLayoutVersion(LayoutVersion newValue); + +/** + * set characters per line for current font. + * @param newValue characters per line. + */ +void setCharactersPerLine(int newValue); + +/** + * set characters per row for current font. + * @param newValue + */ +void setCharactersPerRow(int newValue); + +/** + * call a specific event. + * @param type + * @return true if there is a handler registered. + */ +bool callEvent(EventType type); + +/** + * set mouse position to x,y value. + * @param x x coordinate + * @param y y coordinate + */ +void setMousePosition(int x, int y); + +/** + * register pressed button. + * @param keyCode pressed key. + */ +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.cpp b/src/vkvm.cpp new file mode 100644 index 0000000..45218e4 --- /dev/null +++ b/src/vkvm.cpp @@ -0,0 +1,6 @@ +#include "vkvm.h" +#include "internal.h" + +void initialize(int pid) { + internal.sharedMemoryPid = pid; +} diff --git a/src/vkvm.h b/src/vkvm.h new file mode 100644 index 0000000..a95731f --- /dev/null +++ b/src/vkvm.h @@ -0,0 +1,201 @@ +#ifndef LIBRARY_VKVM_H +#define LIBRARY_VKVM_H + +#include +#include +#include "Color.h" +#include "EventType.h" +#include "GraphicMode.h" +#include "Font.h" +#include "KeyCode.h" +#include "LayoutVersion.h" + +/** + * @since 0.1.0 + * @author Johannes Theiner + */ + +//TODO: better documentation + +/** + * initialize the connection with the shared-memory application + * @param pid pip of shared-memory application + */ +void initialize(int pid); + +/** + * 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); + +/** + * 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); + +/** + * 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); + +/** + * 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); + +/** + * 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 row in text mode. + * @return characters per row. + */ +int getCharactersPerRow(); + +/** + * get characters per column in text mode. + * @return characters per column. + */ +int getCharactersPerColumn(); + +/** + * 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