]>
Commit | Line | Data |
---|---|---|
6fa02541 JH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
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; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
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 General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include "sigview.h" | |
22 | ||
009e1503 | 23 | #include "sigsession.h" |
e3f65ace JH |
24 | #include "signal.h" |
25 | ||
26 | #include <boost/foreach.hpp> | |
27 | ||
28 | using namespace boost; | |
29 | using namespace std; | |
30 | ||
31 | const int SigView::SignalHeight = 50; | |
009e1503 JH |
32 | |
33 | SigView::SigView(SigSession &session, QWidget *parent) : | |
34 | QGLWidget(parent), | |
35 | _session(session) | |
6fa02541 | 36 | { |
009e1503 JH |
37 | connect(&_session, SIGNAL(dataUpdated()), |
38 | this, SLOT(dataUpdated())); | |
39 | ||
d7002724 JH |
40 | setMouseTracking(true); |
41 | } | |
42 | ||
43 | void SigView::initializeGL() | |
44 | { | |
45 | glDisable(GL_TEXTURE_2D); | |
46 | glDisable(GL_DEPTH_TEST); | |
47 | glDisable(GL_COLOR_MATERIAL); | |
48 | glEnable(GL_BLEND); | |
49 | glEnable(GL_POLYGON_SMOOTH); | |
50 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
51 | glClearColor(1.0, 1.0, 1.0, 0); | |
52 | } | |
53 | ||
54 | void SigView::resizeGL(int width, int height) | |
55 | { | |
56 | glViewport(0, 0, (GLint)width, (GLint)height); | |
57 | glMatrixMode(GL_PROJECTION); | |
58 | glLoadIdentity(); | |
59 | glOrtho(0, width, height, 0, -1, 1); | |
60 | glMatrixMode(GL_MODELVIEW); | |
61 | } | |
62 | ||
63 | void SigView::paintGL() | |
64 | { | |
65 | glClear(GL_COLOR_BUFFER_BIT); | |
e3f65ace JH |
66 | |
67 | QRect rect(0, 0, width(), SignalHeight); | |
68 | const vector< shared_ptr<Signal> > &sigs = | |
69 | _session.get_signals(); | |
70 | BOOST_FOREACH(const shared_ptr<Signal> s, sigs) | |
71 | { | |
72 | assert(s); | |
73 | s->paint(*this, rect); | |
74 | rect.translate(0, SignalHeight); | |
75 | } | |
6fa02541 | 76 | } |
009e1503 JH |
77 | |
78 | void SigView::dataUpdated() | |
79 | { | |
e3f65ace | 80 | update(); |
009e1503 JH |
81 | } |
82 |