Back to index

nux  3.0.0
GroupBox2.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "Layout.h"
00025 #include "GroupBox2.h"
00026 
00027 namespace nux
00028 {
00029 
00030   int GroupBox2::CAPTION_X_MARGIN = 6;
00031   int GroupBox2::X_MARGIN = 4;
00032   int GroupBox2::Y_MARGIN = 4;
00033   Color GroupBox2::GROUPBOX2_HEADER_BASE_COLOR = Color(0xFF191919);
00034   Color GroupBox2::GROUPBOX2_HEADER_TEXT_COLOR = Color(0xFFFFFFFF);
00035   int GroupBox2::TOP_HEADER_HEIGHT = 24;
00036 
00037   GroupBox2::GroupBox2(const char *Caption, NUX_FILE_LINE_DECL)
00038     :   View(NUX_FILE_LINE_PARAM)
00039     ,   bCaptionAvailable(false)
00040     ,   m_layout(0)
00041   {
00042     m_CaptionArea = new InputArea(NUX_TRACKER_LOCATION);
00043     SetMinimumSize(DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT + 5);
00044     SetBaseSize(DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT + 5);
00045     SetCaption(Caption);
00046   }
00047 
00048   GroupBox2::~GroupBox2()
00049   {
00050     m_CaptionArea->Dispose();
00051   }
00052 
00053   void GroupBox2::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00054   {
00055     graphics_engine.PushClippingRectangle(GetGeometry());
00056 
00057     Geometry header = GetGeometry();
00058     header.SetHeight(TOP_HEADER_HEIGHT);
00059     Geometry layoutgeomerty = GetGeometry();
00060     layoutgeomerty.OffsetPosition(0, TOP_HEADER_HEIGHT);
00061     layoutgeomerty.OffsetSize(0, -TOP_HEADER_HEIGHT);
00062     GetPainter().PaintShapeCorner(graphics_engine, header, Color(0xFF000000), eSHAPE_CORNER_ROUND4, eCornerTopLeft | eCornerTopRight, false);
00063 
00064     GetPainter().PushDrawShapeLayer(graphics_engine, layoutgeomerty, eSHAPE_CORNER_ROUND4, GROUPBOX2_HEADER_BASE_COLOR, eCornerBottomLeft | eCornerBottomRight);
00065 
00066     //if(bCaptionAvailable)
00067     {
00068       GetPainter().PaintTextLineStatic(graphics_engine, GetSysBoldFont(), m_CaptionArea->GetGeometry(), m_CaptionArea->GetBaseString(), GROUPBOX2_HEADER_TEXT_COLOR);
00069     }
00070 
00071     if (m_layout != 0)
00072     {
00073       m_layout->QueueDraw();
00074     }
00075 
00076     GetPainter().PopBackground();
00077     graphics_engine.PopClippingRectangle();
00078   }
00079 
00080   void GroupBox2::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00081   {
00082     if (m_layout == 0)
00083       return;
00084 
00085     graphics_engine.PushClippingRectangle(m_layout->GetGeometry());
00086     Geometry layoutgeomerty = GetGeometry();
00087     layoutgeomerty.OffsetPosition(0, TOP_HEADER_HEIGHT);
00088     layoutgeomerty.OffsetSize(0, -TOP_HEADER_HEIGHT);
00089 
00090     if (force_draw)
00091       GetPainter().PushDrawShapeLayer(graphics_engine, layoutgeomerty, eSHAPE_CORNER_ROUND4, GROUPBOX2_HEADER_BASE_COLOR, eAllCorners);
00092     else
00093       GetPainter().PushShapeLayer(graphics_engine, layoutgeomerty, eSHAPE_CORNER_ROUND4, GROUPBOX2_HEADER_BASE_COLOR, eAllCorners);
00094 
00095     if (m_layout)
00096     {
00097       graphics_engine.PushClippingRectangle(m_layout->GetGeometry());
00098       m_layout->ProcessDraw(graphics_engine, force_draw);
00099       graphics_engine.PopClippingRectangle();
00100     }
00101 
00102     GetPainter().PopBackground();
00103     graphics_engine.PopClippingRectangle();
00104   }
00105 
00106   void GroupBox2::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00107   {
00108 
00109   }
00110 
00111   bool GroupBox2::SetLayout(Layout *layout)
00112   {
00113     if (View::SetLayout(layout) == false)
00114     {
00115       return false;
00116     }
00117 
00118     m_layout = layout;
00119 
00120     return true;
00121   }
00122 
00123   void GroupBox2::PreLayoutManagement()
00124   {
00125     // Give the managed layout appropriate size and position..
00126     if (GetCompositionLayout())
00127     {
00128       Geometry layout_geo = GetGeometry();
00129       //if(bCaptionAvailable)
00130       {
00131         layout_geo.OffsetPosition(X_MARGIN, TOP_HEADER_HEIGHT + Y_MARGIN);
00132         layout_geo.OffsetSize(-2 * X_MARGIN, -TOP_HEADER_HEIGHT - 2 * Y_MARGIN);
00133       }
00134 //        else
00135 //        {
00136 //            layout_geo.OffsetPosition(X_MARGIN, 2);
00137 //            layout_geo.OffsetSize(-2*X_MARGIN, -2*Y_MARGIN);
00138 //        }
00139       GetCompositionLayout()->SetGeometry(layout_geo);
00140     }
00141   }
00142 
00143   long GroupBox2::PostLayoutManagement(long LayoutResult)
00144   {
00145     // A Group box must tightly group its children.
00146     // So it must embrace the size that was compute for the composition layout.
00147     // Only the size is change is important here of the GroupBox2 is important here.
00148 
00149     long ret = 0;
00150     Geometry old_geo = Area::GetGeometry();
00151 
00152     if (GetCompositionLayout())
00153     {
00154       Geometry base = GetCompositionLayout()->GetGeometry();
00155       //if(bCaptionAvailable)
00156       {
00157         base.OffsetPosition(-X_MARGIN, -TOP_HEADER_HEIGHT - Y_MARGIN);
00158         base.OffsetSize(2 * X_MARGIN, TOP_HEADER_HEIGHT + 2 * Y_MARGIN);
00159       }
00160 //        else
00161 //        {
00162 //            base.OffsetPosition(-X_MARGIN, -2);
00163 //            base.OffsetSize(2*X_MARGIN, 2*Y_MARGIN);
00164 //        }
00165       Area::SetGeometry(base);
00166     }
00167 
00168     Geometry base = GetGeometry();
00169     m_CaptionArea->SetBaseXY(base.x + CAPTION_X_MARGIN, base.y + (TOP_HEADER_HEIGHT - m_CaptionArea->GetBaseHeight()) / 2);
00170 
00171 
00172     if (old_geo.GetWidth() > base.GetWidth())
00173       ret |= eLargerWidth;
00174     else if (old_geo.GetWidth() < base.GetWidth())
00175       ret |= eSmallerWidth;
00176     else
00177       ret |= eCompliantWidth;
00178 
00179     if (old_geo.GetHeight() > base.GetHeight())
00180       ret |= eLargerHeight;
00181     else if (old_geo.GetHeight() < base.GetHeight())
00182       ret |= eSmallerHeight;
00183     else
00184       ret |= eCompliantHeight;
00185 
00186     return ret;
00187   }
00188 
00189   void GroupBox2::ComputeContentPosition(float offsetX, float offsetY)
00190   {
00191     if (GetCompositionLayout())
00192     {
00193       //if(bCaptionAvailable)
00194       {
00195         GetCompositionLayout()->SetBaseX(GetBaseX() + X_MARGIN);
00196         GetCompositionLayout()->SetBaseY(GetBaseY() + TOP_HEADER_HEIGHT + Y_MARGIN);
00197       }
00198 //        else
00199 //        {
00200 //            m_compositionLayout->SetX(GetX() + X_MARGIN);
00201 //            m_compositionLayout->SetY(GetY() + Y_MARGIN);
00202 //        }
00203       GetCompositionLayout()->ComputeContentPosition(offsetX, offsetY);
00204     }
00205 
00206     Geometry base = GetGeometry();
00207     m_CaptionArea->SetBaseXY(base.x + CAPTION_X_MARGIN, base.y + (TOP_HEADER_HEIGHT - m_CaptionArea->GetBaseHeight()) / 2);
00208   }
00209 
00210   void GroupBox2::SetCaption(const char *Caption)
00211   {
00212     if ((Caption == 0) || (StringLength(Caption) == 0))
00213     {
00214       //bCaptionAvailable = false;
00215       m_CaptionArea->SetBaseString("");
00216       m_CaptionArea->SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00217       m_CaptionArea->SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00218     }
00219     else
00220     {
00221       //bCaptionAvailable = true;
00222       m_CaptionArea->SetBaseString(Caption);
00223       m_CaptionArea->SetMinimumSize(4 + GetSysBoldFont()->GetStringWidth(Caption), PRACTICAL_WIDGET_HEIGHT);
00224       m_CaptionArea->SetBaseSize(4 + GetSysBoldFont()->GetStringWidth(Caption), PRACTICAL_WIDGET_HEIGHT);
00225 
00226       Size s = GetMinimumSize();
00227 
00228       if (s.width < 2 * CAPTION_X_MARGIN + m_CaptionArea->GetBaseWidth())
00229       {
00230         SetMinimumSize(2 * CAPTION_X_MARGIN + m_CaptionArea->GetBaseWidth(), s.height);
00231         SetBaseSize(2 * CAPTION_X_MARGIN + m_CaptionArea->GetBaseWidth(), s.height);
00232       }
00233     }
00234   }
00235 
00236   bool GroupBox2::AcceptKeyNavFocus()
00237   {
00238     return false;
00239   }
00240 
00241 }