~karl-qdh/nux/nux.gtkentry-wrapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#include "Nux.h"
#include "FileSelector.h"

#include "EditTextBox.h"
#include "HLayout.h"
#include "Button.h"

namespace nux
{

  Color FILESELECTOR_BUTTON_COLOR = Color (0xFF4D4D4D);
  Color FILESELECTOR_BUTTON_MOUSEOVER_COLOR = Color (0xFF222222);

  FileSelector::FileSelector (NUX_FILE_LINE_DECL)
    :   View (NUX_FILE_LINE_PARAM)
  {
    m_hlayout           = new HLayout (TEXT (""), NUX_TRACKER_LOCATION);
    m_OpenButton        = new Button (TEXT (""), NUX_TRACKER_LOCATION);
    m_FileEditTextBox   = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);

    m_hlayout->AddView (m_FileEditTextBox, 1, eCenter);
    m_hlayout->AddView (m_OpenButton, 0, eCenter);

    //m_OpenButton->setCaption(TEXT("..."));
    m_OpenButton->SetMinimumWidth (20);

    m_OpenButton->OnMouseEnter.connect (sigc::mem_fun (this, &FileSelector::RecvMouseEnter) );
    m_OpenButton->OnMouseLeave.connect (sigc::mem_fun (this, &FileSelector::RecvMouseLeave) );
    m_OpenButton->OnMouseClick.connect (sigc::mem_fun (this, &FileSelector::RecvOpenButtonClick) );

    SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
    SetCompositionLayout (m_hlayout);

    NString Path = NUX_FINDRESOURCELOCATION (TEXT ("Icons/Folder-16x16.png") );
    m_Texture = GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
    m_Texture->Update (Path.GetTCharPtr() );
  }

  FileSelector::~FileSelector()
  {
    m_Texture->UnReference ();
  }

  long FileSelector::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
  {
    long ret = TraverseInfo;
    ret = m_FileEditTextBox->OnEvent (ievent, ret, ProcessEventInfo);
    ret = m_OpenButton->OnEvent (ievent, ret, ProcessEventInfo);
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
    return ret;
  }

  void FileSelector::Draw (GraphicsEngine &GfxContext, bool force_draw)
  {
    Geometry base = GetGeometry();

    GetPainter().PaintBackground (GfxContext, base);

    if (m_OpenButton->IsMouseInside() )
    {

      GetPainter().PaintShapeCorner (GfxContext, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_MOUSEOVER_COLOR, eSHAPE_CORNER_ROUND4,
                                 eCornerTopRight | eCornerBottomRight, false);
    }
    else
    {
      GetPainter().PaintShapeCorner (GfxContext, m_OpenButton->GetGeometry(), FILESELECTOR_BUTTON_COLOR, eSHAPE_CORNER_ROUND4,
                                 eCornerTopRight | eCornerBottomRight, false);
    }

    GeometryPositioning gp (eHACenter, eVACenter);
    Geometry TextureGeo = Geometry (0, 0, m_Texture->GetWidth(), m_Texture->GetHeight() );
    Geometry GeoPo = ComputeGeometryPositioning (m_OpenButton->GetGeometry(), TextureGeo, gp);

    GetThreadGraphicsContext()->GetRenderStates().SetBlend (TRUE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    GetThreadGraphicsContext()->GetRenderStates().SetColorMask (TRUE, TRUE, TRUE, FALSE);

    nux::TexCoordXForm texxform;
    GfxContext.QRP_GLSL_1Tex (GeoPo.x, GeoPo.y, GeoPo.width, GeoPo.height, m_Texture->GetDeviceTexture(), texxform, nux::Color::White);

    GetThreadGraphicsContext()->GetRenderStates().SetColorMask (TRUE, TRUE, TRUE, TRUE);
    GetThreadGraphicsContext()->GetRenderStates().SetBlend (FALSE);

    m_FileEditTextBox->NeedRedraw();
  }

  void FileSelector::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
  {
    Geometry base = GetGeometry();

    m_FileEditTextBox->ProcessDraw (GfxContext, force_draw);
  }

  void FileSelector::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
  {

  }

  void FileSelector::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
  }

  void FileSelector::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {

    NeedRedraw();
  }

  void FileSelector::RecvOpenButtonClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
    sigClick.emit();
  }


}