2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fswitch.cpp - Widget FSwitch *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-31 00:17:00 +01:00
|
|
|
* Copyright 2015-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-07-04 22:51:47 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fswitch.h"
|
2015-07-04 22:51:47 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-07-04 22:51:47 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FSwitch
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FSwitch::FSwitch(FWidget* parent)
|
|
|
|
: FToggleButton(parent)
|
2015-07-04 22:51:47 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
button_width = 11;
|
2015-07-04 22:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-24 04:50:47 +02:00
|
|
|
FSwitch::FSwitch (const FString& txt, FWidget* parent)
|
2015-09-22 04:18:20 +02:00
|
|
|
: FToggleButton(txt, parent)
|
2015-07-04 22:51:47 +02:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
switch_offset_pos = txt.getLength() + 1;
|
2015-09-22 04:18:20 +02:00
|
|
|
button_width = 11;
|
2015-07-04 22:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FSwitch::~FSwitch() // destructor
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-07-04 22:51:47 +02:00
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FSwitch
|
|
|
|
//----------------------------------------------------------------------
|
2017-04-08 02:40:22 +02:00
|
|
|
void FSwitch::setText (const FString& txt)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
FToggleButton::setText(txt);
|
2018-10-17 22:12:52 +02:00
|
|
|
switch_offset_pos = txt.getLength() + 1;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
switch ( ev->key() )
|
|
|
|
{
|
|
|
|
case fc::Fkey_home:
|
|
|
|
case fc::Fkey_left:
|
|
|
|
setChecked();
|
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
case fc::Fkey_right:
|
|
|
|
unsetChecked();
|
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ev->isAccepted() )
|
|
|
|
draw();
|
|
|
|
else
|
|
|
|
FToggleButton::onKeyPress(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::onMouseDown (FMouseEvent* ev)
|
|
|
|
{
|
|
|
|
FToggleButton::onMouseDown(ev);
|
|
|
|
|
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
|
|
|
return;
|
|
|
|
|
|
|
|
button_pressed = true;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::onMouseUp (FMouseEvent* ev)
|
|
|
|
{
|
|
|
|
FToggleButton::onMouseUp(ev);
|
|
|
|
|
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
|
|
|
return;
|
|
|
|
|
|
|
|
button_pressed = false;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-04 22:51:47 +02:00
|
|
|
// private methods of FSwitch
|
2015-07-06 23:15:34 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-07-04 22:51:47 +02:00
|
|
|
void FSwitch::draw()
|
|
|
|
{
|
|
|
|
drawLabel();
|
2015-07-06 10:50:46 +02:00
|
|
|
drawCheckButton();
|
2015-07-04 22:51:47 +02:00
|
|
|
FToggleButton::draw();
|
2015-07-06 10:50:46 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-07-04 22:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::drawCheckButton()
|
|
|
|
{
|
|
|
|
if ( ! isVisible() )
|
|
|
|
return;
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
setPrintPos (1 + int(switch_offset_pos), 1);
|
2015-07-04 22:51:47 +02:00
|
|
|
|
|
|
|
if ( checked )
|
2018-01-31 00:17:00 +01:00
|
|
|
drawChecked();
|
|
|
|
else
|
|
|
|
drawUnchecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::drawChecked()
|
|
|
|
{
|
|
|
|
wchar_t on[6] = L" On ";
|
|
|
|
wchar_t off[6] = L" Off ";
|
|
|
|
|
|
|
|
if ( hasFocus() && ! button_pressed )
|
2015-07-04 22:51:47 +02:00
|
|
|
{
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
2015-07-09 23:29:51 +02:00
|
|
|
{
|
2018-09-16 19:33:40 +02:00
|
|
|
std::wcsncpy (on, L" <On>", 6);
|
2018-01-31 00:17:00 +01:00
|
|
|
setBold(true);
|
2015-07-09 23:29:51 +02:00
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
else if ( getMaxColor() < 16 )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
2018-01-31 00:17:00 +01:00
|
|
|
setBold(true);
|
|
|
|
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
else
|
|
|
|
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( isMonochron() || getMaxColor() < 16 )
|
|
|
|
setColor (wc.button_active_focus_fg, wc.button_active_bg);
|
|
|
|
else
|
|
|
|
setColor (wc.button_hotkey_fg, wc.button_active_bg);
|
|
|
|
}
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
print (on);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2015-10-23 23:57:00 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() || getMaxColor() < 16 )
|
|
|
|
setBold(false);
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
|
|
|
|
print (off);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
setCursorPos (3 + int(switch_offset_pos), 1);
|
2018-01-31 00:17:00 +01:00
|
|
|
}
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FSwitch::drawUnchecked()
|
|
|
|
{
|
|
|
|
wchar_t on[6] = L" On ";
|
|
|
|
wchar_t off[6] = L" Off ";
|
|
|
|
|
|
|
|
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
print (on);
|
|
|
|
|
|
|
|
if ( hasFocus() && ! button_pressed )
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
2015-07-09 23:29:51 +02:00
|
|
|
{
|
2018-09-16 19:33:40 +02:00
|
|
|
std::wcsncpy (off, L"<Off>", 6);
|
2018-01-31 00:17:00 +01:00
|
|
|
setBold(true);
|
2015-07-09 23:29:51 +02:00
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
else if ( getMaxColor() < 16 )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
2018-01-31 00:17:00 +01:00
|
|
|
setBold(true);
|
|
|
|
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
else
|
|
|
|
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( isMonochron() || getMaxColor() < 16 )
|
|
|
|
setColor (wc.button_active_focus_fg, wc.button_active_bg);
|
|
|
|
else
|
|
|
|
setColor (wc.button_hotkey_fg, wc.button_active_bg);
|
|
|
|
}
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
print (off);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
if ( isMonochron() || getMaxColor() < 16 )
|
|
|
|
setBold(false);
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
setCursorPos (7 + int(switch_offset_pos), 1);
|
2015-07-04 22:51:47 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|