diff --git a/convertresources.sh b/convertresources.sh index b26144fc..d81686d8 100644 --- a/convertresources.sh +++ b/convertresources.sh @@ -1,3 +1,13 @@ convert thirdparty/capicon/png/white/059.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/add.png convert thirdparty/capicon/png/white/262.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/select.png -convert thirdparty/capicon/png/white/078.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/picture.png \ No newline at end of file +convert thirdparty/capicon/png/white/078.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/picture.png +convert thirdparty/capicon/png/white/226.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/save.png +convert thirdparty/capicon/png/white/341.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/info.png +convert thirdparty/capicon/png/white/279.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/up.png +convert thirdparty/capicon/png/white/278.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/down.png +convert thirdparty/capicon/png/white/274.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/clip.png +convert thirdparty/capicon/png/white/254.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/rangeselect.png +convert thirdparty/capicon/png/white/057.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/delete.png +convert thirdparty/capicon/png/white/047.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/new.png +convert thirdparty/capicon/png/white/039.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/palette.png +convert thirdparty/capicon/png/white/030.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/trashbin.png diff --git a/resources.qrc b/resources.qrc index ba898fd9..e5054d68 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,7 +1,17 @@ - resources/add.png - resources/select.png - resources/picture.png + resources/add.png + resources/select.png + resources/picture.png + resources/save.png + resources/info.png + resources/up.png + resources/down.png + resources/clip.png + resources/rangeselect.png + resources/delete.png + resources/new.png + resources/palette.png + resources/trashbin.png \ No newline at end of file diff --git a/resources/clip.png b/resources/clip.png new file mode 100644 index 00000000..6a7cb5ea Binary files /dev/null and b/resources/clip.png differ diff --git a/resources/delete.png b/resources/delete.png new file mode 100644 index 00000000..23c99297 Binary files /dev/null and b/resources/delete.png differ diff --git a/resources/down.png b/resources/down.png new file mode 100644 index 00000000..de1a3469 Binary files /dev/null and b/resources/down.png differ diff --git a/resources/info.png b/resources/info.png new file mode 100644 index 00000000..7121282a Binary files /dev/null and b/resources/info.png differ diff --git a/resources/new.png b/resources/new.png new file mode 100644 index 00000000..a0678bed Binary files /dev/null and b/resources/new.png differ diff --git a/resources/palette.png b/resources/palette.png new file mode 100644 index 00000000..4db5e400 Binary files /dev/null and b/resources/palette.png differ diff --git a/resources/rangeselect.png b/resources/rangeselect.png new file mode 100644 index 00000000..2aacc9b8 Binary files /dev/null and b/resources/rangeselect.png differ diff --git a/resources/save.png b/resources/save.png new file mode 100644 index 00000000..8f905b63 Binary files /dev/null and b/resources/save.png differ diff --git a/resources/trashbin.png b/resources/trashbin.png new file mode 100644 index 00000000..de0e3107 Binary files /dev/null and b/resources/trashbin.png differ diff --git a/resources/up.png b/resources/up.png new file mode 100644 index 00000000..35dda21a Binary files /dev/null and b/resources/up.png differ diff --git a/src/main.cpp b/src/main.cpp index 8aeec1ff..c6464253 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ int main(int argc, char ** argv) darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::HighlightedText, Qt::black); qApp->setPalette(darkPalette); - qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); + qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #fc6621; border: 1px solid white; }"); QCoreApplication::setApplicationName("Dust 3D"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 626f3a06..3c907d19 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include "mainwindow.h" #include "skeletoneditwidget.h" @@ -53,28 +55,42 @@ MainWindow::MainWindow() : m_modelingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_modelingWidget->setWindowFlags(Qt::Tool | Qt::Window); m_modelingWidget->setWindowTitle("3D Model"); - - QPushButton *changeTurnaroundButton = new QPushButton(""); - changeTurnaroundButton->setIcon(QIcon(":/resources/picture.png")); - + QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addSpacing(10); - rightLayout->addWidget(changeTurnaroundButton); + + //QPushButton *changeTurnaroundButton = new QPushButton(""); + //changeTurnaroundButton->setIcon(QIcon(":/resources/picture.png")); + //changeTurnaroundButton->setToolTip(tr("Change turnaround reference image")); + //rightLayout->addWidget(changeTurnaroundButton); + rightLayout->addStretch(); QToolBar *toolbar = new QToolBar; toolbar->setIconSize(QSize(16, 16)); toolbar->setOrientation(Qt::Vertical); + QAction *addAction = new QAction(tr("Add"), this); addAction->setIcon(QIcon(":/resources/add.png")); + toolbar->addAction(addAction); + QAction *selectAction = new QAction(tr("Select"), this); selectAction->setIcon(QIcon(":/resources/select.png")); - toolbar->addAction(addAction); toolbar->addAction(selectAction); + QAction *rangeSelectAction = new QAction(tr("Range Select"), this); + rangeSelectAction->setIcon(QIcon(":/resources/rangeselect.png")); + toolbar->addAction(rangeSelectAction); + + //m_clipTableWidget = new QTableWidget; + //m_clipTableWidget->setFixedWidth(32); + //m_clipTableWidget->verticalHeader()->setVisible(false); + QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addWidget(toolbar); leftLayout->addStretch(); + //leftLayout->addWidget(m_clipTableWidget); + leftLayout->addSpacing(10); QHBoxLayout *middleLayout = new QHBoxLayout; middleLayout->addLayout(leftLayout); @@ -106,22 +122,28 @@ MainWindow::MainWindow() : connectResult = connect(m_skeletonEditWidget, SIGNAL(sizeChanged()), this, SLOT(turnaroundChanged())); assert(connectResult); - connectResult = connect(changeTurnaroundButton, SIGNAL(released()), this, SLOT(changeTurnaround())); + connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(changeTurnaroundTriggered()), this, SLOT(changeTurnaround())); assert(connectResult); + + //connectResult = connect(clipButton, SIGNAL(clicked()), this, SLOT(saveClip())); + //assert(connectResult); +} + +void MainWindow::showModelingWidgetAtCorner() +{ + if (!m_modelingWidget->isVisible()) { + QPoint pos = QPoint(QApplication::desktop()->width(), + QApplication::desktop()->height()); + m_modelingWidget->move(pos.x() - m_modelingWidget->width(), + pos.y() - m_modelingWidget->height()); + m_modelingWidget->show(); + } } void MainWindow::meshReady() { Mesh *resultMesh = m_skeletonToMesh->takeResultMesh(); - if (resultMesh) { - if (!m_modelingWidget->isVisible()) { - QRect referenceRect = m_skeletonEditWidget->geometry(); - QPoint pos = QPoint(referenceRect.right() - m_modelingWidget->width(), - referenceRect.bottom() - m_modelingWidget->height()); - m_modelingWidget->move(pos.x(), pos.y()); - m_modelingWidget->show(); - } - } + showModelingWidgetAtCorner(); m_modelingWidget->updateMesh(resultMesh); delete m_skeletonToMesh; m_skeletonToMesh = NULL; @@ -196,3 +218,14 @@ void MainWindow::changeTurnaround() m_turnaroundFilename = fileName; turnaroundChanged(); } + +void MainWindow::saveClip() +{ + QImage image = m_modelingWidget->grabFramebuffer(); + //QTableWidgetItem *item = new QTableWidgetItem; + //item->setSizeHint(QSize(32, 32)); + //item->setIcon(QPixmap::fromImage(image.scaled(32, 32))); + //m_clipTableWidget->insertRow(m_clipTableWidget->rowCount()); + //m_clipTableWidget->setItem(m_clipTableWidget->rowCount() - 1, 0, item); + //image.save("/Users/jeremy/Repositories/dust3d/gl.png"); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 3681d526..bba763dd 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -2,6 +2,8 @@ #define MAIN_WINDOW_H #include #include +#include +#include #include "modelingwidget.h" #include "skeletoneditwidget.h" #include "skeletontomesh.h" @@ -18,6 +20,8 @@ public slots: void turnaroundChanged(); void turnaroundImageReady(); void changeTurnaround(); + void saveClip(); + void showModelingWidgetAtCorner(); private: ModelingWidget *m_modelingWidget; SkeletonEditWidget *m_skeletonEditWidget; diff --git a/src/skeletoneditgraphicsview.cpp b/src/skeletoneditgraphicsview.cpp index ec9a1832..afeb50b2 100644 --- a/src/skeletoneditgraphicsview.cpp +++ b/src/skeletoneditgraphicsview.cpp @@ -35,6 +35,8 @@ SkeletonEditGraphicsView::SkeletonEditGraphicsView(QWidget *parent) : void SkeletonEditGraphicsView::toggleAddNodeMode() { + if (!m_backgroundLoaded) + return; m_inAddNodeMode = !m_inAddNodeMode; applyAddNodeMode(); } @@ -48,12 +50,16 @@ void SkeletonEditGraphicsView::applyAddNodeMode() void SkeletonEditGraphicsView::turnOffAddNodeMode() { + if (!m_backgroundLoaded) + return; m_inAddNodeMode = false; applyAddNodeMode(); } void SkeletonEditGraphicsView::turnOnAddNodeMode() { + if (!m_backgroundLoaded) + return; m_inAddNodeMode = true; applyAddNodeMode(); } @@ -89,6 +95,12 @@ void SkeletonEditGraphicsView::mousePressEvent(QMouseEvent *event) m_lastMousePos = mapToScene(event->pos()); } +void SkeletonEditGraphicsView::mouseDoubleClickEvent(QMouseEvent *event) +{ + QWidget::mouseDoubleClickEvent(event); + emit changeTurnaroundTriggered(); +} + float SkeletonEditGraphicsView::findXForSlave(float x) { return x - m_backgroundItem->boundingRect().width() / 4; @@ -286,11 +298,38 @@ void SkeletonEditGraphicsView::setNextStartNodeItem(SkeletonEditNodeItem *item) void SkeletonEditGraphicsView::updateBackgroundImage(const QImage &image) { + QSizeF oldSceneSize = scene()->sceneRect().size(); QPixmap pixmap = QPixmap::fromImage(image); m_backgroundItem->setPixmap(pixmap); scene()->setSceneRect(pixmap.rect()); + adjustItems(oldSceneSize, scene()->sceneRect().size()); if (!m_backgroundLoaded) { m_backgroundLoaded = true; applyAddNodeMode(); } } + +void SkeletonEditGraphicsView::adjustItems(QSizeF oldSceneSize, QSizeF newSceneSize) +{ + if (oldSceneSize == newSceneSize) + return; + float radiusMul = (float)newSceneSize.height() / oldSceneSize.height(); + float xMul = (float)newSceneSize.width() / oldSceneSize.width(); + float yMul = radiusMul; + QList::iterator it; + QList list = scene()->items(); + for (it = list.begin(); it != list.end(); ++it) { + if ((*it)->data(0).toString() == "node") { + SkeletonEditNodeItem *nodeItem = static_cast(*it); + nodeItem->setRadius(nodeItem->radius() * radiusMul); + QPointF oldOrigin = nodeItem->origin(); + nodeItem->setOrigin(QPointF(oldOrigin.x() * xMul, oldOrigin.y() * yMul)); + } + } + for (it = list.begin(); it != list.end(); ++it) { + if ((*it)->data(0).toString() == "edge") { + SkeletonEditEdgeItem *edgeItem = static_cast(*it); + edgeItem->updatePosition(); + } + } +} diff --git a/src/skeletoneditgraphicsview.h b/src/skeletoneditgraphicsview.h index bfd67c2f..97466bf0 100644 --- a/src/skeletoneditgraphicsview.h +++ b/src/skeletoneditgraphicsview.h @@ -10,6 +10,7 @@ class SkeletonEditGraphicsView : public QGraphicsView Q_OBJECT signals: void nodesChanged(); + void changeTurnaroundTriggered(); public slots: void turnOffAddNodeMode(); void turnOnAddNodeMode(); @@ -21,6 +22,7 @@ protected: void wheelEvent(QWheelEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); private: QGraphicsPixmapItem *m_backgroundItem; QGraphicsEllipseItem *m_pendingNodeItem; @@ -33,6 +35,7 @@ private: QPointF m_lastMousePos; bool m_isMovingNodeItem; bool m_backgroundLoaded; +private: void toggleAddNodeMode(); void applyAddNodeMode(); SkeletonEditNodeItem *findNodeItemByPos(QPointF pos); @@ -41,6 +44,7 @@ private: bool canNodeItemMoveTo(SkeletonEditNodeItem *item, QPointF moveTo); void AddItemRadius(QGraphicsEllipseItem *item, float delta); bool canAddItemRadius(QGraphicsEllipseItem *item, float delta); + void adjustItems(QSizeF oldSceneSize, QSizeF newSceneSize); }; #endif diff --git a/src/skeletoneditnodeitem.cpp b/src/skeletoneditnodeitem.cpp index 54b4e231..6772209e 100644 --- a/src/skeletoneditnodeitem.cpp +++ b/src/skeletoneditnodeitem.cpp @@ -61,6 +61,21 @@ float SkeletonEditNodeItem::radius() return rect().width() / 2; } +void SkeletonEditNodeItem::setRadius(float radius) +{ + QPointF oldOrigin = origin(); + setRect(oldOrigin.x() - radius, oldOrigin.y() - radius, + radius * 2, radius * 2); +} + +void SkeletonEditNodeItem::setOrigin(QPointF point) +{ + QPointF moveBy = point - origin(); + QRectF newRect = rect(); + newRect.adjust(moveBy.x(), moveBy.y(), moveBy.x(), moveBy.y()); + setRect(newRect); +} + void SkeletonEditNodeItem::setHighlighted(bool highlighted) { m_highlighted = highlighted; diff --git a/src/skeletoneditnodeitem.h b/src/skeletoneditnodeitem.h index a74f9878..80f5b1c4 100644 --- a/src/skeletoneditnodeitem.h +++ b/src/skeletoneditnodeitem.h @@ -19,6 +19,8 @@ public: SkeletonEditNodeItem *master(); SkeletonEditNodeItem *slave(); SkeletonEditNodeItem *pair(); + void setRadius(float radius); + void setOrigin(QPointF point); private: bool m_highlighted; bool m_isNextStartNode; diff --git a/src/theme.cpp b/src/theme.cpp index 54c0e88b..27f6d422 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -7,10 +7,10 @@ QColor Theme::skeletonMasterNodeBorderColor = QColor(0xfc, 0x66, 0x21, 128); QColor Theme::skeletonMasterNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 200); QColor Theme::skeletonMasterNodeFillColor = QColor(0xfc, 0x66, 0x21, 50); -int Theme::skeletonMasterNodeBorderSize = 15; +int Theme::skeletonMasterNodeBorderSize = 2; QColor Theme::skeletonSlaveNodeBorderColor = QColor(0xcc, 0xcc, 0xcc, 64); QColor Theme::skeletonSlaveNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 100); QColor Theme::skeletonSlaveNodeFillColor = QColor(0xcc, 0xcc, 0xcc, 25); -int Theme::skeletonSlaveNodeBorderSize = 15; +int Theme::skeletonSlaveNodeBorderSize = 2;