diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/luascript.cc | 33 | ||||
-rw-r--r-- | src/mainwindow.cc | 9 | ||||
-rw-r--r-- | src/outputwindow.cc | 21 | ||||
-rw-r--r-- | src/outputwindow.h | 8 |
4 files changed, 33 insertions, 38 deletions
diff --git a/src/luascript.cc b/src/luascript.cc index 0619228..7a84d1f 100644 --- a/src/luascript.cc +++ b/src/luascript.cc @@ -197,38 +197,6 @@ static int _sleep(lua_State *L) return 0; } -static int _scale(lua_State *L) -{ - //Pracro::checkParameters(L, - // Pracro::T_STRING, - // Pracro::T_END); - - double x = lua_tonumber(L, lua_gettop(L)); - - printf("scale %f\n", x); - - lua_getglobal(L, GLOBAL_POINTER); - LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L)); - - if(!lua) - { - lua_pushstring(L, "No LUA pointer!"); - lua_error(L); - return 1; - } - - if(lua->lua_stop) - { - printf("stopping...\n"); - lua_pushstring(L, "stop"); - lua_error(L); - } - - lua->out.setScale(x); - - return 0; -} - static int _colour(lua_State *L) { //Pracro::checkParameters(L, @@ -417,7 +385,6 @@ void LUAScript::init() lua_register(L, "forward", _forward); lua_register(L, "turn", _turn); lua_register(L, "speed", _speed); - lua_register(L, "scale", _scale); lua_register(L, "reset", _reset); lua_register(L, "colour", _colour); lua_register(L, "loadpen", _loadpen); diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 7e08c46..e52b9f3 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -150,11 +150,16 @@ void MainWindow::loadSettings() QByteArray geometry; QSettings settings; + settings.beginGroup("MainWindow"); state = settings.value("state").toByteArray(); geometry = settings.value("geometry").toByteArray(); settings.endGroup(); + settings.beginGroup("Canvas"); + out->setScale(settings.value("scale", 2.0).toDouble()); + settings.endGroup(); + restoreGeometry(geometry); restoreState(state); } @@ -167,6 +172,10 @@ void MainWindow::saveSettings() settings.setValue("state", saveState()); settings.setValue("geometry", saveGeometry()); settings.endGroup(); + + settings.beginGroup("Canvas"); + settings.setValue("scale", out->getScale()); + settings.endGroup(); } bool MainWindow::checkDirty() diff --git a/src/outputwindow.cc b/src/outputwindow.cc index 815da8c..b7b1a51 100644 --- a/src/outputwindow.cc +++ b/src/outputwindow.cc @@ -29,6 +29,7 @@ #include <QPixmap> #include <QPainter> +#include <QWheelEvent> #include <math.h> @@ -72,7 +73,11 @@ void OutputWindow::loadPen(QString file) void OutputWindow::setScale(double s) { scale = s; - sem.acquire(); +} + +double OutputWindow::getScale() const +{ + return scale; } void OutputWindow::setSpeed(int s) @@ -107,11 +112,22 @@ void OutputWindow::timeout() timer.start(25); } + +void OutputWindow::wheelEvent(QWheelEvent* event) +{ + double delta = event->delta() / 120.0 * scale; + scale += delta / 10.0; + printf("%f\n", scale); + if(scale < 0.3) + { + scale = 0.3; + } +} + void OutputWindow::paintEvent(QPaintEvent *) { //sem.acquire(); QPainter p(this); - //QTransform tp; tp.scale(3, 3); p.setTransform(tp); if(loadpen) { @@ -180,7 +196,6 @@ void OutputWindow::paintEvent(QPaintEvent *) void OutputWindow::reset() { - scale = 2.0; speed = 50; penfile = "gfx/kaiman.png"; loadpen = true; diff --git a/src/outputwindow.h b/src/outputwindow.h index 5e91f71..fc63a44 100644 --- a/src/outputwindow.h +++ b/src/outputwindow.h @@ -47,7 +47,10 @@ public: void stopScript(); void setSpeed(int s); + void setScale(double s); + double getScale() const; + void setColour(int r, int g, int b, int a); void loadPen(QString file); @@ -60,7 +63,8 @@ public slots: void reset(); protected: - void paintEvent(QPaintEvent * event); + void wheelEvent(QWheelEvent* event); + void paintEvent(QPaintEvent* event); private: class ColLine @@ -83,5 +87,5 @@ private: volatile bool loadpen; QString penfile; - volatile float scale; + volatile float scale{2.0f}; }; |