2014-09-13 19:32:00 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QWidget>
|
2014-09-18 04:24:52 -04:00
|
|
|
#include <memory>
|
2014-10-27 18:58:09 -04:00
|
|
|
#include "RegionCache.h"
|
2014-09-13 19:32:00 -04:00
|
|
|
#include "ChunkSource.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BiomeView :
|
|
|
|
public QWidget
|
|
|
|
{
|
|
|
|
typedef QWidget super;
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit BiomeView(QWidget * parent = NULL);
|
|
|
|
|
|
|
|
QSize minimumSizeHint() const;
|
|
|
|
QSize sizeHint() const;
|
|
|
|
|
|
|
|
/** Replaces the chunk source used by the biome view to get the chunk biome data.
|
|
|
|
The entire view is then invalidated and regenerated. */
|
|
|
|
void setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource);
|
|
|
|
|
2014-10-03 06:33:03 -04:00
|
|
|
/** Sets the position of the central pixel of the map to the specified point and redraws the view. */
|
|
|
|
void setPosition(int a_BlockX, int a_BlockZ);
|
|
|
|
|
|
|
|
/** Sets the zoom level to the specified value and redraws the view. */
|
|
|
|
void setZoomLevel(double a_ZoomLevel);
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
signals:
|
2014-10-03 06:33:03 -04:00
|
|
|
/** Signalled when the user uses the wheel to scroll upwards. */
|
|
|
|
void wheelUp();
|
|
|
|
|
|
|
|
/** Signalled when the user uses the wheel to scroll downwards. */
|
|
|
|
void wheelDown();
|
|
|
|
|
|
|
|
/** Signalled when the user presses a key to increase zoom. */
|
|
|
|
void increaseZoom();
|
|
|
|
|
|
|
|
/** Signalled when the user presses a key to decrease zoom. */
|
|
|
|
void decreaseZoom();
|
2014-09-13 19:32:00 -04:00
|
|
|
|
2014-10-03 13:41:42 -04:00
|
|
|
/** Emitted when the user moves the mouse, to reflect the current block under the cursor. */
|
|
|
|
void hoverChanged(int a_BlockX, int a_BlockZ, int a_Biome);
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
public slots:
|
|
|
|
/** Redraw the entire widget area. */
|
|
|
|
void redraw();
|
|
|
|
|
2014-10-27 18:58:09 -04:00
|
|
|
/** A specified region has become available, redraw it. */
|
|
|
|
void regionAvailable(int a_RegionX, int a_RegionZ);
|
2014-09-13 19:32:00 -04:00
|
|
|
|
2014-09-15 11:29:34 -04:00
|
|
|
/** Reloads the current chunk source and redraws the entire workspace. */
|
|
|
|
void reload();
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
protected:
|
|
|
|
double m_X, m_Z;
|
2014-09-14 16:05:10 -04:00
|
|
|
double m_Zoom;
|
|
|
|
|
|
|
|
/** Cache for the loaded chunk data. */
|
2014-10-27 18:58:09 -04:00
|
|
|
RegionCache m_Cache;
|
2014-09-14 16:05:10 -04:00
|
|
|
|
|
|
|
/** The entire view's contents in an offscreen image. */
|
2014-09-13 19:32:00 -04:00
|
|
|
QImage m_Image;
|
|
|
|
|
2014-09-14 16:05:10 -04:00
|
|
|
/** Coords of the mouse for the previous position, used while dragging. */
|
|
|
|
int m_LastX, m_LastY;
|
|
|
|
|
|
|
|
/** Set to true when the user has a mouse button depressed, and is dragging the view. */
|
|
|
|
bool m_IsMouseDragging;
|
|
|
|
|
2014-09-14 16:20:16 -04:00
|
|
|
/** Accumulator for the mouse wheel's delta. When the accumulator hits a threshold, the view zooms. */
|
|
|
|
int m_MouseWheelDelta;
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
/** Data used for rendering a chunk that hasn't been loaded yet */
|
|
|
|
uchar m_EmptyChunkImage[16 * 16 * 4];
|
|
|
|
|
2014-10-28 15:52:04 -04:00
|
|
|
/** Data placeholder for chunks that aren't valid. */
|
|
|
|
short m_EmptyChunkBiomes[16 * 16];
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
|
|
|
|
/** Draws the specified chunk into m_Image */
|
|
|
|
void drawChunk(int a_ChunkX, int a_ChunkZ);
|
|
|
|
|
|
|
|
/** Returns true iff the biome view has been initialized to contain proper biome data. */
|
|
|
|
bool hasData(void) const { return m_Cache.hasData(); }
|
|
|
|
|
|
|
|
/** Called when the widget is resized */
|
|
|
|
virtual void resizeEvent(QResizeEvent *) override;
|
|
|
|
|
|
|
|
/** Paints the entire widget */
|
|
|
|
virtual void paintEvent(QPaintEvent *) override;
|
|
|
|
|
2014-09-14 16:05:10 -04:00
|
|
|
/** Called when the user presses any mouse button. */
|
|
|
|
virtual void mousePressEvent(QMouseEvent * a_Event);
|
|
|
|
|
|
|
|
/** Called when the user moves the mouse. */
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent * a_Event);
|
|
|
|
|
|
|
|
/** Called when the user releases a previously held mouse button. */
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent * a_Event) override;
|
|
|
|
|
|
|
|
/** Called when the user rotates the mouse wheel. */
|
|
|
|
virtual void wheelEvent(QWheelEvent * a_Event) override;
|
|
|
|
|
|
|
|
/** Called when the user presses a key. */
|
|
|
|
virtual void keyPressEvent(QKeyEvent * a_Event) override;
|
2014-09-13 19:32:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|