| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include <string>
- #include <gtkmm/grid.h>
- #include <gtkmm/entry.h>
- #include <gtkmm/label.h>
- #include <gtkmm/scale.h>
- #include <gtkmm/button.h>
- #include <gtkmm/orientable.h>
- #include <gtkmm/adjustment.h>
- #include "control.hpp"
- #include "config.hpp"
- #include "color.hpp"
- namespace cx_light {
- control::control(light *target) {
- this->title = target->get_name();
- this->address = target->get_address();
- this->set_row_spacing(DEFAULT_MARGIN);
- this->set_column_spacing(DEFAULT_MARGIN);
- std::string description_text = "<b>Manage ";
- description_text += this->title;
- description_text += ".</b>";
- this->description = new Gtk::Label(description_text);
- this->description->set_use_markup();
- this->description->set_hexpand();
- this->description->set_halign(Gtk::Align::START);
- this->attach(*this->description, 0, 0, 4, 1);
-
- this->power_description = new Gtk::Label("Brightness");
- this->power_description->set_halign(Gtk::Align::START);
- this->attach(*this->power_description, 0, 1, 1, 1);
- this->power_value = new Glib::RefPtr<Gtk::Adjustment> (
- Gtk::Adjustment::create(512, 0, 1024, 1)
- );
- this->power = new Gtk::Scale(
- *this->power_value,
- Gtk::Orientation::HORIZONTAL
- );
- this->attach(*this->power, 1, 1, 2, 1);
- this->color_description = new Gtk::Label("Color");
- this->color_description->set_halign(Gtk::Align::START);
- this->attach(*this->color_description, 0, 2, 1, 1);
-
- this->color_value = new Glib::RefPtr<Gtk::Adjustment> (
- Gtk::Adjustment::create(6500, 1000, 20000, 1)
- );
- (*this->color_value)->signal_value_changed().connect([&] () {
- this->drawing->queue_draw();
- });
- this->color = new Gtk::Scale(
- *this->color_value,
- Gtk::Orientation::HORIZONTAL
- );
-
- this->attach(*this->color, 1, 2, 2, 1);
- this->drawing = new Gtk::DrawingArea();
- this->drawing->set_draw_func(sigc::mem_fun(*this, &control::redraw));
- this->attach(*this->drawing, 3, 1, 1, 2);
- this->apply = new Gtk::Button("Apply");
- this->attach(*this->apply, 2, 3, 2, 1);
- this->back = new Gtk::Button("Back");;
- this->attach(*this->back, 0, 3, 2, 1);
- }
- control::~control() {
- this->remove(*this->description);
- this->remove(*this->power);
- this->remove(*this->power_description);
- this->remove(*this->color);
- this->remove(*this->color_description);
- this->remove(*this->apply);
- this->remove(*this->back);
- this->remove(*this->drawing);
- delete this->drawing;
- delete this->description;
- delete this->power;
- delete this->power_value;
- delete this->power_description;
- delete this->color;
- delete this->color_value;
- delete this->color_description;
- delete this->apply;
- delete this->back;
- }
- void control::redraw(
- const Cairo::RefPtr<Cairo::Context> &context,
- int width,
- int height
- ) {
- context->set_line_width(10.0);
-
- color
- ::from_white(((*this->color_value)->get_value()))
- .set_source(context);
-
- context->arc(width / 2, height / 2, width / 4, 0.0, 2 * M_PI);
- context->stroke();
- }
- }
|