Add the possibility to change the colors from FButton

This commit is contained in:
Markus Gans 2015-06-19 19:53:30 +02:00
parent 749e8914c2
commit 3d9a08dbba
2 changed files with 149 additions and 86 deletions

View File

@ -40,29 +40,21 @@ void FButton::init()
click_animation = true; click_animation = true;
this->text = ""; this->text = "";
setForegroundColor (wc.button_active_fg);
setBackgroundColor (wc.button_active_bg);
setHotkeyForegroundColor (wc.button_hotkey_fg);
setFocusForegroundColor (wc.button_active_focus_fg);
setFocusBackgroundColor (wc.button_active_focus_bg);
setInactiveForegroundColor (wc.button_inactive_fg);
setInactiveBackgroundColor (wc.button_inactive_bg);
if ( hasFocus() ) if ( hasFocus() )
this->flags = FOCUS; this->flags = FOCUS;
if ( isEnabled() ) if ( isEnabled() )
{
this->flags |= ACTIVE; this->flags |= ACTIVE;
if ( hasFocus() ) updateButtonColor();
{
foregroundColor = wc.button_active_focus_fg;
backgroundColor = wc.button_active_focus_bg;
}
else
{
foregroundColor = wc.button_active_fg;
backgroundColor = wc.button_active_bg;
}
}
else // inactive
{
foregroundColor = wc.button_inactive_fg;
backgroundColor = wc.button_inactive_bg;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -110,7 +102,6 @@ void FButton::draw()
FString txt; FString txt;
int d, i, j, x, mono_offset, margin; int d, i, j, x, mono_offset, margin;
int length, hotkeypos, hotkey_offset, space; int length, hotkeypos, hotkey_offset, space;
int button_fg, button_bg;
bool isActiveFocus, isActive, isFocus, isFlat; bool isActiveFocus, isActive, isFocus, isFlat;
bool isNonFlatShadow, isNoUnderline; bool isNonFlatShadow, isNoUnderline;
@ -190,9 +181,6 @@ void FButton::draw()
else else
margin = 0; margin = 0;
button_fg = foregroundColor;
button_bg = backgroundColor;
if ( isMonochron() && (isActive || isFocus) ) if ( isMonochron() && (isActive || isFocus) )
setReverse(true); setReverse(true);
@ -272,11 +260,12 @@ void FButton::draw()
if ( isMonochron() && isActiveFocus ) if ( isMonochron() && isActiveFocus )
setBold(); setBold();
for (int z=0; x < i+length && z < width; z++,x++) for (int z=0; x < i+length && z < width; z++,x++)
{ {
if ( (z == hotkeypos) && isActive ) if ( (z == hotkeypos) && isActive )
{ {
setColor (wc.button_hotkey_fg, button_bg); setColor (button_hotkey_fg, button_bg);
if ( ! isNoUnderline ) if ( ! isNoUnderline )
setUnderline(); setUnderline();
print ( ButtonText[z] ); print ( ButtonText[z] );
@ -289,8 +278,10 @@ void FButton::draw()
print ( ButtonText[z] ); print ( ButtonText[z] );
} }
} }
if ( isMonochron() && isActiveFocus ) if ( isMonochron() && isActiveFocus )
unsetBold(); unsetBold();
for (x=i+length; x < width-1; x++) for (x=i+length; x < width-1; x++)
print (space); // █ print (space); // █
@ -336,6 +327,29 @@ void FButton::draw()
} }
} }
//----------------------------------------------------------------------
void FButton::updateButtonColor()
{
if ( isEnabled() )
{
if ( hasFocus() )
{
button_fg = button_focus_fg;
button_bg = button_focus_bg;
}
else
{
button_fg = foregroundColor;
button_bg = backgroundColor;
}
}
else // inactive
{
button_fg = button_inactive_fg;
button_bg = button_inactive_bg;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::processClick() void FButton::processClick()
{ {
@ -344,6 +358,58 @@ void FButton::processClick()
// public methods of FButton // public methods of FButton
//----------------------------------------------------------------------
void FButton::setForegroundColor (int color)
{
FWidget::setForegroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setBackgroundColor (int color)
{
FWidget::setBackgroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setHotkeyForegroundColor (int color)
{
if ( color >> 8 == 0 ) // valid colors 0..254
button_hotkey_fg = color;
}
void FButton::setFocusForegroundColor (int color)
{
if ( color >> 8 == 0 ) // valid colors 0..254
button_focus_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setFocusBackgroundColor (int color)
{
if ( color >> 8 == 0 ) // valid colors 0..254
button_focus_bg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveForegroundColor (int color)
{
if ( color >> 8 == 0 ) // valid colors 0..254
button_inactive_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveBackgroundColor (int color)
{
if ( color >> 8 == 0 ) // valid colors 0..254
button_inactive_bg = color;
updateButtonColor();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::hide() void FButton::hide()
{ {
@ -389,24 +455,13 @@ bool FButton::setEnable(bool on)
{ {
this->flags |= ACTIVE; this->flags |= ACTIVE;
setHotkeyAccelerator(); setHotkeyAccelerator();
if ( hasFocus() )
{
foregroundColor = wc.button_active_focus_fg;
backgroundColor = wc.button_active_focus_bg;
}
else
{
foregroundColor = wc.button_active_fg;
backgroundColor = wc.button_active_bg;
}
} }
else else
{ {
this->flags &= ~ACTIVE; this->flags &= ~ACTIVE;
delAccelerator (this); delAccelerator (this);
foregroundColor = wc.button_inactive_fg;
backgroundColor = wc.button_inactive_bg;
} }
updateButtonColor();
return on; return on;
} }
@ -421,8 +476,6 @@ bool FButton::setFocus(bool on)
if ( isEnabled() ) if ( isEnabled() )
{ {
foregroundColor = wc.button_active_focus_fg;
backgroundColor = wc.button_active_focus_bg;
if ( statusBar() ) if ( statusBar() )
{ {
FString msg = getStatusbarMessage(); FString msg = getStatusbarMessage();
@ -436,14 +489,10 @@ bool FButton::setFocus(bool on)
{ {
this->flags &= ~FOCUS; this->flags &= ~FOCUS;
if ( isEnabled() ) if ( isEnabled() && statusBar() )
{
foregroundColor = wc.button_active_fg;
backgroundColor = wc.button_active_bg;
if ( statusBar() )
statusBar()->clearMessage(); statusBar()->clearMessage();
} }
} updateButtonColor();
return on; return on;
} }

View File

@ -20,6 +20,13 @@ class FButton : public FWidget
FString text; FString text;
bool button_down; bool button_down;
bool click_animation; bool click_animation;
int button_fg;
int button_bg;
int button_hotkey_fg;
int button_focus_fg;
int button_focus_bg;
int button_inactive_fg;
int button_inactive_bg;
private: private:
FButton (const FButton&); FButton (const FButton&);
@ -28,6 +35,7 @@ class FButton : public FWidget
uChar getHotkey(); uChar getHotkey();
void setHotkeyAccelerator(); void setHotkeyAccelerator();
void draw(); void draw();
void updateButtonColor();
void processClick(); void processClick();
friend class FDialog; friend class FDialog;
@ -37,7 +45,13 @@ class FButton : public FWidget
virtual ~FButton(); // destructor virtual ~FButton(); // destructor
const char* getClassName() const; const char* getClassName() const;
void setForegroundColor (int);
void setBackgroundColor (int);
void setHotkeyForegroundColor (int);
void setFocusForegroundColor (int);
void setFocusBackgroundColor (int);
void setInactiveForegroundColor (int);
void setInactiveBackgroundColor (int);
void hide(); void hide();
void onKeyPress (FKeyEvent*); void onKeyPress (FKeyEvent*);