nux-1.16.0
FileSelector.cpp
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 "FileSelector.h"
00025 
00026 #include "EditTextBox.h"
00027 #include "HLayout.h"
00028 #include "Button.h"
00029 
00030 namespace nux
00031 {
00032 
00033   Color FILESELECTOR_BUTTON_COLOR = Color (0xFF4D4D4D);
00034   Color FILESELECTOR_BUTTON_MOUSEOVER_COLOR = Color (0xFF222222);
00035 
00036   FileSelector::FileSelector (NUX_FILE_LINE_DECL)
00037     :   View (NUX_FILE_LINE_PARAM)
00038   {
00039     m_hlayout           = new HLayout (NUX_TRACKER_LOCATION);
00040     m_OpenButton        = new Button (TEXT (""), NUX_TRACKER_LOCATION);
00041     m_FileEditTextBox   = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00042 
00043     m_hlayout->AddView (m_FileEditTextBox, 1, eCenter);
00044     m_hlayout->AddView (m_OpenButton, 0, eCenter);
00045 
00046     //m_OpenButton->setCaption(TEXT("..."));
00047     m_OpenButton->SetMinimumWidth (20);
00048 
00049     m_OpenButton->mouse_enter.connect (sigc::mem_fun (this, &FileSelector::RecvMouseEnter) );
00050     m_OpenButton->mouse_leave.connect (sigc::mem_fun (this, &FileSelector::RecvMouseLeave) );
00051     m_OpenButton->mouse_click.connect (sigc::mem_fun (this, &FileSelector::RecvOpenButtonClick) );
00052 
00053     SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00054     SetLayout(m_hlayout);
00055 
00056     NString Path = NUX_FINDRESOURCELOCATION (TEXT ("Icons/Folder-16x16.png") );
00057     m_Texture = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture ();
00058     m_Texture->Update (Path.GetTCharPtr() );
00059   }
00060 
00061   FileSelector::~FileSelector()
00062   {
00063     m_Texture->UnReference ();
00064   }
00065 
00066   long FileSelector::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00067   {
00068     long ret = TraverseInfo;
00069     ret = m_FileEditTextBox->OnEvent (ievent, ret, ProcessEventInfo);
00070     ret = m_OpenButton->OnEvent (ievent, ret, ProcessEventInfo);
00071     ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
00072     return ret;
00073   }
00074 
00075   void FileSelector::Draw (GraphicsEngine &GfxContext, bool force_draw)
00076   {
00077     Geometry base = GetGeometry();
00078 
00079     GetPainter().PaintBackground (GfxContext, base);
00080 
00081     if (m_OpenButton->IsMouseInside() )
00082     {
00083 
00084       GetPainter().PaintShapeCorner (GfxContext, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_MOUSEOVER_COLOR, eSHAPE_CORNER_ROUND4,
00085                                  eCornerTopRight | eCornerBottomRight, false);
00086     }
00087     else
00088     {
00089       GetPainter().PaintShapeCorner (GfxContext, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_COLOR, eSHAPE_CORNER_ROUND4,
00090                                  eCornerTopRight | eCornerBottomRight, false);
00091     }
00092 
00093     GeometryPositioning gp (eHACenter, eVACenter);
00094     Geometry TextureGeo = Geometry (0, 0, m_Texture->GetWidth(), m_Texture->GetHeight() );
00095     Geometry GeoPo = ComputeGeometryPositioning (m_OpenButton->GetGeometry(), TextureGeo, gp);
00096 
00097     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend (TRUE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00098     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetColorMask (TRUE, TRUE, TRUE, FALSE);
00099 
00100     nux::TexCoordXForm texxform;
00101     GfxContext.QRP_1Tex (GeoPo.x, GeoPo.y, GeoPo.width, GeoPo.height, m_Texture->GetDeviceTexture(), texxform, nux::color::White);
00102 
00103     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetColorMask (TRUE, TRUE, TRUE, TRUE);
00104     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend (FALSE);
00105 
00106     m_FileEditTextBox->QueueDraw();
00107   }
00108 
00109   void FileSelector::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00110   {
00111     Geometry base = GetGeometry();
00112 
00113     m_FileEditTextBox->ProcessDraw (GfxContext, force_draw);
00114   }
00115 
00116   void FileSelector::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00117   {
00118 
00119   }
00120 
00121   void FileSelector::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
00122   {
00123     QueueDraw();
00124   }
00125 
00126   void FileSelector::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
00127   {
00128 
00129     QueueDraw();
00130   }
00131 
00132   void FileSelector::RecvOpenButtonClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
00133   {
00134     QueueDraw();
00135     sigClick.emit();
00136   }
00137 
00138 
00139 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends