From 7ddea2b130d75726cd5f0b11828948a1eb621cc4 Mon Sep 17 00:00:00 2001 From: chenhuan Date: Wed, 6 Nov 2019 12:17:23 +0100 Subject: [PATCH 1/9] 1.remake show the bild 2.the GUI can show a bild with the colormap 3.Kommentar --- main/main.cpp | 135 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 102 insertions(+), 33 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 97583c4..9100a35 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2,69 +2,138 @@ #include #include #include +#include #include #include - #define window_height 600 #define window_width 800 -/*****************************************************************************/ +/**************************************[[l***************************************/ /* This class provides a view to copy the offscreen surface to */ -int color_map[window_width][window_height]; -class My_Window : public Fl_Window{ - int x,y,button; - int handle(int e) - { +//Pixel ist ein neue Class fuer ein Pixel +class Pixel : public Fl_Widget { + Fl_Color color; + //Pixel zu malen, x,y sind fuer die Postion in Window.w,h ist width und height.color ist die Farbe von Pixel + void draw() { + fl_draw_box(FL_FLAT_BOX, x(), y(), w(), h(), color); + } - switch (e) - { +public: + //Konstruktor + Pixel(int x, int y, int w, int h) : + Fl_Widget(x, y, w, h, 0) {} + //die Farbe von Pixel einstellen + void set_color(int RGB){ + this->color = fl_rgb_color((uchar) ((RGB & 0xff000000) >> 24), (uchar) ((RGB & 0xff0000) >> 16), + (uchar) ((RGB & 0xff00) >> 8)); + } +}; + + +class My_Window : public Fl_Window { + int x, y, button; + int (*color_map)[window_width][window_height]; + Pixel* pixels[window_width][window_height]; + int c=0xff000000; + //die Inputs von Maus und Tastatur behandln + int handle(int e) { + switch (e) { + //Druck vom Maus behandln + case FL_PUSH: + if(Fl::event_button()==FL_LEFT_MOUSE){ + std::cout << "Mouse:left" << std::endl; + }else if(Fl::event_button()==FL_RIGHT_MOUSE){ + std::cout << "Mouse:right" << std::endl; + }else{ + std::cout << "Mouse:middle" << std::endl; + } + return 1; + //Druck und Bewegung vom Maus behandln + case FL_DRAG: + x = Fl::event_x(); + y = Fl::event_y(); + std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl; + if(Fl::event_button()==FL_LEFT_MOUSE){ + std::cout << "Mouse:left" << std::endl; + }else if(Fl::event_button()==FL_RIGHT_MOUSE){ + std::cout << "Mouse:right" << std::endl; + }else{ + std::cout << "Mouse:middle" << std::endl; + } + return 1; + //Bewegung vom Maus behandln case FL_MOVE: x = Fl::event_x(); y = Fl::event_y(); - std::cout<<"Postion X:"<< x <<" Postion Y:"<< y <(1), x(), y(), w(), h(), color); + //Konstruktor + My_Window(int x, int y, const char *l, int (*color_map)[window_width][window_height]) : Fl_Window(x, y, l) { + this->color_map = color_map; + for (int i = 0; i < window_width; i++) { + for (int j = 0; j < window_height; j++) { + pixels[i][j]=new Pixel(i,j,1,1); + } + } } - -public: - Pixel(int x,int y,int w,int h,int RGB) : - Fl_Widget(x,y,w,h,0) { - this->color = fl_rgb_color((uchar)((RGB&0xff000000)>>24),(uchar)((RGB&0xff0000)>>16),(uchar)((RGB&0xff00)>>8)); + //Window akualisieren, refresh + int draw_bild() { + for (int i = 0; i < window_width; i++) { + for (int j = 0; j < window_height; j++) { + pixels[i][j]->set_color((*color_map)[i][j]); + pixels[i][j]->redraw(); + } + } } }; +//draw_bild() wird regelmaessig anrufen +void refresh(void* pointer){ + ((My_Window*)pointer)->draw_bild(); + Fl::repeat_timeout(0.5, refresh,pointer); +} +//die Farbe von Pixels regekmaessig aendern +void change_color(void* pointer){ + int (*color_map)[window_width][window_height]; + color_map = (typeof(color_map))(pointer); + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { + (*color_map)[i][j] ^= 0xffff0000; + } + } + + Fl::repeat_timeout(1, change_color,pointer); +} + int main(int argc, char **argv) { - for(int i=0;i<100;i++){ - for (int j = 0; j < 100 ; j++) { - color_map[i][j]=0xff000000; + + int color_map[window_width][window_height]; + + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { + color_map[i][j] = 0xff000000; } } - My_Window* window = new My_Window(window_width, window_height, "example"); + My_Window *window = new My_Window(window_width, window_height, "example", &color_map); window->begin(); - for(int i=0;i<100;i++){ - for (int j = 0; j < 100 ; j++) { - new Pixel(i,j,1,1,color_map[i][j]); - } - } + Fl::repeat_timeout(0.5, refresh,window);//refresh anrufen nach 0.5 sec + Fl::repeat_timeout(1,change_color, &color_map);// change_color anrufen nach 1 sec + window->end(); - window->show(argc,argv); + window->show(argc, argv); return Fl::run(); } // main \ No newline at end of file From 2a8b11f6d3a91df04396a67fb792791a1e5645f8 Mon Sep 17 00:00:00 2001 From: Edgar Schkrob Date: Thu, 7 Nov 2019 12:43:16 +0100 Subject: [PATCH 2/9] main.cpp comments updated --- main/main.cpp | 217 +++++++++++++++++++++++++++++++------------------- 1 file changed, 136 insertions(+), 81 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 9100a35..934eceb 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,8 +1,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -10,130 +10,185 @@ #define window_height 600 #define window_width 800 -/**************************************[[l***************************************/ -/* This class provides a view to copy the offscreen surface to */ - -//Pixel ist ein neue Class fuer ein Pixel -class Pixel : public Fl_Widget { - Fl_Color color; - //Pixel zu malen, x,y sind fuer die Postion in Window.w,h ist width und height.color ist die Farbe von Pixel - void draw() { - fl_draw_box(FL_FLAT_BOX, x(), y(), w(), h(), color); - } +//Statusbar**************************************/ +/** The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position. + * @param text: A pointer to a char-array, that can contain a text like a status or whatever you want. + * @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; public: - //Konstruktor - Pixel(int x, int y, int w, int h) : - Fl_Widget(x, y, w, h, 0) {} - //die Farbe von Pixel einstellen - void set_color(int RGB){ - this->color = fl_rgb_color((uchar) ((RGB & 0xff000000) >> 24), (uchar) ((RGB & 0xff0000) >> 16), - (uchar) ((RGB & 0xff00) >> 8)); + /** The constructor of Statusbar has to get additional parameters. + * @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. + */ + Statusbar(int x, int y, int w, int h, char *text) : + Fl_Box(x, y, w, h,text) { + this->text = text; + }; + void set_text(char *text) { + this->text = text; + } + //An exampel to show, how the content of the text can be changed. + void change_text(){ + if(text=="status0") + set_text("status1"); + else + set_text("status0"); + } + //This function refreshes the statusbar + void refresh_label(){ + this->label(text); } }; +//Image**************************************/ +/** The Image-class draws the bitmap that it get from the Shared Memory. + * @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. + */ +class Image : public Fl_Widget { + uchar *buf; + + //Function to draw a bitmap + void draw() { + 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: + /*Constructor*/ + Image(int x, int y, int w, int h) : + Fl_Widget(x, y, w, h, 0) { + buf = new uchar[w * h * 3]; + /*Just an example.*/ + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + 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*/ + void change_color() { + for (int j = 1; j < w() * h() * 3; j++) { + if (buf[j] == 0xff) { + buf[j] = 0; + buf[j - 1] = 0xff; + } + } + if (buf[2] == 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 { int x, y, button; - int (*color_map)[window_width][window_height]; - Pixel* pixels[window_width][window_height]; - int c=0xff000000; - //die Inputs von Maus und Tastatur behandln + + /*Function to handle the input*/ int handle(int e) { switch (e) { - //Druck vom Maus behandln + /*Mousebutton*/ case FL_PUSH: - if(Fl::event_button()==FL_LEFT_MOUSE){ + if (Fl::event_button() == FL_LEFT_MOUSE) { std::cout << "Mouse:left" << std::endl; - }else if(Fl::event_button()==FL_RIGHT_MOUSE){ + } else if (Fl::event_button() == FL_RIGHT_MOUSE) { std::cout << "Mouse:right" << std::endl; - }else{ + } else { std::cout << "Mouse:middle" << std::endl; } return 1; - //Druck und Bewegung vom Maus behandln + /*Mousebutton and movement*/ case FL_DRAG: x = Fl::event_x(); y = Fl::event_y(); std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl; - if(Fl::event_button()==FL_LEFT_MOUSE){ + if (Fl::event_button() == FL_LEFT_MOUSE) { std::cout << "Mouse:left" << std::endl; - }else if(Fl::event_button()==FL_RIGHT_MOUSE){ + } else if (Fl::event_button() == FL_RIGHT_MOUSE) { std::cout << "Mouse:right" << std::endl; - }else{ + } else { std::cout << "Mouse:middle" << std::endl; } return 1; - //Bewegung vom Maus behandln + /*Mousemovement*/ case FL_MOVE: x = Fl::event_x(); y = Fl::event_y(); std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl; return 1; - //Druck von der Tastator behandln + /*keyboardbutton*/ case FL_KEYBOARD: button = Fl::event_button(); std::cout << "Keyboard:" << (unsigned short) button << std::endl; return 1; - // case FL_: } } public: - //Konstruktor - My_Window(int x, int y, const char *l, int (*color_map)[window_width][window_height]) : Fl_Window(x, y, l) { - this->color_map = color_map; - for (int i = 0; i < window_width; i++) { - for (int j = 0; j < window_height; j++) { - pixels[i][j]=new Pixel(i,j,1,1); - } - } - } - //Window akualisieren, refresh - int draw_bild() { - for (int i = 0; i < window_width; i++) { - for (int j = 0; j < window_height; j++) { - pixels[i][j]->set_color((*color_map)[i][j]); - pixels[i][j]->redraw(); - } - } - } + /*Constructor*/ + My_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {} }; -//draw_bild() wird regelmaessig anrufen -void refresh(void* pointer){ - ((My_Window*)pointer)->draw_bild(); - Fl::repeat_timeout(0.5, refresh,pointer); -} -//die Farbe von Pixels regekmaessig aendern -void change_color(void* pointer){ - int (*color_map)[window_width][window_height]; - color_map = (typeof(color_map))(pointer); - for (int i = 0; i < 100; i++) { - for (int j = 0; j < 100; j++) { - (*color_map)[i][j] ^= 0xffff0000; - } - } - - Fl::repeat_timeout(1, change_color,pointer); +/*Functions to refresh the image.*/ +void refresh_image(void *pointer) { + ((Image *) pointer)->redraw(); + Fl::repeat_timeout(0.5, refresh_image, pointer);//nach 0.5 sec refresh_bild(pointer) anrufen. Here pointer ist wie ein Parameter } +void change_color(void *pointer) { + ((Image *) pointer)->change_color(); + Fl::repeat_timeout(1, change_color, pointer); +} + +void refresh_statusbar(void *pointer) { + ((Statusbar **) pointer)[0]->refresh_label(); + Fl::repeat_timeout(0.5, refresh_statusbar, pointer); +} + +void change_status(void *pointer) { + ((Status_Leiste **) pointer)[0]->change_text(); + Fl::repeat_timeout(1, change_status, pointer); +} + +//main*************************************/ +/** + * The main function initializes all needed classes and executes the functions. + */ int main(int argc, char **argv) { - - int color_map[window_width][window_height]; - - for (int i = 0; i < 100; i++) { - for (int j = 0; j < 100; j++) { - color_map[i][j] = 0xff000000; - } - } - My_Window *window = new My_Window(window_width, window_height, "example", &color_map); + My_Window *window = new My_Window(window_width, window_height, "example"); + Status_Leiste *status[5]; window->begin(); - Fl::repeat_timeout(0.5, refresh,window);//refresh anrufen nach 0.5 sec - Fl::repeat_timeout(1,change_color, &color_map);// change_color anrufen nach 1 sec - + Bild *bild = new Bild(0, 30, window_width, window_height - 30); + status[0] = new Status_Leiste(0, 0, 60, 30, "status0"); + status[1] = new Status_Leiste(60, 0, 60, 30, "status1"); + status[2] = new Status_Leiste(120, 0, 60, 30, "status2"); + status[3] = new Status_Leiste(180, 0, 60, 30, "status3"); + status[4] = new Status_Leiste(240, 0, 60, 30, "status4"); + Fl::repeat_timeout(0.5, refresh_bild, bild); + Fl::repeat_timeout(1, change_color, bild); + Fl::repeat_timeout(0.5, refresh_status_leiste, status); + Fl::repeat_timeout(1, change_status, status); window->end(); window->show(argc, argv); return Fl::run(); -} // main \ No newline at end of file +}main \ No newline at end of file From de18073b6990a786260effb24b25b14246e545f4 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 7 Nov 2019 14:01:21 +0000 Subject: [PATCH 3/9] + ci pipeline --- .ci/clang-tidy.sh | 32 ++++++++++++++++++++++ .gitlab-ci.yml | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .ci/clang-tidy.sh create mode 100644 .gitlab-ci.yml diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh new file mode 100644 index 0000000..eae5b12 --- /dev/null +++ b/.ci/clang-tidy.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +echo "Doing clang-tidy..." +bool=false +# explicitly set IFS to contain only a line feed +IFS=' +' +filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name "$(printf "*\n*")")" +for file in $filelist; do + if echo "$file" | grep -q -E ".*\.cpp$" ; then + #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + for tidy_line in $clang_tidy_lib_check; do + echo "$tidy_line" | grep -q -v -E "^Error while processing*" + if [ $? -eq 1 ]; then + bool=true + fi + echo "$tidy_line" | grep -q -v -E ".* error: .*" + if [ $? -eq 1 ]; then + bool=true + fi + echo "$tidy_line" + done + fi +done +if $bool; then + exit 1 +else + echo "No clang-tidy errors found." +fi + +exit 0 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..32d0eb7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,68 @@ +--- + +image: samueldebruyn/debian-git:latest + +stages: + - style + - test + - build + + +clang_tidy: + image: jhasse/clang-tidy + stage: style + tags: + - docker-ci + script: + - sh .ci/clang-tidy.sh; + +make_test: + stage: test + tags: + - docker-ci + script: + - apt-get update + - apt-get install -y g++ make cmake clang-tidy libfltk1.3 libfltk1.3-dev + - mkdir current + - ls | grep -v current | xargs mv -t current + - git clone https://github.com/catchorg/Catch2.git + - cd Catch2 + - cmake -Bbuild -H. -DBUILD_TESTING=OFF + - cmake --build build/ --target install + - cd .. + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git + - mkdir library/build + - cd library/build + - cmake .. + - make + - cd ../../current + - mkdir build + - cd build + - cmake .. + - make + - make test + +cmake_build: + stage: build + tags: + - docker-ci + script: + - apt-get update + - apt-get install -y g++ make cmake clang-tidy libfltk1.3 libfltk1.3-dev + - mkdir current + - ls | grep -v current | xargs mv -t current + - git clone https://github.com/catchorg/Catch2.git + - cd Catch2 + - cmake -Bbuild -H. -DBUILD_TESTING=OFF + - cmake --build build/ --target install + - cd .. + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git + - mkdir library/build + - cd library/build + - cmake .. + - make + - cd ../../current + - mkdir build + - cd build + - cmake .. + - make \ No newline at end of file From 24a7b22878cf297957551dbf1fcf18410e940ef1 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 11:12:08 +0000 Subject: [PATCH 4/9] ~ CI: clang_tidy step now contains catch2 & fltk --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 32d0eb7..033cd86 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ stages: clang_tidy: - image: jhasse/clang-tidy + image: joethei/clang_tidy stage: style tags: - docker-ci From f85ff6b45a660107f0fc743a536aacad3f338975 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 11:41:30 +0000 Subject: [PATCH 5/9] ~ default argument calls are now allowed --- .ci/clang-tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index eae5b12..c20c8fb 100644 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -9,7 +9,7 @@ filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name for file in $filelist; do if echo "$file" | grep -q -E ".*\.cpp$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. - clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-argument-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" for tidy_line in $clang_tidy_lib_check; do echo "$tidy_line" | grep -q -v -E "^Error while processing*" if [ $? -eq 1 ]; then From ea4c9187583c15d8bd59d67b89d1f1342cc79874 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 15:20:24 +0100 Subject: [PATCH 6/9] ~ clang-tidy checks all files now --- .ci/clang-tidy.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index c20c8fb..913c79a 100644 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -5,11 +5,11 @@ bool=false # explicitly set IFS to contain only a line feed IFS=' ' -filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name "$(printf "*\n*")")" +filelist="$(find . -not \( -path './*build*' -prune \) -type f ! -name "$(printf "*\n*")")" for file in $filelist; do - if echo "$file" | grep -q -E ".*\.cpp$" ; then + if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. - clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-argument-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-arguments-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" for tidy_line in $clang_tidy_lib_check; do echo "$tidy_line" | grep -q -v -E "^Error while processing*" if [ $? -eq 1 ]; then From 2a6a0afd1a5f0ef0a167ad854cf265e070dee3ab Mon Sep 17 00:00:00 2001 From: chenhuan Date: Thu, 14 Nov 2019 11:54:47 +0100 Subject: [PATCH 7/9] 1.remake show the bild 2.the GUI can show a bild with the colormap 3.Kommentar 4.connect with library --- main/main.cpp | 121 +++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 66 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 934eceb..4ffe6c7 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2,85 +2,75 @@ #include #include #include -#include #include #include +#include "vkvm.hpp" + #define window_height 600 #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. - * @param text: A pointer to a char-array, that can contain a text like a status or whatever you want. - * @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 { +//Es ist Class fuer Status +class Status_Leiste : public Fl_Box { char *text; public: - /** The constructor of Statusbar has to get additional parameters. - * @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. - */ - Statusbar(int x, int y, int w, int h, char *text) : +//Konstruktor + Status_Leiste(int x, int y, int w, int h, char *text) : Fl_Box(x, y, w, h,text) { this->text = text; }; void set_text(char *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(){ if(text=="status0") set_text("status1"); else set_text("status0"); } - //This function refreshes the statusbar + //der neue Inhalt von Status zeigen void refresh_label(){ this->label(text); } }; -//Image**************************************/ -/** The Image-class draws the bitmap that it get from the Shared Memory. - * @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. - */ +//Pixel ist ein neue Class fuer ein Pixel +class Bild : public Fl_Widget { + 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 { - uchar *buf; - - //Function to draw a bitmap + //buf ist das Bitmap fuer das Bild, x,y fuer Postion in Window, w, h, bedeutet height und width void draw() { 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: - /*Constructor*/ - Image(int x, int y, int w, int h) : +//Konstruktor + Bild(int x, int y, int w, int h) : Fl_Widget(x, y, w, h, 0) { buf = new uchar[w * h * 3]; - /*Just an example.*/ +//nur als Beispiel for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { 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() { + 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++) { if (buf[j] == 0xff) { buf[j] = 0; @@ -89,24 +79,18 @@ public: } if (buf[2] == 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 { int x, y, button; - /*Function to handle the input*/ +//die Inputs von Maus und Tastatur behandln int handle(int e) { switch (e) { - /*Mousebutton*/ +//Druck vom Maus behandln case FL_PUSH: if (Fl::event_button() == FL_LEFT_MOUSE) { std::cout << "Mouse:left" << std::endl; @@ -116,7 +100,7 @@ class My_Window : public Fl_Window { std::cout << "Mouse:middle" << std::endl; } return 1; - /*Mousebutton and movement*/ +//Druck und Bewegung vom Maus behandln case FL_DRAG: x = Fl::event_x(); y = Fl::event_y(); @@ -129,52 +113,57 @@ class My_Window : public Fl_Window { std::cout << "Mouse:middle" << std::endl; } return 1; - /*Mousemovement*/ +//Bewegung vom Maus behandln case FL_MOVE: x = Fl::event_x(); y = Fl::event_y(); std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl; return 1; - /*keyboardbutton*/ +//Druck von der Tastator behandln case FL_KEYBOARD: button = Fl::event_button(); - std::cout << "Keyboard:" << (unsigned short) button << std::endl; + std::cout << "Keyboard:" << (unsigned short) button << " down"<redraw(); - Fl::repeat_timeout(0.5, refresh_image, pointer);//nach 0.5 sec refresh_bild(pointer) anrufen. Here pointer ist wie ein Parameter +//draw() wird regelmaessig anrufen +void refresh_bild(void *pointer) { + ((Bild *) pointer)->redraw(); + 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) { - ((Image *) pointer)->change_color(); + ((Bild *) pointer)->change_color(); Fl::repeat_timeout(1, change_color, pointer); } -void refresh_statusbar(void *pointer) { - ((Statusbar **) pointer)[0]->refresh_label(); - Fl::repeat_timeout(0.5, refresh_statusbar, pointer); +//refresh_status() von Status0 wird regelmaessig anrufen +void refresh_status_leiste(void *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) { ((Status_Leiste **) pointer)[0]->change_text(); Fl::repeat_timeout(1, change_status, pointer); } - -//main*************************************/ -/** - * The main function initializes all needed classes and executes the functions. - */ +// main int main(int argc, char **argv) { + vkvm::initialize(0); + My_Window *window = new My_Window(window_width, window_height, "example"); Status_Leiste *status[5]; window->begin(); @@ -191,4 +180,4 @@ int main(int argc, char **argv) { window->end(); window->show(argc, argv); return Fl::run(); -}main \ No newline at end of file +} \ No newline at end of file From a72cc768db8a199653b5618b569eaddf5fad724f Mon Sep 17 00:00:00 2001 From: Edgar Schkrob Date: Thu, 14 Nov 2019 12:36:40 +0100 Subject: [PATCH 8/9] Aktuellste Version der GUI-main.cpp. Farben werden nun von der Shared Mamory ausgelesen. --- main/main.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 934eceb..5eb50c6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -14,10 +14,6 @@ /** The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position. * @param text: A pointer to a char-array, that can contain a text like a status or whatever you want. - * @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; @@ -68,7 +64,6 @@ class Image : public Fl_Widget { */ public: - /*Constructor*/ Image(int x, int y, int w, int h) : Fl_Widget(x, y, w, h, 0) { buf = new uchar[w * h * 3]; From 5d55c2ec9567662fed23386acca3561b6b7cf47e Mon Sep 17 00:00:00 2001 From: Edgar Schkrob Date: Thu, 14 Nov 2019 12:40:34 +0100 Subject: [PATCH 9/9] Aktuellste Version der GUI-main.cpp. Farben werden nun von der Mamory ausgelesen. --- main/main.cpp | 134 +++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 5eb50c6..aca54ba 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2,10 +2,11 @@ #include #include #include -#include #include #include +#include "vkvm.hpp" + #define window_height 600 #define window_width 800 @@ -15,7 +16,8 @@ /** The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position. * @param text: A pointer to a char-array, that can contain a text like a status or whatever you want. */ -class Statusbar: public Fl_Box { + +class Statusbar : public Fl_Box { char *text; public: /** The constructor of Statusbar has to get additional parameters. @@ -24,7 +26,7 @@ public: * @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) : + Statusbar (int x, int y, int w, int h, char *text) : Fl_Box(x, y, w, h,text) { this->text = text; }; @@ -38,54 +40,12 @@ public: else set_text("status0"); } - //This function refreshes the statusbar + //This function refreshes the statusbar. void refresh_label(){ this->label(text); } }; -//Image**************************************/ -/** The Image-class draws the bitmap that it get from the Shared Memory. - * @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. - */ - -class Image : public Fl_Widget { - uchar *buf; - - //Function to draw a bitmap - void draw() { - 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: - Image(int x, int y, int w, int h) : - Fl_Widget(x, y, w, h, 0) { - buf = new uchar[w * h * 3]; - /*Just an example.*/ - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - 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*/ - void change_color() { - for (int j = 1; j < w() * h() * 3; j++) { - if (buf[j] == 0xff) { - buf[j] = 0; - buf[j - 1] = 0xff; - } - } - if (buf[2] == 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. @@ -95,6 +55,7 @@ public: * @parame y The mouse-position on the y-axis. * @parame button The button that was pushed last. */ + class My_Window : public Fl_Window { int x, y, button; @@ -133,21 +94,69 @@ class My_Window : public Fl_Window { /*keyboardbutton*/ case FL_KEYBOARD: button = Fl::event_button(); - std::cout << "Keyboard:" << (unsigned short) button << std::endl; + std::cout << "Keyboard:" << (unsigned short) button << " down"<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_image, pointer);//nach 0.5 sec refresh_image(pointer) anrufen. Here pointer ist wie ein Parameter } void change_color(void *pointer) { @@ -161,29 +170,30 @@ void refresh_statusbar(void *pointer) { } void change_status(void *pointer) { - ((Status_Leiste **) pointer)[0]->change_text(); + ((Statusbar **) pointer)[0]->change_text(); Fl::repeat_timeout(1, change_status, pointer); } - //main*************************************/ /** * The main function initializes all needed classes and executes the functions. */ int main(int argc, char **argv) { + vkvm::initialize(0); + My_Window *window = new My_Window(window_width, window_height, "example"); - Status_Leiste *status[5]; + Statusbar *status[5]; window->begin(); - Bild *bild = new Bild(0, 30, window_width, window_height - 30); - status[0] = new Status_Leiste(0, 0, 60, 30, "status0"); - status[1] = new Status_Leiste(60, 0, 60, 30, "status1"); - status[2] = new Status_Leiste(120, 0, 60, 30, "status2"); - status[3] = new Status_Leiste(180, 0, 60, 30, "status3"); - status[4] = new Status_Leiste(240, 0, 60, 30, "status4"); - Fl::repeat_timeout(0.5, refresh_bild, bild); - Fl::repeat_timeout(1, change_color, bild); - Fl::repeat_timeout(0.5, refresh_status_leiste, status); + Image *image = new Image(0, 30, window_width, window_height - 30); + status[0] = new Statusbar(0, 0, 60, 30, "status0"); + status[1] = new Statusbar(60, 0, 60, 30, "status1"); + status[2] = new Statusbar(120, 0, 60, 30, "status2"); + status[3] = new Statusbar(180, 0, 60, 30, "status3"); + status[4] = new Statusbar(240, 0, 60, 30, "status4"); + Fl::repeat_timeout(0.5, refresh_image, image); + Fl::repeat_timeout(1, change_color, image); + Fl::repeat_timeout(0.5, refresh_statusbar, status); Fl::repeat_timeout(1, change_status, status); window->end(); window->show(argc, argv); return Fl::run(); -}main \ No newline at end of file +} \ No newline at end of file