BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
371800c
Branches
Tags
master
libetherpix
simulator
draw.cpp
begin of simulator: window skeleton
Stefan Schuermans
commited
371800c
at 2017-06-07 21:38:03
draw.cpp
Blame
History
Raw
/* * EtherPix simulator * * Copyright 2017 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <gtkmm.h> #include "draw.h" /** * @brief constructor * @param[in] Gtk Window object (a C object) * @param[in] builder reference to GTK builder object */ Draw::Draw(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder): Gtk::DrawingArea(cobject), m_builder(builder) { /* TODO // connect callbacks (seems to be needed for gtkmm-2.4 < V2.16) signal_configure_event().connect( sigc::mem_fun(*this, &Draw::on_configure_event)); signal_expose_event().connect( sigc::mem_fun(*this, &Draw::on_expose_event)); */ // initialize image updateImage(); queue_draw(); } /// virtual destructor Draw::~Draw() { } /** * @brief widget is (re)configured * @param[in] cfg configuration event * @return if callback was completely handled */ bool Draw::on_configure_event(GdkEventConfigure *cfg) { // update image updateImage(); queue_draw(); return true; (void)cfg; } /** * @brief widget is being drawn * @param[in] cairo cairo context for drawing * @return if callback was completely handled */ bool Draw::on_draw(const Cairo::RefPtr<Cairo::Context> &cairo) { // draw image if (m_image) { cairo->set_source(m_image, 0, 0); cairo->rectangle(0, 0, m_image->get_width(), m_image->get_height()); cairo->fill(); } return true; } /// update image void Draw::updateImage() { // get size of drawing area Gtk::Allocation allocation = get_allocation(); int width = allocation.get_width(); int height = allocation.get_height(); // create new image m_image = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, width, height); // create ciaro context for drawing Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create(m_image); // draw background cairo->set_source_rgb(0.0, 0.0, 0.0); cairo->rectangle(0, 0, width, height); cairo->fill(); // TODO // draw circles cairo->set_source_rgb(1.0, 0.0, 0.0); cairo->arc(0.5 * width, 0.5 * height, 0.03 * (width + height), 0.0, 2.0 * M_PI); cairo->fill(); cairo->set_source_rgb(0.0, 1.0, 0.0); cairo->arc(0.7 * width, 0.3 * height, 0.03 * (width + height), 0.0, 2.0 * M_PI); cairo->fill(); cairo->set_source_rgb(0.0, 0.0, 1.0); cairo->arc(0.7 * width, 0.7 * height, 0.03 * (width + height), 0.0, 2.0 * M_PI); cairo->fill(); }