1.remake show the bild
2.the GUI can show a bild with the colormap 3.Kommentar 4.connect with library
This commit is contained in:
parent
ea4c918758
commit
2a6a0afd1a
121
main/main.cpp
121
main/main.cpp
@ -2,85 +2,75 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Fl/Fl.H>
|
#include <Fl/Fl.H>
|
||||||
#include <Fl/Fl_Box.H>
|
#include <Fl/Fl_Box.H>
|
||||||
#include <Fl/Fl_Output.H>
|
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
|
|
||||||
|
#include "vkvm.hpp"
|
||||||
|
|
||||||
|
|
||||||
#define window_height 600
|
#define window_height 600
|
||||||
#define window_width 800
|
#define window_width 800
|
||||||
|
|
||||||
//Statusbar**************************************/
|
/**************************************[[l***************************************/
|
||||||
|
|
||||||
/** The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position.
|
//Es ist Class fuer Status
|
||||||
* @param text: A pointer to a char-array, that can contain a text like a status or whatever you want.
|
class Status_Leiste : public Fl_Box {
|
||||||
* @parameter x: The mouse-position on the x-axis.
|
|
||||||
* @parameter y: The mouse-position on the y-axis:
|
|
||||||
* @parameter w: The width of a single pixel,
|
|
||||||
* @parameter h: The height of a single pixel.
|
|
||||||
*/
|
|
||||||
class Statusbar: public Fl_Box {
|
|
||||||
char *text;
|
char *text;
|
||||||
public:
|
public:
|
||||||
/** The constructor of Statusbar has to get additional parameters.
|
//Konstruktor
|
||||||
* @param x: The mouse-position on the x-axis.
|
Status_Leiste(int x, int y, int w, int h, char *text) :
|
||||||
* @param y: The mouse-position on the y-axis:
|
|
||||||
* @param w: The width of a single pixel,
|
|
||||||
* @param h: The height of a single pixel.
|
|
||||||
*/
|
|
||||||
Statusbar(int x, int y, int w, int h, char *text) :
|
|
||||||
Fl_Box(x, y, w, h,text) {
|
Fl_Box(x, y, w, h,text) {
|
||||||
this->text = text;
|
this->text = text;
|
||||||
};
|
};
|
||||||
void set_text(char *text) {
|
void set_text(char *text) {
|
||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
//An exampel to show, how the content of the text can be changed.
|
//nur zu Beispiel, zu zeigen, dass der Inhalt von Status einfach geaendert werden kann.
|
||||||
void change_text(){
|
void change_text(){
|
||||||
if(text=="status0")
|
if(text=="status0")
|
||||||
set_text("status1");
|
set_text("status1");
|
||||||
else
|
else
|
||||||
set_text("status0");
|
set_text("status0");
|
||||||
}
|
}
|
||||||
//This function refreshes the statusbar
|
//der neue Inhalt von Status zeigen
|
||||||
void refresh_label(){
|
void refresh_label(){
|
||||||
this->label(text);
|
this->label(text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Image**************************************/
|
//Pixel ist ein neue Class fuer ein Pixel
|
||||||
/** The Image-class draws the bitmap that it get from the Shared Memory.
|
class Bild : public Fl_Widget {
|
||||||
* @param *buf: A pointer to the bitmap, that the image-class has to draw. Three chars are needed to get the RGB-value of a pixel, so the size equals window_height * window_width * 3.
|
uchar *buf;//Bitmap fuer das Bild, es braucht 3 char um ein Pixel zu erklaren(RGB), deshalb die Groesse von buf ist window_height * window_width * 3
|
||||||
*/
|
|
||||||
|
|
||||||
class Image : public Fl_Widget {
|
//buf ist das Bitmap fuer das Bild, x,y fuer Postion in Window, w, h, bedeutet height und width
|
||||||
uchar *buf;
|
|
||||||
|
|
||||||
//Function to draw a bitmap
|
|
||||||
void draw() {
|
void draw() {
|
||||||
fl_draw_image(buf, x(), y(), w(), h());
|
fl_draw_image(buf, x(), y(), w(), h());
|
||||||
}
|
}
|
||||||
/** The constructor of the image class, get additional
|
|
||||||
* @param x: The mouse-position on the x-axis.
|
|
||||||
* @param y: The mouse-position on the y-axis:
|
|
||||||
* @param w: The width of a single pixel,
|
|
||||||
* @param h: The height of a single pixel.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*Constructor*/
|
//Konstruktor
|
||||||
Image(int x, int y, int w, int h) :
|
Bild(int x, int y, int w, int h) :
|
||||||
Fl_Widget(x, y, w, h, 0) {
|
Fl_Widget(x, y, w, h, 0) {
|
||||||
buf = new uchar[w * h * 3];
|
buf = new uchar[w * h * 3];
|
||||||
/*Just an example.*/
|
//nur als Beispiel
|
||||||
for (int i = 0; i < h; i++) {
|
for (int i = 0; i < h; i++) {
|
||||||
for (int j = 0; j < w; j++) {
|
for (int j = 0; j < w; j++) {
|
||||||
buf[(j + (i * w)) * 3 + 1] = 0xff;
|
buf[(j + (i * w)) * 3 + 1] = 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*A function to change the colors of the image-class. The colors are changing in this order: green, blue, red*/
|
|
||||||
|
//die Farbe vom Bild aendern(Die Reihenfolge: gruen, rot, blau, gruen )
|
||||||
void change_color() {
|
void change_color() {
|
||||||
|
for (int i = 0; i < h(); i++) {
|
||||||
|
for (int j = 0; j < w(); j++) {
|
||||||
|
vkvm::Color c = vkvm::getPixel(j,i);
|
||||||
|
buf[(i * w() + j) * 3 + 0] = c.getRed();
|
||||||
|
buf[(i * w() + j) * 3 + 1] = c.getGreen();
|
||||||
|
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
for (int j = 1; j < w() * h() * 3; j++) {
|
for (int j = 1; j < w() * h() * 3; j++) {
|
||||||
if (buf[j] == 0xff) {
|
if (buf[j] == 0xff) {
|
||||||
buf[j] = 0;
|
buf[j] = 0;
|
||||||
@ -89,24 +79,18 @@ public:
|
|||||||
}
|
}
|
||||||
if (buf[2] == 0xff)
|
if (buf[2] == 0xff)
|
||||||
buf[w() * h() * 3 - 1] = 0xff;
|
buf[w() * h() * 3 - 1] = 0xff;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//My_Window*************************************/
|
|
||||||
/** The My_Windows-class generates a window, within the window it recognizes the curretn mouse-position.
|
|
||||||
* It also recognizes if a button is pushed on the keyboard or the mouse. Furthermore the class depict the
|
|
||||||
* content of the Image-class and provides functions to refresh it.
|
|
||||||
* @parame x The mouse-position on the x-axis.
|
|
||||||
* @parame y The mouse-position on the y-axis.
|
|
||||||
* @parame button The button that was pushed last.
|
|
||||||
*/
|
|
||||||
class My_Window : public Fl_Window {
|
class My_Window : public Fl_Window {
|
||||||
int x, y, button;
|
int x, y, button;
|
||||||
|
|
||||||
/*Function to handle the input*/
|
//die Inputs von Maus und Tastatur behandln
|
||||||
int handle(int e) {
|
int handle(int e) {
|
||||||
switch (e) {
|
switch (e) {
|
||||||
/*Mousebutton*/
|
//Druck vom Maus behandln
|
||||||
case FL_PUSH:
|
case FL_PUSH:
|
||||||
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
||||||
std::cout << "Mouse:left" << std::endl;
|
std::cout << "Mouse:left" << std::endl;
|
||||||
@ -116,7 +100,7 @@ class My_Window : public Fl_Window {
|
|||||||
std::cout << "Mouse:middle" << std::endl;
|
std::cout << "Mouse:middle" << std::endl;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
/*Mousebutton and movement*/
|
//Druck und Bewegung vom Maus behandln
|
||||||
case FL_DRAG:
|
case FL_DRAG:
|
||||||
x = Fl::event_x();
|
x = Fl::event_x();
|
||||||
y = Fl::event_y();
|
y = Fl::event_y();
|
||||||
@ -129,52 +113,57 @@ class My_Window : public Fl_Window {
|
|||||||
std::cout << "Mouse:middle" << std::endl;
|
std::cout << "Mouse:middle" << std::endl;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
/*Mousemovement*/
|
//Bewegung vom Maus behandln
|
||||||
case FL_MOVE:
|
case FL_MOVE:
|
||||||
x = Fl::event_x();
|
x = Fl::event_x();
|
||||||
y = Fl::event_y();
|
y = Fl::event_y();
|
||||||
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
/*keyboardbutton*/
|
//Druck von der Tastator behandln
|
||||||
case FL_KEYBOARD:
|
case FL_KEYBOARD:
|
||||||
button = Fl::event_button();
|
button = Fl::event_button();
|
||||||
std::cout << "Keyboard:" << (unsigned short) button << std::endl;
|
std::cout << "Keyboard:" << (unsigned short) button << " down"<<std::endl;
|
||||||
|
return 1;
|
||||||
|
case FL_KEYUP:
|
||||||
|
button = Fl::event_button();
|
||||||
|
std::cout << "Keyboard:" << (unsigned short) button << " up"<<std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*Constructor*/
|
//Konstruktor
|
||||||
My_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
My_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Functions to refresh the image.*/
|
//draw() wird regelmaessig anrufen
|
||||||
void refresh_image(void *pointer) {
|
void refresh_bild(void *pointer) {
|
||||||
((Image *) pointer)->redraw();
|
((Bild *) pointer)->redraw();
|
||||||
Fl::repeat_timeout(0.5, refresh_image, pointer);//nach 0.5 sec refresh_bild(pointer) anrufen. Here pointer ist wie ein Parameter
|
Fl::repeat_timeout(0.5, refresh_bild, pointer);//nach 0.5 sec refresh_bild(pointer) anrufen. Here pointer ist wie ein Parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//die Farbe von Pixels regekmaessig aendern
|
||||||
void change_color(void *pointer) {
|
void change_color(void *pointer) {
|
||||||
((Image *) pointer)->change_color();
|
((Bild *) pointer)->change_color();
|
||||||
Fl::repeat_timeout(1, change_color, pointer);
|
Fl::repeat_timeout(1, change_color, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh_statusbar(void *pointer) {
|
//refresh_status() von Status0 wird regelmaessig anrufen
|
||||||
((Statusbar **) pointer)[0]->refresh_label();
|
void refresh_status_leiste(void *pointer) {
|
||||||
Fl::repeat_timeout(0.5, refresh_statusbar, pointer);
|
((Status_Leiste **) pointer)[0]->refresh_label();
|
||||||
|
Fl::repeat_timeout(0.5, refresh_status_leiste, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//der Inhalt von Status0 regekmaessig aendern
|
||||||
void change_status(void *pointer) {
|
void change_status(void *pointer) {
|
||||||
((Status_Leiste **) pointer)[0]->change_text();
|
((Status_Leiste **) pointer)[0]->change_text();
|
||||||
Fl::repeat_timeout(1, change_status, pointer);
|
Fl::repeat_timeout(1, change_status, pointer);
|
||||||
}
|
}
|
||||||
|
// main
|
||||||
//main*************************************/
|
|
||||||
/**
|
|
||||||
* The main function initializes all needed classes and executes the functions.
|
|
||||||
*/
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
vkvm::initialize(0);
|
||||||
|
|
||||||
My_Window *window = new My_Window(window_width, window_height, "example");
|
My_Window *window = new My_Window(window_width, window_height, "example");
|
||||||
Status_Leiste *status[5];
|
Status_Leiste *status[5];
|
||||||
window->begin();
|
window->begin();
|
||||||
@ -191,4 +180,4 @@ int main(int argc, char **argv) {
|
|||||||
window->end();
|
window->end();
|
||||||
window->show(argc, argv);
|
window->show(argc, argv);
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
}main
|
}
|
Loading…
Reference in New Issue
Block a user