begin of simulator: window...
Stefan Schuermans authored 7 years ago
|
1) /*
2) * EtherPix simulator
3) *
4) * Copyright 2017 Stefan Schuermans <stefan schuermans info>
5) *
6) * This program is free software: you can redistribute it and/or modify
7) * it under the terms of the GNU General Public License as published by
8) * the Free Software Foundation, version 3 of the License.
9) *
10) *
11) * This program is distributed in the hope that it will be useful,
12) * but WITHOUT ANY WARRANTY; without even the implied warranty of
13) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14) * GNU General Public License for more details.
15) *
16) * You should have received a copy of the GNU Lesser General Public License
17) * along with this program. If not, see <http://www.gnu.org/licenses/>.
18) */
19)
20) #include <gtkmm.h>
21)
|
implement drawing pixels
Stefan Schuermans authored 7 years ago
|
22) #include "config.h"
|
begin of simulator: window...
Stefan Schuermans authored 7 years ago
|
23) #include "draw.h"
|
implement drawing pixels
Stefan Schuermans authored 7 years ago
|
24) #include "transform.h"
|
begin of simulator: window...
Stefan Schuermans authored 7 years ago
|
25)
26) /**
27) * @brief constructor
28) * @param[in] Gtk Window object (a C object)
29) * @param[in] builder reference to GTK builder object
30) */
31) Draw::Draw(BaseObjectType *cobject,
32) const Glib::RefPtr<Gtk::Builder> &builder):
33) Gtk::DrawingArea(cobject),
|
implement drawing pixels
Stefan Schuermans authored 7 years ago
|
34) m_builder(builder),
35) m_config(NULL)
|
begin of simulator: window...
Stefan Schuermans authored 7 years ago
|
36) {
37) // initialize image
38) updateImage();
39) queue_draw();
40) }
41)
42) /// virtual destructor
43) Draw::~Draw()
44) {
45) }
46)
|
implement drawing pixels
Stefan Schuermans authored 7 years ago
|
47) /// set configuration object
48) void Draw::setConfig(Config const&config)
49) {
50) m_config = &config;
51)
52) // re-initialize image
53) updateImage();
54) queue_draw();
55) }
|
begin of simulator: window...
Stefan Schuermans authored 7 years ago
|
56)
57) /**
58) * @brief widget is (re)configured
59) * @param[in] cfg configuration event
60) * @return if callback was completely handled
61) */
62) bool Draw::on_configure_event(GdkEventConfigure *cfg)
63) {
64) // update image
65) updateImage();
66) queue_draw();
67)
68) return true;
69) (void)cfg;
70) }
71)
72) /**
73) * @brief widget is being drawn
74) * @param[in] cairo cairo context for drawing
75) * @return if callback was completely handled
76) */
77) bool Draw::on_draw(const Cairo::RefPtr<Cairo::Context> &cairo)
78) {
79) // draw image
80) if (m_image) {
81) cairo->set_source(m_image, 0, 0);
82) cairo->rectangle(0, 0, m_image->get_width(), m_image->get_height());
83) cairo->fill();
84) }
85) return true;
86) }
87)
88) /// update image
89) void Draw::updateImage()
90) {
91) // get size of drawing area
92) Gtk::Allocation allocation = get_allocation();
93) int width = allocation.get_width();
94) int height = allocation.get_height();
95)
96) // create new image
97) m_image = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, width, height);
98)
99) // create ciaro context for drawing
100) Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create(m_image);
101)
102) // draw background
103) cairo->set_source_rgb(0.0, 0.0, 0.0);
104) cairo->rectangle(0, 0, width, height);
105) cairo->fill();
106)
|
implement drawing pixels
Stefan Schuermans authored 7 years ago
|
107) // compute coordinate transformation
108) if (! m_config)
109) return;
110) Transform tf(m_config->getBBox(), width, height);
111)
112) // draw pixels of all distributors
113) cairo->set_source_rgb(1.0, 0.0, 0.0); // FIXME
114) m_config->draw(cairo, tf);
|