//usr/bin/env g++ -static -std=c++11 -Wall $0 -L./target/release -lcgui -lpthread -ldl && exec sh -c "./a.out ; #rm ./a.out" || exec echo compile failed #include #include #include #include // Just put the header file anywhere and add libcgui.a to your compile path #include "src/cgui.hpp" void write_rect(CGui w, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint8_t red, uint8_t green, uint8_t blue) { for (int x=x1; x < x2; x++) { for (int y=y1; y < y2; y++) { w.write_px(x, y, red, green, blue); } } } int main(int argc, char** argv) { std::cout << "Inside C++ code..." << std::endl; CGui w; w.init(); int square_size = 5; int x = 15; int y = 15; while (true) { std::string event = w.event_tick(); std::cout << "got event " << event << std::endl; if (event == "WinShown") { // Draw a blue bg write_rect(w, 0,0, 300,200, 0,0,0); // and a red square write_rect(w, x,y, x+square_size,y+square_size, 255,255,255); w.redraw_dirty(); } else if (event == "KeyPress,q") { break; } else if (event == "KeyPress,w" || event == "KeyPress,a" || event == "KeyPress,s" || event == "KeyPress,d") { // erase current square write_rect(w, x,y, x+square_size,y+square_size, 0,0,0); if (event == "KeyPress,w" && y - square_size > 0) { y -= square_size; } else if (event == "KeyPress,a" && x - square_size > 0) { x -= square_size; } else if (event == "KeyPress,s" && y + square_size < 300) { y += square_size; } else if (event == "KeyPress,d" && x + square_size < 300) { x += square_size; } // Write red square and flush write_rect(w, x,y, x+square_size,y+square_size, 255,255,255); w.redraw_dirty(); } } return 0; }