5c70d9d85a6f690ae5c591b7d884677efad7fbaa
Stefan Schuermans complete implementation of...

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) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

20) #include <gtkmm.h>
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

21) #include <stdint.h>
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

22) 
23) #include "bbox.h"
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

24) #include "pixel.h"
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

25) #include "transform.h"
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

26) 
27) /// default constructor
28) Pixel::Pixel():
29)   m_x(0.5),
30)   m_y(0.5),
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

31)   m_r(0.0),
32)   m_red  (64),
33)   m_green(64),
34)   m_blue (64)
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

35) {
36) }
37) 
38) /// constructor based on coordinates and radius
39) Pixel::Pixel(double x, double y, double r):
40)   m_x(x),
41)   m_y(y),
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

42)   m_r(r),
43)   m_red  (64),
44)   m_green(64),
45)   m_blue (64)
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

46) {
47) }
48) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

49) /**
50)  * @brief add pixel to the bounding box
51)  * @param[in,out] bb bounding box
52)  */
53) void Pixel::updateBBox(BBox &bb) const
54) {
55)   // add pixel plus some border to bounding box
56)   bb.add(m_x - 2 * m_r, m_y - 2 * m_r);
57)   bb.add(m_x + 2 * m_r, m_y + 2 * m_r);
58) }
59) 
60) /**
61)  * @brief draw pixel
62)  * @param[in] cairo cairo context for drawing
63)  * @param[in] tf coordinate transformation
64)  */
65) void Pixel::draw(Cairo::RefPtr<Cairo::Context> &cairo,
66)                  Transform const &tf) const
67) {
68)   double x, y, r;
69)   tf.apply(m_x, m_y, x, y);
70)   tf.applyZoom(m_r, r);
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

71)   cairo->set_source_rgb(m_red / 255.0, m_green / 255.0, m_blue / 255.0);