core_window.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <gtkmm/widget.h>
  2. #include <gtkmm/button.h>
  3. #include <gtkmm/window.h>
  4. #include <gtkmm/box.h>
  5. #include <gtkmm/frame.h>
  6. #include <gtkmm/orientable.h>
  7. #include <gtkmm/widget.h>
  8. #include <iostream>
  9. #include "strings.hpp"
  10. #include "config.hpp"
  11. #include "core_window.hpp"
  12. #include "lights_list.hpp"
  13. #include "light_adder.hpp"
  14. #include "welcome.hpp"
  15. #include "control.hpp"
  16. #include "editor.hpp"
  17. namespace cx_light {
  18. core_window::core_window() {
  19. this->current_visible = NULL;
  20. this->set_title(__(WINDOW_TITLE));
  21. this->set_default_size(600, 200);
  22. this->init_default();
  23. }
  24. core_window::~core_window() {
  25. delete this->center;
  26. delete this->current;
  27. delete this->lights;
  28. delete this->current_frame;
  29. if (this->current_visible != NULL) {
  30. delete this->current_visible;
  31. }
  32. }
  33. void core_window::init_default() {
  34. this->center = new Gtk::Box();
  35. this->center->set_orientation(Gtk::Orientation::HORIZONTAL);
  36. this->set_child(*this->center);
  37. this->current = new Gtk::Box();
  38. this->current->set_margin(DEFAULT_MARGIN);
  39. this->current_frame = new Gtk::Frame();
  40. this->current_frame->set_margin(DEFAULT_MARGIN);
  41. this->current_frame->set_child(*this->current);
  42. this->create_lights_list();
  43. this->center->append(*this->current_frame);
  44. this->set_view(new welcome());
  45. }
  46. void core_window::create_lights_list() {
  47. this->lights = new lights_list();
  48. this->center->append(*this->lights);
  49. this->lights->set_add_light_callback([&] () {
  50. this->set_view(new light_adder());
  51. });
  52. this->lights->set_edit_light_callback([&] (light *target) {
  53. this->set_view(new editor(target));
  54. });
  55. this->lights->set_show_light_callback([&] (light *target) {
  56. this->set_view(new control(target));
  57. });
  58. }
  59. void core_window::set_view(Gtk::Widget *target) {
  60. if (this->current_visible != NULL) {
  61. this->current->remove(*this->current_visible);
  62. delete this->current_visible;
  63. }
  64. this->current_visible = target;
  65. this->current->append(*target);
  66. }
  67. }