File indexing completed on 2024-04-06 12:11:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <algorithm>
0015 #include <cassert>
0016 #include "TGPicture.h"
0017 #include "TVirtualX.h"
0018
0019 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 FWCustomIconsButton::FWCustomIconsButton(const TGWindow* iParent,
0033 const TGPicture* iUpIcon,
0034 const TGPicture* iDownIcon,
0035 const TGPicture* iDisabledIcon,
0036 const TGPicture* iBelowMouseIcon,
0037 Int_t id,
0038 GContext_t norm,
0039 UInt_t option)
0040 : TGButton(iParent, id, norm, option),
0041 m_upIcon(iUpIcon),
0042 m_downIcon(iDownIcon),
0043 m_disabledIcon(iDisabledIcon),
0044 m_belowMouseIcon(iBelowMouseIcon),
0045 m_inside(false) {
0046 assert(nullptr != iUpIcon);
0047 assert(nullptr != iDownIcon);
0048 assert(nullptr != iDisabledIcon);
0049 gVirtualX->ShapeCombineMask(GetId(), 0, 0, iUpIcon->GetMask());
0050 SetBackgroundPixmap(iUpIcon->GetPicture());
0051 Resize(iUpIcon->GetWidth(), iUpIcon->GetHeight());
0052 fTWidth = iUpIcon->GetWidth();
0053 fTHeight = iUpIcon->GetHeight();
0054 }
0055
0056
0057
0058
0059
0060
0061 FWCustomIconsButton::~FWCustomIconsButton() {}
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 void FWCustomIconsButton::swapIcons(const TGPicture*& iUpIcon,
0079 const TGPicture*& iDownIcon,
0080 const TGPicture*& iDisabledIcon) {
0081 std::swap(iUpIcon, m_upIcon);
0082 std::swap(iDownIcon, m_downIcon);
0083 std::swap(iDisabledIcon, m_disabledIcon);
0084 gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
0085 fClient->NeedRedraw(this);
0086 }
0087
0088 void FWCustomIconsButton::setIcons(const TGPicture* iUpIcon,
0089 const TGPicture* iDownIcon,
0090 const TGPicture* iDisabledIcon,
0091 const TGPicture* iBelowMouseIcon) {
0092 m_upIcon = iUpIcon;
0093 m_downIcon = iDownIcon;
0094 m_disabledIcon = iDisabledIcon;
0095 m_belowMouseIcon = iBelowMouseIcon;
0096
0097 gVirtualX->ShapeCombineMask(GetId(), 0, 0, m_upIcon->GetMask());
0098 fClient->NeedRedraw(this);
0099 }
0100
0101
0102
0103
0104
0105
0106 bool FWCustomIconsButton::HandleCrossing(Event_t* event) {
0107 if (event->fType == kEnterNotify)
0108 m_inside = true;
0109 else if (event->fType == kLeaveNotify)
0110 m_inside = false;
0111
0112 fClient->NeedRedraw(this);
0113
0114 return TGButton::HandleCrossing(event);
0115 }
0116
0117 void FWCustomIconsButton::DoRedraw() {
0118
0119
0120
0121 int x = (fWidth - fTWidth) >> 1;
0122 int y = (fHeight - fTHeight) >> 1;
0123
0124 switch (fState) {
0125 case kButtonUp:
0126 if (m_belowMouseIcon && m_inside)
0127 m_belowMouseIcon->Draw(fId, fNormGC, x, y);
0128 else
0129 m_upIcon->Draw(fId, fNormGC, x, y);
0130 break;
0131 case kButtonEngaged:
0132 case kButtonDown:
0133 m_downIcon->Draw(fId, fNormGC, x, y);
0134 break;
0135 case kButtonDisabled:
0136 default:
0137 m_disabledIcon->Draw(fId, fNormGC, x, y);
0138 }
0139 }
0140
0141
0142
0143