]> sigrok.org Git - pulseview.git/blame - sigview.cpp
Initial rendering of traces
[pulseview.git] / sigview.cpp
CommitLineData
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
28using namespace boost;
29using namespace std;
30
31const int SigView::SignalHeight = 50;
009e1503
JH
32
33SigView::SigView(SigSession &session, QWidget *parent) :
34 QGLWidget(parent),
3b18c57d
JH
35 _session(session),
36 _scale(1000000000ULL),
37 _offset(0)
6fa02541 38{
009e1503
JH
39 connect(&_session, SIGNAL(dataUpdated()),
40 this, SLOT(dataUpdated()));
41
d7002724
JH
42 setMouseTracking(true);
43}
44
45void SigView::initializeGL()
46{
47 glDisable(GL_TEXTURE_2D);
48 glDisable(GL_DEPTH_TEST);
49 glDisable(GL_COLOR_MATERIAL);
50 glEnable(GL_BLEND);
51 glEnable(GL_POLYGON_SMOOTH);
52 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
53 glClearColor(1.0, 1.0, 1.0, 0);
54}
55
56void SigView::resizeGL(int width, int height)
57{
58 glViewport(0, 0, (GLint)width, (GLint)height);
59 glMatrixMode(GL_PROJECTION);
60 glLoadIdentity();
61 glOrtho(0, width, height, 0, -1, 1);
62 glMatrixMode(GL_MODELVIEW);
63}
64
65void SigView::paintGL()
66{
67 glClear(GL_COLOR_BUFFER_BIT);
e3f65ace
JH
68
69 QRect rect(0, 0, width(), SignalHeight);
70 const vector< shared_ptr<Signal> > &sigs =
71 _session.get_signals();
72 BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
73 {
74 assert(s);
3b18c57d 75 s->paint(*this, rect, _scale, _offset);
e3f65ace
JH
76 rect.translate(0, SignalHeight);
77 }
6fa02541 78}
009e1503
JH
79
80void SigView::dataUpdated()
81{
e3f65ace 82 update();
009e1503
JH
83}
84