File: UIStyle.cpp

package info (click to toggle)
arkrpg 0.1.4b-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,104 kB
  • ctags: 5,445
  • sloc: cpp: 28,145; sh: 9,006; ansic: 3,259; makefile: 344
file content (121 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (3)
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
114
115
116
117
118
119
120
121
#include <Ark/ArkSystem.h>

#include <Client/UIStyle.h>

namespace Client
{
   Style::Style(UIRenderer *ui) :
      m_Textures(UI_DECORATIONS_NBR),
      m_Placements(UI_DECORATIONS_NBR)
   {
      struct
      {
	    uchar Anchor;
	    const char *Name;
      } textures[] = 
	 {
	    {UI_BACKGROUND, "Background"},
	    {UI_RIGHT, "BorderRight"},
	    {UI_LEFT, "BorderLeft"},
	    {UI_TOP, "BorderTop" },
	    {UI_BOTTOM, "BorderBottom"},

	    {UI_UPLEFT, "BorderUpLeft"},
	    {UI_UPRIGHT, "BorderUpRight"},
	    {UI_DOWNLEFT, "BorderDownLeft"},
	    {UI_DOWNRIGHT, "BorderDownRight"},

	    {UI_UPLEFT+4, "SBorderUpLeft"},
	    {UI_UPRIGHT+4, "SBorderUpRight"},
	    {UI_DOWNLEFT+4, "SBorderDownLeft"},
	    {UI_DOWNRIGHT+4, "SBorderDownRight"}
	 };

      Ark::Config cfg; cfg.Load("{game}/data/misc/uistyle.cfg");
      for (size_t i = 0; i < UI_DECORATIONS_NBR; ++i)
      {
	 uchar Anchor = textures[i].Anchor;
	 Ark::String name = Ark::String("UI::") + textures[i].Name;
	 SetTextureAt (ui, Anchor, cfg.GetStr(name, ""));

	 m_Placements[Anchor].x = cfg.GetInt(name + "::PlacementX", 0);
	 m_Placements[Anchor].y = cfg.GetInt(name + "::PlacementY", 0);
      }
   }

   Style::~Style()
   {
   }

   /**************************************************************************
    **
    *************************************************************************/
   bool Style::SetTextureAt(UIRenderer* Renderer, uchar Anch,
			    const Ark::String &path)
   {
      if (Anch > m_Textures.size())
	 return false;

      Ark::TexturePtr tex;
      Renderer->Rdr()->GetCache().Get(Ark::V_TEXTURE, path, tex);

      if (!tex)
      {
	 // some warning here...
	  std::cerr << "Could not load texture " << path << std::endl;
	 return false;
      }

      m_Textures[Anch] = tex;
      m_Textures[Anch]->Configure();

      // the last 4 bitmaps are corner decorations with alpha
      if (Anch > UI_DOWNRIGHT && tex->m_Format != Ark::Image::RGBA_8888)
      {
	 Ark::Sys()->Log("Style texture %d: '%s' is not RGBA_8888\n",
			 (int)Anch, path.c_str());
      }
    
      return true;
   }
  
   void	Style::RenderSkin(UIRenderer* Renderer, int X, int Y, int W, int H)
   {
      // cycle for every part of skin
      for (size_t i = 0; i < UI_DECORATIONS_NBR; ++i)
      {
	 int tx = X, ty = Y, tw = m_Textures[i]->m_Width,
	    th = m_Textures[i]->m_Height;
	
	 switch (i)
	 {
	    case UI_BACKGROUND: tw = W; th = H; break;
	    
	    // sides
	    case UI_LEFT: th = H; break;
	    case UI_RIGHT: tx += W; th = H; break;
	    case UI_TOP: tw = W; break;
	    case UI_BOTTOM: ty += H; tw = W; break;

	    // corners
	    case UI_UPLEFT: break;
	    case UI_UPRIGHT: tx += W; break;
	    case UI_DOWNLEFT: ty += H; break;
	    case UI_DOWNRIGHT: tx += W; ty += H; break;

	    // corners
	    case UI_UPRIGHT + 4: tx += W; break;
	    case UI_UPLEFT + 4: break;
	    case UI_DOWNRIGHT + 4: tx += W; ty += H; break;
	    case UI_DOWNLEFT + 4: ty += H; break;
	 }

	 tx += m_Placements[i].x;
	 ty += m_Placements[i].y;

	 Renderer->SetTexture(m_Textures[i]);
	 Renderer->DrawTexturedRectangle(tx, ty, tw, th);
	 Renderer->Flush();
      }
   }
}