fractorium/Source/Fractorium/GLEmberController.h
mfeemster 9e94170a70 0.4.1.3 Beta 10/14/2014
--User Changes
 Size is no longer fixed to the window size.
 Size scaling is done differently in the final render dialog. This fixes several bugs.
 Remove Xml saving size from settings and options dialog, it no longer applies.
 Final render can be broken into strips.
 Set default save path to the desktop if none is found in the settings file.
 Set default output size to 1920x1080 if none is found in the settings file.

--Bug Fixes
 Better memory size reporting in final render dialog.

--Code Changes
 Migrate to C++11, Qt 5.3.1, and Visual Studio 2013.
 Change most instances of unsigned int to size_t, and int to intmax_t.
 Add m_OrigPixPerUnit and m_ScaleType to Ember for scaling purposes.
 Replace some sprintf_s() calls in XmlToEmber with ostringstream.
 Move more non-templated members into RendererBase.
 Add CopyVec() overload that takes a per element function pointer.
 Add vector Memset().
 Replace '&' with '+' instead of "&" in XmlToEmber for much faster parsing.
 Break strips rendering out into EmberCommon and call from EmberRender and Fractorium.
 Make AddAndWriteBuffer() just call WriteBuffer().
 Make AddAndWriteImage() delete the existing image first before replacing it.
 Add SetOutputTexture() to RendererCL to support making new textures in response to resize events.
 Remove multiple return statements in RendererCL, and replace with a bool that tracks results.
 Add ToDouble(), MakeEnd(), ToString() and Exists() wrappers in Fractorium.
 Add Size() wrapper in EmberFile.
 Make QString function arguments const QString&, and string with const string&.
 Make ShowCritical() wrapper for invoking a message box from another thread.
 Add combo box to TwoButtonWidget and rename.
2014-10-14 08:53:15 -07:00

146 lines
4.5 KiB
C++

#pragma once
#include "FractoriumPch.h"
/// <summary>
/// GLEmberControllerBase and GLEmberController<T> classes.
/// </summary>
/// <summary>
/// Use/draw pre or post affine transform.
/// </summary>
enum eAffineType { AffinePre, AffinePost };
/// <summary>
/// Hovering over nothing, the x axis, the y axis or the center.
/// </summary>
enum eHoverType { HoverNone, HoverXAxis, HoverYAxis, HoverTranslation };
/// <summary>
/// Dragging an affine transform or panning, rotating or scaling the image.
/// </summary>
enum eDragState { DragNone, DragPanning, DragDragging, DragRotateScale };
/// <summary>
/// Dragging with no keys pressed, shift, control or alt.
/// </summary>
enum eDragModifier { DragModNone = 0x00, DragModShift = 0x01, DragModControl = 0x02, DragModAlt = 0x04 };
/// <summary>
/// GLController, FractoriumEmberController, GLWidget and Fractorium need each other, but each can't all include the other.
/// So GLWidget includes this file, and GLWidget, FractoriumEmberController and Fractorium are declared as forward declarations here.
/// </summary>
class GLWidget;
class Fractorium;
template <typename T> class FractoriumEmberController;
/// <summary>
/// GLEmberControllerBase serves as a non-templated base class with virtual
/// functions which will be overridden in a derived class that takes a template parameter.
/// The controller serves as a way to access both the GLWidget and the underlying ember
/// objects through an interface that doesn't require template argument, but does allow
/// templated objects to be used underneath.
/// The functions not implemented in this file can be found in GLWidget.cpp near the area of code which uses them.
/// </summary>
class GLEmberControllerBase
{
public:
GLEmberControllerBase(Fractorium* fractorium, GLWidget* glWidget);
virtual ~GLEmberControllerBase();
void ClearDrag();
bool Allocate(bool force = false);
virtual void DrawImage() { }
virtual void DrawAffines(bool pre, bool post) { }
virtual void ClearWindow() { }
virtual bool KeyPress(QKeyEvent* e);
virtual bool KeyRelease(QKeyEvent* e);
virtual void MousePress(QMouseEvent* e) { }
virtual void MouseRelease(QMouseEvent* e) { }
virtual void MouseMove(QMouseEvent* e) { }
virtual void Wheel(QWheelEvent* e) { }
virtual bool SizesMatch() { return false; }
virtual bool CheckForSizeMismatch(int w, int h) { return true; }
virtual void QueryMatrices(bool print) { }
protected:
unsigned int m_DragModifier;
glm::ivec2 m_MousePos;
glm::ivec2 m_MouseDownPos;
glm::ivec4 m_Viewport;
eDragState m_DragState;
eHoverType m_HoverType;
eAffineType m_AffineType;
GLWidget* m_GL;
Fractorium* m_Fractorium;
};
/// <summary>
/// Templated derived class which implements all interaction functionality between the embers
/// of a specific template type and the GLWidget;
/// </summary>
template<typename T>
class GLEmberController : public GLEmberControllerBase
{
public:
GLEmberController(Fractorium* fractorium, GLWidget* glWidget, FractoriumEmberController<T>* controller);
virtual ~GLEmberController();
virtual void DrawImage() override;
virtual void DrawAffines(bool pre, bool post) override;
virtual void ClearWindow() override;
virtual void MousePress(QMouseEvent* e) override;
virtual void MouseRelease(QMouseEvent* e) override;
virtual void MouseMove(QMouseEvent* e) override;
virtual void Wheel(QWheelEvent* e) override;
virtual void QueryMatrices(bool print) override;
virtual bool SizesMatch() override;
virtual bool CheckForSizeMismatch(int w, int h) override;
T CalcScale();
T CalcRotation();
Affine2D<T> CalcDragXAxis();
Affine2D<T> CalcDragYAxis();
Affine2D<T> CalcDragTranslation();
void SetEmber(Ember<T>* ember);
void SetSelectedXform(Xform<T>* xform);
void DrawAffine(Xform<T>* xform, bool pre, bool selected);
int UpdateHover(v3T& glCoords);
bool CheckXformHover(Xform<T>* xform, v3T& glCoords, T& bestDist, bool pre, bool post);
private:
v3T SnapToGrid(v3T& vec);
v3T SnapToNormalizedAngle(v3T& vec, unsigned int divisions);
v3T WindowToWorld(v3T& v, bool flip);
void QueryVMP();
void MultMatrix(m4T& mat);
T m_CenterDownX;
T m_CenterDownY;
T m_RotationDown;
T m_ScaleDown;
v4T m_BoundsDown;
v3T m_MouseWorldPos;
v3T m_MouseDownWorldPos;
v3T m_DragHandlePos;
v3T m_DragHandleOffset;
v3T m_HoverHandlePos;
m4T m_Modelview;
m4T m_Projection;
Affine2D<T> m_DragSrcTransform;
Xform<T>* m_HoverXform;
Xform<T>* m_SelectedXform;
FractoriumEmberController<T>* m_FractoriumEmberController;
T GridStep;
};
template class GLEmberController<float>;
#ifdef DO_DOUBLE
template class GLEmberController<double>;
#endif