aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/direct3d/evas_direct3d_object_font.h
blob: e8c01968273973a6871e868ae7039290a91df8c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef __EVAS_DIRECT3D_OBJECT_FONT_H__
#define __EVAS_DIRECT3D_OBJECT_FONT_H__

#include "evas_engine.h"

#include "ref.h"
#include "array.h"

#include "evas_direct3d_object.h"

class D3DObjectFont : public D3DObject
{
public:

   class Glyph : public Referenc
   {
   public:
      Glyph(void *source)
         : _source(source), _width(0), _height(0) {};

      bool Compare(void *source)
      {
         return (_source == source);
      }
      void *Source()
      {
         return _source;
      }

   private:
      friend class D3DObjectFont;
      void *_source;
      TArray<BYTE> _data;
      int _width;
      int _height;
   };

public:
   D3DObjectFont(void *source, int image_id);
   ~D3DObjectFont();

   inline bool Compare(void *source);
   void CopyTo(D3DObjectFont *font);

   virtual void Draw(D3DDevice *d3d);
   static void EndCache(D3DDevice *d3d);

   inline void SetColor(DWORD color);

   Glyph *GetGlyph(void *source);
   Glyph *AddGlyph(D3DDevice *d3d, void *source, BYTE *data8, int width, int height, int pitch);
   void PushForDraw(Glyph *glyph, int x, int y);

protected:
   static void BeginCache(int image_id);

private:
   struct Vertex
   {
      FLOAT x, y;
      FLOAT u, v;
   };

   struct Color
   {
      union
      {
         struct
         {
            BYTE b, g, r, a;
         };
         DWORD color;
      };

      FLOAT Alpha() { return FLOAT(a) / 255.f; }
   };

   class Cache
   {
   public:
      Cache()
         : enabled(false), image_id(-1), width(0), height(0) {};
   public:
      TArray<DWORD> data;
      TArray<POINT> dirty;  // Start, End
      bool enabled;
      int image_id;
      int width;
      int height;
      RECT valid_rect;
   };

private:
   DWORD _color;
   void *_source;
   int _image_id;

   TArray<Ref<Glyph> > _glyphs;

   static Cache _cache;
};

bool D3DObjectFont::Compare(void *source)
{
   return (_source == source);
}

void D3DObjectFont::SetColor(DWORD color)
{
   _color = color;
}

#endif  // __EVAS_DIRECT3D_OBJECT_FONT_H__