finalcut/src/fswitch.cpp

171 lines
4.0 KiB
C++
Raw Normal View History

2015-07-04 22:51:47 +02:00
// fswitch.cpp
// class FSwitch
#include "fswitch.h"
//----------------------------------------------------------------------
// class FSwitch
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FSwitch::FSwitch(FWidget* parent) : FToggleButton(parent)
{
switch_offset_pos = 0;
init();
2015-07-04 22:51:47 +02:00
}
//----------------------------------------------------------------------
FSwitch::FSwitch ( const FString& txt,
FWidget* parent ) : FToggleButton(txt, parent)
{
switch_offset_pos = int(txt.getLength()) + 1;
init();
2015-07-04 22:51:47 +02:00
}
//----------------------------------------------------------------------
FSwitch::~FSwitch() // destructor
{
}
// private methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::init()
{
button_width = 11;
button_pressed = false;
}
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
{
2015-07-09 23:29:51 +02:00
if ( isMonochron() || getMaxColor() < 16 )
{
wcsncpy ( on, L" <On>", 6);
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);
print (on);
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);
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-07-09 23:29:51 +02:00
print (on);
if ( hasFocus() && ! button_pressed )
2015-07-09 23:29:51 +02:00
{
if ( isMonochron() || getMaxColor() < 16 )
{
wcsncpy ( off, L"<Off>", 6);
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);
print (off);
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();
}