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>
15 CControl::CControl(int EdgeX, int FillX, int InnerX, int EdgeY, int FillY, int InnerY, ::std::vector<uint32_t>&& data):
27 void CControl::Render(CSurface& dest, const CRect& rect) const
29 if( rect.m_w < m_edge_x*2 + m_fill_x*2 + m_inner_x )
31 if( rect.m_h < m_edge_y*2 + m_fill_y*2 + m_inner_y )
34 const int ctrl_width = m_edge_x + m_fill_x + m_inner_x + (m_inner_x ? m_fill_x : 0) + m_edge_x;
36 const int top_fill_end = rect.m_h / 2 - m_inner_y;
37 const int bot_fill_start = top_fill_end + m_inner_y;
38 const int bot_fill_end = rect.m_h - m_edge_y;
40 ::std::vector<uint32_t> scanline( rect.m_w );
44 for( int i = 0; i < m_edge_y; i ++ )
45 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
48 while( y < top_fill_end )
50 for( int i = 0; i < m_fill_y && y < top_fill_end; i ++ )
51 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
57 for( int i = 0; i < m_inner_y; i ++ )
58 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
59 base_ofs += m_inner_y;
66 while( y < bot_fill_end )
68 for( int i = 0; i < m_fill_y && y < bot_fill_end; i ++ )
69 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
73 for( int i = 0; i < m_edge_y; i ++ )
74 renderLine(dest, y++, scanline, rect, &m_data[(base_ofs+i)*ctrl_width]);
78 void CControl::renderLine(CSurface& dest, int y, ::std::vector<uint32_t>& scanline, const CRect& rect, const uint32_t* ctrl_line) const
80 const int left_fill_end = rect.m_w / 2 - m_inner_x;
81 const int right_fill_end = rect.m_w - m_edge_x;
86 for( int i = 0; i < m_edge_x; i ++ )
87 scanline[x++] = ctrl_line[base_ofs + i];
90 while( x < left_fill_end )
92 for( int i = 0; i < m_fill_x && x < left_fill_end; i ++ )
93 scanline[x++] = ctrl_line[base_ofs + i];
99 for( int i = 0; i < m_inner_x; i ++ )
100 scanline[x++] = ctrl_line[base_ofs + i];
101 base_ofs += m_inner_x;
105 base_ofs -= m_fill_x;
108 while( x < right_fill_end )
110 for( int i = 0; i < m_fill_x && x < right_fill_end; i ++ )
111 scanline[x++] = ctrl_line[base_ofs + i];
113 base_ofs += m_fill_x;
115 for( int i = 0; i < m_edge_x; i ++ )
116 scanline[x++] = ctrl_line[base_ofs + i];
117 base_ofs += m_edge_x;
119 dest.DrawScanline(rect.m_y + y, rect.m_x, rect.m_w, scanline.data());
122 // ---- Standard Controls ---
123 // Standard button control
124 CControl StdButton(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
125 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
126 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
127 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
128 0xC0C0C0, 0xFFD0D0, 0xFFD0D0, 0xFFD0D0, 0xC0C0C0,
129 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
133 CControl StdText(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
134 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
135 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
136 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
137 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
138 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
141 const CControl* CControl::GetByName(const ::std::string& name)
143 if( name == "StdButton" )
145 if( name == "StdText" )
147 // TODO: Use another exception
151 const CControl* CControl::GetByID(uint16_t id)
155 case 0x00: return &StdButton;
156 case 0x01: return &StdText;
157 default: return nullptr;