Merge branch 'dev' into 'master'

Merge Dev to master

See merge request link/projekte/ws19/vkvm-new/library!1
This commit is contained in:
Julian Hinxlage 2019-11-02 11:02:17 +00:00
commit 1eac105871
15 changed files with 468 additions and 6 deletions

View File

@ -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

View File

@ -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 <vkvm.h>
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);
}
```

8
src/Color.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "Color.h"
Color::Color(unsigned char red, unsigned char green, unsigned char blue)
: red(red), green(green), blue(blue){
}

25
src/Color.h Normal file
View File

@ -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

20
src/EventType.h Normal file
View File

@ -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

17
src/Font.h Normal file
View File

@ -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

16
src/GraphicMode.h Normal file
View File

@ -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

9
src/KeyCode.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "KeyCode.h"
KeyCode::KeyCode(int value) : value(value) {}
int KeyCode::getValue() {
return value;
}

15
src/KeyCode.h Normal file
View File

@ -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

8
src/LayoutVersion.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef LIBRARY_LAYOUTVERSION_H
#define LIBRARY_LAYOUTVERSION_H
enum LayoutVersion {
V1 = 1
};
#endif

5
src/internal.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "internal.h"
Internal internal;

97
src/internal.h Normal file
View File

@ -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

12
src/notes.txt Normal file
View File

@ -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;
};

6
src/vkvm.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "vkvm.h"
#include "internal.h"
void initialize(int pid) {
internal.sharedMemoryPid = pid;
}

201
src/vkvm.h Normal file
View File

@ -0,0 +1,201 @@
#ifndef LIBRARY_VKVM_H
#define LIBRARY_VKVM_H
#include <string>
#include <functional>
#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<void()> 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<int, int> getMousePosition();
/**
* get key code of last key press.
* @return KeyCode of last key press.
*/
KeyCode getLastPressedKey();
#endif