Advertisement
Taz8du29

matrixEditor.cpp

Jan 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. /* matrixEditor.cpp
  2.  *
  3.  * Main file for the matrixNecklace editor
  4.  *
  5.  * Copyright 2017 (C) Taz8du29
  6.  * Refer to LICENSE.md for more infos about copyright
  7. */
  8.  
  9.  
  10. #ifndef _MATRIXEDITOR_CPP_
  11. #define _MATRIXEDITOR_CPP_
  12.  
  13. #include "matrixEditor.h"
  14.  
  15.  
  16. /* CLASS "Led" */
  17.  
  18. Led::Led(uint8_t index, bool state) : Fl_Button(0, 0, this->dotSize, this->dotSize)
  19. {
  20.     this->index = index;
  21.     this->position(
  22.         (int) (index / 8) * this->dotSize,
  23.         (int) (index % 8) * this->dotSize + 30
  24.     );
  25.  
  26.     this->box(FL_FRAME_BOX);
  27.     this->down_box(FL_NO_BOX);
  28.  
  29.     if (state) { this->set(); this->image(led_on); }
  30.     else { this->clear(); this->image(led_off); }
  31. }
  32.  
  33. void Led::invert(void)
  34. {
  35.     if (this->value()) { this->clear(); this->image(led_off); }
  36.     else { this->set(); this->image(led_on); }
  37.  
  38.     this->redraw();
  39. }
  40.  
  41. int Led::handle(int event)
  42. {
  43.     switch (event) {
  44.         case FL_PUSH:
  45.             if (Fl::event_button() == FL_LEFT_MOUSE) { this->invert(); return 1; }
  46.             else { return 0; }
  47.         default:
  48.             return Fl_Widget::handle(event);
  49.     }
  50. }
  51.  
  52.  
  53.  
  54. /* CLASS "Application" */
  55.  
  56. Fl_Double_Window* Application::makeWindow(void)
  57. {
  58.     // Create main window
  59.     Fl_Double_Window* win = new Fl_Double_Window(Led::lineSize, (130 + Led::lineSize), this->label);
  60.  
  61.     // Menu Bar at the top of the window
  62.     Fl_Menu_Bar* topMenu = makeMenu();
  63.     win->add(topMenu);
  64.  
  65.     // Leds are all children of 'ledMatrix'. Their UID defines their position.
  66.     Fl_Group* ledMatrix = new Fl_Group(0, 30, Led::lineSize, Led::lineSize);
  67.     for (uint8_t i = 0; i < 64; i++) ledMatrix->add( new Led(i, false) );
  68.     ledMatrix->end();
  69.     win->add(ledMatrix);
  70.  
  71.     // Logs / text output field
  72.     this->logs = new LoggerField(0, (Led::lineSize + 30), Led::lineSize, 100);
  73.     win->add(logs);
  74.  
  75.     // Select double buffering and full color
  76.     Fl::visual(FL_DOUBLE|FL_RGB);
  77.  
  78.     // Finish creating window and return object to caller
  79.     win->end();
  80.     return win;
  81. }
  82.  
  83.  
  84.  
  85. /* MAIN PROGRAM */
  86.  
  87. int main(int argc, char* argv[]) {
  88.     // Create application object
  89.     Application app;
  90.  
  91.     // Create the main window
  92.     Fl_Double_Window* window = app.makeWindow();
  93.     window->show(argc, argv);
  94.  
  95.     // Run !
  96.     return Fl::run();
  97. }
  98.  
  99.  
  100. #endif  /* !_MATRIXEDITOR_CPP_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement