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>
16 CControl::CControl(int EdgeX, int FillX, int InnerX, int EdgeY, int FillY, int InnerY, ::std::vector<uint32_t>&& data):
28 void CControl::Render(CSurface& dest, const CRect& rect) const
30 if( rect.m_w < m_edge_x*2 + m_fill_x*2 + m_inner_x )
32 if( rect.m_h < m_edge_y*2 + m_fill_y*2 + m_inner_y )
35 const int ctrl_width = m_edge_x + m_fill_x + m_inner_x + (m_inner_x ? m_fill_x : 0) + m_edge_x;
37 const int top_fill_end = rect.m_h / 2 - m_inner_y;
38 const int bot_fill_start = top_fill_end + m_inner_y;
39 const int bot_fill_end = rect.m_h - m_edge_y;
41 ::std::vector<uint32_t> scanline( rect.m_w );
45 for( int i = 0; i < m_edge_y; i ++ )
46 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
49 while( y < top_fill_end )
51 for( int i = 0; i < m_fill_y && y < top_fill_end; i ++ )
52 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
58 for( int i = 0; i < m_inner_y; i ++ )
59 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
60 base_ofs += m_inner_y;
67 while( y < bot_fill_end )
69 for( int i = 0; i < m_fill_y && y < bot_fill_end; i ++ )
70 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
74 for( int i = 0; i < m_edge_y; i ++ )
75 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
79 void CControl::renderLine(CSurface& dest, int y, ::std::vector<uint32_t>& scanline, const CRect& rect, const uint32_t* ctrl_line) const
81 const int left_fill_end = rect.m_w / 2 - m_inner_x;
82 const int right_fill_end = rect.m_w - m_edge_x;
87 for( int i = 0; i < m_edge_x; i ++ )
88 scanline[x++] = ctrl_line[base_ofs + i];
91 while( x < left_fill_end )
93 for( int i = 0; i < m_fill_x && x < left_fill_end; i ++ )
94 scanline[x++] = ctrl_line[base_ofs + i];
100 for( int i = 0; i < m_inner_x; i ++ )
101 scanline[x++] = ctrl_line[base_ofs + i];
102 base_ofs += m_inner_x;
106 base_ofs -= m_fill_x;
109 while( x < right_fill_end )
111 for( int i = 0; i < m_fill_x && x < right_fill_end; i ++ )
112 scanline[x++] = ctrl_line[base_ofs + i];
114 base_ofs += m_fill_x;
116 for( int i = 0; i < m_edge_x; i ++ )
117 scanline[x++] = ctrl_line[base_ofs + i];
118 base_ofs += m_edge_x;
120 dest.DrawScanline(rect.m_y + y, rect.m_x, rect.m_w, scanline.data());
123 // ---- Standard Controls ---
124 // Standard button control
125 CControl StdButton(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
126 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
127 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
128 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
129 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
130 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
134 CControl StdToolbar(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
135 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
136 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
137 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
138 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
139 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
143 CControl StdText(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
144 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
145 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
146 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
147 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
148 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
151 const CControl* CControl::GetByName(const ::std::string& name)
153 if( name == "StdButton" )
155 if( name == "StdText" )
157 // TODO: Use another exception
161 const CControl* CControl::GetByID(uint16_t id)
165 case AXWIN4_CTL_BUTTON: return &StdButton;
166 case AXWIN4_CTL_TOOLBAR: return &StdToolbar;
167 case AXWIN4_CTL_TEXTBOX: return &StdText;
168 default: return nullptr;