/* ColourBox::onMouseLeftDown * Called when the colour box is left clicked. Pops up either a * colour selection dialog, or a palette dialog if a palette has been * given to the colour box *******************************************************************/ void ColourBox::onMouseLeftDown(wxMouseEvent& e) { if (!palette) { wxColour col = wxGetColourFromUser(GetParent(), wxColour(colour.r, colour.g, colour.b)); if (col.Ok()) { colour.r = col.Red(); colour.g = col.Green(); colour.b = col.Blue(); sendChangeEvent(); Refresh(); } } else { PaletteDialog pd(palette); if (pd.ShowModal() == wxID_OK) { rgba_t col = pd.getSelectedColour(); if (col.a > 0) { colour = col; sendChangeEvent(); Refresh(); } } } }
/* ColourBox::onMouseRightDown * Called when the colour box is right clicked. Pops up a simple * dialog with a slider control to select the colour alpha value, * if alpha is enabled *******************************************************************/ void ColourBox::onMouseRightDown(wxMouseEvent& e) { // Do nothing if alpha disabled if (!alpha) return; // Popup a dialog with a slider control for alpha wxDialog dlg(NULL, -1, "Set Alpha", wxDefaultPosition, wxDefaultSize); wxBoxSizer* box = new wxBoxSizer(wxVERTICAL); dlg.SetSizer(box); wxSlider* slider = new wxSlider(&dlg, -1, colour.a, 0, 255, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL); box->Add(slider, 1, wxEXPAND|wxALL, 4); box->Add(dlg.CreateButtonSizer(wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 4); dlg.SetInitialSize(); if (dlg.ShowModal() == wxID_OK) { colour.a = slider->GetValue(); sendChangeEvent(); Refresh(); } }
//-------------------------------------------------------------- // key pressed void mgSimpleField::keyDown( void* source, int keyCode, int modifiers) { switch (keyCode) { case MG_EVENT_KEY_RETURN: // add input to history if (m_history != NULL) { m_history->add(m_text); m_historyPosn = m_history->length()-1; } sendChangeEvent(); break; case MG_EVENT_KEY_INSERT: // toggle insert mode m_insertMode = !m_insertMode; break; case MG_EVENT_KEY_DELETE: // delete at cursor if (m_cursorPosn < m_text.length()) { m_text.deleteLettersAt(m_cursorPosn, 1); m_changed = true; } break; case MG_EVENT_KEY_BACKSPACE: // delete before cursor if (m_cursorPosn > 0) { if (m_cursorPosn <= m_text.length()) { m_cursorPosn = m_text.prevLetter(m_cursorPosn); m_text.deleteLettersAt(m_cursorPosn, 1); m_changed = true; } else m_cursorPosn--; // cursor beyond end of text updateScrollPosn(); } break; case MG_EVENT_KEY_LEFT: // move cursor m_cursorPosn = m_text.prevLetter(m_cursorPosn); m_cursorPosn = max(0, m_cursorPosn); updateScrollPosn(); break; case MG_EVENT_KEY_RIGHT: // move cursor m_cursorPosn = m_text.nextLetter(m_cursorPosn); updateScrollPosn(); break; case MG_EVENT_KEY_UP: if (m_history != NULL && m_history->length() > 0) { setText(m_history->getAt(m_historyPosn)); m_historyPosn = max(0, m_historyPosn-1); } break; case MG_EVENT_KEY_DOWN: if (m_history != NULL && m_history->length() > 0) { m_historyPosn = min(m_history->length()-1, m_historyPosn+1); setText(m_history->getAt(m_historyPosn)); } break; case MG_EVENT_KEY_HOME: // move cursor to start m_cursorPosn = 0; updateScrollPosn(); break; case MG_EVENT_KEY_END: // move cursor to end m_cursorPosn = m_text.length(); updateScrollPosn(); break; default: return; // skip damage } damage(); }