~jaytaoko/unity/unity.coverflow.fix

« back to all changes in this revision

Viewing changes to dash/FilterBar.cpp

  • Committer: Jay Taoko
  • Date: 2012-06-14 18:07:29 UTC
  • mfrom: (1897.2.513 unity)
  • Revision ID: jay.taoko@canonical.com-20120614180729-mk56rx7i432uteok
Fixing Coverflow

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <Nux/VLayout.h>
24
24
#include <NuxCore/Logger.h>
25
25
 
 
26
#include "unity-shared/DashStyle.h"
26
27
#include "FilterBar.h"
27
28
#include "FilterExpanderLabel.h"
28
29
#include "FilterFactory.h"
36
37
 
37
38
nux::logging::Logger logger("unity.dash.filterbar");
38
39
 
39
 
const int SEPARATOR_LEFT_PADDING = 5;
40
 
const int SEPARATOR_WIDTH_SOTTRACTOR = 9;
41
 
 
42
40
}
43
41
 
44
42
NUX_IMPLEMENT_OBJECT_TYPE(FilterBar);
59
57
 
60
58
void FilterBar::Init()
61
59
{
 
60
  dash::Style& style = dash::Style::Instance();
 
61
 
62
62
  nux::LinearLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
63
 
  layout->SetSpaceBetweenChildren(10);
 
63
  layout->SetTopAndBottomPadding(style.GetFilterBarTopPadding() - style.GetFilterHighlightPadding());
 
64
  layout->SetSpaceBetweenChildren(style.GetSpaceBetweenFilterWidgets() - style.GetFilterHighlightPadding());
64
65
  SetLayout(layout);
65
66
}
66
67
 
81
82
  AddChild(filter_view);
82
83
  filter_map_[filter] = filter_view;
83
84
  GetLayout()->AddView(filter_view, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
 
85
 
 
86
  UpdateDrawSeparators();
84
87
}
85
88
 
86
89
void FilterBar::RemoveFilter(Filter::Ptr const& filter)
96
99
      break;
97
100
    }
98
101
  }
 
102
 
 
103
  UpdateDrawSeparators();
99
104
}
100
105
 
101
106
void FilterBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
112
117
  GfxContext.PushClippingRectangle(GetGeometry());
113
118
  GetLayout()->ProcessDraw(GfxContext, force_draw);
114
119
 
115
 
  nux::Color col(0.13f, 0.13f, 0.13f, 0.13f);
116
 
 
117
 
  std::list<Area *>& layout_list = GetLayout()->GetChildren();
118
 
  int i = 0;
119
 
  int num_separators = layout_list.size() - 1;
120
 
 
121
 
  for (auto iter : layout_list)
 
120
  GfxContext.PopClippingRectangle();
 
121
}
 
122
 
 
123
void FilterBar::UpdateDrawSeparators()
 
124
{
 
125
  std::list<Area*> children = GetLayout()->GetChildren();
 
126
  std::list<Area*>::reverse_iterator rit;
 
127
  bool found_one = false;
 
128
 
 
129
  for (rit = children.rbegin(); rit != children.rend(); ++rit)
122
130
  {
123
 
    if (i != num_separators)
124
 
    {
125
 
      nux::Area* filter_view = iter;
126
 
      nux::Geometry const& geom = filter_view->GetGeometry();
127
 
 
128
 
      unsigned int alpha = 0, src = 0, dest = 0;
129
 
      GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
130
 
 
131
 
      GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
132
 
      GfxContext.GetRenderStates().SetColorMask(true, true, true, false);
133
 
      nux::GetPainter().Draw2DLine(GfxContext,
134
 
                                   geom.x + SEPARATOR_LEFT_PADDING, geom.y + geom.height - 1,
135
 
                                   geom.x + geom.width - SEPARATOR_WIDTH_SOTTRACTOR, geom.y + geom.height - 1,
136
 
                                   col);
137
 
      GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
138
 
    }
139
 
    ++i;
 
131
    FilterExpanderLabel* widget = dynamic_cast<FilterExpanderLabel*>(*rit);
 
132
 
 
133
    if (!widget)
 
134
      continue;
 
135
 
 
136
    widget->draw_separator = found_one;
 
137
    found_one = true;
140
138
  }
141
 
 
142
 
  GfxContext.PopClippingRectangle();
143
139
}
144
140
 
 
141
//
 
142
// Key navigation
 
143
//
 
144
 
145
145
bool FilterBar::AcceptKeyNavFocus()
146
146
{
147
147
  return false;
157
157
 
158
158
void FilterBar::AddProperties(GVariantBuilder* builder)
159
159
{
 
160
  variant::BuilderWrapper(builder)
 
161
    .add("x", GetAbsoluteX())
 
162
    .add("y", GetAbsoluteY())
 
163
    .add("width", GetAbsoluteWidth())
 
164
    .add("height", GetAbsoluteHeight());
160
165
}
161
166
 
162
167
} // namespace dash