3 * - By John Hodge (thePowersGang)
6 * - Common "Control" Drawing
8 * Handles drawing of resizable controls defined by a bitmap and four region sizes
10 #include <draw_control.hpp>
11 #include <axwin4/definitions.h>
12 #include <acess/sys.h>
18 CControl::CControl(int EdgeX, int FillX, int InnerX, int EdgeY, int FillY, int InnerY, ::std::vector<uint32_t>&& data):
27 _SysDebug("CControl(X={E:%i,F:%i,I:%i}, Y={E:%i,F:%i,I:%i}, data={Size:%i})",
28 m_edge_x, m_fill_x, m_inner_x, m_edge_y, m_fill_y, m_inner_y, m_data.size());
31 void CControl::Render(CSurface& dest, const CRect& rect) const
33 if( rect.m_w < m_edge_x*2 + m_fill_x*2 + m_inner_x )
35 if( rect.m_h < m_edge_y*2 + m_fill_y*2 + m_inner_y )
38 const int ctrl_width = m_edge_x + m_fill_x + m_inner_x + (m_inner_x ? m_fill_x : 0) + m_edge_x;
40 const int top_fill_end = rect.m_h / 2 - m_inner_y;
41 const int bot_fill_start = top_fill_end + m_inner_y;
42 const int bot_fill_end = rect.m_h - m_edge_y;
44 ::std::vector<uint32_t> scanline( rect.m_w );
48 for( int i = 0; i < m_edge_y; i ++ )
49 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
52 assert(m_fill_y > 0 || y == top_fill_end);
53 while( y < top_fill_end )
55 for( int i = 0; i < m_fill_y && y < top_fill_end; i ++ )
56 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
62 for( int i = 0; i < m_inner_y; i ++ )
63 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
64 base_ofs += m_inner_y;
71 while( y < bot_fill_end )
73 for( int i = 0; i < m_fill_y && y < bot_fill_end; i ++ )
74 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
78 for( int i = 0; i < m_edge_y; i ++ )
79 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
83 void CControl::renderLine(CSurface& dest, int y, ::std::vector<uint32_t>& scanline, const CRect& rect, const uint32_t* ctrl_line) const
85 //_SysDebug("renderLine: (y=%i,rect={(%i,%i) %ix%i}", y, rect.m_x, rect.m_y, rect.m_w, rect.m_h);
86 const int left_fill_end = rect.m_w / 2 - m_inner_x;
87 const int right_fill_end = rect.m_w - m_edge_x;
92 for( int i = 0; i < m_edge_x; i ++ )
93 scanline[x++] = ctrl_line[base_ofs + i];
96 while( x < left_fill_end )
98 for( int i = 0; i < m_fill_x && x < left_fill_end; i ++ )
99 scanline[x++] = ctrl_line[base_ofs + i];
101 base_ofs += m_fill_x;
105 for( int i = 0; i < m_inner_x; i ++ )
106 scanline[x++] = ctrl_line[base_ofs + i];
107 base_ofs += m_inner_x;
111 base_ofs -= m_fill_x;
114 while( x < right_fill_end )
116 for( int i = 0; i < m_fill_x && x < right_fill_end; i ++ )
117 scanline[x++] = ctrl_line[base_ofs + i];
119 base_ofs += m_fill_x;
121 for( int i = 0; i < m_edge_x; i ++ )
122 scanline[x++] = ctrl_line[base_ofs + i];
123 base_ofs += m_edge_x;
125 dest.DrawScanline(rect.m_y + y, rect.m_x, rect.m_w, scanline.data());
128 // ---- Standard Controls ---
129 // Standard button control
130 CControl StdButton(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
131 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
132 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
133 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
134 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
135 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
139 CControl StdToolbar(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
140 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
141 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
142 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
143 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
144 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
148 CControl StdText(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
149 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
150 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
151 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
152 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
153 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
156 const CControl* CControl::GetByName(const ::std::string& name)
158 if( name == "StdButton" )
160 if( name == "StdText" )
162 // TODO: Use another exception
166 const CControl* CControl::GetByID(uint16_t id)
170 case AXWIN4_CTL_BUTTON: return &StdButton;
171 case AXWIN4_CTL_TOOLBAR: return &StdToolbar;
172 case AXWIN4_CTL_TEXTBOX: return &StdText;
173 default: return nullptr;