• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

Molecular Modeling Software


コミットメタ情報

リビジョンaa1b4ce10d4c0603a446a4a886775ce0cfb0c266 (tree)
日時2022-09-19 00:37:47
作者Toshi Nagata <alchemist.2005@nift...>
コミッターToshi Nagata

ログメッセージ

MyToggleButton is aware of the activeness of the window

変更サマリ

差分

--- a/wxSources/MyToggleButton.cpp
+++ b/wxSources/MyToggleButton.cpp
@@ -17,6 +17,7 @@
1717
1818 #include "MyToggleButton.h"
1919 #include "wx/dcclient.h"
20+#include "wx/toplevel.h"
2021
2122 IMPLEMENT_DYNAMIC_CLASS(MyToggleButton, wxToggleButton)
2223
@@ -33,12 +34,22 @@ MyToggleButton::OnPaint(wxPaintEvent &event)
3334 wxSize size = GetSize();
3435 dc.SetPen(*wxGREY_PEN);
3536 const wxBrush *brush;
37+ bool isActive;
38+ int col;
39+ // Get the nearest TopLevelWindow and see if it is active or not
40+ wxWindow *win = this;
41+ while (win != NULL && !win->IsKindOf(wxCLASSINFO(wxTopLevelWindow)))
42+ win = win->GetParent();
43+ if (win != NULL && ((wxTopLevelWindow *)win)->IsActive())
44+ isActive = true;
45+ else isActive = false;
3646 if (IsPressed())
37- brush = wxTheBrushList->FindOrCreateBrush(wxColour(128, 128, 128));
47+ col = (isActive ? 128 : 180);
3848 else if (GetValue())
39- brush = wxTheBrushList->FindOrCreateBrush(wxColour(180, 180, 180));
49+ col = (isActive ? 180 : 220);
4050 else
41- brush = wxTheBrushList->FindOrCreateBrush(wxColour(240, 240, 240));
51+ col = 240;
52+ brush = wxTheBrushList->FindOrCreateBrush(wxColour(col, col, col));
4253 dc.SetBrush(*brush);
4354 dc.DrawRectangle(0, 0, size.x, size.y);
4455 wxString label = GetLabel();
@@ -47,7 +58,10 @@ MyToggleButton::OnPaint(wxPaintEvent &event)
4758 dc.GetTextExtent(label, &w, &h, &descent);
4859 x = (size.x - w) / 2;
4960 y = (size.y - h) / 2;
50- dc.SetPen(*wxBLACK_PEN);
61+ if (isActive)
62+ dc.SetTextForeground(*wxBLACK);
63+ else
64+ dc.SetTextForeground(wxColour(128, 128, 128));
5165 dc.DrawText(label, x, y);
5266 }
5367
@@ -62,17 +76,19 @@ MyToggleButton::OnLeftDown(wxMouseEvent &event)
6276 void
6377 MyToggleButton::OnLeftUp(wxMouseEvent &event)
6478 {
65- ReleaseMouse();
66- SetPressed(false);
67- int x = event.GetX();
68- int y = event.GetY();
69- wxSize sz = GetSize();
70- if (x > 0 && x < sz.x && y > 0 && y < sz.y) {
71- SetValue(!GetValue());
72- wxCommandEvent cmdevt(wxEVT_TOGGLEBUTTON, GetId());
73- cmdevt.SetInt(GetValue());
74- cmdevt.SetEventObject(this);
75- ProcessCommand(cmdevt);
76- Refresh();
79+ if (HasCapture()) {
80+ ReleaseMouse();
81+ SetPressed(false);
82+ int x = event.GetX();
83+ int y = event.GetY();
84+ wxSize sz = GetSize();
85+ if (x > 0 && x < sz.x && y > 0 && y < sz.y) {
86+ SetValue(!GetValue());
87+ wxCommandEvent cmdevt(wxEVT_TOGGLEBUTTON, GetId());
88+ cmdevt.SetInt(GetValue());
89+ cmdevt.SetEventObject(this);
90+ ProcessCommand(cmdevt);
91+ Refresh();
92+ }
7793 }
7894 }
旧リポジトリブラウザで表示