-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrenderer.cpp
More file actions
94 lines (73 loc) · 1.72 KB
/
renderer.cpp
File metadata and controls
94 lines (73 loc) · 1.72 KB
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
// this file is part of osmbrowser
// copyright Martijn Versteegh
// osmbrowser is licenced under the gpl v3
#include "renderer.h"
#include <wx/image.h>
void RendererWxBitmap::DrawCenteredText(char const *s, double x, double y, double angle, int r, int g, int b, int a, int layer)
{
// not implemented yet
}
void RendererWxBitmap::Setup(wxBitmap *bitmap)
{
m_output = bitmap;
int w = bitmap->GetWidth();
int h = bitmap->GetHeight();
m_outputWidth = w;
m_outputHeight = h;
for (int i = 0; i < m_numLayers; i++)
{
m_layer[i].Create(w, h);
m_dc[i].SelectObject(m_layer[i]);
if (i)
{
m_dc[i].SetBackground(wxBrush(m_maskColor));
}
}
}
void RendererWxBitmap::DrawPolygon()
{
ScalePoints();
m_dc[m_curLayer].SetPen(m_pen);
m_dc[m_curLayer].SetBrush(m_brush);
m_dc[m_curLayer].DrawPolygon(m_numPoints, m_wxPoints);
}
void RendererWxBitmap::DrawLine()
{
ScalePoints();
m_dc[m_curLayer].SetPen(m_pen);
m_dc[m_curLayer].DrawLines(m_numPoints, m_wxPoints);
}
void RendererWxBitmap::BlitWithTransparency(wxBitmap *from, wxImage *to)
{
wxImage f = from->ConvertToImage();
int w = f.GetWidth();
int h = f.GetHeight();
int mr = m_maskColor.Red();
int mg = m_maskColor.Green();
int mb = m_maskColor.Blue();
for (int y = 0; y < h ; y++)
{
for (int x = 0; x < w; x++)
{
int r = f.GetRed(x, y);
int g = f.GetGreen(x, y);
int b = f.GetBlue(x, y);
if (r != mr || g != mg || b != mb)
{
to->SetRGB(x, y, r, g, b);
}
}
}
}
void RendererWxBitmap::Commit()
{
wxMemoryDC to;
to.SelectObject(*m_output);
wxImage composite = m_layer[0].ConvertToImage();
for (int i = 1; i < m_numLayers; i++)
{
BlitWithTransparency(m_layer + i, &composite);
}
wxBitmap c(composite);
to.DrawBitmap(c,0,0);
}