From f4f1629809a4ef3fb824bbe3cec9495b66b4828d Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 1 Jul 2015 22:34:40 +0200 Subject: [PATCH] Class FButton: use the object timer for the click animation --- src/fbutton.cpp | 19 +++++++++++++------ src/fbutton.h | 2 ++ test/calculator.cpp | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 7cf51e5f..5a6c3b70 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -28,6 +28,7 @@ FButton::FButton (const FString& txt, FWidget* parent) : FWidget(parent) FButton::~FButton() // destructor { delAccelerator (this); + delAllTimer(); } @@ -38,6 +39,7 @@ void FButton::init() flags = 0; button_down = false; click_animation = true; + click_time = 150; this->text = ""; setForegroundColor (wc.button_active_fg); @@ -545,8 +547,7 @@ void FButton::onKeyPress (FKeyEvent* event) if ( click_animation ) { setDown(); - usleep(150000); - setUp(); + addTimer(click_time); } processClick(); event->accept(); @@ -609,6 +610,14 @@ void FButton::onMouseMove (FMouseEvent* event) } } +//---------------------------------------------------------------------- +void FButton::onTimer (FTimerEvent* ev) +{ + //delAllTimer(); + delTimer(ev->timerId()); + setUp(); +} + //---------------------------------------------------------------------- void FButton::onAccel (FAccelEvent* event) { @@ -632,10 +641,8 @@ void FButton::onAccel (FAccelEvent* event) else if ( click_animation ) setDown(); if ( click_animation ) - { - usleep(150000); - setUp(); - } + addTimer(click_time); + processClick(); event->accept(); } diff --git a/src/fbutton.h b/src/fbutton.h index 680121a0..3eab424b 100644 --- a/src/fbutton.h +++ b/src/fbutton.h @@ -20,6 +20,7 @@ class FButton : public FWidget FString text; bool button_down; bool click_animation; + int click_time; int button_fg; int button_bg; int button_hotkey_fg; @@ -58,6 +59,7 @@ class FButton : public FWidget void onMouseDown (FMouseEvent*); void onMouseUp (FMouseEvent*); void onMouseMove (FMouseEvent*); + void onTimer (FTimerEvent*); void onAccel (FAccelEvent*); void onFocusIn (FFocusEvent*); void onFocusOut (FFocusEvent*); diff --git a/test/calculator.cpp b/test/calculator.cpp index d1e43f51..7cabee1d 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -244,9 +244,10 @@ Calc::Calc (FWidget* parent) : FDialog(parent) } btn->setFlat(); btn->setNoUnderline(); - btn->unsetClickAnimation(); btn->setText(button_text[key]); btn->setDoubleFlatLine(fc::top); + if ( isNewFont() ) + btn->unsetClickAnimation(); if ( key <= Three ) btn->setDoubleFlatLine(fc::bottom); @@ -273,7 +274,6 @@ Calc::Calc (FWidget* parent) : FDialog(parent) calculator_buttons[Change_sign]->addAccelerator('#'); calculator_buttons[Equals]->addAccelerator(fc::Fkey_return); calculator_buttons[Equals]->addAccelerator(fc::Fkey_enter); - } //----------------------------------------------------------------------