Back to index

nux  3.0.0
GroupBox.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 "GroupBox.h"
00026 
00027 namespace nux
00028 {
00029 
00030   GroupBox::GroupBox(const char *Caption, NUX_FILE_LINE_DECL)
00031     :   View(NUX_FILE_LINE_PARAM)
00032     ,   bCaptionAvailable(false)
00033     ,   m_layout(0)
00034   {
00035     m_CaptionArea.SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00036     m_CaptionArea.SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00037 
00038     SetMinimumSize(DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT + 5);
00039     SetBaseSize(DEFAULT_WIDGET_WIDTH + 5, 2 * PRACTICAL_WIDGET_HEIGHT);
00040     SetCaption("");
00041   }
00042 
00043   GroupBox::~GroupBox()
00044   {
00045 
00046   }
00047 
00048   void GroupBox::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00049   {
00050     graphics_engine.PushClippingRectangle(GetGeometry());
00051 
00052     Geometry wireborder_geo = GetGeometry();
00053 
00054     //if(bCaptionAvailable)
00055     {
00056       wireborder_geo.OffsetPosition(0, 10);
00057       wireborder_geo.OffsetSize(0, -10);
00058     }
00059 //    else
00060 //    {
00061 //        wireborder_geo.OffsetPosition(0, 0);
00062 //        wireborder_geo.OffsetSize(0, 0);
00063 //    }
00064 
00065     //if(bCaptionAvailable)
00066     {
00067       //GetPainter().Paint2DQuadColor(m_CaptionArea.GetGeometry(), COLOR_BACKGROUND_PRIMARY);
00068       //GetPainter().PaintTextLineStatic(m_CaptionArea.GetGeometry(), m_CaptionArea.GetCaptionString(), eAlignTextCenter);
00069       GetPainter().PaintTextLineStatic(graphics_engine, GetSysBoldFont(), m_CaptionArea.GetGeometry(), m_CaptionArea.GetBaseString().GetTCharPtr(), GetTextColor(),
00070                                     true, eAlignTextCenter);
00071     }
00072 
00073     if (m_layout != 0)
00074     {
00075       m_layout->QueueDraw();
00076     }
00077 
00078     graphics_engine.PopClippingRectangle();
00079   }
00080 
00081   void GroupBox::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00082   {
00083     graphics_engine.PushClippingRectangle(GetGeometry());
00084 
00085     if (m_layout)
00086     {
00087       graphics_engine.PushClippingRectangle(m_layout->GetGeometry());
00088       m_layout->ProcessDraw(graphics_engine, force_draw);
00089       graphics_engine.PopClippingRectangle();
00090     }
00091 
00092     graphics_engine.PopClippingRectangle();
00093   }
00094 
00095   void GroupBox::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00096   {
00097 
00098   }
00099 
00100   bool GroupBox::SetLayout(Layout *layout)
00101   {
00102     if (View::SetLayout(layout) == false)
00103     {
00104       return false;
00105     }
00106 
00107     m_layout = layout;
00108 
00109     return true;
00110 
00111 //    Geometry geo = GetGeometry();
00112 //    Geometry layout_geo = Geometry(geo.x + m_border, geo.y + m_top_border,
00113 //        geo.GetWidth() - 2*m_border, geo.GetHeight() - m_border - m_top_border);
00114 //    m_layout->SetGeometry(layout_geo);
00115   }
00116 
00117   void GroupBox::PreLayoutManagement()
00118   {
00119     // Give the managed layout appropriate size and position..
00120     if (view_layout_)
00121     {
00122       Geometry layout_geo = GetGeometry();
00123       //if(bCaptionAvailable)
00124       {
00125         layout_geo.OffsetPosition(2, 20);
00126         layout_geo.OffsetSize(-4, -22);
00127       }
00128 //        else
00129 //        {
00130 //            layout_geo.OffsetPosition(2, 2);
00131 //            layout_geo.OffsetSize(-4, -4);
00132 //        }
00133       view_layout_->SetGeometry(layout_geo);
00134     }
00135   }
00136 
00137   long GroupBox::PostLayoutManagement(long LayoutResult)
00138   {
00139     // A Group box must tightly group its children.
00140     // So it must embrace the size that was compute for the composition layout.
00141     // Only the size is change is important here of the GroupBox is important here.
00142 
00143     long ret = 0;
00144     Geometry old_geo = Area::GetGeometry();
00145 
00146     if (view_layout_)
00147     {
00148       Geometry base = view_layout_->GetGeometry();
00149       //if(bCaptionAvailable)
00150       {
00151         base.OffsetPosition(-2, -20);
00152         base.OffsetSize(4, 22);
00153       }
00154 //        else
00155 //        {
00156 //            base.OffsetPosition(-2, -2);
00157 //            base.OffsetSize(4, 4);
00158 //        }
00159       Area::SetGeometry(base);
00160     }
00161 
00162     Geometry base = GetGeometry();
00163     m_CaptionArea.SetBaseXY(base.x + 6, base.y);
00164 
00165     if (old_geo.GetWidth() > base.GetWidth())
00166       ret |= eLargerWidth;
00167     else if (old_geo.GetWidth() < base.GetWidth())
00168       ret |= eSmallerWidth;
00169     else
00170       ret |= eCompliantWidth;
00171 
00172     if (old_geo.GetHeight() > base.GetHeight())
00173       ret |= eLargerHeight;
00174     else if (old_geo.GetHeight() < base.GetHeight())
00175       ret |= eSmallerHeight;
00176     else
00177       ret |= eCompliantHeight;
00178 
00179     return ret;
00180   }
00181 
00182   void GroupBox::ComputeContentPosition(float offsetX, float offsetY)
00183   {
00184     if (view_layout_)
00185     {
00186       //if(bCaptionAvailable)
00187       {
00188         view_layout_->SetBaseX(GetBaseX() + 2);
00189         view_layout_->SetBaseY(GetBaseY() + 20);
00190       }
00191 //        else
00192 //        {
00193 //            view_layout_->SetX(GetX() + 2);
00194 //            view_layout_->SetY(GetY() + 2);
00195 //        }
00196       view_layout_->ComputeContentPosition(offsetX, offsetY);
00197     }
00198 
00199     Geometry base = GetGeometry();
00200     m_CaptionArea.SetBaseXY(base.x + 6, base.y);
00201   }
00202 
00203   void GroupBox::SetCaption(const char *name)
00204   {
00205     if ((name == 0) || strlen(name) == 0)
00206     {
00207       //bCaptionAvailable = false;
00208       m_CaptionArea.SetBaseString("");
00209       m_CaptionArea.SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00210       m_CaptionArea.SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00211     }
00212     else
00213     {
00214       //bCaptionAvailable = true;
00215       m_CaptionArea.SetBaseString(name);
00216       m_CaptionArea.SetMinimumSize(4 + GetSysBoldFont()->GetStringWidth(name), PRACTICAL_WIDGET_HEIGHT);
00217       m_CaptionArea.SetBaseSize(4 + GetSysBoldFont()->GetStringWidth(name), PRACTICAL_WIDGET_HEIGHT);
00218     }
00219   }
00220 
00221   bool GroupBox::AcceptKeyNavFocus()
00222   {
00223     return false;
00224   }
00225 }