|
| 1 | +#ifndef MAS_NSIMAGECONTEXT_HPP |
| 2 | +#define MAS_NSIMAGECONTEXT_HPP |
| 3 | + |
| 4 | +#include "NUIE_DrawingContext.hpp" |
| 5 | +#include "NUIE_Drawing.hpp" |
| 6 | +#include "NUIE_DrawingCacheKeys.hpp" |
| 7 | +#include "MAS_NSImageLoader.hpp" |
| 8 | + |
| 9 | +#include <unordered_map> |
| 10 | + |
| 11 | +#ifdef __cplusplus |
| 12 | +#ifdef __OBJC__ |
| 13 | + @class NSView; |
| 14 | + @class NSFont; |
| 15 | + @class NSImage; |
| 16 | +#else |
| 17 | + struct NSView; |
| 18 | + struct NSFont; |
| 19 | + struct NSImage; |
| 20 | +#endif |
| 21 | +#endif |
| 22 | + |
| 23 | +namespace MAS |
| 24 | +{ |
| 25 | + |
| 26 | +class NSImageContext : public NUIE::NativeDrawingContext |
| 27 | +{ |
| 28 | +public: |
| 29 | + NSImageContext (); |
| 30 | + NSImageContext (const NSImageLoaderPtr& imageLoader); |
| 31 | + NSImageContext (const NSImageContext& rhs) = delete; |
| 32 | + virtual ~NSImageContext (); |
| 33 | + |
| 34 | + virtual void Init (void* nativeHandle) override; |
| 35 | + virtual void BlitToWindow (void* nativeHandle) override; |
| 36 | + virtual void BlitToContext (void* nativeContext) override; |
| 37 | + |
| 38 | + virtual void Resize (int newWidth, int newHeight) override; |
| 39 | + |
| 40 | + virtual int GetWidth () const override; |
| 41 | + virtual int GetHeight () const override; |
| 42 | + |
| 43 | + virtual void BeginDraw () override; |
| 44 | + virtual void EndDraw () override; |
| 45 | + |
| 46 | + virtual bool NeedToDraw (ItemPreviewMode mode) override; |
| 47 | + |
| 48 | + virtual void DrawLine (const NUIE::Point& beg, const NUIE::Point& end, const NUIE::Pen& pen) override; |
| 49 | + virtual void DrawBezier (const NUIE::Point& p1, const NUIE::Point& p2, const NUIE::Point& p3, const NUIE::Point& p4, const NUIE::Pen& pen) override; |
| 50 | + |
| 51 | + virtual void DrawRect (const NUIE::Rect& rect, const NUIE::Pen& pen) override; |
| 52 | + virtual void FillRect (const NUIE::Rect& rect, const NUIE::Color& color) override; |
| 53 | + |
| 54 | + virtual void DrawEllipse (const NUIE::Rect& rect, const NUIE::Pen& pen) override; |
| 55 | + virtual void FillEllipse (const NUIE::Rect& rect, const NUIE::Color& color) override; |
| 56 | + |
| 57 | + virtual void DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor) override; |
| 58 | + virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override; |
| 59 | + |
| 60 | + virtual bool CanDrawIcon () override; |
| 61 | + virtual void DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId) override; |
| 62 | + |
| 63 | +private: |
| 64 | + NSFont* GetFont (const NUIE::Font& font); |
| 65 | + |
| 66 | + int width; |
| 67 | + int height; |
| 68 | + NSView* nsView; |
| 69 | + NSImageLoaderPtr imageLoader; |
| 70 | + NSImage* image; |
| 71 | + |
| 72 | + std::unordered_map<NUIE::FontCacheKey, NSFont*> fontCache; |
| 73 | +}; |
| 74 | + |
| 75 | +} |
| 76 | + |
| 77 | +#endif |
0 commit comments