finalcut/src/fswitch.cpp

202 lines
4.4 KiB
C++
Raw Normal View History

// File: fswitch.cpp
// Provides: class FSwitch
2015-07-04 22:51:47 +02:00
#include "fswitch.h"
//----------------------------------------------------------------------
// class FSwitch
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FSwitch::FSwitch(FWidget* parent)
: FToggleButton(parent)
, switch_offset_pos(0)
, button_pressed(false)
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
}
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FSwitch::FSwitch ( const FString& txt, FWidget* parent )
: FToggleButton(txt, parent)
, switch_offset_pos(0)
, button_pressed(false)
2015-07-04 22:51:47 +02:00
{
switch_offset_pos = int(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
// private methods of FSwitch
//----------------------------------------------------------------------
2015-07-04 22:51:47 +02:00
void FSwitch::draw()
{
setUpdateVTerm(false);
drawLabel();
2015-07-06 10:50:46 +02:00
drawCheckButton();
2015-07-04 22:51:47 +02:00
setUpdateVTerm(true);
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;
2015-07-09 23:29:51 +02:00
wchar_t on[6] = L" On ";
wchar_t off[6] = L" Off ";
gotoxy (xpos+xmin-1+switch_offset_pos, ypos+ymin-1);
2015-07-04 22:51:47 +02:00
if ( checked )
{
if ( hasFocus() && ! button_pressed )
2015-07-09 23:29:51 +02:00
{
if ( isMonochron() )
2015-07-09 23:29:51 +02:00
{
wcsncpy ( on, L" <On>", 6);
2015-10-23 23:57:00 +02:00
setBold(true);
}
else if ( getMaxColor() < 16 )
{
setBold(true);
2015-07-09 23:29:51 +02:00
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
}
else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
}
2015-07-04 22:51:47 +02:00
else
2015-07-09 23:29:51 +02:00
if ( isMonochron() || getMaxColor() < 16 )
setColor (wc.button_active_focus_fg, wc.button_active_bg);
else
setColor (wc.button_hotkey_fg, wc.button_active_bg);
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
setReverse(false);
2015-07-09 23:29:51 +02:00
print (on);
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
setReverse(true);
2015-10-23 23:57:00 +02:00
if ( isMonochron() || getMaxColor() < 16 )
setBold(false);
2015-07-04 22:51:47 +02:00
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
2015-07-09 23:29:51 +02:00
print (off);
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
2015-10-10 04:01:22 +02:00
setCursorPos ( xpos + xmin + 1 + switch_offset_pos
, ypos + ymin - 1 );
2015-07-04 22:51:47 +02:00
}
else
{
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(true);
2015-07-09 23:29:51 +02:00
print (on);
if ( hasFocus() && ! button_pressed )
2015-07-09 23:29:51 +02:00
{
if ( isMonochron() )
2015-07-09 23:29:51 +02:00
{
wcsncpy ( off, L"<Off>", 6);
2015-10-23 23:57:00 +02:00
setBold(true);
}
else if ( getMaxColor() < 16 )
{
setBold(true);
2015-07-09 23:29:51 +02:00
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
}
else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
}
2015-07-04 22:51:47 +02:00
else
2015-07-09 23:29:51 +02:00
if ( isMonochron() || getMaxColor() < 16 )
setColor (wc.button_active_focus_fg, wc.button_active_bg);
else
setColor (wc.button_hotkey_fg, wc.button_active_bg);
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
setReverse(false);
2015-07-09 23:29:51 +02:00
print (off);
2015-10-11 21:56:16 +02:00
2015-10-23 23:57:00 +02:00
if ( isMonochron() || getMaxColor() < 16 )
setBold(false);
2015-10-10 04:01:22 +02:00
setCursorPos ( xpos + xmin + 5 + switch_offset_pos
, ypos + ymin - 1 );
2015-07-04 22:51:47 +02:00
}
}
// public methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::setText (FString txt)
{
FToggleButton::setText(txt);
switch_offset_pos = int(txt.getLength()) + 1;
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FSwitch::onKeyPress (FKeyEvent* ev)
2015-07-04 22:51:47 +02:00
{
2015-09-20 05:44:50 +02:00
switch ( ev->key() )
2015-07-04 22:51:47 +02:00
{
case fc::Fkey_home:
case fc::Fkey_left:
setChecked();
2015-09-20 05:44:50 +02:00
ev->accept();
2015-07-04 22:51:47 +02:00
break;
case fc::Fkey_end:
case fc::Fkey_right:
unsetChecked();
2015-09-20 05:44:50 +02:00
ev->accept();
break;
default:
2015-07-04 22:51:47 +02:00
break;
}
2015-09-20 05:44:50 +02:00
if ( ev->isAccepted() )
2015-07-04 22:51:47 +02:00
draw();
else
2015-09-20 05:44:50 +02:00
FToggleButton::onKeyPress(ev);
2015-07-04 22:51:47 +02:00
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FSwitch::onMouseDown (FMouseEvent* ev)
{
2015-09-20 05:44:50 +02:00
FToggleButton::onMouseDown(ev);
2015-09-20 05:44:50 +02:00
if ( ev->getButton() != LeftButton )
return;
button_pressed = true;
draw();
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FSwitch::onMouseUp (FMouseEvent* ev)
{
2015-09-20 05:44:50 +02:00
FToggleButton::onMouseUp(ev);
2015-09-20 05:44:50 +02:00
if ( ev->getButton() != LeftButton )
return;
button_pressed = false;
draw();
}