From aed4f9d80e67beb84fb0ec9f185adb8fde46532d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 12 Nov 2013 23:15:35 +0100 Subject: [PATCH] Refactoring of BasePreview --- data/ui_pictures.qrc | 4 + src/editing/baseform.cpp | 1 + src/editing/baseform.h | 15 +--- src/editing/common/freeformhelper.cpp | 5 +- src/editing/common/freeformhelper.h | 7 +- src/editing/common/mainwindow.cpp | 4 +- src/editing/common/previewrenderer.cpp | 25 ------ src/editing/common/previewrenderer.h | 22 ----- src/editing/dialognoise.cpp | 1 + src/editing/dialognoise.h | 3 +- src/editing/editing.pro | 8 -- src/editing/editing_global.h | 1 + src/editing/formatmosphere.cpp | 17 ++-- src/editing/formatmosphere.h | 5 +- src/editing/formclouds.cpp | 2 + src/editing/formclouds.h | 5 +- src/editing/formrender.cpp | 1 + src/editing/formtextures.cpp | 3 + src/editing/formtextures.h | 5 +- src/editing/formwater.cpp | 3 +- src/editing/formwater.h | 5 +- src/editing/lighting/SmallPreviewColor.h | 2 +- src/editing/lighting/SmallPreviewHues.h | 2 +- src/editing/previewmaterial.cpp | 6 +- src/editing/previewmaterial.h | 10 ++- src/editing/previewosd.h | 45 ---------- src/editing/terrain/mainterrainform.cpp | 1 + src/editing/terrain/mainterrainform.h | 7 +- src/editing/terrain/previewterrainshape.cpp | 10 +-- src/editing/terrain/previewterrainshape.h | 9 +- .../terrain/widgetterrainbasenoisepreview.h | 2 +- src/editing/textures/PreviewCumul.cpp | 6 +- src/editing/textures/PreviewCumul.h | 9 +- src/editing/textures/PreviewLayerCoverage.cpp | 6 +- src/editing/textures/PreviewLayerCoverage.h | 9 +- src/editing/textures/PreviewLayerLook.cpp | 6 +- src/editing/textures/PreviewLayerLook.h | 9 +- src/editing/tools.cpp | 2 +- .../AtmosphereColorPreviewRenderer.cpp | 10 +-- .../preview/AtmosphereColorPreviewRenderer.h | 2 +- src/render/preview/Base2dPreviewRenderer.cpp | 18 +++- src/render/preview/Base2dPreviewRenderer.h | 12 ++- .../preview/BasePreview.cpp} | 67 ++++++++++++--- .../preview/BasePreview.h} | 83 ++++--------------- .../preview}/DrawingWidget.cpp | 0 .../common => render/preview}/DrawingWidget.h | 8 ++ .../preview/PreviewOsd.cpp} | 57 ++----------- src/render/preview/PreviewOsd.h | 33 ++++++++ src/render/preview/PreviewOsdItem.cpp | 52 ++++++++++++ src/render/preview/PreviewOsdItem.h | 36 ++++++++ src/render/preview/preview.pro | 13 ++- src/render/preview/preview_global.h | 10 ++- 52 files changed, 359 insertions(+), 325 deletions(-) delete mode 100644 src/editing/common/previewrenderer.cpp delete mode 100644 src/editing/common/previewrenderer.h delete mode 100644 src/editing/previewosd.h rename src/{editing/basepreview.cpp => render/preview/BasePreview.cpp} (93%) rename src/{editing/basepreview.h => render/preview/BasePreview.h} (70%) rename src/{editing/common => render/preview}/DrawingWidget.cpp (100%) rename src/{editing/common => render/preview}/DrawingWidget.h (82%) rename src/{editing/previewosd.cpp => render/preview/PreviewOsd.cpp} (51%) create mode 100644 src/render/preview/PreviewOsd.h create mode 100644 src/render/preview/PreviewOsdItem.cpp create mode 100644 src/render/preview/PreviewOsdItem.h diff --git a/data/ui_pictures.qrc b/data/ui_pictures.qrc index 4e7e83e..0cff924 100644 --- a/data/ui_pictures.qrc +++ b/data/ui_pictures.qrc @@ -30,4 +30,8 @@ images/logo_64.png images/logo_256.png + + images/toggle_on.png + images/choice_on.png + diff --git a/src/editing/baseform.cpp b/src/editing/baseform.cpp index 54e866f..1248829 100644 --- a/src/editing/baseform.cpp +++ b/src/editing/baseform.cpp @@ -10,6 +10,7 @@ #include "inputmaterial.h" #include "inputenum.h" #include "inputlayers.h" +#include "BasePreview.h" #include #include diff --git a/src/editing/baseform.h b/src/editing/baseform.h index 8a99fae..f0b440e 100644 --- a/src/editing/baseform.h +++ b/src/editing/baseform.h @@ -1,9 +1,10 @@ #ifndef _PAYSAGES_QT_BASEFORM_H_ #define _PAYSAGES_QT_BASEFORM_H_ +#include "editing_global.h" + #include #include -#include "basepreview.h" #include "baseinput.h" #include "dialoglayers.h" #include "shared/types.h" @@ -14,18 +15,6 @@ class QPushButton; class QComboBox; -namespace paysages { -namespace system { - class PackStream; -} -namespace basics { - class NoiseGenerator; -} -namespace definition { - class Layers; -} -} - class BaseForm : public QWidget { Q_OBJECT diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp index 49b838f..cff8afd 100644 --- a/src/editing/common/freeformhelper.cpp +++ b/src/editing/common/freeformhelper.cpp @@ -8,11 +8,14 @@ #include #include #include +#include #include "mainwindow.h" #include "dialogrender.h" #include "dialogexplorer.h" #include "Scenery.h" +#include "BasePreview.h" #include "renderer.h" +#include "camera.h" #include "tools.h" Q_DECLARE_METATYPE(double*) @@ -79,7 +82,7 @@ void FreeFormHelper::startManaging() processGlobalRefresh(); } -void FreeFormHelper::addPreview(BasePreview* preview, PreviewRenderer* renderer) +void FreeFormHelper::addPreview(BasePreview* preview, Base2dPreviewRenderer* renderer) { _previews.append(preview); preview->setRenderer(renderer); diff --git a/src/editing/common/freeformhelper.h b/src/editing/common/freeformhelper.h index c651381..7bca5eb 100644 --- a/src/editing/common/freeformhelper.h +++ b/src/editing/common/freeformhelper.h @@ -1,14 +1,17 @@ #ifndef FREEFORMHELPER_H #define FREEFORMHELPER_H +#include "editing_global.h" + #include #include #include "widgetsliderdecimal.h" -#include "../basepreview.h" class QSlider; class QPushButton; +class QLabel; +class Renderer; class FreeFormHelper:public QObject { @@ -20,7 +23,7 @@ public: void startManaging(); - void addPreview(BasePreview* preview, PreviewRenderer* renderer); + void addPreview(BasePreview* preview, Base2dPreviewRenderer* renderer); void addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0); void setApplyButton(QPushButton* button); void setRevertButton(QPushButton* button); diff --git a/src/editing/common/mainwindow.cpp b/src/editing/common/mainwindow.cpp index 39f25ff..59520a1 100644 --- a/src/editing/common/mainwindow.cpp +++ b/src/editing/common/mainwindow.cpp @@ -12,7 +12,9 @@ #include #include -#include "basepreview.h" +#include "BasePreview.h" +#include "PreviewOsd.h" +#include "PreviewOsdItem.h" #include "formclouds.h" #include "formatmosphere.h" #include "formwater.h" diff --git a/src/editing/common/previewrenderer.cpp b/src/editing/common/previewrenderer.cpp deleted file mode 100644 index 18d98cb..0000000 --- a/src/editing/common/previewrenderer.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "previewrenderer.h" - -#include "SoftwareRenderer.h" - -PreviewRenderer::PreviewRenderer() -{ -} - -PreviewRenderer::~PreviewRenderer() -{ -} - -Color PreviewRenderer::getColor2D(double, double, double) const -{ - return COLOR_BLACK; -} - -void PreviewRenderer::bindEvent(BasePreview*) -{ -} - -void PreviewRenderer::updateEvent() -{ - renderer->prepare(); -} diff --git a/src/editing/common/previewrenderer.h b/src/editing/common/previewrenderer.h deleted file mode 100644 index 1d0cf06..0000000 --- a/src/editing/common/previewrenderer.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef PREVIEWRENDERER_H -#define PREVIEWRENDERER_H - -#include "rendering_global.h" - -#include "Base2dPreviewRenderer.h" -#include "renderer.h" - -class BasePreview; - -class PreviewRenderer : public Base2dPreviewRenderer -{ -public: - PreviewRenderer(); - virtual ~PreviewRenderer(); - - virtual void bindEvent(BasePreview* preview); - virtual void updateEvent(); - virtual Color getColor2D(double x, double y, double scaling) const override; -}; - -#endif // PREVIEWRENDERER_H diff --git a/src/editing/dialognoise.cpp b/src/editing/dialognoise.cpp index 722d2d1..fd32a06 100644 --- a/src/editing/dialognoise.cpp +++ b/src/editing/dialognoise.cpp @@ -11,6 +11,7 @@ #include #include #include "tools/color.h" +#include "BasePreview.h" /**************** Previews ****************/ class PreviewLevel:public BasePreview diff --git a/src/editing/dialognoise.h b/src/editing/dialognoise.h index bc72d4b..bc27dc4 100644 --- a/src/editing/dialognoise.h +++ b/src/editing/dialognoise.h @@ -1,9 +1,10 @@ #ifndef _PAYSAGES_QT_DIALOGNOISE_H_ #define _PAYSAGES_QT_DIALOGNOISE_H_ +#include "editing_global.h" + #include #include -#include "basepreview.h" #include "tools.h" #include "NoiseGenerator.h" diff --git a/src/editing/editing.pro b/src/editing/editing.pro index afea6c0..100b0a0 100644 --- a/src/editing/editing.pro +++ b/src/editing/editing.pro @@ -13,7 +13,6 @@ HEADERS += \ terrain/widgetheightmap.h \ widgetcurveeditor.h \ tools.h \ - previewosd.h \ previewmaterial.h \ previewcolorgradation.h \ inputnoise.h \ @@ -38,7 +37,6 @@ HEADERS += \ dialogexplorer.h \ dialogcurve.h \ dialogcolorgradation.h \ - basepreview.h \ baseinput.h \ baseformlayer.h \ baseform.h \ @@ -49,14 +47,12 @@ HEADERS += \ common/freeformhelper.h \ terrain/previewterrainshape.h \ common/widgetsliderdecimal.h \ - common/previewrenderer.h \ terrain/widgetterrainbasenoisepreview.h \ common/mainwindow.h \ terrain/dialogbaseterrainnoise.h \ textures/maintexturesform.h \ common/freelayerhelper.h \ lighting/DialogMaterialEditor.h \ - common/DrawingWidget.h \ lighting/SmallPreviewColor.h \ lighting/SmallPreviewHues.h \ textures/PreviewLayerCoverage.h \ @@ -69,7 +65,6 @@ SOURCES += \ terrain/widgetheightmap.cpp \ widgetcurveeditor.cpp \ tools.cpp \ - previewosd.cpp \ previewmaterial.cpp \ previewcolorgradation.cpp \ inputnoise.cpp \ @@ -94,7 +89,6 @@ SOURCES += \ dialogexplorer.cpp \ dialogcurve.cpp \ dialogcolorgradation.cpp \ - basepreview.cpp \ baseinput.cpp \ baseformlayer.cpp \ baseform.cpp \ @@ -105,14 +99,12 @@ SOURCES += \ common/freeformhelper.cpp \ terrain/previewterrainshape.cpp \ common/widgetsliderdecimal.cpp \ - common/previewrenderer.cpp \ terrain/widgetterrainbasenoisepreview.cpp \ common/mainwindow.cpp \ terrain/dialogbaseterrainnoise.cpp \ textures/maintexturesform.cpp \ common/freelayerhelper.cpp \ lighting/DialogMaterialEditor.cpp \ - common/DrawingWidget.cpp \ lighting/SmallPreviewColor.cpp \ lighting/SmallPreviewHues.cpp \ textures/PreviewLayerCoverage.cpp \ diff --git a/src/editing/editing_global.h b/src/editing/editing_global.h index 930ee0d..18d9b83 100644 --- a/src/editing/editing_global.h +++ b/src/editing/editing_global.h @@ -4,5 +4,6 @@ #include "definition_global.h" #include "software_global.h" #include "opengl_global.h" +#include "preview_global.h" #endif // EDITING_GLOBAL_H diff --git a/src/editing/formatmosphere.cpp b/src/editing/formatmosphere.cpp index f85b57d..baa29bc 100644 --- a/src/editing/formatmosphere.cpp +++ b/src/editing/formatmosphere.cpp @@ -9,12 +9,13 @@ #include "atmosphere/public.h" #include "AtmosphereColorPreviewRenderer.h" #include "Scenery.h" +#include "BasePreview.h" #include "renderer.h" static AtmosphereDefinition* _definition; /**************** Previews ****************/ -class PreviewSkyEast:public PreviewRenderer, public AtmosphereColorPreviewRenderer +class PreviewSkyEast:public AtmosphereColorPreviewRenderer { public: void bindEvent(BasePreview* preview) override @@ -22,14 +23,14 @@ public: preview->configHdrToneMapping(true); preview->configScaling(0.5, 5.0, 0.5, 2.5); } - void updateData() + void updateEvent() override { - /*AtmosphereRendererClass.bind(_renderer, _definition); - _renderer->prepare();*/ + /*AtmosphereRendererClass.bind(renderer, _definition); + renderer->prepare();*/ } }; -class PreviewSkyWest:public PreviewRenderer, public AtmosphereColorPreviewRenderer +class PreviewSkyWest:public AtmosphereColorPreviewRenderer { public: void bindEvent(BasePreview* preview) override @@ -37,10 +38,10 @@ public: preview->configHdrToneMapping(true); preview->configScaling(0.5, 5.0, 0.5, 2.5); } - void updateData() + void updateEvent() override { - /*AtmosphereRendererClass.bind(_renderer, _definition); - _renderer->prepare();*/ + /*AtmosphereRendererClass.bind(renderer, _definition); + renderer->prepare();*/ } }; diff --git a/src/editing/formatmosphere.h b/src/editing/formatmosphere.h index 1c999a2..202564d 100644 --- a/src/editing/formatmosphere.h +++ b/src/editing/formatmosphere.h @@ -1,9 +1,10 @@ #ifndef _PAYSAGES_QT_FORMATMOSPHERE_H_ #define _PAYSAGES_QT_FORMATMOSPHERE_H_ -#include -#include "basepreview.h" +#include "editing_global.h" + #include "baseform.h" +class QWidget; class FormAtmosphere : public BaseForm { diff --git a/src/editing/formclouds.cpp b/src/editing/formclouds.cpp index 742c315..9c6b4a4 100644 --- a/src/editing/formclouds.cpp +++ b/src/editing/formclouds.cpp @@ -4,6 +4,8 @@ #include "tools/color.h" #include "tools/euclid.h" #include "Scenery.h" +#include "BasePreview.h" +#include "renderer.h" #include "tools.h" diff --git a/src/editing/formclouds.h b/src/editing/formclouds.h index 8838fd1..3ed69ee 100644 --- a/src/editing/formclouds.h +++ b/src/editing/formclouds.h @@ -1,10 +1,11 @@ #ifndef _PAYSAGES_QT_FORMCLOUDS_H_ #define _PAYSAGES_QT_FORMCLOUDS_H_ -#include -#include "basepreview.h" +#include "editing_global.h" + #include "baseformlayer.h" #include "clouds/public.h" +class QWidget; class FormClouds : public BaseFormLayer { diff --git a/src/editing/formrender.cpp b/src/editing/formrender.cpp index b1098be..eefa6a1 100644 --- a/src/editing/formrender.cpp +++ b/src/editing/formrender.cpp @@ -13,6 +13,7 @@ #include "Scenery.h" #include "PackStream.h" #include "SoftwareRenderer.h" +#include "BasePreview.h" /**************** Previews ****************/ class PreviewRenderLandscape : public BasePreview diff --git a/src/editing/formtextures.cpp b/src/editing/formtextures.cpp index 075e0cb..b7be8b0 100644 --- a/src/editing/formtextures.cpp +++ b/src/editing/formtextures.cpp @@ -1,7 +1,10 @@ #include "formtextures.h" #include "Scenery.h" +#include "BasePreview.h" +#include "renderer.h" #include "tools.h" +#include "camera.h" /**************** Previews ****************/ class PreviewTexturesCoverage : public BasePreview diff --git a/src/editing/formtextures.h b/src/editing/formtextures.h index 57a4a3a..1d64000 100644 --- a/src/editing/formtextures.h +++ b/src/editing/formtextures.h @@ -1,10 +1,11 @@ #ifndef _PAYSAGES_QT_FORMTEXTURES_H_ #define _PAYSAGES_QT_FORMTEXTURES_H_ -#include -#include "basepreview.h" +#include "editing_global.h" + #include "baseformlayer.h" #include "textures/public.h" +class QWidget; class FormTextures : public BaseFormLayer { diff --git a/src/editing/formwater.cpp b/src/editing/formwater.cpp index 0c99c1d..4701e4f 100644 --- a/src/editing/formwater.cpp +++ b/src/editing/formwater.cpp @@ -1,4 +1,3 @@ -#include "basepreview.h" #include "formwater.h" #include @@ -13,6 +12,8 @@ #include "atmosphere/public.h" #include "tools.h" #include "Scenery.h" +#include "BasePreview.h" +#include "camera.h" static WaterDefinition* _definition; diff --git a/src/editing/formwater.h b/src/editing/formwater.h index 71ed80a..b436eb9 100644 --- a/src/editing/formwater.h +++ b/src/editing/formwater.h @@ -1,9 +1,10 @@ #ifndef _PAYSAGES_QT_FORMWATER_H_ #define _PAYSAGES_QT_FORMWATER_H_ -#include -#include "basepreview.h" +#include "editing_global.h" + #include "baseform.h" +class QWidget; class FormWater : public BaseForm { diff --git a/src/editing/lighting/SmallPreviewColor.h b/src/editing/lighting/SmallPreviewColor.h index 87bd6f4..5c1bb5d 100644 --- a/src/editing/lighting/SmallPreviewColor.h +++ b/src/editing/lighting/SmallPreviewColor.h @@ -1,7 +1,7 @@ #ifndef SMALLPREVIEWCOLOR_H #define SMALLPREVIEWCOLOR_H -#include "common/DrawingWidget.h" +#include "DrawingWidget.h" #include "tools/color.h" diff --git a/src/editing/lighting/SmallPreviewHues.h b/src/editing/lighting/SmallPreviewHues.h index 34e4c96..831d260 100644 --- a/src/editing/lighting/SmallPreviewHues.h +++ b/src/editing/lighting/SmallPreviewHues.h @@ -1,7 +1,7 @@ #ifndef SMALLPREVIEWHUES_H #define SMALLPREVIEWHUES_H -#include "common/DrawingWidget.h" +#include "DrawingWidget.h" class SmallPreviewHues: public DrawingWidget { diff --git a/src/editing/previewmaterial.cpp b/src/editing/previewmaterial.cpp index 0548f06..71f859f 100644 --- a/src/editing/previewmaterial.cpp +++ b/src/editing/previewmaterial.cpp @@ -4,9 +4,11 @@ #include #include "tools.h" #include "SoftwareRenderer.h" +#include "BasePreview.h" #include "tools/lighting.h" #include "tools/color.h" +#include "camera.h" /***** Shared renderer *****/ MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material) @@ -24,7 +26,7 @@ MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material) _material = material; Vector3 camera_location = {0.0, 0.0, 10.0}; - cameraSetLocation(renderer->render_camera, camera_location); + cameraSetLocation(render_camera, camera_location); _color_profile = colorProfileCreate(); colorProfileSetToneMapping(_color_profile, TONE_MAPPING_UNCHARTED, 1.0); @@ -64,7 +66,7 @@ Color MaterialPreviewRenderer::getColor2D(double x, double y, double) } point = v3Normalize(point); - color = lightingApplyOneLight(&_light, renderer->getCameraLocation(renderer, point), point, point, _material); + color = lightingApplyOneLight(&_light, getCameraLocation(this, point), point, point, _material); if (dist > 0.95) { color.a = (1.0 - dist) / 0.05; diff --git a/src/editing/previewmaterial.h b/src/editing/previewmaterial.h index fb24cf9..7571a63 100644 --- a/src/editing/previewmaterial.h +++ b/src/editing/previewmaterial.h @@ -1,16 +1,18 @@ #ifndef _PAYSAGES_QT_PREVIEWMATERIAL_H_ #define _PAYSAGES_QT_PREVIEWMATERIAL_H_ -#include "basepreview.h" -#include "common/previewrenderer.h" +#include "editing_global.h" + +#include "Base2dPreviewRenderer.h" +#include #include "tools/lighting.h" #include "renderer.h" -class MaterialPreviewRenderer:public PreviewRenderer { +class MaterialPreviewRenderer:public Base2dPreviewRenderer { public: MaterialPreviewRenderer(SurfaceMaterial* material); - ~MaterialPreviewRenderer(); + virtual ~MaterialPreviewRenderer(); virtual void bindEvent(BasePreview* preview); virtual Color getColor2D(double x, double y, double scaling); diff --git a/src/editing/previewosd.h b/src/editing/previewosd.h deleted file mode 100644 index 2c5ada5..0000000 --- a/src/editing/previewosd.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _PAYSAGES_QT_PREVIEWOSD_H_ -#define _PAYSAGES_QT_PREVIEWOSD_H_ - -#include -#include "camera.h" - -class PreviewOsdItem:public QImage -{ -public: - PreviewOsdItem(int width, int height); - - void setLocation(double x, double y); - inline double xlocation() {return _xlocation;}; - inline double ylocation() {return _ylocation;}; - - void setToolTip(QString text); - QString getToolTip(double x, double y, double scaling); - - void drawCamera(CameraDefinition* camera); - -private: - double _xlocation; - double _ylocation; - QString _tooltip; -}; - -class PreviewOsd -{ -public: - PreviewOsd(); - ~PreviewOsd(); - - static PreviewOsd* getInstance(QString name); - - void clearItems(); - PreviewOsdItem* newItem(int width, int height); - PreviewOsdItem* newItem(QImage image); - void apply(QImage* mask, double xoffset, double yoffset, double scaling); - QString getToolTip(double x, double y, double scaling); - -private: - QVector _items; -}; - -#endif diff --git a/src/editing/terrain/mainterrainform.cpp b/src/editing/terrain/mainterrainform.cpp index 71970fa..dd978f8 100644 --- a/src/editing/terrain/mainterrainform.cpp +++ b/src/editing/terrain/mainterrainform.cpp @@ -5,6 +5,7 @@ #include "dialogbaseterrainnoise.h" #include "dialogterrainpainting.h" #include "previewterrainshape.h" +#include "common/freeformhelper.h" #include "tools.h" #include "Scenery.h" #include "textures/public.h" diff --git a/src/editing/terrain/mainterrainform.h b/src/editing/terrain/mainterrainform.h index 5c7a816..dbc9022 100644 --- a/src/editing/terrain/mainterrainform.h +++ b/src/editing/terrain/mainterrainform.h @@ -1,9 +1,12 @@ #ifndef MAINTERRAINFORM_H #define MAINTERRAINFORM_H +#include "editing_global.h" + #include -#include "common/freeformhelper.h" + #include "terrain/public.h" +class FreeFormHelper; namespace Ui { class MainTerrainForm; @@ -36,7 +39,7 @@ private: TerrainDefinition* _terrain; - PreviewRenderer* _renderer_shape; + Base2dPreviewRenderer* _renderer_shape; }; #endif // MAINTERRAINFORM_H diff --git a/src/editing/terrain/previewterrainshape.cpp b/src/editing/terrain/previewterrainshape.cpp index 7ec4565..19e61d2 100644 --- a/src/editing/terrain/previewterrainshape.cpp +++ b/src/editing/terrain/previewterrainshape.cpp @@ -1,7 +1,7 @@ #include "previewterrainshape.h" #include "SoftwareRenderer.h" -#include "basepreview.h" +#include "BasePreview.h" #include "water/public.h" PreviewTerrainShape::PreviewTerrainShape(TerrainDefinition* terrain) @@ -9,7 +9,7 @@ PreviewTerrainShape::PreviewTerrainShape(TerrainDefinition* terrain) _terrain = terrain; _highlight_enabled = true; - terrainAlterPreviewRenderer(renderer); + terrainAlterPreviewRenderer(this); } void PreviewTerrainShape::bindEvent(BasePreview* preview) @@ -23,12 +23,12 @@ void PreviewTerrainShape::bindEvent(BasePreview* preview) void PreviewTerrainShape::updateEvent() { - TerrainRendererClass.bind(renderer, _terrain); + TerrainRendererClass.bind(this, _terrain); } -Color PreviewTerrainShape::getColor2D(double x, double y, double scaling) const +Color PreviewTerrainShape::getColor2D(double x, double y, double scaling) { - return waterGetPreviewCoverage(renderer, x, y, scaling, _highlight_enabled ? 1 : 0); + return waterGetPreviewCoverage(this, x, y, scaling, _highlight_enabled ? 1 : 0); } void PreviewTerrainShape::toggleChangeEvent(QString key, bool value) diff --git a/src/editing/terrain/previewterrainshape.h b/src/editing/terrain/previewterrainshape.h index 5561c31..5ff9458 100644 --- a/src/editing/terrain/previewterrainshape.h +++ b/src/editing/terrain/previewterrainshape.h @@ -1,11 +1,12 @@ #ifndef PREVIEWTERRAINSHAPE_H #define PREVIEWTERRAINSHAPE_H -#include "common/previewrenderer.h" -#include "renderer.h" +#include "editing_global.h" + +#include "Base2dPreviewRenderer.h" #include "terrain/public.h" -class PreviewTerrainShape : public PreviewRenderer +class PreviewTerrainShape : public Base2dPreviewRenderer { public: explicit PreviewTerrainShape(TerrainDefinition* terrain); @@ -13,7 +14,7 @@ public: protected: virtual void bindEvent(BasePreview* preview); virtual void updateEvent(); - virtual Color getColor2D(double x, double y, double scaling) const override; + virtual Color getColor2D(double x, double y, double scaling) override; virtual void toggleChangeEvent(QString key, bool value); private: diff --git a/src/editing/terrain/widgetterrainbasenoisepreview.h b/src/editing/terrain/widgetterrainbasenoisepreview.h index 206a467..06f760b 100644 --- a/src/editing/terrain/widgetterrainbasenoisepreview.h +++ b/src/editing/terrain/widgetterrainbasenoisepreview.h @@ -3,7 +3,7 @@ #include "editing_global.h" -#include "common/DrawingWidget.h" +#include "DrawingWidget.h" class QPainter; class WidgetTerrainBaseNoisePreview : public DrawingWidget diff --git a/src/editing/textures/PreviewCumul.cpp b/src/editing/textures/PreviewCumul.cpp index bc3e9cd..ac7ceea 100644 --- a/src/editing/textures/PreviewCumul.cpp +++ b/src/editing/textures/PreviewCumul.cpp @@ -1,7 +1,7 @@ #include "PreviewCumul.h" #include "SoftwareRenderer.h" -#include "basepreview.h" +#include "BasePreview.h" #include "textures/tex_preview.h" void PreviewCumul::setTextures(TexturesDefinition* textures) @@ -28,7 +28,7 @@ void PreviewCumul::updateEvent() { if (textures) { - TexturesPreviewCumul_bind(renderer, textures); + TexturesPreviewCumul_bind(this, textures); } } @@ -36,7 +36,7 @@ Color PreviewCumul::getColor2D(double x, double y, double scaling) { if (textures) { - return TexturesPreviewCumul_getColor(renderer, x, y, scaling, layer); + return TexturesPreviewCumul_getColor(this, x, y, scaling, layer); } else { diff --git a/src/editing/textures/PreviewCumul.h b/src/editing/textures/PreviewCumul.h index fd01eeb..f06ef08 100644 --- a/src/editing/textures/PreviewCumul.h +++ b/src/editing/textures/PreviewCumul.h @@ -1,16 +1,17 @@ #ifndef EDITING_TEXTURES_PREVIEWCUMUL_H #define EDITING_TEXTURES_PREVIEWCUMUL_H -#include "common/previewrenderer.h" +#include "editing_global.h" + +#include "Base2dPreviewRenderer.h" -class BasePreview; class TexturesDefinition; -class PreviewCumul : public PreviewRenderer +class PreviewCumul : public Base2dPreviewRenderer { public: explicit PreviewCumul(): - PreviewRenderer(),textures(0){} + Base2dPreviewRenderer(),textures(0){} void setTextures(TexturesDefinition* textures); void setLayer(int layer); diff --git a/src/editing/textures/PreviewLayerCoverage.cpp b/src/editing/textures/PreviewLayerCoverage.cpp index 05f6df6..6f2d00c 100644 --- a/src/editing/textures/PreviewLayerCoverage.cpp +++ b/src/editing/textures/PreviewLayerCoverage.cpp @@ -1,7 +1,7 @@ #include "PreviewLayerCoverage.h" #include "SoftwareRenderer.h" -#include "basepreview.h" +#include "BasePreview.h" #include "textures/tex_preview.h" void PreviewLayerCoverage::setTextures(TexturesDefinition* textures) @@ -26,7 +26,7 @@ void PreviewLayerCoverage::updateEvent() { if (textures) { - TexturesPreviewLayerCoverage_bind(renderer, textures); + TexturesPreviewLayerCoverage_bind(this, textures); } } @@ -34,7 +34,7 @@ Color PreviewLayerCoverage::getColor2D(double x, double y, double scaling) { if (textures) { - return TexturesPreviewLayerCoverage_getColor(renderer, x, y, scaling, layer); + return TexturesPreviewLayerCoverage_getColor(this, x, y, scaling, layer); } else { diff --git a/src/editing/textures/PreviewLayerCoverage.h b/src/editing/textures/PreviewLayerCoverage.h index 3105ab4..b5f2371 100644 --- a/src/editing/textures/PreviewLayerCoverage.h +++ b/src/editing/textures/PreviewLayerCoverage.h @@ -1,16 +1,17 @@ #ifndef EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H #define EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H -#include "common/previewrenderer.h" +#include "editing_global.h" + +#include "Base2dPreviewRenderer.h" -class BasePreview; class TexturesDefinition; -class PreviewLayerCoverage : public PreviewRenderer +class PreviewLayerCoverage : public Base2dPreviewRenderer { public: explicit PreviewLayerCoverage(): - PreviewRenderer(),textures(0){} + Base2dPreviewRenderer(),textures(0){} void setTextures(TexturesDefinition* textures); void setLayer(int layer); diff --git a/src/editing/textures/PreviewLayerLook.cpp b/src/editing/textures/PreviewLayerLook.cpp index 6accca5..8b17a11 100644 --- a/src/editing/textures/PreviewLayerLook.cpp +++ b/src/editing/textures/PreviewLayerLook.cpp @@ -1,7 +1,7 @@ #include "PreviewLayerLook.h" #include "SoftwareRenderer.h" -#include "basepreview.h" +#include "BasePreview.h" #include "textures/tex_preview.h" void PreviewLayerLook::setTextures(TexturesDefinition* textures) @@ -25,7 +25,7 @@ void PreviewLayerLook::updateEvent() { if (textures) { - TexturesPreviewLayerLook_bind(renderer, textures); + TexturesPreviewLayerLook_bind(this, textures); } } @@ -33,7 +33,7 @@ Color PreviewLayerLook::getColor2D(double x, double y, double scaling) { if (textures) { - return TexturesPreviewLayerLook_getColor(renderer, x, y, scaling, layer); + return TexturesPreviewLayerLook_getColor(this, x, y, scaling, layer); } else { diff --git a/src/editing/textures/PreviewLayerLook.h b/src/editing/textures/PreviewLayerLook.h index b768a8d..50a9194 100644 --- a/src/editing/textures/PreviewLayerLook.h +++ b/src/editing/textures/PreviewLayerLook.h @@ -1,16 +1,17 @@ #ifndef EDITING_TEXTURES_PREVIEWLAYERLOOK_H #define EDITING_TEXTURES_PREVIEWLAYERLOOK_H -#include "common/previewrenderer.h" +#include "editing_global.h" + +#include "Base2dPreviewRenderer.h" -class BasePreview; class TexturesDefinition; -class PreviewLayerLook : public PreviewRenderer +class PreviewLayerLook : public Base2dPreviewRenderer { public: explicit PreviewLayerLook(): - PreviewRenderer(),textures(0){} + Base2dPreviewRenderer(),textures(0){} void setTextures(TexturesDefinition* textures); void setLayer(int layer); diff --git a/src/editing/tools.cpp b/src/editing/tools.cpp index 8680967..01d51ab 100644 --- a/src/editing/tools.cpp +++ b/src/editing/tools.cpp @@ -1,7 +1,7 @@ #include "tools.h" #include -#include "basepreview.h" +#include "BasePreview.h" DialogWithPreview::DialogWithPreview(QWidget* parent) : QDialog(parent) { diff --git a/src/render/preview/AtmosphereColorPreviewRenderer.cpp b/src/render/preview/AtmosphereColorPreviewRenderer.cpp index f2042c9..3c5d361 100644 --- a/src/render/preview/AtmosphereColorPreviewRenderer.cpp +++ b/src/render/preview/AtmosphereColorPreviewRenderer.cpp @@ -147,10 +147,10 @@ static inline int _checkHit(Vector3 eye, Vector3 direction, Vector3* hit, Vector AtmosphereColorPreviewRenderer::AtmosphereColorPreviewRenderer(): heading(0.0) { - cameraSetLocation(renderer->render_camera, Vector3(0.0, 7.0, 0.0)); + cameraSetLocation(render_camera, Vector3(0.0, 7.0, 0.0)); } -Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double) const +Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double) { Vector3 eye = {0.0, 7.0, 0.0}; Vector3 direction = {x, y, -1.0}; @@ -166,13 +166,13 @@ Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double) con normal = m4Transform(rotation, normal); hit = m4Transform(rotation, hit); - color = renderer->applyLightingToSurface(renderer, hit, normal, &MOUNT_MATERIAL); - return renderer->atmosphere->applyAerialPerspective(renderer, hit, color).final; + color = this->applyLightingToSurface(this, hit, normal, &MOUNT_MATERIAL); + return this->atmosphere->applyAerialPerspective(this, hit, color).final; } else { direction = m4Transform(rotation, direction); - return renderer->atmosphere->getSkyColor(renderer, direction).final; + return this->atmosphere->getSkyColor(this, direction).final; } } diff --git a/src/render/preview/AtmosphereColorPreviewRenderer.h b/src/render/preview/AtmosphereColorPreviewRenderer.h index f26ad4b..abbe762 100644 --- a/src/render/preview/AtmosphereColorPreviewRenderer.h +++ b/src/render/preview/AtmosphereColorPreviewRenderer.h @@ -11,7 +11,7 @@ class AtmosphereColorPreviewRenderer:public Base2dPreviewRenderer public: AtmosphereColorPreviewRenderer(); - virtual Color getColor2D(double x, double y, double scaling) const override; + virtual Color getColor2D(double x, double y, double scaling) override; protected: double heading; diff --git a/src/render/preview/Base2dPreviewRenderer.cpp b/src/render/preview/Base2dPreviewRenderer.cpp index 8973dc7..91a355e 100644 --- a/src/render/preview/Base2dPreviewRenderer.cpp +++ b/src/render/preview/Base2dPreviewRenderer.cpp @@ -1,18 +1,28 @@ #include "Base2dPreviewRenderer.h" +#include "Scenery.h" #include "SoftwareRenderer.h" -Base2dPreviewRenderer::Base2dPreviewRenderer() +Base2dPreviewRenderer::Base2dPreviewRenderer(): + SoftwareRenderer() +{ + scenery = new Scenery(); +} + +Base2dPreviewRenderer::~Base2dPreviewRenderer() +{ + delete scenery; +} + +void Base2dPreviewRenderer::bindEvent(BasePreview*) { - renderer = new SoftwareRenderer(); } void Base2dPreviewRenderer::updateEvent() { - delete renderer; } -Color Base2dPreviewRenderer::getColor2D(double, double, double) const +Color Base2dPreviewRenderer::getColor2D(double, double, double) { return COLOR_BLACK; } diff --git a/src/render/preview/Base2dPreviewRenderer.h b/src/render/preview/Base2dPreviewRenderer.h index d6ebb34..20d110d 100644 --- a/src/render/preview/Base2dPreviewRenderer.h +++ b/src/render/preview/Base2dPreviewRenderer.h @@ -3,22 +3,28 @@ #include "preview_global.h" +#include "SoftwareRenderer.h" #include "tools/color.h" +class Scenery; + namespace paysages { namespace preview { -class PREVIEWSHARED_EXPORT Base2dPreviewRenderer +class PREVIEWSHARED_EXPORT Base2dPreviewRenderer: protected SoftwareRenderer { public: Base2dPreviewRenderer(); + virtual ~Base2dPreviewRenderer(); + + virtual void bindEvent(BasePreview* preview); virtual void updateEvent(); - virtual Color getColor2D(double x, double y, double scaling) const; + virtual Color getColor2D(double x, double y, double scaling); protected: - SoftwareRenderer* renderer; + Scenery* scenery; }; } diff --git a/src/editing/basepreview.cpp b/src/render/preview/BasePreview.cpp similarity index 93% rename from src/editing/basepreview.cpp rename to src/render/preview/BasePreview.cpp index 5f454da..a798485 100644 --- a/src/editing/basepreview.cpp +++ b/src/render/preview/BasePreview.cpp @@ -1,4 +1,4 @@ -#include "basepreview.h" +#include "BasePreview.h" #include #include @@ -6,11 +6,15 @@ #include #include #include -#include -#include +#include +#include +#include +#include #include "tools.h" #include "System.h" #include "PackStream.h" +#include "Base2dPreviewRenderer.h" +#include "PreviewOsd.h" /*************** PreviewChunk ***************/ class PreviewChunk @@ -142,9 +146,50 @@ private: int _ysize; }; +class PreviewDrawingThread; +class PreviewDrawingManager +{ +public: + PreviewDrawingManager(); + void startThreads(); + void stopThreads(); + void addChunk(PreviewChunk* chunk); + void removeChunks(BasePreview* preview); + void updateChunks(BasePreview* preview); + void suspendChunks(BasePreview* preview); + void updateAllChunks(); + void performOneThreadJob(); + int chunkCount(); + +private: + int _thread_count; + QVector _threads; + QVector _chunks; + QList _updateQueue; + QMutex _lock; +}; + static PreviewDrawingManager* _drawing_manager = NULL; /*************** PreviewDrawingThread ***************/ +class PreviewDrawingThread : public QThread +{ +public: + PreviewDrawingThread(); + void askStop(); + + static inline void usleep(int us) + { + QThread::usleep(us); + } + +protected: + void run(); + +private: + bool _running; +}; + PreviewDrawingThread::PreviewDrawingThread() : QThread() { @@ -184,7 +229,7 @@ void PreviewDrawingManager::startThreads() void PreviewDrawingManager::stopThreads() { - logDebug(QString("[Previews] Stopping all render threads")); + qDebug("[Previews] Stopping all render threads"); for (int i = 0; i < _threads.size(); i++) { _threads.at(i)->askStop(); @@ -226,7 +271,7 @@ void PreviewDrawingManager::removeChunks(BasePreview* preview) } } - logDebug(QString("[Previews] %1 chunks removed, %2 remaining").arg(removed).arg(_chunks.size())); + qDebug("[Previews] %d chunks removed, %d remaining", removed, _chunks.size()); } void PreviewDrawingManager::suspendChunks(BasePreview* preview) @@ -270,7 +315,7 @@ void PreviewDrawingManager::updateChunks(BasePreview* preview) void PreviewDrawingManager::updateAllChunks() { - logDebug(QString("[Previews] Reviving all %1 preview chunks").arg(_chunks.size())); + qDebug("[Previews] Reviving all %d preview chunks", _chunks.size()); for (int i = 0; i < _chunks.size(); i++) { PreviewChunk* chunk; @@ -388,7 +433,7 @@ BasePreview::~BasePreview() delete _lock_drawing; } -void BasePreview::setRenderer(PreviewRenderer* renderer) +void BasePreview::setRenderer(Base2dPreviewRenderer* renderer) { _renderer = renderer; _renderer->bindEvent(this); @@ -605,7 +650,7 @@ QColor BasePreview::getPixelColor(int x, int y) { colorNormalize(&col); } - return colorToQColor(col); + return QColor::fromRgbF(col.r, col.g, col.b, col.a); } void BasePreview::timerEvent(QTimerEvent*) @@ -681,7 +726,7 @@ void BasePreview::resizeEvent(QResizeEvent* event) added++; } } - logDebug(QString("[Previews] %1 chunks added, %2 total").arg(added).arg(_drawing_manager->chunkCount())); + qDebug("[Previews] %d chunks added, %d total", added, _drawing_manager->chunkCount()); delete image; @@ -770,7 +815,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event) action->setProperty("value", i); if (i == iter1.value().current) { - action->setIcon(QIcon(getDataPath("images/choice_on.png"))); + action->setIcon(QIcon(":/images/choice_on.png")); action->setIconVisibleInMenu(true); } } @@ -793,7 +838,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event) action->setProperty("value", not iter2.value().value); if (iter2.value().value) { - action->setIcon(QIcon(getDataPath("images/toggle_on.png"))); + action->setIcon(QIcon(":/images/toggle_on.png")); action->setIconVisibleInMenu(true); } } diff --git a/src/editing/basepreview.h b/src/render/preview/BasePreview.h similarity index 70% rename from src/editing/basepreview.h rename to src/render/preview/BasePreview.h index fd73204..e57bc4d 100644 --- a/src/editing/basepreview.h +++ b/src/render/preview/BasePreview.h @@ -1,26 +1,18 @@ -#ifndef _PAYSAGES_QT_BASEPREVIEW_H_ -#define _PAYSAGES_QT_BASEPREVIEW_H_ +#ifndef BASEPREVIEW_H +#define BASEPREVIEW_H -#include "editing_global.h" +#include "preview_global.h" -#include -#include -#include -#include -#include -#include -#include - -#include "previewosd.h" -#include "common/DrawingWidget.h" -#include "common/previewrenderer.h" +#include "DrawingWidget.h" #include "tools/color.h" +#include +#include +class QPainter; +class QMutex; +class QLabel; namespace paysages { -namespace system { - class PackStream; -} -} +namespace preview { class _ContextChoice { @@ -37,8 +29,6 @@ public: bool value; }; -class QPainter; - class BasePreview : public DrawingWidget { Q_OBJECT @@ -47,7 +37,7 @@ public: BasePreview(QWidget* parent); ~BasePreview(); - void setRenderer(PreviewRenderer* renderer); + void setRenderer(Base2dPreviewRenderer* renderer); virtual void savePack(PackStream* stream); virtual void loadPack(PackStream* stream); @@ -110,7 +100,7 @@ private: QLabel* _info; - PreviewRenderer* _renderer; + Base2dPreviewRenderer* _renderer; int _width; int _height; @@ -149,50 +139,7 @@ private slots: void choiceSelected(QAction* action); }; +} +} - -/*** Private section ***/ -class PreviewChunk; - -class PreviewDrawingThread : public QThread -{ -public: - PreviewDrawingThread(); - void askStop(); - - static inline void usleep(int us) - { - QThread::usleep(us); - } - -protected: - void run(); - -private: - bool _running; -}; - -class PreviewDrawingManager -{ -public: - PreviewDrawingManager(); - void startThreads(); - void stopThreads(); - void addChunk(PreviewChunk* chunk); - void removeChunks(BasePreview* preview); - void updateChunks(BasePreview* preview); - void suspendChunks(BasePreview* preview); - void updateAllChunks(); - void performOneThreadJob(); - int chunkCount(); - -private: - int _thread_count; - QVector _threads; - QVector _chunks; - QList _updateQueue; - QMutex _lock; -}; - - -#endif +#endif // BASEPREVIEW_H diff --git a/src/editing/common/DrawingWidget.cpp b/src/render/preview/DrawingWidget.cpp similarity index 100% rename from src/editing/common/DrawingWidget.cpp rename to src/render/preview/DrawingWidget.cpp diff --git a/src/editing/common/DrawingWidget.h b/src/render/preview/DrawingWidget.h similarity index 82% rename from src/editing/common/DrawingWidget.h rename to src/render/preview/DrawingWidget.h index dd3db01..fd733cf 100644 --- a/src/editing/common/DrawingWidget.h +++ b/src/render/preview/DrawingWidget.h @@ -1,11 +1,16 @@ #ifndef DRAWINGWIDGET_H #define DRAWINGWIDGET_H +#include "preview_global.h" + #include class QPaintEvent; class QPainter; +namespace paysages { +namespace preview { + class DrawingWidget : public QWidget { Q_OBJECT @@ -17,5 +22,8 @@ private: virtual void paintEvent(QPaintEvent* event); }; +} +} + #endif /* DRAWINGWIDGET_H */ diff --git a/src/editing/previewosd.cpp b/src/render/preview/PreviewOsd.cpp similarity index 51% rename from src/editing/previewosd.cpp rename to src/render/preview/PreviewOsd.cpp index 2e87712..ef702e3 100644 --- a/src/editing/previewosd.cpp +++ b/src/render/preview/PreviewOsd.cpp @@ -1,59 +1,12 @@ -#include "previewosd.h" +#include "PreviewOsd.h" +#include #include #include -#include +#include "PreviewOsdItem.h" static QHash _instances; -/*************** PreviewOsdItem ***************/ -PreviewOsdItem::PreviewOsdItem(int width, int height) : QImage(width, height, QImage::Format_ARGB32) -{ - _xlocation = 0.0; - _ylocation = 0.0; - fill(0x00000000); -} - -void PreviewOsdItem::setLocation(double x, double y) -{ - _xlocation = x; - _ylocation = y; -} - -void PreviewOsdItem::drawCamera(CameraDefinition* camera) -{ - Vector3 camera_location = cameraGetLocation(camera); - VectorSpherical camera_direction = cameraGetDirectionSpherical(camera); - int w2 = width() / 2; - int h2 = height() / 2; - - _xlocation = camera_location.x; - _ylocation = camera_location.z; - - QPainter painter(this); - painter.setPen(QPen(Qt::red, 2)); - painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true); - painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi - M_PI_4), h2 - h2 * sin(camera_direction.phi - M_PI_4)); - painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi + M_PI_4), h2 - h2 * sin(camera_direction.phi + M_PI_4)); -} - -void PreviewOsdItem::setToolTip(QString text) -{ - _tooltip = text; -} - -QString PreviewOsdItem::getToolTip(double x, double y, double scaling) -{ - if (_tooltip.isEmpty() or (x > _xlocation - (width() / 2) * scaling and x < _xlocation + (width() / 2) * scaling and y > _ylocation - (height() / 2) * scaling and y < _ylocation + (height() / 2) * scaling)) - { - return _tooltip; - } - else - { - return QString(); - } -} - /*************** PreviewOsd ***************/ PreviewOsd::PreviewOsd() { @@ -97,7 +50,7 @@ PreviewOsdItem* PreviewOsd::newItem(int width, int height) return item; } -PreviewOsdItem* PreviewOsd::newItem(QImage image) +PreviewOsdItem* PreviewOsd::newItem(const QImage &image) { PreviewOsdItem* item = newItem(image.width(), image.height()); QPainter painter(item); @@ -105,7 +58,7 @@ PreviewOsdItem* PreviewOsd::newItem(QImage image) return item; } -void PreviewOsd::apply(QImage* mask, double xoffset, double yoffset, double scaling) +void PreviewOsd::apply(QImage *mask, double xoffset, double yoffset, double scaling) { QPainter painter(mask); diff --git a/src/render/preview/PreviewOsd.h b/src/render/preview/PreviewOsd.h new file mode 100644 index 0000000..9771429 --- /dev/null +++ b/src/render/preview/PreviewOsd.h @@ -0,0 +1,33 @@ +#ifndef PREVIEWOSD_H +#define PREVIEWOSD_H + +#include "preview_global.h" + +#include +class QImage; + +namespace paysages { +namespace preview { + +class PreviewOsd +{ +public: + PreviewOsd(); + ~PreviewOsd(); + + static PreviewOsd* getInstance(QString name); + + void clearItems(); + PreviewOsdItem* newItem(int width, int height); + PreviewOsdItem* newItem(const QImage& image); + void apply(QImage* mask, double xoffset, double yoffset, double scaling); + QString getToolTip(double x, double y, double scaling); + +private: + QVector _items; +}; + +} +} + +#endif diff --git a/src/render/preview/PreviewOsdItem.cpp b/src/render/preview/PreviewOsdItem.cpp new file mode 100644 index 0000000..0f8e929 --- /dev/null +++ b/src/render/preview/PreviewOsdItem.cpp @@ -0,0 +1,52 @@ +#include "PreviewOsdItem.h" + +#include +#include "Vector3.h" +#include "camera.h" + +PreviewOsdItem::PreviewOsdItem(int width, int height) : QImage(width, height, QImage::Format_ARGB32) +{ + _xlocation = 0.0; + _ylocation = 0.0; + fill(0x00000000); +} + +void PreviewOsdItem::setLocation(double x, double y) +{ + _xlocation = x; + _ylocation = y; +} + +void PreviewOsdItem::drawCamera(CameraDefinition* camera) +{ + Vector3 camera_location = cameraGetLocation(camera); + VectorSpherical camera_direction = cameraGetDirectionSpherical(camera); + int w2 = width() / 2; + int h2 = height() / 2; + + _xlocation = camera_location.x; + _ylocation = camera_location.z; + + QPainter painter(this); + painter.setPen(QPen(Qt::red, 2)); + painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true); + painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi - M_PI_4), h2 - h2 * sin(camera_direction.phi - M_PI_4)); + painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi + M_PI_4), h2 - h2 * sin(camera_direction.phi + M_PI_4)); +} + +void PreviewOsdItem::setToolTip(QString text) +{ + _tooltip = text; +} + +QString PreviewOsdItem::getToolTip(double x, double y, double scaling) +{ + if (_tooltip.isEmpty() or (x > _xlocation - (width() / 2) * scaling and x < _xlocation + (width() / 2) * scaling and y > _ylocation - (height() / 2) * scaling and y < _ylocation + (height() / 2) * scaling)) + { + return _tooltip; + } + else + { + return QString(); + } +} diff --git a/src/render/preview/PreviewOsdItem.h b/src/render/preview/PreviewOsdItem.h new file mode 100644 index 0000000..38b821a --- /dev/null +++ b/src/render/preview/PreviewOsdItem.h @@ -0,0 +1,36 @@ +#ifndef PREVIEWOSDITEM_H +#define PREVIEWOSDITEM_H + +#include "preview_global.h" + +#include + +class CameraDefinition; + +namespace paysages { +namespace preview { + +class PreviewOsdItem:public QImage +{ +public: + PreviewOsdItem(int width, int height); + + void setLocation(double x, double y); + inline double xlocation() {return _xlocation;} + inline double ylocation() {return _ylocation;} + + void setToolTip(QString text); + QString getToolTip(double x, double y, double scaling); + + void drawCamera(CameraDefinition* camera); + +private: + double _xlocation; + double _ylocation; + QString _tooltip; +}; + +} +} + +#endif // PREVIEWOSDITEM_H diff --git a/src/render/preview/preview.pro b/src/render/preview/preview.pro index 8c95f0b..4c44d92 100644 --- a/src/render/preview/preview.pro +++ b/src/render/preview/preview.pro @@ -6,17 +6,26 @@ TARGET = paysages_render_preview TEMPLATE = lib +QT += gui widgets DEFINES += PREVIEW_LIBRARY include(../../common.pri) SOURCES += Base2dPreviewRenderer.cpp \ - AtmosphereColorPreviewRenderer.cpp + AtmosphereColorPreviewRenderer.cpp \ + BasePreview.cpp \ + PreviewOsd.cpp \ + DrawingWidget.cpp \ + PreviewOsdItem.cpp HEADERS += Base2dPreviewRenderer.h\ preview_global.h \ - AtmosphereColorPreviewRenderer.h + AtmosphereColorPreviewRenderer.h \ + BasePreview.h \ + PreviewOsd.h \ + DrawingWidget.h \ + PreviewOsdItem.h unix:!symbian { maemo5 { diff --git a/src/render/preview/preview_global.h b/src/render/preview/preview_global.h index cdb99e3..ced5573 100644 --- a/src/render/preview/preview_global.h +++ b/src/render/preview/preview_global.h @@ -11,10 +11,16 @@ #include "software_global.h" +// TEMP +class Scenery; + namespace paysages { namespace preview { -class Base2dPreviewRenderer; -class AtmosphereColorPreviewRenderer; + class PreviewOsd; + class PreviewOsdItem; + class BasePreview; + class Base2dPreviewRenderer; + class AtmosphereColorPreviewRenderer; } } using namespace paysages::preview;