Commit is being made to allow additions of GPL3+ code previously un-addable. With these changes, contributions back to cuberite are possible with the backporting exemtion, as well as adding stuff in minetest with minetest code properly being read through and implimented to upgrade it to GPL3 from GPL2. project still has Apache2.0 license and credits to all its contributers, but now has the freedom of GPL3+ and all the code that can be implimented and shared with it.
134 lines
3.8 KiB
C++
134 lines
3.8 KiB
C++
|
|
/*
|
|
* Copyright 2011-2022 Cuberite Contributors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#pragma once
|
|
|
|
#include <QWidget>
|
|
#include <memory>
|
|
#include "RegionCache.h"
|
|
#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);
|
|
|
|
/** 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);
|
|
|
|
signals:
|
|
/** 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();
|
|
|
|
/** 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);
|
|
|
|
public slots:
|
|
/** Redraw the entire widget area. */
|
|
void redraw();
|
|
|
|
/** A specified region has become available, redraw it. */
|
|
void regionAvailable(int a_RegionX, int a_RegionZ);
|
|
|
|
/** Reloads the current chunk source and redraws the entire workspace. */
|
|
void reload();
|
|
|
|
protected:
|
|
double m_X, m_Z;
|
|
double m_Zoom;
|
|
|
|
/** Cache for the loaded chunk data. */
|
|
RegionCache m_Cache;
|
|
|
|
/** The entire view's contents in an offscreen image. */
|
|
QImage m_Image;
|
|
|
|
/** 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;
|
|
|
|
/** Accumulator for the mouse wheel's delta. When the accumulator hits a threshold, the view zooms. */
|
|
int m_MouseWheelDelta;
|
|
|
|
/** Data used for rendering a chunk that hasn't been loaded yet */
|
|
uchar m_EmptyChunkImage[16 * 16 * 4];
|
|
|
|
/** Data placeholder for chunks that aren't valid. */
|
|
short m_EmptyChunkBiomes[16 * 16];
|
|
|
|
|
|
/** 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;
|
|
|
|
/** 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;
|
|
};
|
|
|
|
|
|
|
|
|
|
|