control.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <string>
  2. #include <gtkmm/grid.h>
  3. #include <gtkmm/entry.h>
  4. #include <gtkmm/label.h>
  5. #include <gtkmm/scale.h>
  6. #include <gtkmm/button.h>
  7. #include <gtkmm/orientable.h>
  8. #include <gtkmm/adjustment.h>
  9. #include "control.hpp"
  10. #include "config.hpp"
  11. #include "color.hpp"
  12. namespace cx_light {
  13. control::control(light *target) {
  14. this->title = target->get_name();
  15. this->address = target->get_address();
  16. this->set_row_spacing(DEFAULT_MARGIN);
  17. this->set_column_spacing(DEFAULT_MARGIN);
  18. std::string description_text = "<b>Manage ";
  19. description_text += this->title;
  20. description_text += ".</b>";
  21. this->description = new Gtk::Label(description_text);
  22. this->description->set_use_markup();
  23. this->description->set_hexpand();
  24. this->description->set_halign(Gtk::Align::START);
  25. this->attach(*this->description, 0, 0, 4, 1);
  26. this->power_description = new Gtk::Label("Brightness");
  27. this->power_description->set_halign(Gtk::Align::START);
  28. this->attach(*this->power_description, 0, 1, 1, 1);
  29. this->power_value = new Glib::RefPtr<Gtk::Adjustment> (
  30. Gtk::Adjustment::create(512, 0, 1024, 1)
  31. );
  32. this->power = new Gtk::Scale(
  33. *this->power_value,
  34. Gtk::Orientation::HORIZONTAL
  35. );
  36. this->attach(*this->power, 1, 1, 2, 1);
  37. this->color_description = new Gtk::Label("Color");
  38. this->color_description->set_halign(Gtk::Align::START);
  39. this->attach(*this->color_description, 0, 2, 1, 1);
  40. this->color_value = new Glib::RefPtr<Gtk::Adjustment> (
  41. Gtk::Adjustment::create(6500, 1000, 20000, 1)
  42. );
  43. (*this->color_value)->signal_value_changed().connect([&] () {
  44. this->drawing->queue_draw();
  45. });
  46. this->color = new Gtk::Scale(
  47. *this->color_value,
  48. Gtk::Orientation::HORIZONTAL
  49. );
  50. this->attach(*this->color, 1, 2, 2, 1);
  51. this->drawing = new Gtk::DrawingArea();
  52. this->drawing->set_draw_func(sigc::mem_fun(*this, &control::redraw));
  53. this->attach(*this->drawing, 3, 1, 1, 2);
  54. this->apply = new Gtk::Button("Apply");
  55. this->attach(*this->apply, 2, 3, 2, 1);
  56. this->back = new Gtk::Button("Back");;
  57. this->attach(*this->back, 0, 3, 2, 1);
  58. }
  59. control::~control() {
  60. this->remove(*this->description);
  61. this->remove(*this->power);
  62. this->remove(*this->power_description);
  63. this->remove(*this->color);
  64. this->remove(*this->color_description);
  65. this->remove(*this->apply);
  66. this->remove(*this->back);
  67. this->remove(*this->drawing);
  68. delete this->drawing;
  69. delete this->description;
  70. delete this->power;
  71. delete this->power_value;
  72. delete this->power_description;
  73. delete this->color;
  74. delete this->color_value;
  75. delete this->color_description;
  76. delete this->apply;
  77. delete this->back;
  78. }
  79. void control::redraw(
  80. const Cairo::RefPtr<Cairo::Context> &context,
  81. int width,
  82. int height
  83. ) {
  84. context->set_line_width(10.0);
  85. color
  86. ::from_white(((*this->color_value)->get_value()))
  87. .set_source(context);
  88. context->arc(width / 2, height / 2, width / 4, 0.0, 2 * M_PI);
  89. context->stroke();
  90. }
  91. }