diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 307caf84..afb5f9ed 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -40,29 +40,21 @@ void FButton::init() click_animation = true; 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() ) this->flags = FOCUS; if ( isEnabled() ) - { this->flags |= ACTIVE; - 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 // inactive - { - foregroundColor = wc.button_inactive_fg; - backgroundColor = wc.button_inactive_bg; - } + updateButtonColor(); } //---------------------------------------------------------------------- @@ -110,7 +102,6 @@ void FButton::draw() FString txt; int d, i, j, x, mono_offset, margin; int length, hotkeypos, hotkey_offset, space; - int button_fg, button_bg; bool isActiveFocus, isActive, isFocus, isFlat; bool isNonFlatShadow, isNoUnderline; @@ -190,9 +181,6 @@ void FButton::draw() else margin = 0; - button_fg = foregroundColor; - button_bg = backgroundColor; - if ( isMonochron() && (isActive || isFocus) ) setReverse(true); @@ -272,11 +260,12 @@ void FButton::draw() if ( isMonochron() && isActiveFocus ) setBold(); + for (int z=0; x < i+length && z < width; z++,x++) { if ( (z == hotkeypos) && isActive ) { - setColor (wc.button_hotkey_fg, button_bg); + setColor (button_hotkey_fg, button_bg); if ( ! isNoUnderline ) setUnderline(); print ( ButtonText[z] ); @@ -289,8 +278,10 @@ void FButton::draw() print ( ButtonText[z] ); } } + if ( isMonochron() && isActiveFocus ) unsetBold(); + for (x=i+length; x < width-1; x++) 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() { @@ -344,6 +358,58 @@ void FButton::processClick() // 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() { @@ -389,24 +455,13 @@ bool FButton::setEnable(bool on) { this->flags |= ACTIVE; 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 { this->flags &= ~ACTIVE; delAccelerator (this); - foregroundColor = wc.button_inactive_fg; - backgroundColor = wc.button_inactive_bg; } + updateButtonColor(); return on; } @@ -421,8 +476,6 @@ bool FButton::setFocus(bool on) if ( isEnabled() ) { - foregroundColor = wc.button_active_focus_fg; - backgroundColor = wc.button_active_focus_bg; if ( statusBar() ) { FString msg = getStatusbarMessage(); @@ -436,14 +489,10 @@ bool FButton::setFocus(bool on) { this->flags &= ~FOCUS; - if ( isEnabled() ) - { - foregroundColor = wc.button_active_fg; - backgroundColor = wc.button_active_bg; - if ( statusBar() ) - statusBar()->clearMessage(); - } + if ( isEnabled() && statusBar() ) + statusBar()->clearMessage(); } + updateButtonColor(); return on; } diff --git a/src/fbutton.h b/src/fbutton.h index c636fcaf..680121a0 100644 --- a/src/fbutton.h +++ b/src/fbutton.h @@ -20,15 +20,23 @@ class FButton : public FWidget FString text; bool button_down; 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: FButton (const FButton&); FButton& operator = (const FButton&); - void init(); - uChar getHotkey(); - void setHotkeyAccelerator(); - void draw(); - void processClick(); + void init(); + uChar getHotkey(); + void setHotkeyAccelerator(); + void draw(); + void updateButtonColor(); + void processClick(); friend class FDialog; public: @@ -36,48 +44,54 @@ class FButton : public FWidget FButton (const FString&, FWidget* parent=0); // constructor 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 onMouseDown (FMouseEvent*); + void onMouseUp (FMouseEvent*); + void onMouseMove (FMouseEvent*); + void onAccel (FAccelEvent*); + void onFocusIn (FFocusEvent*); + void onFocusOut (FFocusEvent*); - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onAccel (FAccelEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + bool setNoUnderline(bool); + bool setNoUnderline(); + bool unsetNoUnderline(); - bool setNoUnderline(bool); - bool setNoUnderline(); - bool unsetNoUnderline(); + bool setEnable(bool); + bool setEnable(); + bool unsetEnable(); + bool setDisable(); + bool setFocus(bool); + bool setFocus(); + bool unsetFocus(); + bool setFlat(bool); + bool setFlat(); + bool unsetFlat(); + bool isFlat() const; + bool setShadow(bool); + bool setShadow(); + bool unsetShadow(); + bool hasShadow() const; + bool setDown(bool); + bool setDown(); + bool setUp(); + bool isDown() const; + bool setClickAnimation(bool); + bool setClickAnimation(); + bool unsetClickAnimation(); + bool hasClickAnimation(); - bool setEnable(bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); - bool setFocus(bool); - bool setFocus(); - bool unsetFocus(); - bool setFlat(bool); - bool setFlat(); - bool unsetFlat(); - bool isFlat() const; - bool setShadow(bool); - bool setShadow(); - bool unsetShadow(); - bool hasShadow() const; - bool setDown(bool); - bool setDown(); - bool setUp(); - bool isDown() const; - bool setClickAnimation(bool); - bool setClickAnimation(); - bool unsetClickAnimation(); - bool hasClickAnimation(); - - void setText (const FString&); - FString& getText(); + void setText (const FString&); + FString& getText(); }; #pragma pack(pop)