18
18
* Authored by: Gordon Allott <gord.allott@canonical.com>
24
#include <NuxCore/Logger.h>
26
22
#include "DashStyle.h"
27
23
#include "FilterBasicButton.h"
31
nux::logging::Logger logger("unity.dash.FilterBasicButton");
36
FilterBasicButton::FilterBasicButton (nux::TextureArea *image, NUX_FILE_LINE_DECL)
37
: nux::ToggleButton (image, NUX_FILE_LINE_PARAM)
45
FilterBasicButton::FilterBasicButton (const std::string label, NUX_FILE_LINE_DECL)
46
: nux::ToggleButton (NUX_FILE_LINE_PARAM)
55
FilterBasicButton::FilterBasicButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_DECL)
56
: nux::ToggleButton (image, NUX_FILE_LINE_PARAM)
65
FilterBasicButton::FilterBasicButton (NUX_FILE_LINE_DECL)
66
: nux::ToggleButton (NUX_FILE_LINE_PARAM)
74
FilterBasicButton::~FilterBasicButton() {
81
void FilterBasicButton::InitTheme()
83
if (prelight_ == NULL)
85
prelight_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
86
active_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED));
87
normal_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL));
90
// SetMinimumHeight(32);
93
void FilterBasicButton::RedrawTheme (nux::Geometry const& geom, cairo_t *cr, nux::ButtonVisualState faked_state)
95
dash::Style::Instance().Button(cr, faked_state, label_);
98
long FilterBasicButton::ComputeContentSize ()
100
long ret = nux::Button::ComputeContentSize();
101
if (cached_geometry_ != GetGeometry())
103
nux::Geometry geo = GetGeometry();
104
prelight_->Invalidate(geo);
105
active_->Invalidate(geo);
106
normal_->Invalidate(geo);
109
cached_geometry_ = GetGeometry();
113
void FilterBasicButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
114
gPainter.PaintBackground(GfxContext, GetGeometry());
115
// set up our texture mode
116
nux::TexCoordXForm texxform;
117
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
118
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
120
// clear what is behind us
121
unsigned int alpha = 0, src = 0, dest = 0;
122
GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
123
GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
125
nux::Color col = nux::color::Black;
127
GfxContext.QRP_Color(GetGeometry().x,
130
GetGeometry().height,
133
nux::BaseTexture *texture = normal_->GetTexture();
135
texture = active_->GetTexture();
136
else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
137
texture = prelight_->GetTexture();
138
else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
140
texture = active_->GetTexture();
143
GfxContext.QRP_1Tex(GetGeometry().x,
146
GetGeometry().height,
147
texture->GetDeviceTexture(),
149
nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
151
GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
154
void FilterBasicButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
157
void FilterBasicButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
158
nux::Button::PostDraw(GfxContext, force_draw);
27
const int kMinButtonHeight = 30;
28
const int kMinButtonWidth = 48;
36
FilterBasicButton::FilterBasicButton(nux::TextureArea* image, NUX_FILE_LINE_DECL)
37
: nux::ToggleButton(image, NUX_FILE_LINE_PARAM)
42
FilterBasicButton::FilterBasicButton(std::string const& label, NUX_FILE_LINE_DECL)
43
: nux::ToggleButton(NUX_FILE_LINE_PARAM)
49
FilterBasicButton::FilterBasicButton(std::string const& label, nux::TextureArea* image, NUX_FILE_LINE_DECL)
50
: nux::ToggleButton(image, NUX_FILE_LINE_PARAM)
56
FilterBasicButton::FilterBasicButton(NUX_FILE_LINE_DECL)
57
: nux::ToggleButton(NUX_FILE_LINE_PARAM)
62
FilterBasicButton::~FilterBasicButton()
66
void FilterBasicButton::Init()
69
SetAcceptKeyNavFocusOnMouseDown(false);
72
void FilterBasicButton::InitTheme()
76
nux::Geometry const& geo = GetGeometry();
78
prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
79
active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
80
normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
83
SetMinimumHeight(kMinButtonHeight);
84
SetMinimumWidth(kMinButtonWidth);
87
void FilterBasicButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
89
Style::Instance().Button(cr, faked_state, label_);
92
long FilterBasicButton::ComputeContentSize()
94
long ret = nux::Button::ComputeContentSize();
96
nux::Geometry const& geo = GetGeometry();
98
if (cached_geometry_ != geo)
100
prelight_->Invalidate(geo);
101
active_->Invalidate(geo);
102
normal_->Invalidate(geo);
104
cached_geometry_ = geo;
110
void FilterBasicButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
112
nux::Geometry const& geo = GetGeometry();
114
gPainter.PaintBackground(GfxContext, geo);
115
// set up our texture mode
116
nux::TexCoordXForm texxform;
117
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
118
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
120
// clear what is behind us
121
unsigned int alpha = 0, src = 0, dest = 0;
122
GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
123
GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
125
nux::Color col = nux::color::Black;
127
GfxContext.QRP_Color(geo.x,
133
nux::BaseTexture* texture = normal_->GetTexture();
135
texture = active_->GetTexture();
136
else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
137
texture = prelight_->GetTexture();
138
else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
139
texture = active_->GetTexture();
141
GfxContext.QRP_1Tex(geo.x,
145
texture->GetDeviceTexture(),
147
nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
149
GfxContext.GetRenderStates().SetBlend(alpha, src, dest);