#ifndef __Text__
#define __Text__

#ifndef CORE_DLL 
    #ifdef CORE_BUILD
	    #define CORE_DLL __declspec(dllexport)
    #else
	    #define CORE_DLL __declspec(dllimport)
        #pragma comment(lib, "Core.lib")
    #endif
#endif

#include <string>
#include "../../Core/types.h"
#include "Transform.h"

#include <windows.h>
#include <dxgi.h>
#include <d2d1.h>
#include <dwrite.h>
#include <wincodec.h>


class CORE_DLL Text : public Transform {
public:
    static const uint32 FONT_STYLE_REGULAR = 0;
    static const uint32 FONT_STYLE_BOLD = 1;
    static const uint32 FONT_STYLE_ITALIC = 2;
    static const uint32 FONT_STYLE_UNDERLINE = 4;
    static const uint32 FONT_STYLE_STRIKETHROUGH = 8;

    static const uint32 H_ALIGN_LEFT = 1;
    static const uint32 H_ALIGN_CENTER = 2;
    static const uint32 H_ALIGN_RIGHT = 4;
    static const uint32 V_ALIGN_TOP = 8;
    static const uint32 V_ALIGN_CENTER = 16;
    static const uint32 V_ALIGN_BOTTOM = 32;


    Text(const wchar_t* text = L"");
    virtual ~Text();

    bool isDirty();
    void setDirty(bool dirty);

    std::wstring& getString();
    const wchar_t* getText() const;
    void setText(const wchar_t* text);

    float getWidth();
    float getHeight();

    float getMaxWidth();
    float getMaxHeight();

    void setMaxWidth(float maxWidth);
    void setMaxHeight(float maxHeight);

    void setFont(const wchar_t* font, const wchar_t* color, float size, uint32 style, uint32 alignment); 
    
    const wchar_t* getFontName();
    const wchar_t* getFontColor();
    float getFontSize();
    uint32 getFontStyle();
    uint32 getTextAlignment();


    static ID2D1Factory*        getD2DFactory();
    static IWICImagingFactory*  getWICFactory();
    static IDWriteFactory*      getDWriteFactory();
    
    IDWriteTextFormat* getTextFormat();
    IDWriteTextLayout* getTextLayout();

    void* getResourceHandle();
    void  setResourceHandle(void* resourceHandle);

protected:
    void recreateTextLayout();

    static int64 _refCount;

    static ID2D1Factory*        _d2dFactory;
    static IWICImagingFactory*  _wicFactory;
    static IDWriteFactory*      _dwriteFactory;

    IDWriteTextFormat*   _textFormat;
    IDWriteTextLayout*   _textLayout;

    void* _resourceHandle;

    float _width, _height;
    float _maxWidth, _maxHeight;

    std::wstring    _fontName;
    std::wstring    _fontColor;
    float           _fontSize;
    uint32          _fontStyle;
    uint32          _textAlignment;

    bool _dirty;
    std::wstring _text;
};

#endif