~vanvugt/unity/fix-865006

« back to all changes in this revision

Viewing changes to launcher/Decaymulator.cpp

  • Committer: Andrea Azzarone
  • Date: 2012-06-12 08:23:23 UTC
  • mfrom: (2400 unity)
  • mto: This revision was merged to the branch mainline in revision 2404.
  • Revision ID: azzaronea@gmail.com-20120612082323-zdw8jxwjcia8vi71
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
Decaymulator::Decaymulator()
26
26
{
27
 
  on_decay_handle = 0;
28
27
  value.changed.connect(sigc::mem_fun(this, &Decaymulator::OnValueChanged));
29
28
}
30
29
 
31
 
Decaymulator::~Decaymulator()
32
 
{
33
 
  if (on_decay_handle)
34
 
    g_source_remove(on_decay_handle);
35
 
}
36
 
 
37
30
void Decaymulator::OnValueChanged(int value)
38
31
{
39
 
  if (!on_decay_handle && value > 0)
 
32
  if (!decay_timer_ && value > 0)
40
33
  {
41
 
    on_decay_handle = g_timeout_add(10, &Decaymulator::OnDecayTimeout, this);
 
34
    decay_timer_.reset(new glib::Timeout(10, sigc::mem_fun(this, &Decaymulator::OnDecayTimeout)));
42
35
  }
43
36
}
44
37
 
45
 
gboolean Decaymulator::OnDecayTimeout(gpointer data)
 
38
bool Decaymulator::OnDecayTimeout()
46
39
{
47
 
  Decaymulator* self = (Decaymulator*) data;
48
 
 
49
 
  int partial_decay = self->rate_of_decay / 100;
50
 
 
51
 
  if (self->value <= partial_decay)
 
40
  int partial_decay = rate_of_decay / 100;
 
41
 
 
42
  if (value <= partial_decay)
52
43
  {
53
 
    self->value = 0;
54
 
    self->on_decay_handle = 0;
55
 
    return FALSE;
 
44
    value = 0;
 
45
    decay_timer_.reset();
 
46
    return false;
56
47
  }
57
48
 
58
 
  self->value = self->value - partial_decay;
59
 
  return TRUE;
 
49
  value = value - partial_decay;
 
50
  return true;
60
51
}
61
52
 
62
53
}