diff --git a/code/nel/tools/3d/panoply_preview/CMakeLists.txt b/code/nel/tools/3d/panoply_preview/CMakeLists.txt index 83c74b9b2..48dac7e01 100644 --- a/code/nel/tools/3d/panoply_preview/CMakeLists.txt +++ b/code/nel/tools/3d/panoply_preview/CMakeLists.txt @@ -1,9 +1,15 @@ FILE(GLOB SRCS *.cpp) FILE(GLOB HDRS *.h) +IF (WIN32) + FILE(GLOB RSRC *.rc) +ENDIF (WIN32) FILE(GLOB RESOURCES *.qrc) -SOURCE_GROUP("" FILES ${SRCS} ${HDRS} ${RESOURCES}) +FILE(GLOB PANOPLY_MAKER ../panoply_maker/color_modifier.cpp ../panoply_maker/color_modifier.h) + +SOURCE_GROUP("" FILES ${SRCS} ${HDRS} ${RSRC} ${RESOURCES}) +SOURCE_GROUP("panoply_maker" FILES ${PANOPLY_MAKER}) SET(CMAKE_AUTOMOC ON) @@ -12,7 +18,9 @@ QT5_ADD_RESOURCES(RESOURCE_ADDED ${RESOURCES}) ADD_EXECUTABLE(nl_panoply_preview WIN32 ${SRC} ${SRCS} ${HDRS} + ${RSRC} ${RESOURCE_ADDED} + ${PANOPLY_MAKER} ) TARGET_LINK_LIBRARIES(nl_panoply_preview diff --git a/code/nel/tools/3d/panoply_preview/command_log.cpp b/code/nel/tools/3d/panoply_preview/command_log.cpp index faf76f1eb..8a530f7f9 100644 --- a/code/nel/tools/3d/panoply_preview/command_log.cpp +++ b/code/nel/tools/3d/panoply_preview/command_log.cpp @@ -47,6 +47,7 @@ CCommandLog::CCommandLog(QWidget *parent) : QWidget(parent) setLayout(layout); connect(m_CommandInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); + connect(this, SIGNAL(tSigDisplay(const QColor &, const QString &)), this, SLOT(tSlotDisplay(const QColor &, const QString &))); DebugLog->addDisplayer(this); InfoLog->addDisplayer(this); @@ -66,25 +67,29 @@ CCommandLog::~CCommandLog() void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message) { + QColor color; switch (args.LogType) { case CLog::LOG_DEBUG: - m_DisplayerOutput->setTextColor(Qt::darkGray); + color = Qt::gray; break; case CLog::LOG_STAT: - m_DisplayerOutput->setTextColor(Qt::darkGreen); + color = Qt::green; break; case CLog::LOG_NO: case CLog::LOG_UNKNOWN: case CLog::LOG_INFO: - m_DisplayerOutput->setTextColor(Qt::black); + color = Qt::white; break; case CLog::LOG_WARNING: - m_DisplayerOutput->setTextColor(Qt::darkBlue); + color = Qt::yellow; break; case CLog::LOG_ERROR: case CLog::LOG_ASSERT: - m_DisplayerOutput->setTextColor(Qt::darkRed); + color = Qt::red; + break; + default: + color = Qt::black; break; } @@ -164,7 +169,13 @@ void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message) } str += pos; - m_DisplayerOutput->append(str.substr(0, str.size() - 1).c_str()); + tSigDisplay(color, str.substr(0, str.size() - 1).c_str()); +} + +void CCommandLog::tSlotDisplay(const QColor &c, const QString &text) +{ + m_DisplayerOutput->setTextColor(c); + m_DisplayerOutput->append(text); } void CCommandLog::returnPressed() diff --git a/code/nel/tools/3d/panoply_preview/command_log.h b/code/nel/tools/3d/panoply_preview/command_log.h index 8c8d774d3..a8d1521b7 100644 --- a/code/nel/tools/3d/panoply_preview/command_log.h +++ b/code/nel/tools/3d/panoply_preview/command_log.h @@ -50,8 +50,12 @@ public: protected: virtual void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message); +signals: + void tSigDisplay(const QColor &c, const QString &text); + private slots: void returnPressed(); + void tSlotDisplay(const QColor &c, const QString &text); private: QTextEdit *m_DisplayerOutput; diff --git a/code/nel/tools/3d/panoply_preview/greenpill.ico b/code/nel/tools/3d/panoply_preview/greenpill.ico new file mode 100644 index 000000000..d2b9e8a20 Binary files /dev/null and b/code/nel/tools/3d/panoply_preview/greenpill.ico differ diff --git a/code/nel/tools/3d/panoply_preview/icon.rc b/code/nel/tools/3d/panoply_preview/icon.rc new file mode 100644 index 000000000..64e741cac --- /dev/null +++ b/code/nel/tools/3d/panoply_preview/icon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "greenpill.ico" \ No newline at end of file diff --git a/code/nel/tools/3d/panoply_preview/main_window.cpp b/code/nel/tools/3d/panoply_preview/main_window.cpp index fcce034d7..b04cd36bb 100644 --- a/code/nel/tools/3d/panoply_preview/main_window.cpp +++ b/code/nel/tools/3d/panoply_preview/main_window.cpp @@ -66,14 +66,16 @@ CMainWindow::CMainWindow(const QMap &customSizeHints, QWidget *p m_AboutAct(NULL) { setObjectName("CMainWindow"); + setWindowTitle(tr("NeL Panoply Preview")); - m_PanoplyPreview = new CPanoplyPreview(this); - setCentralWidget(m_PanoplyPreview); - createActions(); createMenus(); createToolBars(); createStatusBar(); + + m_PanoplyPreview = new CPanoplyPreview(this); + setCentralWidget(m_PanoplyPreview); + createDockWindows(); } @@ -95,8 +97,6 @@ void CMainWindow::createMenus() { m_WidgetsMenu = menuBar()->addMenu(QString::null); - menuBar()->addSeparator(); - m_HelpMenu = menuBar()->addMenu(QString::null); m_HelpMenu->addAction(m_AboutAct); @@ -119,14 +119,13 @@ void CMainWindow::createDockWindows() // CommandLog (Console) { m_CommandLogDock = new QDockWidget(this); + m_CommandLogDock->setWindowTitle(tr("Console")); m_CommandLogDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); m_CommandLog = new CCommandLog(m_CommandLogDock); m_CommandLogDock->setWidget(m_CommandLog); addDockWidget(Qt::BottomDockWidgetArea, m_CommandLogDock); m_WidgetsMenu->addAction(m_CommandLogDock->toggleViewAction()); } - - m_CommandLogDock->setWindowTitle(tr("Command Log")); } void CMainWindow::about() diff --git a/code/nel/tools/3d/panoply_preview/main_window.h b/code/nel/tools/3d/panoply_preview/main_window.h index ff957c968..7bf96388a 100644 --- a/code/nel/tools/3d/panoply_preview/main_window.h +++ b/code/nel/tools/3d/panoply_preview/main_window.h @@ -56,6 +56,8 @@ public: CMainWindow(const QMap &customSizeHints, QWidget *parent = 0, Qt::WindowFlags flags = 0); virtual ~CMainWindow(); + inline QMenu *widgetsMenu() { return m_WidgetsMenu; } + private slots: void about(); diff --git a/code/nel/tools/3d/panoply_preview/panoply_preview.cpp b/code/nel/tools/3d/panoply_preview/panoply_preview.cpp index c7af90cb3..0e3306470 100644 --- a/code/nel/tools/3d/panoply_preview/panoply_preview.cpp +++ b/code/nel/tools/3d/panoply_preview/panoply_preview.cpp @@ -21,20 +21,113 @@ // Qt includes #include +#include +#include +#include +#include +#include +#include +#include +#include // NeL includes #include #include #include +#include +#include +#include // Project includes +#include "main_window.h" +#include "../panoply_maker/color_modifier.h" using namespace std; using namespace NLMISC; namespace NLTOOLS { -CPanoplyPreview::CPanoplyPreview(QWidget *parent) : QWidget(parent) +class CColorThread : public NLMISC::IRunnable +{ +public: + // Called when a thread is run. + virtual void run() + { + while (Running) + { + SettingsMutex.enter(); + if (!Running) + { + SettingsMutex.leave(); + return; + } + if (!Process) + { + SettingsMutex.leave(); + nlSleep(100); + continue; + } + nldebug("Update color modifier"); + m_ColorModifier.Hue = Hue; + m_ColorModifier.Lightness = Lightness; + m_ColorModifier.Saturation = Saturation; + m_ColorModifier.Luminosity = Luminosity; + m_ColorModifier.Saturation = Saturation; + SettingsMutex.leave(); + + BitmapMutex.enter(); + if (!Running) + { + BitmapMutex.leave(); + return; + } + if (!m_BitmapsOk) + { + nldebug("Bitmaps not ready"); + BitmapMutex.leave(); + nlSleep(100); + continue; + } + float retDeltaHue; + m_ColorModifier.convertBitmap(DestBitmap, ColorBitmap, MaskBitmap, retDeltaHue); + BitmapMutex.leave(); + + PanoplyPreview->displayBitmap(DestBitmap); + + nlSleep(100); + } + } + + CColorThread() : m_BitmapsOk(false), Hue(0), Lightness(0), Saturation(0), Luminosity(0), Contrast(0), Process(false), Running(true) { } + virtual ~CColorThread() { } + virtual void getName (std::string &result) const { result = "CColorThread"; } + +private: + CColorModifier m_ColorModifier; + bool m_BitmapsOk; + +public: + CPanoplyPreview *PanoplyPreview; + + NLMISC::CMutex BitmapMutex; + NLMISC::CBitmap ColorBitmap; + NLMISC::CBitmap MaskBitmap; + NLMISC::CBitmap DestBitmap; + + NLMISC::CMutex SettingsMutex; + float Hue; + float Lightness; + float Saturation; + float Luminosity; + float Contrast; + bool Process; + + bool Running; +}; + +// ***************************************************************** + +CPanoplyPreview::CPanoplyPreview(CMainWindow *parent) : QWidget(parent) { m_DisplayerOutput = new QTextEdit(); m_DisplayerOutput->setReadOnly(true); @@ -47,13 +140,274 @@ CPanoplyPreview::CPanoplyPreview(QWidget *parent) : QWidget(parent) setLayout(layout); // connect(m_CommandInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); + + createDockWindows(parent); + + m_ColorThread = new CColorThread(); + m_ColorThread->PanoplyPreview = this; + m_Thread = IThread::create(m_ColorThread); + m_Thread->start(); } CPanoplyPreview::~CPanoplyPreview() +{ + m_ColorThread->BitmapMutex.enter(); + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Running = false; + m_ColorThread->SettingsMutex.leave(); + m_ColorThread->BitmapMutex.leave(); + m_Thread->wait(); + delete m_Thread; + delete m_ColorThread; +} + +void CPanoplyPreview::displayBitmap(const CBitmap &bitmap) // Called from thread! +{ + nldebug("display bitmap!"); +} + +void CPanoplyPreview::colorEdited(const QString &text) +{ + +} + +void CPanoplyPreview::maskEdited(const QString &text) +{ + +} + +void CPanoplyPreview::goPushed() { } +void CPanoplyPreview::hueChanged(int value) +{ + float v = (float)value; + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Hue = v; + m_ColorThread->Process = true; + m_ColorThread->SettingsMutex.leave(); +} + +void CPanoplyPreview::lightnessChanged(int value) +{ + float v = (float)value * 0.01f; + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Lightness = v; + m_ColorThread->Process = true; + m_ColorThread->SettingsMutex.leave(); +} + +void CPanoplyPreview::saturationChanged(int value) +{ + float v = (float)value * 0.01f; + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Saturation = v; + m_ColorThread->Process = true; + m_ColorThread->SettingsMutex.leave(); +} + +void CPanoplyPreview::luminosityChanged(int value) +{ + float v = (float)value; + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Luminosity = v; + m_ColorThread->Process = true; + m_ColorThread->SettingsMutex.leave(); +} + +void CPanoplyPreview::contrastChanged(int value) +{ + float v = (float)value; + m_ColorThread->SettingsMutex.enter(); + m_ColorThread->Contrast = v; + m_ColorThread->Process = true; + m_ColorThread->SettingsMutex.leave(); +} + +// ***************************************************************** + +CSliderTextEdit::CSliderTextEdit(QWidget *parent, QLineEdit *lineEdit, float scale) : QSlider(Qt::Horizontal, parent), m_LineEdit(lineEdit), m_Updating(false), m_Scale(scale) +{ + connect(this, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int))); + connect(lineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(lineEditTextEdited(const QString &))); +} + +CSliderTextEdit::~CSliderTextEdit() +{ + +} + +void CSliderTextEdit::lineEditTextEdited(const QString &text) +{ + if (!m_Updating) + { + m_Updating = true; + setValue((int)(text.toFloat() * m_Scale)); + m_Updating = false; + } +} + +void CSliderTextEdit::sliderValueChanged(int value) +{ + if (!m_Updating) + { + m_Updating = true; + m_LineEdit->setText(QString::number((double)value / (double)m_Scale)); + m_Updating = false; + } +} + +// ***************************************************************** + +void CPanoplyPreview::createDockWindows(CMainWindow *mainWindow) +{ + nlassert(mainWindow); + + // Color Modifier + { + QDockWidget *dockWidget = new QDockWidget(mainWindow); + nlassert(dockWidget); + dockWidget->setWindowTitle(tr("Color Modifier")); + dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + QScrollArea *scrollArea = new QScrollArea(dockWidget); + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea->setWidgetResizable(true); + QWidget *widget = new QWidget(scrollArea); + QVBoxLayout *vboxLayout = new QVBoxLayout(widget); + + // Input File Paths + { + QGroupBox *groupBox = new QGroupBox(widget); + groupBox->setTitle(tr("Input File Paths")); + QGridLayout *groupLayout = new QGridLayout(groupBox); + + QLabel *colorLabel = new QLabel(groupBox); + colorLabel->setText(tr("Color: ")); + groupLayout->addWidget(colorLabel, 0, 0); + + QLineEdit *colorFile = new QLineEdit(groupBox); + groupLayout->addWidget(colorFile, 0, 1); + + QLabel *maskLabel = new QLabel(groupBox); + maskLabel->setText(tr("Mask: ")); + groupLayout->addWidget(maskLabel, 1, 0); + + QLineEdit *maskFile = new QLineEdit(groupBox); + groupLayout->addWidget(maskFile, 1, 1); + + QPushButton *go = new QPushButton(groupBox); + go->setText(tr("Go")); + groupLayout->addWidget(go, 2, 0, 1, 2); + + groupBox->setLayout(groupLayout); + vboxLayout->addWidget(groupBox); + } + + // Color Modifier + { + QGroupBox *groupBox = new QGroupBox(widget); + groupBox->setTitle(tr("Color Modifier")); + QGridLayout *groupLayout = new QGridLayout(groupBox); + + QLabel *label; + QLineEdit *edit; + CSliderTextEdit *slider; + + label = new QLabel(groupBox); + label->setText(tr("Hue [0, 360]: ")); + groupLayout->addWidget(label, 0, 0); + + edit = new QLineEdit(groupBox); + edit->setText("0"); + groupLayout->addWidget(edit, 0, 1); + + slider = new CSliderTextEdit(groupBox, edit, 1.0f); + slider->setMinimum(0); + slider->setMaximum(360); + slider->setValue(0); + groupLayout->addWidget(slider, 1, 0, 1, 2); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(hueChanged(int))); + + label = new QLabel(groupBox); + label->setText(tr("Lightness [-1, 1]: ")); + groupLayout->addWidget(label, 2, 0); + + edit = new QLineEdit(groupBox); + edit->setText("0"); + groupLayout->addWidget(edit, 2, 1); + + slider = new CSliderTextEdit(groupBox, edit, 100.0f); + slider->setMinimum(-100); + slider->setMaximum(100); + slider->setValue(0); + groupLayout->addWidget(slider, 3, 0, 1, 2); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(lightnessChanged(int))); + + label = new QLabel(groupBox); + label->setText(tr("Saturation [-1, 1]: ")); + groupLayout->addWidget(label, 4, 0); + + edit = new QLineEdit(groupBox); + edit->setText("0"); + groupLayout->addWidget(edit, 4, 1); + + slider = new CSliderTextEdit(groupBox, edit, 100.0f); + slider->setMinimum(-100); + slider->setMaximum(100); + slider->setValue(0); + groupLayout->addWidget(slider, 5, 0, 1, 2); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(saturationChanged(int))); + + label = new QLabel(groupBox); + label->setText(tr("Luminosity [-100, 100]: ")); + groupLayout->addWidget(label, 6, 0); + + edit = new QLineEdit(groupBox); + edit->setText("0"); + groupLayout->addWidget(edit, 6, 1); + + slider = new CSliderTextEdit(groupBox, edit, 1.0f); + slider->setMinimum(-100); + slider->setMaximum(100); + slider->setValue(0); + groupLayout->addWidget(slider, 7, 0, 1, 2); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(luminosityChanged(int))); + + label = new QLabel(groupBox); + label->setText(tr("Contrast [-100, 100]: ")); + groupLayout->addWidget(label, 8, 0); + + edit = new QLineEdit(groupBox); + edit->setText("0"); + groupLayout->addWidget(edit, 8, 1); + + slider = new CSliderTextEdit(groupBox, edit, 1.0f); + slider->setMinimum(-100); + slider->setMaximum(100); + slider->setValue(0); + groupLayout->addWidget(slider, 9, 0, 1, 2); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(contrastChanged(int))); + + groupBox->setLayout(groupLayout); + vboxLayout->addWidget(groupBox); + } + + vboxLayout->addStretch(); + widget->setLayout(vboxLayout); + scrollArea->setWidget(widget); + dockWidget->setWidget(scrollArea); + mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget); + mainWindow->widgetsMenu()->addAction(dockWidget->toggleViewAction()); + } +} + } /* namespace NLTOOLS */ /* end of file */ diff --git a/code/nel/tools/3d/panoply_preview/panoply_preview.h b/code/nel/tools/3d/panoply_preview/panoply_preview.h index fe4bbcd08..bddacf77c 100644 --- a/code/nel/tools/3d/panoply_preview/panoply_preview.h +++ b/code/nel/tools/3d/panoply_preview/panoply_preview.h @@ -24,6 +24,7 @@ #include #include #include +#include // NeL includes #include @@ -31,7 +32,14 @@ // Project includes +namespace NLMISC { + class CBitmap; + class IThread; +} + namespace NLTOOLS { + class CMainWindow; + class CColorThread; /** * CPanoplyPreview @@ -44,22 +52,57 @@ class CPanoplyPreview : public QWidget Q_OBJECT public: - CPanoplyPreview(QWidget *parent); + CPanoplyPreview(CMainWindow *parent); virtual ~CPanoplyPreview(); -//private slots: - // ... + void displayBitmap(const NLMISC::CBitmap &bitmap); // Called from thread! + +private slots: + void colorEdited(const QString &text); + void maskEdited(const QString &text); + void goPushed(); + + void hueChanged(int value); + void lightnessChanged(int value); + void saturationChanged(int value); + void luminosityChanged(int value); + void contrastChanged(int value); + +private: + void createDockWindows(CMainWindow *mainWindow); private: QTextEdit *m_DisplayerOutput; QLineEdit *m_CommandInput; + NLMISC::IThread *m_Thread; + CColorThread *m_ColorThread; + private: CPanoplyPreview(const CPanoplyPreview &); CPanoplyPreview &operator=(const CPanoplyPreview &); }; /* class CPanoplyPreview */ +class CSliderTextEdit : public QSlider +{ + Q_OBJECT + +public: + CSliderTextEdit(QWidget *parent, QLineEdit *lineEdit, float scale); + virtual ~CSliderTextEdit(); + +private slots: + void lineEditTextEdited(const QString &text); + void sliderValueChanged(int value); + +private: + QLineEdit *m_LineEdit; + bool m_Updating; + float m_Scale; + +}; + } /* namespace NLTOOLS */ #endif /* #ifndef NLTOOLS_PANOPLY_PREVIEW_H */