paysages: Qt GUI (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@213 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-05 16:32:41 +00:00 committed by ThunderK
parent e3f692800b
commit deeadf33ca
14 changed files with 188 additions and 411 deletions

104
gui_qt/baseform.cpp Normal file
View file

@ -0,0 +1,104 @@
#include "baseform.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QSlider>
class DoubleSliderWidget:public QWidget
{
public:
DoubleSliderWidget(QWidget* parent, double* value, double min, double max, double small_step, double large_step):
QWidget(parent),
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{
setObjectName("_form_doubleslider_");
setLayout(new QHBoxLayout());
slider = new QSlider(this);
slider->setOrientation(Qt::Horizontal);
slider->setMinimum(min / small_step);
slider->setMaximum(max / small_step);
slider->setValue(*value / small_step);
slider->setTickInterval(large_step / small_step);
slider->setTickPosition(QSlider::TicksBelow);
layout()->addWidget(slider);
}
void revert()
{
slider->setValue(*value / small_step);
}
private:
QSlider* slider;
double* value;
double min;
double max;
double small_step;
double large_step;
};
BaseForm::BaseForm(QWidget* parent) :
QWidget(parent)
{
QWidget* hwidget;
QWidget* buttons;
QVBoxLayout* vlayout;
QHBoxLayout* hlayout;
vlayout = new QVBoxLayout();
hlayout = new QHBoxLayout();
hwidget = new QWidget(this);
previews = new QWidget(this);
previews->setLayout(new QVBoxLayout());
form = new QWidget(this);
form->setLayout(new QGridLayout());
buttons = new QWidget(this);
hlayout->addWidget(previews);
hlayout->addWidget(form);
vlayout->addWidget(hwidget);
vlayout->addWidget(buttons);
hwidget->setLayout(hlayout);
this->setLayout(vlayout);
}
void BaseForm::revertConfig()
{
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++)
{
list_previews[i]->redraw();
}
QList<DoubleSliderWidget*> list_doubles = form->findChildren<DoubleSliderWidget*>("_form_doubleslider_");
for (int i = 0; i < list_doubles.size(); i++)
{
list_doubles[i]->revert();
}
}
void BaseForm::addPreview(Preview* preview, QString label)
{
previews->layout()->addWidget(new QLabel(label, previews));
previews->layout()->addWidget(preview);
preview->setObjectName("_form_preview_");
}
void BaseForm::addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step)
{
QGridLayout* layout = (QGridLayout*)form->layout();
int row = layout->rowCount();
layout->addWidget(new QLabel(label, form), row, 0);
layout->addWidget(new DoubleSliderWidget(form, value, min, max, small_step, large_step), row, 1);
}

24
gui_qt/baseform.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef _GUI_QT_BASEFORM_H_
#define _GUI_QT_BASEFORM_H_
#include <QWidget>
#include "preview.h"
class BaseForm:public QWidget
{
public:
BaseForm(QWidget* parent);
public slots:
virtual void revertConfig();
protected:
void addPreview(Preview* preview, QString label);
void addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step);
private:
QWidget* previews;
QWidget* form;
};
#endif // _GUI_QT_BASEFORM_H_

View file

@ -1,7 +1,7 @@
#include "preview.h"
#include "formwater.h"
#include "ui_formwater.h"
#include <QColor>
#include <QSlider>
#include <math.h>
#include "../lib_paysages/terrain.h"
@ -122,45 +122,32 @@ private:
/**************** Form ****************/
FormWater::FormWater(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormWater)
BaseForm(parent)
{
ui->setupUi(this);
findChild<QToolBox*>("water_configs")->setCurrentIndex(0);
_definition = waterCreateDefinition();
previewCoverage = new PreviewCoverage(findChild<QWidget*>("water_preview_coverage"));
previewColor = new PreviewColor(findChild<QWidget*>("water_preview_color"));
previewCoverage = new PreviewCoverage(this);
previewColor = new PreviewColor(this);
addPreview(previewCoverage, QString("Coverage preview"));
addPreview(previewColor, QString("Color preview"));
QObject::connect(findChild<QSlider*>("water_height"), SIGNAL(valueChanged(int)), this, SLOT(configChange()));
QObject::connect(findChild<QSlider*>("water_transparency"), SIGNAL(valueChanged(int)), this, SLOT(configChange()));
QObject::connect(findChild<QSlider*>("water_reflection"), SIGNAL(valueChanged(int)), this, SLOT(configChange()));
QObject::connect(findChild<QSlider*>("water_depth_limit"), SIGNAL(valueChanged(int)), this, SLOT(configChange()));
addDoubleSlider("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0);
addDoubleSlider("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addDoubleSlider("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addDoubleSlider("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
revertConfig();
}
FormWater::~FormWater()
{
delete ui;
}
void FormWater::dataUpdated()
{
revertConfig();
}
void FormWater::configChange()
{
_definition.height = (double)findChild<QSlider*>("water_height")->value() / 10.0;
/*_definition.height = (double)findChild<QSlider*>("water_height")->value() / 10.0;
_definition.transparency = (double)findChild<QSlider*>("water_transparency")->value() / 1000.0;
_definition.reflection = (double)findChild<QSlider*>("water_reflection")->value() / 1000.0;
_definition.transparency_depth = (double)findChild<QSlider*>("water_depth_limit")->value() / 10.0;
previewCoverage->redraw();
previewColor->redraw();
previewColor->redraw();*/
}
void FormWater::applyConfig()
@ -172,12 +159,5 @@ void FormWater::applyConfig()
void FormWater::revertConfig()
{
waterCopyDefinition(waterGetDefinition(), &_definition);
findChild<QSlider*>("water_height")->setValue(_definition.height * 10.0);
findChild<QSlider*>("water_transparency")->setValue(_definition.transparency * 1000.0);
findChild<QSlider*>("water_reflection")->setValue(_definition.reflection * 1000.0);
findChild<QSlider*>("water_depth_limit")->setValue(_definition.transparency_depth * 10.0);
previewCoverage->redraw();
previewColor->redraw();
BaseForm::revertConfig();
}

View file

@ -1,32 +1,25 @@
#ifndef FORMWATER_H
#define FORMWATER_H
#ifndef _GUI_QT_FORMWATER_H_
#define _GUI_QT_FORMWATER_H_
#include <QWidget>
#include "preview.h"
#include "baseform.h"
namespace Ui {
class FormWater;
}
class FormWater : public QWidget
class FormWater : public BaseForm
{
Q_OBJECT
public:
explicit FormWater(QWidget *parent = 0);
~FormWater();
void dataUpdated();
public slots:
virtual void revertConfig();
void configChange();
void applyConfig();
void revertConfig();
private:
Ui::FormWater *ui;
Preview* previewCoverage;
Preview* previewColor;
};
#endif // FORMWATER_H
#endif // _GUI_QT_FORMWATER_H_

View file

@ -1,344 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormWater</class>
<widget class="QWidget" name="FormWater">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>739</width>
<height>591</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>279</x>
<y>550</y>
<width>451</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="water_buttons">
<item>
<widget class="QPushButton" name="water_apply">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="water_revert">
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>258</width>
<height>566</height>
</rect>
</property>
<layout class="QVBoxLayout" name="water_previews">
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Coverage preview</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="water_preview_coverage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="baseSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Color preview</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="water_preview_color" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="baseSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBox" name="water_configs">
<property name="geometry">
<rect>
<x>280</x>
<y>10</y>
<width>451</width>
<height>531</height>
</rect>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="water_config_coverage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>438</height>
</rect>
</property>
<attribute name="label">
<string>Coverage</string>
</attribute>
<widget class="QWidget" name="formLayoutWidget_5">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>431</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_5">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="heightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="water_height">
<property name="minimum">
<number>-300</number>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="water_config_waves">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>438</height>
</rect>
</property>
<attribute name="label">
<string>Waves</string>
</attribute>
</widget>
<widget class="QWidget" name="water_config_colors">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>438</height>
</rect>
</property>
<attribute name="label">
<string>Colors</string>
</attribute>
<widget class="QWidget" name="formLayoutWidget_6">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>431</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_6">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="transparencyLabel">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="water_transparency">
<property name="maximum">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="reflectionLabel">
<property name="text">
<string>Reflection</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="water_reflection">
<property name="maximum">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>100</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="surfaceColorLabel">
<property name="text">
<string>Surface color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pushButton_7">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="depthColorLabel">
<property name="text">
<string>Depth color</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="depthLimitLabel">
<property name="text">
<string>Depth limit</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pushButton_8">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSlider" name="water_depth_limit">
<property name="maximum">
<number>500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -14,10 +14,11 @@ LIBS += -L../lib_paysages/ -lpaysages
HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
mainwindow.h \
formwater.h \
preview.h
FORMS += mainwindow.ui \
formwater.ui
preview.h \
baseform.h
FORMS += mainwindow.ui
SOURCES += main.cc \
mainwindow.cpp \
formwater.cpp \
preview.cpp
preview.cpp \
baseform.cpp

View file

@ -47,7 +47,9 @@ Preview::Preview(QWidget* parent) :
this->need_rerender = 0;
this->need_render = 0;
this->resize(parent->size());
this->setMinimumSize(256, 256);
this->setMaximumSize(256, 256);
this->resize(256, 256);
}
void Preview::startUpdater()

View file

@ -1,5 +1,5 @@
#ifndef PREVIEW_H
#define PREVIEW_H
#ifndef _GUI_QT_PREVIEW_H_
#define _GUI_QT_PREVIEW_H_
#include <QMutex>
#include <QImage>
@ -45,4 +45,4 @@ protected:
//SmallPreviewCallback renderer;
};
#endif // PREVIEW_H
#endif // _GUI_QT_PREVIEW_H_

View file

@ -12,6 +12,7 @@
#include "water.h"
#include "clouds.h"
#include "sky.h"
#include "modifiers.h"
#include "terrain.h"
#include "textures.h"

View file

@ -1,5 +1,6 @@
#include "shared/types.h"
#include "shared/functions.h"
#include "modifiers.h"
#include <stdlib.h>

27
lib_paysages/modifiers.h Normal file
View file

@ -0,0 +1,27 @@
#ifndef _PAYSAGES_MODIFIERS_H_
#define _PAYSAGES_MODIFIERS_H_
#include "shared/types.h"
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct HeightModifier HeightModifier;
HeightModifier* modifierCreate();
HeightModifier* modifierCreateCopy(HeightModifier* source);
void modifierDelete(HeightModifier* modifier);
void modifierSave(HeightModifier* modifier, FILE* f);
void modifierLoad(HeightModifier* modifier, FILE* f);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);
Vector3 modifierApply(HeightModifier* modifier, Vector3 location);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -105,17 +105,6 @@ void lightingSetSunAngle(double hor, double ver);
void lightingSetSunColor(Color col);
Color lightingApply(Vector3 location, Vector3 normal, double shadowing, Color base, double reflection, double shininess);
/* modifiers.c */
HeightModifier* modifierCreate();
HeightModifier* modifierCreateCopy(HeightModifier* source);
void modifierDelete(HeightModifier* modifier);
void modifierSave(HeightModifier* modifier, FILE* f);
void modifierLoad(HeightModifier* modifier, FILE* f);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);
Vector3 modifierApply(HeightModifier* modifier, Vector3 location);
/* noise.c */
NoiseGenerator* noiseCreateGenerator();
void noiseDeleteGenerator(NoiseGenerator* generator);

View file

@ -100,8 +100,6 @@ typedef struct NoiseGenerator NoiseGenerator;
typedef struct Zone Zone;
typedef struct HeightModifier HeightModifier;
typedef void (*PreviewCallbackResize)(int width, int height);
typedef void (*PreviewCallbackClear)(Color col);
typedef void (*PreviewCallbackDraw)(int x, int y, Color col);

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_TERRAIN_H_
#include "shared/types.h"
#include "modifiers.h"
#include <stdio.h>
#ifdef __cplusplus