void VideoSlider::OnMouse(wxMouseEvent &event) { int x = event.GetX(); if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) { // If the slider didn't already have focus, don't seek if the user // clicked very close to the current location as they were probably // just trying to focus the slider if (wxWindow::FindFocus() != this && abs(x - GetXAtValue(val)) < 4) { SetFocus(); return; } // Shift click to snap to keyframe if (event.m_shiftDown) { int clickedFrame = GetValueAtX(x); std::vector<int>::const_iterator pos = lower_bound(keyframes.begin(), keyframes.end(), clickedFrame); if (pos == keyframes.end()) --pos; else if (pos + 1 != keyframes.end() && clickedFrame - *pos > (*pos + 1) - clickedFrame) ++pos; if (*pos == val) return; SetValue(*pos); } // Normal click else { int go = GetValueAtX(x); if (go == val) return; SetValue(go); } if (c->videoController->IsPlaying()) { c->videoController->Stop(); c->videoController->JumpToFrame(val); c->videoController->Play(); } else c->videoController->JumpToFrame(val); SetFocus(); return; } if (event.ButtonDown(wxMOUSE_BTN_RIGHT) || event.ButtonDown(wxMOUSE_BTN_MIDDLE)) { SetFocus(); } else if (!c->videoController->IsPlaying()) event.Skip(); }
void VideoSlider::DrawImage(wxDC &destdc) { int w,h; GetClientSize(&w,&h); // Back buffer wxMemoryDC dc; wxBitmap bmp(w,h); dc.SelectObject(bmp); // Colors wxColour shad = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); wxColour high = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); wxColour face = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColour sel(123,251,232); wxColour notSel(sel.Red()*2/5,sel.Green()*2/5,sel.Blue()*2/5); wxColour bord(0,0,0); int x1,x2,y1,y2; // Background dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(face); dc.DrawRectangle(0,0,w,h); // Selection border bool selected = wxWindow::FindFocus() == this; if (selected) { dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(wxPen(shad,1,wxDOT)); dc.DrawRectangle(0,0,w,h); } // Draw slider x1 = 5; x2 = w-5; y1 = 8; y2 = h-8; dc.SetPen(wxPen(shad)); dc.DrawLine(x1,y1,x2,y1); dc.DrawLine(x1,y1,x1,y2); dc.SetPen(wxPen(high)); dc.DrawLine(x1,y2,x2,y2); dc.DrawLine(x2,y1,x2,y2); // Draw keyframes int curX; if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) { dc.SetPen(wxPen(shad)); for (size_t i=0;i<keyframes.size();i++) { curX = GetXAtValue(keyframes[i]); dc.DrawLine(curX,2,curX,8); } } // Draw cursor curX = GetXAtValue(val); // Fill bg dc.SetBrush(wxBrush(face)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(curX-2,y1-1,4,y2-y1+5); dc.SetBrush(wxNullBrush); // Draw cursor highlights dc.SetPen(wxPen(high)); dc.DrawLine(curX,y1-2,curX-4,y1+2); dc.DrawLine(curX-3,y1+2,curX-3,y2+5); // Draw cursor shades dc.SetPen(wxPen(shad)); dc.DrawLine(curX+1,y1-1,curX+4,y1+2); dc.DrawLine(curX+3,y1+2,curX+3,y2+5); dc.DrawLine(curX-3,y2+4,curX+3,y2+4); // Draw cursor outline dc.SetPen(wxPen(bord)); dc.DrawLine(curX,y1-3,curX-4,y1+1); dc.DrawLine(curX,y1-3,curX+4,y1+1); dc.DrawLine(curX-4,y1+1,curX-4,y2+5); dc.DrawLine(curX+4,y1+1,curX+4,y2+5); dc.DrawLine(curX-3,y2+5,curX+4,y2+5); dc.DrawLine(curX-3,y2,curX+4,y2); // Draw selection dc.SetPen(*wxTRANSPARENT_PEN); if (selected) dc.SetBrush(wxBrush(sel)); else dc.SetBrush(wxBrush(notSel)); dc.DrawRectangle(curX-3,y2+1,7,4); // Draw final destdc.Blit(0,0,w,h,&dc,0,0); }
////////////// // Draw image void VideoSlider::DrawImage(wxDC &dc) { // Get dimensions int w,h; GetClientSize(&w,&h); // Draw background dc.Clear(); // Colors wxColour shad = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); wxColour high = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); wxColour face = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); //wxColour sel(244,198,38); wxColour sel(123,251,232); wxColour notSel(sel.Red()*2/5,sel.Green()*2/5,sel.Blue()*2/5); wxColour bord(0,0,0); int x1,x2,y1,y2; // Selection border bool selected = wxWindow::FindFocus() == this; if (selected) { dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(wxPen(shad,1,wxDOT)); dc.DrawRectangle(0,0,w,h); } // Draw slider x1 = 5; x2 = w-5; y1 = 8; y2 = h-8; dc.SetPen(wxPen(shad)); dc.DrawLine(x1,y1,x2,y1); dc.DrawLine(x1,y1,x1,y2); dc.SetPen(wxPen(high)); dc.DrawLine(x1,y2,x2,y2); dc.DrawLine(x2,y1,x2,y2); // Draw keyframes int curX; if (Display && Options.AsBool(_T("Show keyframes on video slider"))) { dc.SetPen(wxPen(shad)); wxArrayInt KeyFrames = Display->GetKeyFrames(); int keys = KeyFrames.Count(); for (int i=0;i<keys;i++) { curX = GetXAtValue(KeyFrames[i]); dc.DrawLine(curX,2,curX,8); } } // Draw cursor curX = GetXAtValue(GetValue()); // Fill bg dc.SetBrush(wxBrush(face)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(curX-2,y1-1,4,y2-y1+5); dc.SetBrush(wxNullBrush); // Draw cursor highlights dc.SetPen(wxPen(high)); dc.DrawLine(curX,y1-2,curX-4,y1+2); dc.DrawLine(curX-3,y1+2,curX-3,y2+5); // Draw cursor shades dc.SetPen(wxPen(shad)); dc.DrawLine(curX+1,y1-1,curX+4,y1+2); dc.DrawLine(curX+3,y1+2,curX+3,y2+5); dc.DrawLine(curX-3,y2+4,curX+3,y2+4); // Draw cursor outline dc.SetPen(wxPen(bord)); dc.DrawLine(curX,y1-3,curX-4,y1+1); dc.DrawLine(curX,y1-3,curX+4,y1+1); dc.DrawLine(curX-4,y1+1,curX-4,y2+5); dc.DrawLine(curX+4,y1+1,curX+4,y2+5); dc.DrawLine(curX-3,y2+5,curX+4,y2+5); dc.DrawLine(curX-3,y2,curX+4,y2); // Draw selection dc.SetPen(*wxTRANSPARENT_PEN); if (selected) dc.SetBrush(wxBrush(sel)); else dc.SetBrush(wxBrush(notSel)); dc.DrawRectangle(curX-3,y2+1,7,4); }
//////////////// // Mouse events void VideoSlider::OnMouse(wxMouseEvent &event) { // Coordinates int x = event.GetX(); int y = event.GetY(); bool shift = event.m_shiftDown; // Left click if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) { // Check if it's OK to drag bool canDrag = wxWindow::FindFocus() == this; if (!canDrag) { int tolerance = 4; int curX = GetXAtValue(GetValue()); if (x-curX < -tolerance || x-curX > tolerance) canDrag = true; } // Drag if (canDrag) { // Shift click to snap to keyframe if (shift && Display) { wxArrayInt KeyFrames = Display->GetKeyFrames(); int keys = KeyFrames.Count(); int clickedFrame = GetValueAtX(x); int closest = 0; int cur; // Find closest for (int i=0;i<keys;i++) { cur = KeyFrames[i]; if (abs(cur-clickedFrame) < abs(closest-clickedFrame)) { closest = cur; } } // Jump to frame if (closest == GetValue()) return; SetValue(closest); } // Normal click else { int go = GetValueAtX(x); if (go == GetValue()) return; SetValue(go); } Refresh(false); // Playing? if (Display->IsPlaying) { Display->Stop(); UpdateVideo(); Display->Play(); } else UpdateVideo(); } // Get focus SetFocus(); } // Right/middle click if (event.ButtonDown(wxMOUSE_BTN_RIGHT) || event.ButtonDown(wxMOUSE_BTN_MIDDLE)) { SetFocus(); } // Something else else if (!Display->IsPlaying) event.Skip(); }