2026-03-06 00:06:21
コードめも の編集
## 0006:コードめも ############### // Filename: xeyes.cpp // Last Change: 2015-07-13 Mon 06:14:50. // #include "wx/wx.h" class EyeFrame : public wxFrame { DECLARE_EVENT_TABLE() private: static const int a = 24; static const int b = 36; static const int ball = 6; static const float r = 1.9; // for dynamic movement wxPoint lc = wxPoint(30, 40); // center of Left-Eye wxPoint rc = wxPoint(84, 40); // center of Right-Eye wxPanel* m_panel; public: EyeFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL); ~EyeFrame(); void OnUpdateUI(wxUpdateUIEvent&); }; // Constructor EyeFrame::EyeFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) { wxBoxSizer* bSizerTop = new wxBoxSizer(wxVERTICAL); m_panel = new wxPanel(this, 5000, wxDefaultPosition, wxSize(120, 80), wxTAB_TRAVERSAL); bSizerTop->Add(m_panel, 0, wxALL|wxALIGN_RIGHT, 5); this->SetSizer(bSizerTop); this->Layout(); } EyeFrame::~EyeFrame() { } // Event Table BEGIN_EVENT_TABLE(EyeFrame, wxFrame) EVT_UPDATE_UI(5000, EyeFrame::OnUpdateUI) END_EVENT_TABLE() /* Event Handlers & Functions ***************************************/ // Event Handlers void EyeFrame::OnUpdateUI(wxUpdateUIEvent& event) { int sw, sh; wxDisplaySize(&sw, &sh); wxMouseState ms = wxGetMouseState(); wxPoint m = ms.GetPosition(); wxPoint p = m_panel->GetScreenPosition(); wxPoint slc = p + lc; wxPoint src = p + rc; wxClientDC dc(m_panel); dc.SetPen(wxPen(*wxBLACK, 3, wxSOLID)); // left eye float s = (m.x - slc.x) * a / sw * r; float t = (m.y - slc.y) * b / sh * r; if (s * s / (a * a) + t * t / (b * b) < 1) { if (s < 0) s += ball / 2; else s -= ball / 2; if (t < 0) t += ball / 2; else t -= ball / 2; dc.SetBrush(*wxWHITE); dc.DrawEllipse(wxRect(lc.x - a, lc.y - b, a * 2, b * 2)); dc.SetBrush(*wxBLACK); dc.DrawCircle((int)(lc.x + s), (int)(lc.y + t), ball); } // right eye s = (m.x - src.x) * a / sw * r; t = (m.y - src.y) * b / sh * r; if (s * s / (a * a) + t * t / (b * b) < 1) { if (s < 0) s += ball / 2; else s -= ball / 2; if (t < 0) t += ball / 2; else t -= ball / 2; dc.SetBrush(*wxWHITE); dc.DrawEllipse(wxRect(rc.x - a, rc.y - b, a * 2, b * 2)); dc.SetBrush(*wxBLACK); dc.DrawCircle((int)(rc.x + s), (int)(rc.y + t), ball); } //this->SetTitle(wxString::Format(wxT("%d,%d (%f,%f)"), m.x, m.y, x, y)); } #comment
パスワード
キャンセル
- since 2016.02.02 -
version 2017.09.24(2031)