00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_widgetbackground.hpp"
00012
00013 #include "xrb_gltexture.hpp"
00014 #include "xrb_render.hpp"
00015 #include "xrb_simpletransform2.hpp"
00016
00017 namespace Xrb
00018 {
00019
00020
00021
00022
00023
00024 WidgetBackground *WidgetBackgroundColored::CreateClone () const
00025 {
00026 return new WidgetBackgroundColored(m_color);
00027 }
00028
00029 void WidgetBackgroundColored::Draw (
00030 RenderContext const &render_context,
00031 ScreenCoordRect const &widget_screen_rect,
00032 ScreenCoordVector2 const &frame_margins) const
00033 {
00034 Render::DrawScreenRect(
00035 render_context,
00036 m_color,
00037 widget_screen_rect);
00038 }
00039
00040
00041
00042
00043
00044 WidgetBackgroundTextured::WidgetBackgroundTextured (
00045 std::string const &texture_path)
00046 :
00047 WidgetBackground()
00048 {
00049 ASSERT1(texture_path.length() > 0);
00050
00051 m_texture =
00052 Singleton::ResourceLibrary().LoadPath<GLTexture>(
00053 GLTexture::Create,
00054 texture_path);
00055 ASSERT1(m_texture.IsValid());
00056 }
00057
00058 WidgetBackgroundTextured::WidgetBackgroundTextured (
00059 Resource<GLTexture> const &texture)
00060 :
00061 WidgetBackground()
00062 {
00063 m_texture = texture;
00064 }
00065
00066 WidgetBackgroundTextured::~WidgetBackgroundTextured ()
00067 {
00068 }
00069
00070 WidgetBackground *WidgetBackgroundTextured::CreateClone () const
00071 {
00072 return new WidgetBackgroundTextured(m_texture);
00073 }
00074
00075 void WidgetBackgroundTextured::Draw (
00076 RenderContext const &render_context,
00077 ScreenCoordRect const &widget_screen_rect,
00078 ScreenCoordVector2 const &frame_margins) const
00079 {
00080 ASSERT1(m_texture.IsValid());
00081 Render::DrawScreenRectTexture(
00082 render_context,
00083 *m_texture,
00084 widget_screen_rect);
00085 }
00086
00087
00088
00089
00090
00091 WidgetBackgroundStylized::WidgetBackgroundStylized (
00092 std::string const &corner_texture_name,
00093 std::string const &top_texture_name,
00094 std::string const &left_texture_name,
00095 std::string const ¢er_texture_name)
00096 :
00097 WidgetBackground()
00098 {
00099 m_corner_texture =
00100 Singleton::ResourceLibrary().LoadPath<GLTexture>(
00101 GLTexture::Create,
00102 corner_texture_name);
00103 ASSERT1(m_corner_texture.IsValid());
00104
00105 m_top_texture =
00106 Singleton::ResourceLibrary().LoadPath<GLTexture>(
00107 GLTexture::Create,
00108 top_texture_name);
00109 ASSERT1(m_top_texture.IsValid());
00110
00111 m_left_texture =
00112 Singleton::ResourceLibrary().LoadPath<GLTexture>(
00113 GLTexture::Create,
00114 left_texture_name);
00115 ASSERT1(m_left_texture.IsValid());
00116
00117 m_center_texture =
00118 Singleton::ResourceLibrary().LoadPath<GLTexture>(
00119 GLTexture::Create,
00120 center_texture_name);
00121 ASSERT1(m_center_texture.IsValid());
00122 }
00123
00124 WidgetBackgroundStylized::WidgetBackgroundStylized (
00125 Resource<GLTexture> const &corner_texture,
00126 Resource<GLTexture> const &top_texture,
00127 Resource<GLTexture> const &left_texture,
00128 Resource<GLTexture> const ¢er_texture)
00129 :
00130 WidgetBackground()
00131 {
00132 ASSERT1(corner_texture.IsValid());
00133 ASSERT1(top_texture.IsValid());
00134 ASSERT1(left_texture.IsValid());
00135 ASSERT1(center_texture.IsValid());
00136
00137 m_corner_texture = corner_texture;
00138 m_top_texture = top_texture;
00139 m_left_texture = left_texture;
00140 m_center_texture = center_texture;
00141 }
00142
00143 WidgetBackgroundStylized::~WidgetBackgroundStylized ()
00144 {
00145 }
00146
00147 WidgetBackground *WidgetBackgroundStylized::CreateClone () const
00148 {
00149 return new WidgetBackgroundStylized(
00150 m_corner_texture,
00151 m_top_texture,
00152 m_left_texture,
00153 m_center_texture);
00154 }
00155
00156 void WidgetBackgroundStylized::Draw (
00157 RenderContext const &render_context,
00158 ScreenCoordRect const &widget_screen_rect,
00159 ScreenCoordVector2 const &frame_margins) const
00160 {
00161 ASSERT1(m_corner_texture.IsValid());
00162 ASSERT1(m_top_texture.IsValid());
00163 ASSERT1(m_left_texture.IsValid());
00164 ASSERT1(m_center_texture.IsValid());
00165 ASSERT1(frame_margins[Dim::X] >= 0);
00166 ASSERT1(frame_margins[Dim::Y] >= 0);
00167
00168
00169 ScreenCoord horizontal[4] =
00170 {
00171 widget_screen_rect.Left(),
00172 widget_screen_rect.Left() + frame_margins[Dim::X],
00173 widget_screen_rect.Right() - frame_margins[Dim::X],
00174 widget_screen_rect.Right()
00175 };
00176 ScreenCoord vertical[4] =
00177 {
00178 widget_screen_rect.Bottom(),
00179 widget_screen_rect.Bottom() + frame_margins[Dim::Y],
00180 widget_screen_rect.Top() - frame_margins[Dim::Y],
00181 widget_screen_rect.Top()
00182 };
00183
00184
00185 ScreenCoordRect bottom_left(
00186 horizontal[0], vertical[0],
00187 horizontal[1], vertical[1]);
00188 ScreenCoordRect bottom_center(
00189 horizontal[1], vertical[0],
00190 horizontal[2], vertical[1]);
00191 ScreenCoordRect bottom_right(
00192 horizontal[2], vertical[0],
00193 horizontal[3], vertical[1]);
00194 ScreenCoordRect center_left(
00195 horizontal[0], vertical[1],
00196 horizontal[1], vertical[2]);
00197 ScreenCoordRect center_center(
00198 horizontal[1], vertical[1],
00199 horizontal[2], vertical[2]);
00200 ScreenCoordRect center_right(
00201 horizontal[2], vertical[1],
00202 horizontal[3], vertical[2]);
00203 ScreenCoordRect top_left(
00204 horizontal[0], vertical[2],
00205 horizontal[1], vertical[3]);
00206 ScreenCoordRect top_center(
00207 horizontal[1], vertical[2],
00208 horizontal[2], vertical[3]);
00209 ScreenCoordRect top_right(
00210 horizontal[2], vertical[2],
00211 horizontal[3], vertical[3]);
00212
00213
00214 Render::DrawScreenRectTexture(
00215 render_context,
00216 *m_corner_texture,
00217 top_left,
00218 FloatSimpleTransform2( 1.0f, 1.0f, 0.0f, 0.0f));
00219 Render::DrawScreenRectTexture(
00220 render_context,
00221 *m_top_texture,
00222 top_center,
00223 FloatSimpleTransform2( 1.0f, 1.0f, 0.0f, 0.0f));
00224 Render::DrawScreenRectTexture(
00225 render_context,
00226 *m_corner_texture,
00227 top_right,
00228 FloatSimpleTransform2(-1.0f, 1.0f, 1.0f, 0.0f));
00229
00230 Render::DrawScreenRectTexture(
00231 render_context,
00232 *m_left_texture,
00233 center_left,
00234 FloatSimpleTransform2( 1.0f, 1.0f, 0.0f, 0.0f));
00235 Render::DrawScreenRectTexture(
00236 render_context,
00237 *m_center_texture,
00238 center_center,
00239 FloatSimpleTransform2( 1.0f, 1.0f, 0.0f, 0.0f));
00240 Render::DrawScreenRectTexture(
00241 render_context,
00242 *m_left_texture,
00243 center_right,
00244 FloatSimpleTransform2(-1.0f, 1.0f, 1.0f, 0.0f));
00245
00246 Render::DrawScreenRectTexture(
00247 render_context,
00248 *m_corner_texture,
00249 bottom_left,
00250 FloatSimpleTransform2( 1.0f, -1.0f, 0.0f, 1.0f));
00251 Render::DrawScreenRectTexture(
00252 render_context,
00253 *m_top_texture,
00254 bottom_center,
00255 FloatSimpleTransform2( 1.0f, -1.0f, 0.0f, 1.0f));
00256 Render::DrawScreenRectTexture(
00257 render_context,
00258 *m_corner_texture,
00259 bottom_right,
00260 FloatSimpleTransform2(-1.0f, -1.0f, 1.0f, 1.0f));
00261 }
00262
00263 }