paysages: Qt GUI (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@221 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-10 20:51:27 +00:00 committed by ThunderK
parent 4b559f5cbb
commit f91ed2c7f3
16 changed files with 2224 additions and 21 deletions

View file

@ -1,13 +1,18 @@
all: all:
cd lib_paysages && make cd lib_paysages && make
cd cli && make
cd gui_gtk && make cd gui_gtk && make
cd gui_qt && qmake && make cd gui_qt && qmake && make
clean: clean:
cd lib_paysages && make clean cd lib_paysages && make clean
cd cli && make clean
cd gui_gtk && make clean cd gui_gtk && make clean
cd gui_qt && make clean && rm -f Makefile paysages-qt cd gui_qt && make clean && rm -f Makefile paysages-qt
run_cli:
LD_LIBRARY_PATH=lib_paysages ./cli/paysages-cli
run_gtk: run_gtk:
LD_LIBRARY_PATH=lib_paysages ./gui_gtk/paysages-gtk LD_LIBRARY_PATH=lib_paysages ./gui_gtk/paysages-gtk

21
cli/Makefile Normal file
View file

@ -0,0 +1,21 @@
SOURCES=$(wildcard *.c)
OBJECTS=${SOURCES:.c=.o}
HEADERS=$(wildcard ../lib_paysages/shared/*.h ../lib_paysages/*.h *.h)
RESULT=paysages-cli
CC_FLAGS=-g -pg -Wall
CC_LDFLAGS=-L../lib_paysages/ -lpaysages
all:${RESULT}
clean:
rm -f ${OBJECTS}
rm -f ${RESULT}
%.o:%.c ${HEADERS}
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} $^ ${CC_LDFLAGS} -o $@
.PHONY:all clean

10
cli/main.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <stdio.h>
#include "../lib_paysages/shared/functions.h"
int main(int argc, char** argv)
{
paysagesInit();
return 0;
}

View file

@ -67,7 +67,7 @@ void guiInit()
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
gui_definition = gtk_builder_new(); gui_definition = gtk_builder_new();
gtk_builder_add_from_file(gui_definition, "data/gui.glade", &p_err); gtk_builder_add_from_file(gui_definition, "gui_gtk/gui.glade", &p_err);
_main_window = GTK_WINDOW(GET_WIDGET("main_window")); _main_window = GTK_WINDOW(GET_WIDGET("main_window"));
g_signal_connect(_main_window, "delete_event", G_CALLBACK(_cbQuit), NULL); g_signal_connect(_main_window, "delete_event", G_CALLBACK(_cbQuit), NULL);

2091
gui_gtk/gui.glade Normal file

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,6 @@
BaseForm::BaseForm(QWidget* parent) : BaseForm::BaseForm(QWidget* parent) :
QWidget(parent) QWidget(parent)
{ {
QPushButton* button;
QWidget* hwidget; QWidget* hwidget;
QVBoxLayout* vlayout; QVBoxLayout* vlayout;
QHBoxLayout* hlayout; QHBoxLayout* hlayout;
@ -43,11 +42,14 @@ BaseForm::BaseForm(QWidget* parent) :
hwidget->setLayout(hlayout); hwidget->setLayout(hlayout);
this->setLayout(vlayout); this->setLayout(vlayout);
this->setObjectName("_base_form_");
button = addButton("Apply"); button_apply = addButton("Apply");
connect(button, SIGNAL(clicked()), this, SLOT(applyConfig())); button_apply->setEnabled(false);
button = addButton("Revert"); connect(button_apply, SIGNAL(clicked()), this, SLOT(applyConfig()));
connect(button, SIGNAL(clicked()), this, SLOT(revertConfig())); button_revert = addButton("Revert");
button_revert->setEnabled(false);
connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig()));
} }
void BaseForm::applyConfigPreview() void BaseForm::applyConfigPreview()
@ -57,6 +59,9 @@ void BaseForm::applyConfigPreview()
{ {
list_previews[i]->redraw(); list_previews[i]->redraw();
} }
button_apply->setEnabled(true);
button_revert->setEnabled(true);
} }
void BaseForm::revertConfig() void BaseForm::revertConfig()
@ -68,6 +73,9 @@ void BaseForm::revertConfig()
} }
BaseForm::applyConfigPreview(); BaseForm::applyConfigPreview();
button_apply->setEnabled(false);
button_revert->setEnabled(false);
} }
void BaseForm::applyConfig() void BaseForm::applyConfig()

View file

@ -35,6 +35,8 @@ private:
QWidget* previews; QWidget* previews;
QWidget* form; QWidget* form;
QWidget* buttons; QWidget* buttons;
QPushButton* button_apply;
QPushButton* button_revert;
}; };
#endif // _PAYSAGES_QT_BASEFORM_H_ #endif // _PAYSAGES_QT_BASEFORM_H_

View file

@ -62,7 +62,7 @@ public:
} }
}; };
DialogRender::DialogRender(QWidget *parent) : DialogRender::DialogRender(QWidget *parent, int quality, int width, int height):
QDialog(parent) QDialog(parent)
{ {
QScrollArea* scroll; QScrollArea* scroll;
@ -74,7 +74,7 @@ DialogRender::DialogRender(QWidget *parent) :
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
scroll = new QScrollArea(this); scroll = new QScrollArea(this);
scroll->setMinimumSize(850, 650); scroll->setMinimumSize(width > 800 ? 850 : width + 50, height > 600 ? 650 : height + 50);
scroll->setAlignment(Qt::AlignCenter); scroll->setAlignment(Qt::AlignCenter);
area = new RenderArea(scroll); area = new RenderArea(scroll);
scroll->setWidget(area); scroll->setWidget(area);
@ -83,13 +83,39 @@ DialogRender::DialogRender(QWidget *parent) :
progress = new QProgressBar(this); progress = new QProgressBar(this);
progress->setMinimum(0); progress->setMinimum(0);
progress->setMaximum(1000); progress->setMaximum(1000);
progress->setValue(0);
layout()->addWidget(progress); layout()->addWidget(progress);
progress_value = 0; progress_value = 0;
renderSetSize(800, 600); renderSetSize(width, height);
autoSetRenderQuality(5); autoSetRenderQuality(quality);
renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate); renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate);
render_thread = new RenderThread(); render_thread = new RenderThread();
render_thread->start(); render_thread->start();
} }
void DialogRender::closeEvent(QCloseEvent* e)
{
renderInterrupt();
render_thread->wait();
renderSetPreviewCallbacks(NULL, NULL, NULL, NULL);
delete render_thread;
delete pixbuf;
}
void DialogRender::reject()
{
renderInterrupt();
render_thread->wait();
renderSetPreviewCallbacks(NULL, NULL, NULL, NULL);
delete render_thread;
delete pixbuf;
QDialog::reject();
}

View file

@ -9,15 +9,17 @@ class DialogRender : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogRender(QWidget *parent = 0); explicit DialogRender(QWidget *parent, int quality, int width, int height);
QImage* pixbuf; QImage* pixbuf;
QWidget* area; QWidget* area;
QProgressBar* progress; QProgressBar* progress;
int progress_value; int progress_value;
signals:
public slots: public slots:
virtual void reject();
protected:
virtual void closeEvent(QCloseEvent* e);
private: private:
QThread* render_thread; QThread* render_thread;

View file

@ -5,11 +5,15 @@
/**************** Form ****************/ /**************** Form ****************/
FormRender::FormRender(QWidget *parent) : FormRender::FormRender(QWidget *parent) :
BaseForm(parent), BaseForm(parent),
_quality(5) _quality(5),
_width(800),
_height(600)
{ {
QPushButton* button; QPushButton* button;
addInputInt("Quality", &_quality, 1, 10, 1, 1); addInputInt("Quality", &_quality, 1, 10, 1, 1);
addInputInt("Image width", &_width, 100, 2000, 10, 100);
addInputInt("Image height", &_height, 100, 2000, 10, 100);
button = addButton("Start new render"); button = addButton("Start new render");
connect(button, SIGNAL(clicked()), this, SLOT(startRender())); connect(button, SIGNAL(clicked()), this, SLOT(startRender()));
@ -23,7 +27,7 @@ FormRender::FormRender(QWidget *parent) :
void FormRender::startRender() void FormRender::startRender()
{ {
DialogRender* dialog = new DialogRender(); DialogRender* dialog = new DialogRender(this, _quality, _width, _height);
dialog->exec(); dialog->exec();
delete dialog; delete dialog;

View file

@ -17,6 +17,8 @@ private slots:
private: private:
int _quality; int _quality;
int _width;
int _height;
}; };
#endif // _PAYSAGES_QT_FORMRENDER_H_ #endif // _PAYSAGES_QT_FORMRENDER_H_

View file

@ -7,6 +7,7 @@
#include "formwater.h" #include "formwater.h"
#include "formsky.h" #include "formsky.h"
#include "formrender.h" #include "formrender.h"
#include "dialogrender.h"
#include "../lib_paysages/shared/functions.h" #include "../lib_paysages/shared/functions.h"
@ -36,28 +37,53 @@ MainWindow::MainWindow(QWidget *parent) :
tabs->addTab(new FormSky(tabs), "Sky"); tabs->addTab(new FormSky(tabs), "Sky");
tabs->addTab(new FormRender(tabs), "Render"); tabs->addTab(new FormRender(tabs), "Render");
menu = menuBar()->addMenu("File"); menu = menuBar()->addMenu("Scene");
menu->addAction("New", this, SLOT(fileNew())); menu->addAction("New", this, SLOT(fileNew()));
menu->addAction("Save", this, SLOT(fileSave())); menu->addAction("Save", this, SLOT(fileSave()));
menu->addAction("Load", this, SLOT(fileLoad())); menu->addAction("Load", this, SLOT(fileLoad()));
menu->addAction("Quit", this, SLOT(close())); menu->addAction("Quit", this, SLOT(close()));
menu = menuBar()->addMenu("Render");
menu->addAction("Quick render", this, SLOT(quickPreview()), QKeySequence("F2"));
setCentralWidget(tabs); setCentralWidget(tabs);
} }
void MainWindow::refreshAll()
{
QList<BaseForm*> list_forms = this->findChildren<BaseForm*>("_base_form_");
for (int i = 0; i < list_forms.size(); i++)
{
list_forms[i]->revertConfig();
}
}
void MainWindow::fileNew() void MainWindow::fileNew()
{ {
// TODO autoGenRealisticLandscape(0);
refreshAll();
} }
void MainWindow::fileSave() void MainWindow::fileSave()
{ {
QString filepath = QFileDialog::getSaveFileName(this); QString filepath = QFileDialog::getSaveFileName(this);
if (!filepath.isNull())
{
autoSave((char*)filepath.toStdString().c_str()); autoSave((char*)filepath.toStdString().c_str());
} }
}
void MainWindow::fileLoad() void MainWindow::fileLoad()
{ {
QString filepath = QFileDialog::getOpenFileName(this); QString filepath = QFileDialog::getOpenFileName(this);
if (!filepath.isNull())
{
autoLoad((char*)filepath.toStdString().c_str()); autoLoad((char*)filepath.toStdString().c_str());
refreshAll();
}
}
void MainWindow::quickPreview()
{
DialogRender(this, 3, 400, 300).exec();
} }

View file

@ -15,9 +15,11 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
public slots: public slots:
void refreshAll();
void fileNew(); void fileNew();
void fileSave(); void fileSave();
void fileLoad(); void fileLoad();
void quickPreview();
}; };
#endif // _PAYSAGES_QT_MAINWINDOW_H_ #endif // _PAYSAGES_QT_MAINWINDOW_H_

View file

@ -2,8 +2,8 @@ SOURCES=$(wildcard *.c)
OBJECTS=${SOURCES:.c=.o} OBJECTS=${SOURCES:.c=.o}
HEADERS=$(wildcard shared/*.h *.h) HEADERS=$(wildcard shared/*.h *.h)
RESULT=libpaysages.so RESULT=libpaysages.so
CC_FLAGS=-g -pg -Wall $(shell pkg-config --cflags glib-2.0) CC_FLAGS=-g -pg -Wall $(shell pkg-config --cflags glib-2.0 gthread-2.0)
CC_LDFLAGS=$(shell pkg-config --libs glib-2.0) -lIL -lILU CC_LDFLAGS=$(shell pkg-config --libs glib-2.0 gthread-2.0) -lIL -lILU
all:${RESULT} all:${RESULT}

View file

@ -136,6 +136,8 @@ void renderClear()
scanline_right = render_width - 1; scanline_right = render_width - 1;
_progress = 0.0; _progress = 0.0;
_progress_step_start = 0.0;
_progress_step_length = 0.0;
_interrupt = 0; _interrupt = 0;
_cb_preview_clear(background_color); _cb_preview_clear(background_color);

View file

@ -75,6 +75,8 @@ WaterDefinition waterCreateDefinition()
{ {
WaterDefinition result; WaterDefinition result;
result.main_color = COLOR_BLACK;
result.depth_color = COLOR_BLACK;
result.height = -1000.0; result.height = -1000.0;
result.height_noise = noiseCreateGenerator(); result.height_noise = noiseCreateGenerator();
result.height_noise_factor = 1.0; result.height_noise_factor = 1.0;