-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryBitmap.cpp
105 lines (80 loc) · 1.67 KB
/
MemoryBitmap.cpp
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
#include <vgui/ISurface.h>
#include "memorybitmap.h"
#include "vgui_internal.h"
using namespace vgui;
MemoryBitmap::MemoryBitmap(unsigned char *texture, int wide, int tall)
{
_texture = texture;
_id = 0;
_uploaded = false;
_color = Color(255, 255, 255, 255);
_pos[0] = _pos[1] = 0;
_valid = true;
_w = wide;
_h = tall;
ForceUpload(texture, wide, tall);
}
MemoryBitmap::~MemoryBitmap(void)
{
}
void MemoryBitmap::GetSize(int &wide, int &tall)
{
wide = 0;
tall = 0;
if (!_valid)
return;
g_pSurface->DrawGetTextureSize(_id, wide, tall);
}
void MemoryBitmap::GetContentSize(int &wide, int &tall)
{
GetSize(wide, tall);
}
void MemoryBitmap::SetSize(int x, int y)
{
}
void MemoryBitmap::SetPos(int x, int y)
{
_pos[0] = x;
_pos[1] = y;
}
void MemoryBitmap::SetColor(Color col)
{
_color = col;
}
const char *MemoryBitmap::GetName(void)
{
return "MemoryBitmap";
}
void MemoryBitmap::Paint(void)
{
if (!_valid)
return;
if (!_id)
_id = g_pSurface->CreateNewTextureID(true);
if (!_uploaded)
ForceUpload(_texture,_w,_h);
g_pSurface->DrawSetTexture(_id);
g_pSurface->DrawSetColor(_color[0], _color[1], _color[2], _color[3]);
int wide, tall;
GetSize(wide, tall);
g_pSurface->DrawTexturedRect(_pos[0], _pos[1], _pos[0] + wide, _pos[1] + tall);
}
void MemoryBitmap::ForceUpload(unsigned char *texture, int wide, int tall)
{
_texture = texture;
_w = wide;
_h = tall;
if (!_valid)
return;
if (_w == 0 || _h == 0)
return;
if (!_id)
_id = g_pSurface->CreateNewTextureID(true);
g_pSurface->DrawSetTextureBGRA(_id, _texture, _w, _h, false, true);
_uploaded = true;
_valid = g_pSurface->IsTextureIDValid(_id);
}
HTexture MemoryBitmap::GetID(void)
{
return _id;
}