Back to index

nux  3.0.0
FileSelector.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 "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("", NUX_TRACKER_LOCATION);
00041     m_FileEditTextBox   = new EditTextBox("", 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("...");
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("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   void FileSelector::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00067   {
00068     Geometry base = GetGeometry();
00069 
00070     GetPainter().PaintBackground(graphics_engine, base);
00071 
00072     if (m_OpenButton->IsMouseInside())
00073     {
00074 
00075       GetPainter().PaintShapeCorner(graphics_engine, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_MOUSEOVER_COLOR, eSHAPE_CORNER_ROUND4,
00076                                  eCornerTopRight | eCornerBottomRight, false);
00077     }
00078     else
00079     {
00080       GetPainter().PaintShapeCorner(graphics_engine, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_COLOR, eSHAPE_CORNER_ROUND4,
00081                                  eCornerTopRight | eCornerBottomRight, false);
00082     }
00083 
00084     GeometryPositioning gp(eHACenter, eVACenter);
00085     Geometry TextureGeo = Geometry(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight());
00086     Geometry GeoPo = ComputeGeometryPositioning(m_OpenButton->GetGeometry(), TextureGeo, gp);
00087 
00088     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend(TRUE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00089     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetColorMask(TRUE, TRUE, TRUE, FALSE);
00090 
00091     nux::TexCoordXForm texxform;
00092     graphics_engine.QRP_1Tex(GeoPo.x, GeoPo.y, GeoPo.width, GeoPo.height, m_Texture->GetDeviceTexture(), texxform, nux::color::White);
00093 
00094     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetColorMask(TRUE, TRUE, TRUE, TRUE);
00095     GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend(FALSE);
00096 
00097     m_FileEditTextBox->QueueDraw();
00098   }
00099 
00100   void FileSelector::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00101   {
00102     Geometry base = GetGeometry();
00103 
00104     m_FileEditTextBox->ProcessDraw(graphics_engine, force_draw);
00105   }
00106 
00107   void FileSelector::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00108   {
00109 
00110   }
00111 
00112   void FileSelector::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
00113   {
00114     QueueDraw();
00115   }
00116 
00117   void FileSelector::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
00118   {
00119 
00120     QueueDraw();
00121   }
00122 
00123   void FileSelector::RecvOpenButtonClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
00124   {
00125     QueueDraw();
00126     sigClick.emit();
00127   }
00128 
00129 
00130 }