/******************************************************************************
*	File		-	map_canvas.h
*	Author		-	Joey Pollack
*	Date		-	2022/02/14 (y/m/d)
*	Mod Date	-	2022/02/14 (y/m/d)
*	Description	-	the canvas panel for painting map tiles
******************************************************************************/

#ifndef MAP_CANVAS_H_
#define MAP_CANVAS_H_

#include <gui/panel.h>
#include <editor/contents/definitions.h>
#include <string>

namespace lunarium { class Image; class IGraphics; }

namespace lunarium { namespace editor
{
    class MapEditor;
    class TileMap;

    class MapCanvas : public gui::Panel
    {
    public:
        MapCanvas(MapEditor* editor);
        void Update(float delta);
        bool DoFrame();

        void SetTileMap(TileMap* pMap);

        void SetSelectedTile(TileRef tile);
        TileRef GetSelectedTile() const;

        // Force the image to redraw and recreate the frame buffer
        void MapSizeChanged();
        // void Invalidate();

    private:
        MapEditor* mpMapEditor;
        Vec2f mWorkAreaPos;
        Vec2f mWorkAreaSize;
        Vec2f mScrollOffset;
        bool mScrollDragged;
        float mZoomFactor;
        std::string mMouseStatusInfo;
        int mFrameBuffer;
        Image* mpCanvasImage;
        TileMap* mMap;          // TODO: Replace with a World
        TileRef mSelectedTile;
        bool mMapSizeChanged;

        // TESTING
        Vec2i mCurrentRegion;
        std::string mRegionString;


    private:    // HELPERS
        void DoToolBar();

    };
}}

#endif  // MAP_CANVAS_H_