~om26er/ubuntu/oneiric/nux/sru-819721

« back to all changes in this revision

Viewing changes to Nux/AbstractComboBox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "Nux.h"
 
24
#include "AbstractComboBox.h"
 
25
#include "HLayout.h"
 
26
 
 
27
namespace nux
 
28
{
 
29
 
 
30
  Color AbstractComboBox::m_sCOMBO_COLOR = Color (0xFF9F9F9F);
 
31
  Color AbstractComboBox::m_sCOMBO_BUTTON_COLOR = Color (0xFF4D4D4D);
 
32
  Color AbstractComboBox::m_sCOMBO_MOUSEOVER_COLOR = Color (0xFF222222);
 
33
 
 
34
  AbstractComboBox::AbstractComboBox (NUX_FILE_LINE_DECL)
 
35
    :   View (NUX_FILE_LINE_PARAM)
 
36
    ,   m_MenuIsActive (false)
 
37
  {
 
38
    InitializeLayout();
 
39
    InitializeWidgets();
 
40
  }
 
41
 
 
42
  AbstractComboBox::~AbstractComboBox()
 
43
  {
 
44
    DestroyLayout();
 
45
  }
 
46
 
 
47
  void AbstractComboBox::InitializeWidgets()
 
48
  {
 
49
    m_hlayout->AddView (m_ComboArea, 1);
 
50
    m_hlayout->AddView (m_Button, 0);
 
51
    m_hlayout->SetHorizontalExternalMargin (0);
 
52
    m_hlayout->SetVerticalExternalMargin (0);
 
53
    SetCompositionLayout (m_hlayout);
 
54
 
 
55
    m_ComboArea->OnMouseEnter.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseEnter) );
 
56
    m_ComboArea->OnMouseLeave.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseLeave) );
 
57
 
 
58
    m_Button->OnMouseEnter.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseEnter) );
 
59
    m_Button->OnMouseLeave.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseLeave) );
 
60
 
 
61
    SetTextColor (Color::Black);
 
62
  }
 
63
 
 
64
  void AbstractComboBox::InitializeLayout()
 
65
  {
 
66
    m_hlayout   = new HLayout();
 
67
    m_ComboArea = new CoreArea();
 
68
    m_Button    = new CoreArea();
 
69
  }
 
70
 
 
71
  void AbstractComboBox::DestroyLayout()
 
72
  {
 
73
  }
 
74
 
 
75
  void AbstractComboBox::Draw (GraphicsEngine &GfxContext, bool force_draw)
 
76
  {
 
77
    Geometry base = GetGeometry();
 
78
    GetPainter().PaintBackground (GfxContext, base);
 
79
    GetPainter().PaintShape (GfxContext, base, m_sCOMBO_COLOR,  eSHAPE_CORNER_ROUND4);
 
80
    GetPainter().PaintTextLineStatic (GfxContext, GetFont(), m_ComboArea->GetGeometry(), m_ComboArea->GetBaseString().GetTCharPtr(), GetTextColor(), eAlignTextLeft);
 
81
    Geometry button_geo = m_Button->GetGeometry();
 
82
    button_geo.OffsetSize (-5, -2);
 
83
    button_geo.OffsetPosition (+4, +1);
 
84
 
 
85
    if (m_ComboArea->IsMouseInside() || m_Button->IsMouseInside() )
 
86
      GetPainter().PaintShape (GfxContext, button_geo, m_sCOMBO_MOUSEOVER_COLOR,  eSHAPE_CORNER_ROUND4);
 
87
    else
 
88
      GetPainter().PaintShape (GfxContext, button_geo, m_sCOMBO_BUTTON_COLOR,  eSHAPE_CORNER_ROUND4);
 
89
 
 
90
    GeometryPositioning gp (eHACenter, eVACenter);
 
91
    Geometry GeoPo = ComputeGeometryPositioning (button_geo, GetTheme().GetImageGeometry (eCOMBOBOX_OPEN_BUTTON), gp);
 
92
    GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eCOMBOBOX_OPEN_BUTTON);
 
93
 
 
94
    Geometry popup_geometry;
 
95
    popup_geometry.SetX (m_ComboArea->GetBaseX() );
 
96
    popup_geometry.SetY (m_ComboArea->GetBaseY() + m_ComboArea->GetBaseHeight() );
 
97
    popup_geometry.SetWidth (m_ComboArea->GetBaseWidth() );
 
98
    popup_geometry.SetHeight (m_ComboArea->GetBaseHeight() );
 
99
  }
 
100
 
 
101
  void AbstractComboBox::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
 
102
  {
 
103
    GfxContext.PushClippingRectangle (GetGeometry() );
 
104
 
 
105
    GfxContext.PopClippingRectangle();
 
106
  }
 
107
 
 
108
  void AbstractComboBox::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
 
109
  {
 
110
 
 
111
  }
 
112
 
 
113
  void AbstractComboBox::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
114
  {
 
115
    NeedRedraw();
 
116
  }
 
117
 
 
118
  void AbstractComboBox::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
119
  {
 
120
    NeedRedraw();
 
121
  }
 
122
 
 
123
 
 
124
 
 
125
}