BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
5c70d9d
Branches
Tags
master
libetherpix
simulator
draw.cpp
implement receiving packets
Stefan Schuermans
commited
5c70d9d
at 2017-06-11 15:48:14
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 "config.h" #include "draw.h" #include "transform.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), m_config(NULL) { reqUpdate(); } /// virtual destructor Draw::~Draw() { } /// set configuration object void Draw::setConfig(Config const&config) { m_config = &config; reqUpdate(); } /// request image update void Draw::reqUpdate() { updateImage(); queue_draw(); } /** * @brief widget is (re)configured * @param[in] cfg configuration event * @return if callback was completely handled */ bool Draw::on_configure_event(GdkEventConfigure *cfg) { reqUpdate(); 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(); // compute coordinate transformation if (! m_config) return; Transform tf(m_config->getBBox(), width, height); // draw pixels of all distributors m_config->draw(cairo, tf); }