changeset 357:1b8362a26692

Work towards Qt based editor.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Oct 2012 20:09:11 +0300
parents 2a22b0f1a469
children 3bdc776a4b33
files Makefile.gen edtimeline.cpp edtimeline.h edwaveform.cpp edwaveform.h
diffstat 5 files changed, 315 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Tue Oct 16 19:07:30 2012 +0300
+++ b/Makefile.gen	Tue Oct 16 20:09:11 2012 +0300
@@ -21,7 +21,8 @@
 endif
 endif
 
-EDITOR_MAKEFILE = Makefile.editor
+EDITOR_PRO = $(DMLIB)editor.pro
+EDITOR_MAKEFILE = $(DMLIB)Makefile.editor
 EDITOR_SOURCES = edmain.cpp edgui.cpp edtimeline.cpp edwaveform.cpp
 EDITOR_HEADERS = edmain.h edtimeline.h edwaveform.h
 
@@ -368,21 +369,32 @@
 ###
 ### Editor targets
 ###
-$(BINPATH)ed_$(DEMO_BIN)$(EXEEXT): $(DMLIB)editor.pro $(addprefix $(DMLIB),$(EDITOR_SOURCES)) $(addprefix $(OBJPATH),$(DEMO_OBJS)) $(DMLIB_A)
+$(EDITOR_PRO): $(DMLIB)Makefile.gen config.mak $(addprefix $(DMLIB),$(EDITOR_SOURCES)) $(addprefix $(OBJPATH),$(DEMO_OBJS)) $(DMLIB_A)
+	@echo " CREATE $@"
+	@echo > $@
+	@echo "POST_TARGETDEPS = $(filter %.o %.a,$+)" >> $@
+	@echo "QMAKE_CXXFLAGS += $(DM_CFLAGS) $(SDL_CFLAGS)" >> $@
+	@echo "QMAKE_LIBS += $(DM_LDFLAGS) $(SDL_LDFLAGS)" >> $@
+	@echo "MAKEFILE = $(EDITOR_MAKEFILE)" >> $@
+	@echo "CONFIG += debug" >> $@
+	@echo "QT += core gui opengl" >> $@
+	@echo "TARGET = editor" >> $@
+	@echo "TEMPLATE = app" >> $@
+	@echo "SOURCES = $(EDITOR_SOURCES)" >> $@
+	@echo "HEADERS = $(EDITOR_HEADERS)" >> $@
+	
+
+$(EDITOR_MAKEFILE): $(EDITOR_PRO)
 	@echo " QMAKE $+"
-	qmake -Wall MAKEFILE="$(EDITOR_MAKEFILE)" \
-		POST_TARGETDEPS="$(filter %.o %.a,$+)" \
-		QMAKE_CXXFLAGS="$(DM_CFLAGS) $(SDL_CFLAGS)" \
-		QMAKE_LIBS="$(DM_LDFLAGS) $(SDL_LDFLAGS)"
-		SOURCES="$(EDITOR_SOURCES)" \
-		HEADERS="$(EDITOR_HEADERS)" $<
-	make -f $(EDITOR_MAKEFILE)
+	@qmake -Wall $<
+
+$(BINPATH)ed_$(DEMO_BIN)$(EXEEXT): $(EDITOR_MAKEFILE)
+	@make -f $<
 
 
 ###
 ### Special targets
 ###
 clean:
-	$(RM) $(TARGETS) $(OBJPATH)*.o $(EDITOR_MAKEFILE)
+	$(RM) $(TARGETS) $(OBJPATH)*.o $(EDITOR_MAKEFILE) $(EDITOR_PRO)
 
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edtimeline.cpp	Tue Oct 16 20:09:11 2012 +0300
@@ -0,0 +1,116 @@
+#include <QtGui>
+#include "edtimeline.h"
+
+
+TimelineTrackView::TimelineTrackView(QWidget *parent) : QWidget(parent)
+{
+    track = NULL;
+    time = offs = 0;
+    scale = 1.0f;
+}
+
+
+void TimelineTrackView::setTrack(DMTimelineTrack *mtrack)
+{
+    track = mtrack;
+    update();
+}
+
+
+DMTimelineTrack * TimelineTrackView::getTrack()
+{
+    return track;
+}
+
+
+void TimelineTrackView::setTime(const int mtime)
+{
+    time = mtime;
+    update();
+}
+
+
+void TimelineTrackView::setOffset(const int moffs)
+{
+    offs = moffs;
+    update();
+}
+
+
+void TimelineTrackView::setScale(const float mscale)
+{
+    if (mscale > 0.05)
+        scale = mscale;
+    update();
+}
+
+
+void TimelineTrackView::paintEvent(QPaintEvent *)
+{
+    QColor eventColor(150, 150, 150);
+    QColor markerColor(255,255,255);
+
+    QPainter painter(this);
+    painter.setRenderHint(QPainter::Antialiasing);
+
+    painter.save();
+    painter.scale(scale, 1);
+
+    for (int event = 0; event < track->nevents; event++)
+    {
+        DMTimelineEvent *ev = track->events[event];
+
+        if (ev->startTime >= offs && ev->startTime < twidth ||
+            ev->startTime + ev->duration >= offs)
+        {
+            int ex0 = x0 + (ev->startTime - offs) * scale,
+                ew = ex0 + ev->duration * scale,
+                ex1 = ex0 + ew <= x1 ? ex0 + ew : x1;
+
+            painter.setPen(waveColor);
+            dmFillRect(screen, ex0, y0, ex1, y1, eventColor);
+            //dmDrawTTFText(screen, font, fontcol, ex0, y0, "'%s'", ev->effect->name);
+        }
+    }
+
+    if (time >= offs * scale && time - offs <= width() * scale)
+    {
+        int xc = time - offs;
+        painter.scale(scale, 1);
+        painter.setPen(markerColor);
+        painter.drawLine(xc, 0, xc, height());
+    }
+}
+
+
+void TimelineTrackView::mousePressEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton)
+    {
+        lastPoint = ev->pos();
+        scribbling = true;
+    }
+*/
+}
+
+
+void TimelineTrackView::mouseMoveEvent(QMouseEvent *ev)
+{
+/*
+    if ((ev->buttons() & Qt::LeftButton) && scribbling)
+        drawLineTo(ev->pos());
+*/
+}
+
+
+void TimelineTrackView::mouseReleaseEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton && scribbling)
+    {
+        drawLineTo(ev->pos());
+        scribbling = false;
+    }
+*/
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edtimeline.h	Tue Oct 16 20:09:11 2012 +0300
@@ -0,0 +1,33 @@
+#ifndef EDTIMELINE_H
+#define EDTIMELINE_H
+
+#include <QWidget>
+#include "dmtimeline.h"
+
+class TimelineTrackView : public QWidget
+{
+    Q_OBJECT
+
+public:
+    TimelineTrackView(QWidget *parent = 0);
+    void setTrack(DMTimelineTrack *mtrack);
+    DMTimelineTrack * getTrack();
+
+    void setTime(const int mtime);
+    void setOffset(const int moffs);
+    void setScale(const float mscale);
+
+protected:
+    void mousePressEvent(QMouseEvent *event);
+    void mouseMoveEvent(QMouseEvent *event);
+    void mouseReleaseEvent(QMouseEvent *event);
+
+    void paintEvent(QPaintEvent *event);
+
+private:
+    float scale;
+    int time, offs;
+    DMTimelineTrack *track;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edwaveform.cpp	Tue Oct 16 20:09:11 2012 +0300
@@ -0,0 +1,111 @@
+#include <QtGui>
+#include "edwaveform.h"
+
+
+WaveformView::WaveformView(QWidget *parent) : QWidget(parent)
+{
+    track = NULL;
+    time = offs = 0;
+    scale = 1.0f;
+}
+
+
+void WaveformView::setTrack(DMWaveform *mtrack)
+{
+    track = mtrack;
+    update();
+}
+
+
+DMWaveform * WaveformView::getTrack()
+{
+    return track;
+}
+
+
+void WaveformView::setTime(const int mtime)
+{
+    time = mtime;
+    update();
+}
+
+
+void WaveformView::setOffset(const int moffs)
+{
+    offs = moffs;
+    update();
+}
+
+
+void WaveformView::setScale(const float mscale)
+{
+    if (mscale > 0.05)
+        scale = mscale;
+    update();
+}
+
+
+void WaveformView::paintEvent(QPaintEvent *)
+{
+    QColor waveColor(0, 150, 0);
+    QColor markerColor(255,255,255);
+
+    QPainter painter(this);
+    painter.setRenderHint(QPainter::Antialiasing);
+
+    painter.save();
+    painter.translate(0, height() / 2);
+    painter.scale(scale, height() / 32768.0f);
+    painter.setPen(waveColor);
+
+    int prevY = 0, prevX = 0;
+    for (int xc = 0; xc < width(); xc++)
+    {
+        qint16 value = data[(offs + xc) * scale];
+        painter.drawLine(prevX, prevY, xc, value);
+        prevY = value; prevX = xc;
+    }
+    painter.restore();
+    
+    
+    if (time >= offs * scale && time - offs <= width() * scale)
+    {
+        int xc = time - offs;
+        painter.scale(scale, 1);
+        painter.setPen(markerColor);
+        painter.drawLine(xc, 0, xc, height());
+    }
+}
+
+
+void WaveformView::mousePressEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton)
+    {
+        lastPoint = ev->pos();
+        scribbling = true;
+    }
+*/
+}
+
+
+void WaveformView::mouseMoveEvent(QMouseEvent *ev)
+{
+/*
+    if ((ev->buttons() & Qt::LeftButton) && scribbling)
+        drawLineTo(ev->pos());
+*/
+}
+
+
+void WaveformView::mouseReleaseEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton && scribbling)
+    {
+        drawLineTo(ev->pos());
+        scribbling = false;
+    }
+*/
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edwaveform.h	Tue Oct 16 20:09:11 2012 +0300
@@ -0,0 +1,32 @@
+#ifndef EDWAVEFORM_H
+#define EDWAVEFORM_H
+
+#include <QWidget>
+#include "dmengine.h"
+
+class WaveformView : public QWidget
+{
+    Q_OBJECT
+
+public:
+    WaveformView(QWidget *parent = 0);
+    void setWaveform(qint16 *mdata, int len);
+
+    void setTime(const int mtime);
+    void setOffset(const int moffs);
+    void setScale(const float mscale);
+
+protected:
+    void mousePressEvent(QMouseEvent *event);
+    void mouseMoveEvent(QMouseEvent *event);
+    void mouseReleaseEvent(QMouseEvent *event);
+
+    void paintEvent(QPaintEvent *event);
+
+private:
+    float scale;
+    int time, offs, len;
+    qint16 *data;
+};
+
+#endif