void ofxTLCameraTrack::mouseDragged(ofMouseEventArgs& args, bool snapped) { if(canDrag) { for(int i = 0; i < selectedTrackPoints.size(); i++) { track.getSamples()[ selectedTrackPoints[i] ].frame = indexForScreenX(args.x - dragOffsets[i]); } } else if(selectedTrackPoints.size() == 0) { if(bounds.inside(args.x, args.y)) { float index = indexForScreenX(args.x); track.moveCameraToFrame(index); if(timeline->getMovePlayheadOnDrag()) { timeline->setCurrentFrame(index); } } } }
void ofxTLVideoPlayer::mouseDragged(ofMouseEventArgs& args, bool snapped){ if(bounds.inside(args.x, args.y)){ selectFrame( indexForScreenX(args.x) ); if(timeline->getMovePlayheadOnDrag()){ // cout << "setting percent complete " << timeline->setPercentComplete(screenXtoNormalizedX(args.x, zoomBounds)); } } }
void ofxTLTicker::updateTimelinePosition(){ if(timeline->getIsFrameBased()){ timeline->setCurrentFrame(indexForScreenX(ofGetMouseX())); } else{ timeline->setCurrentTime(timeForScreenX(ofGetMouseX())); } }
void ofxTLTrigger::draw(){ if(bounds.height < 2){ return; } ofPushStyle(); ofNoFill(); if(hover){ ofSetColor(timeline->getColors().highlightColor); } else if(focused){ ofSetColor(timeline->getColors().highlightColor); } else{ ofSetColor(timeline->getColors().outlineColor); } ofRect(bounds.x, bounds.y, bounds.width, bounds.height); ofFill(); ofSetLineWidth(5); for(int i = triggers.size()-1; i >= 0; i--){ int screenX = normalizedXtoScreenX(triggers[i].pt, zoomBounds); if(&triggers[i] == selectedTrigger){ ofSetColor(timeline->getColors().textColor); } else if(&triggers[i] == hoverTrigger){ ofSetColor(timeline->getColors().highlightColor); } else{ ofSetColor(timeline->getColors().keyColor); } int textHeight = bounds.y + 10 + ( (20*i) % int(bounds.height) ); ofLine(screenX, bounds.y, screenX, bounds.y+bounds.height); ofSetColor(timeline->getColors().backgroundColor); ofRect(screenX+2.5, textHeight-10, 100, 15); ofSetColor(timeline->getColors().textColor); if(enterText && &triggers[i] == selectedTrigger){ textfield.draw(screenX, textHeight-10); //-10 accounts for textfield's offset } else { string timeString = timeline->getIsFrameBased() ? ofToString(indexForScreenX(screenX)) : ofToString(triggers[i].pt * timeline->getDurationInSeconds()); ofDrawBitmapString(timeString+"|" +triggers[i].name, screenX+5, textHeight); } } ofPopStyle(); }
int ofxTLElement::indexForScreenX(int screenX){ return indexForScreenX(screenX, timeline->getDurationInFrames()); }
void ofxTLTicker::draw(){ ofPushStyle(); int textH, textW; string text; if(timeline->getIsFrameBased()){ int curStartFrame = ofMap(zoomBounds.min, 0, 1.0, 0, timeline->getDurationInFrames()); int curEndFrame = ofMap(zoomBounds.max, 0, 1.0, 0, timeline->getDurationInFrames()); int framesInView = curEndFrame-curStartFrame; float framesPerPixel = framesInView / bounds.width; int frameStepSize = 1; //TODO make adaptive if we are way zoomed in don't draw so many //draw ticker marks for(int i = curStartFrame; i <= curEndFrame; i++){ float x = ofMap(i, curStartFrame, curEndFrame, totalDrawRect.x, totalDrawRect.x+totalDrawRect.width, true); ofSetColor(200, 180, 40); float heightMultiplier = 0.0; if(i % 10 == 0){ ofSetLineWidth(3); heightMultiplier = .5; } else { ofSetLineWidth(1); heightMultiplier = .75; } ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height); } } //Time based else { //draw tickers with time float startTime = zoomBounds.min * timeline->getDurationInSeconds(); float endTime = zoomBounds.max * timeline->getDurationInSeconds(); float durationInview = endTime-startTime; float secondsPerPixel = durationInview / bounds.width; //draw ticker marks ofSetLineWidth(1); ofSetColor(200, 180, 40); float heightMultiplier = .75; for(float i = startTime; i <= endTime; i += secondsPerPixel*5){ //float x = ofMap(i, curStartFrame, curEndFrame, totalDrawRect.x, totalDrawRect.x+totalDrawRect.width, true); float x = screenXForTime(i); ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height); } //draw regular increments int bigTickStep; if(durationInview < 1){ //draw big tick every 100 millis bigTickStep = .1; } else if(durationInview < 60){ // draw big tick every second bigTickStep = 1; } else { bigTickStep = 60; } ofSetLineWidth(3); heightMultiplier = .5; for(float i = startTime-fmod(startTime, bigTickStep); i <= endTime; i+=bigTickStep){ float x = screenXForTime(i); ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height); } if(drawBPMGrid){ updateBPMPoints(); ofPushStyle(); ofSetColor(255, 255, 255, 50); for(int i = 0; i < bpmScreenPoints.size(); i++){ ofSetLineWidth(bpmScreenPoints[i].weight); ofLine(bpmScreenPoints[i].screenX, totalDrawRect.y, bpmScreenPoints[i].screenX, totalDrawRect.y+totalDrawRect.height-20); } ofPopStyle(); } } //highlite current mouse position if(hover){ //draw background rect ofSetColor(timeline->getColors().backgroundColor); if (timeline->getIsFrameBased()) { text = ofToString(indexForScreenX(ofGetMouseX())); } else{ //text = ofToString(); text = timeline->formatTime(timeForScreenX(ofGetMouseX())); } textH = 10; textW = (text.size()+1)*7; ofRect(ofGetMouseX(), bounds.y+textH, textW, textH); //draw playhead line ofSetColor(timeline->getColors().textColor); ofDrawBitmapString(text, ofGetMouseX()+5, bounds.y+textH*2); ofSetColor(timeline->getColors().highlightColor); ofSetLineWidth(1); ofLine(ofGetMouseX(), totalDrawRect.y, ofGetMouseX(), totalDrawRect.y+totalDrawRect.height); } //draw current frame int currentFrameX; if (timeline->getIsFrameBased()) { text = ofToString(timeline->getCurrentFrame()); currentFrameX = screenXForIndex(timeline->getCurrentFrame()); } else{ //text = ofToString(); text = timeline->formatTime(timeline->getCurrentTime()); currentFrameX = screenXForTime(timeline->getCurrentTime()); } textH = 10; textW = (text.size()+1)*7; ofSetColor(timeline->getColors().backgroundColor); ofRect(currentFrameX, bounds.y, textW, textH); ofSetColor(timeline->getColors().textColor); ofDrawBitmapString(text, currentFrameX+5, bounds.y+textH); if(timeline->getIsPlaying()){ ofSetColor(timeline->getColors().keyColor); } else{ ofSetColor(timeline->getColors().outlineColor); } //draw playhead line ofSetLineWidth(1); ofLine(currentFrameX, totalDrawRect.y, currentFrameX, totalDrawRect.y+totalDrawRect.height); //draw in/out point float inPointX = normalizedXtoScreenX(timeline->getInOutRange().min, zoomBounds); float outPointX = normalizedXtoScreenX(timeline->getInOutRange().max, zoomBounds); if(bounds.x < inPointX){ ofSetColor(timeline->getColors().disabledColor,120); ofRect(bounds.x, bounds.y, inPointX - bounds.x, totalDrawRect.height); ofSetColor(timeline->getColors().highlightColor); ofLine(inPointX, bounds.y, inPointX, bounds.y+totalDrawRect.height); } if(bounds.x+bounds.width > outPointX){ ofSetColor(timeline->getColors().disabledColor,120); ofRect(outPointX, bounds.y, (bounds.x+bounds.width) - outPointX, totalDrawRect.height); ofSetColor(timeline->getColors().highlightColor); ofLine(outPointX, bounds.y, outPointX, bounds.y+totalDrawRect.height); } //draw bounds ofNoFill(); ofSetColor(200, 180, 40); ofRect(bounds); ofPopStyle(); }