1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00
vcmi/mapeditor/mapview.h

175 lines
3.0 KiB
C
Raw Normal View History

2022-08-31 20:05:57 +02:00
#ifndef MAPVIEW_H
#define MAPVIEW_H
#include <QGraphicsScene>
#include <QGraphicsView>
2022-09-01 03:51:29 +02:00
#include "../lib/int3.h"
2022-08-31 20:05:57 +02:00
2022-09-01 03:51:29 +02:00
class int3;
2022-09-01 13:54:39 +02:00
class CGObjectInstance;
2022-08-31 20:05:57 +02:00
class MainWindow;
class MapScene;
class BasicView
{
public:
BasicView(MainWindow * m, MapScene * s);
virtual void update() = 0;
void show(bool show);
2022-09-01 03:51:29 +02:00
void redraw();
2022-08-31 20:05:57 +02:00
protected:
MainWindow * main;
MapScene * scene;
bool isShown = false;
std::unique_ptr<QPixmap> pixmap;
2022-09-01 13:04:34 +02:00
QPixmap emptyPixmap;
2022-08-31 20:05:57 +02:00
private:
std::unique_ptr<QGraphicsPixmapItem> item;
};
class MapView : public QGraphicsView
{
2022-09-01 03:51:29 +02:00
public:
enum class SelectionTool
{
None, Brush, Brush2, Brush4, Area, Lasso
};
2022-08-31 20:05:57 +02:00
public:
MapView(QWidget *parent);
void setMain(MainWindow * m);
2022-09-01 03:51:29 +02:00
SelectionTool selectionTool;
2022-08-31 20:05:57 +02:00
public slots:
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
MainWindow * main;
2022-09-01 03:51:29 +02:00
QPointF mouseStart;
int3 tileStart;
int3 tilePrev;
bool pressedOnSelected;
2022-08-31 20:05:57 +02:00
};
class GridView: public BasicView
{
public:
GridView(MainWindow * m, MapScene * s);
void update() override;
};
class PassabilityView: public BasicView
{
public:
PassabilityView(MainWindow * m, MapScene * s);
void update() override;
};
2022-09-01 03:51:29 +02:00
class SelectionTerrainView: public BasicView
{
public:
SelectionTerrainView(MainWindow * m, MapScene * s);
void update() override;
void draw();
void select(const int3 & tile);
void erase(const int3 & tile);
void clear();
const std::set<int3> & selection() const;
private:
std::set<int3> area, areaAdd, areaErase;
};
class TerrainView: public BasicView
{
public:
TerrainView(MainWindow * m, MapScene * s);
void update() override;
void draw(bool onlyDirty = true);
void setDirty(const int3 & tile);
private:
std::set<int3> dirty;
};
2022-09-01 13:54:39 +02:00
class ObjectsView: public BasicView
{
public:
ObjectsView(MainWindow * m, MapScene * s);
void update() override;
2022-09-01 15:08:03 +02:00
void draw(bool onlyDirty = true); //TODO: implement dirty
2022-09-01 13:54:39 +02:00
void setDirty(int x, int y);
void setDirty(const CGObjectInstance * object);
private:
std::set<const CGObjectInstance *> dirty;
};
2022-09-01 15:08:03 +02:00
class SelectionObjectsView: public BasicView
{
public:
SelectionObjectsView(MainWindow * m, MapScene * s);
void update() override;
void draw();
CGObjectInstance * selectObjectAt(int x, int y);
std::set<CGObjectInstance *> selectObjects(int x1, int y1, int x2, int y2);
void selectObject(CGObjectInstance *);
bool isSelected(const CGObjectInstance *) const;
void moveSelection(int x, int y);
2022-09-01 15:08:03 +02:00
void clear();
2022-09-02 23:04:28 +02:00
bool applyShift();
void deleteSelection();
QPoint shift;
CGObjectInstance * newObject;
2022-09-01 15:08:03 +02:00
private:
std::set<CGObjectInstance *> selectedObjects;
};
2022-08-31 20:05:57 +02:00
class MapScene : public QGraphicsScene
{
public:
MapScene(MainWindow *parent, int l);
2022-09-01 03:51:29 +02:00
void updateViews();
2022-08-31 20:05:57 +02:00
GridView gridView;
PassabilityView passabilityView;
2022-09-01 03:51:29 +02:00
SelectionTerrainView selectionTerrainView;
TerrainView terrainView;
2022-09-01 13:54:39 +02:00
ObjectsView objectsView;
2022-09-01 15:08:03 +02:00
SelectionObjectsView selectionObjectsView;
2022-08-31 20:05:57 +02:00
const int level;
private:
MainWindow * main;
};
#endif // MAPVIEW_H