Exemplo n.º 1
0
bool ofxTLKeyframes::mousePressed(ofMouseEventArgs& args, long millis){
	
	
	ofVec2f screenpoint = ofVec2f(args.x, args.y);
	
    keysAreDraggable = !ofGetModifierShiftPressed();
    keysDidDrag = false;
	selectedKeyframe =  keyframeAtScreenpoint(screenpoint);
    //if we clicked OFF of a keyframe OR...
    //if we clicked on a keyframe outside of the current selection and we aren't holding down shift, clear all
    if(!ofGetModifierSelection() && (isActive() || selectedKeyframe != NULL) ){
        bool didJustDeselect = false;
	    if( selectedKeyframe == NULL || !isKeyframeSelected(selectedKeyframe)){
            //settings this to true causes the first click off of the timeline to deselct rather than create a new keyframe
            didJustDeselect = timeline->getTotalSelectedItems() > 1;
    	    timeline->unselectAll();
        }

        //if we didn't just deselect everything and clicked in an empty space add a new keyframe there
        if(selectedKeyframe == NULL && !didJustDeselect){
			createNewOnMouseup = args.button == 0 && !ofGetModifierControlPressed();
        }
    }

   
	if(selectedKeyframe != NULL){
         //add the keyframe to the selection, whether it was just generated or not
    	if(!isKeyframeSelected(selectedKeyframe)){
			selectedKeyframes.push_back(selectedKeyframe);
        }
        //unselect it if it's selected and we clicked the key with shift pressed
        else if(ofGetModifierSelection()){
        	deselectKeyframe(selectedKeyframe);
			selectedKeyframe = NULL;
        }
	}
//	if(isActive()){
//		cout << "MOUSE PRESSED args button " << args.button << " control pressed? " << (ofGetModifierControlPressed() ? "YES":"NO") << " shift/cmd pressed? " << (ofGetModifierSelection() ? "YES":"NO") << endl;
//		}
    //if we have any keyframes selected update the grab offsets and check for showing the modal window
	if(selectedKeyframes.size() != 0){
        updateDragOffsets(screenpoint, millis);
		if(selectedKeyframe != NULL){

			if(args.button == 0 && !ofGetModifierSelection() && !ofGetModifierControlPressed()){
	            timeline->setDragTimeOffset(selectedKeyframe->grabTimeOffset);
				//move the playhead
				if(timeline->getMovePlayheadOnDrag()){
					timeline->setCurrentTimeMillis(selectedKeyframe->time);
				}
			}
			if(args.button == 2 || ofGetModifierControlPressed()){
				selectedKeySecondaryClick(args);
			}
		}
	}
	return selectedKeyframe != NULL;
}
void ofxTLKeyframes::mouseMoved(ofMouseEventArgs& args, long millis){
	ofxTLTrack::mouseMoved(args, millis);
	hoverKeyframe = keyframeAtScreenpoint( ofVec2f(args.x, args.y));
}
bool ofxTLKeyframes::mousePressed(ofMouseEventArgs& args, long millis){
	
	ofVec2f screenpoint = ofVec2f(args.x, args.y);
	keysAreStretchable = ofGetModifierShiftPressed() && ofGetModifierControlPressed();
    keysDidDrag = false;
	if(keysAreStretchable && timeline->getTotalSelectedItems() > 1){
		unsigned long long minSelected = timeline->getEarliestSelectedTime();
		unsigned long long maxSelected = timeline->getLatestSelectedTime();
		if(minSelected == maxSelected){
			keysAreStretchable = false;
		}
		else {
			unsigned long long midSelection = (maxSelected-minSelected)/2 + minSelected;
			//the anchor is the selected key opposite to where we are stretching
			stretchAnchor = midSelection <= millis ? minSelected : maxSelected;
//			cout << "Min selected " << ofxTimecode::timecodeForMillis(minSelected) << " Mid Selected " << ofxTimecode::timecodeForMillis(midSelection) << " Max selected " << ofxTimecode::timecodeForMillis(maxSelected) << " anchor "  << ofxTimecode::timecodeForMillis(stretchAnchor) << " millis down " << ofxTimecode::timecodeForMillis(millis) << endl;
			stretchSelectPoint = millis;
			//don't do anything else, like create or deselect keyframes
			updateStretchOffsets(screenpoint, millis);
		}
		return true;
	}
	
    keysAreDraggable = !ofGetModifierShiftPressed();
	selectedKeyframe =  keyframeAtScreenpoint(screenpoint);
    //if we clicked OFF of a keyframe OR...
    //if we clicked on a keyframe outside of the current selection and we aren't holding down shift, clear all
    if(!ofGetModifierSelection() && (isActive() || selectedKeyframe != NULL) ){
        bool didJustDeselect = false;
	    if( selectedKeyframe == NULL || !isKeyframeSelected(selectedKeyframe)){
            //settings this to true causes the first click off of the timeline to deselct rather than create a new keyframe
            didJustDeselect = timeline->getTotalSelectedItems() > 1;
    	    timeline->unselectAll();
        }

        //if we didn't just deselect everything and clicked in an empty space add a new keyframe there
        if(selectedKeyframe == NULL && !didJustDeselect){
			createNewOnMouseup = args.button == 0 && !ofGetModifierControlPressed();
        }
    }

	if(selectedKeyframe != NULL){
         //add the keyframe to the selection, whether it was just generated or not
    	if(!isKeyframeSelected(selectedKeyframe)){
			selectedKeyframes.push_back(selectedKeyframe);
			updateKeyframeSort();
//			selectKeyframe(selectedKeyframe);
        }
        //unselect it if it's selected and we clicked the key with shift pressed
        else if(ofGetModifierSelection()){
        	deselectKeyframe(selectedKeyframe);
			selectedKeyframe = NULL;
        }
	}
	
    //if we have any keyframes selected update the grab offsets and check for showing the modal window
	if(selectedKeyframes.size() != 0){
        updateDragOffsets(screenpoint, millis);
		if(selectedKeyframe != NULL){

			if(args.button == 0 && !ofGetModifierSelection() && !ofGetModifierControlPressed()){

	            timeline->setDragTimeOffset(selectedKeyframe->grabTimeOffset);
				//move the playhead
				if(timeline->getMovePlayheadOnDrag()){
					timeline->setCurrentTimeMillis(selectedKeyframe->time);
				}
			}
			if(args.button == 2 || ofGetModifierControlPressed()){
				selectedKeySecondaryClick(args);
			}
		}
	}
	return selectedKeyframe != NULL;
}
Exemplo n.º 4
0
void ofxTLKeyframer::mouseMoved(ofMouseEventArgs& args) {
    ofxTLElement::mouseMoved(args);
    int unused;
    hoverKeyframe = keyframeAtScreenpoint( ofVec2f(args.x, args.y), unused );
}
Exemplo n.º 5
0
void ofxTLKeyframer::mousePressed(ofMouseEventArgs& args) {
    if(!enabled) return;

    ofVec2f screenpoint = ofVec2f(args.x, args.y);
    if(drawingEasingWindow) {
        //see if we clicked on an
        drawingEasingWindow = false;

        for(int i = 0; i < easingFunctions.size(); i++) {
            if(easingFunctions[i]->bounds.inside(screenpoint-easingWindowPosition)) {
                selectedKeyframe->easeFunc = easingFunctions[i];
                if(autosave) save();
                return;
            }
        }
        for(int i = 0; i < easingTypes.size(); i++) {
            if(easingTypes[i]->bounds.inside(screenpoint-easingWindowPosition)) {
                selectedKeyframe->easeType = easingTypes[i];
                if(autosave) save();
                return;
            }
        }
    }

    bool clickIsInRect = screenpointIsInBounds(screenpoint);
    if(!focused) {
        focused = clickIsInRect;
        if(!focused) {
            selectedKeyframe = NULL;
            drawingEasingWindow = false;
        }
        return;
    }

    if(!clickIsInRect) {
        focused = false;
        selectedKeyframe = NULL;
        drawingEasingWindow = false;
        return;
    }

    selectedKeyframe = keyframeAtScreenpoint(screenpoint, selectedKeyframeIndex);
    //cout << "selected index is " << selectedKeyframeIndex << endl;
    if(selectedKeyframe == NULL) {
        //add a new one
        selectedKeyframe = newKeyframe( keyframePointForCoord(screenpoint) );

        grabOffset = ofVec2f(0,0);
        updateKeyframeSort();
        //find bounds
        for(int i = 0; i < keyframes.size(); i++) {
            if(keyframes[i] == selectedKeyframe) {
                selectedKeyframeIndex = i;
            }
        }
    }

    //grabbed a keyframe
    if(selectedKeyframe != NULL) {
        timeline->setPercentComplete(selectedKeyframe->position.x);

        if(args.button == 0) {
            grabOffset = screenpoint - coordForKeyframePoint(selectedKeyframe->position);
            if(keyframes.size() == 1) {
                minBound = 0.0;
                maxBound = 1.0;
            }
            else if(selectedKeyframeIndex == 0) {
                minBound = 0.0;
                maxBound = keyframes[selectedKeyframeIndex+1]->position.x;
            }
            else if(selectedKeyframeIndex == keyframes.size()-1) {
                minBound = keyframes[selectedKeyframeIndex-1]->position.x;
                maxBound = 1.0;
            }
            else {
                minBound = keyframes[selectedKeyframeIndex-1]->position.x;
                maxBound = keyframes[selectedKeyframeIndex+1]->position.x;
                //cout << "keyframe point is " << selectedKeyframe->position.x << " min bound is " << minBound << " max bound is " << maxBound << endl;
            }
        }
        else if(args.button == 2) {
            easingWindowPosition = screenpoint;
            drawingEasingWindow = true;
        }
    }
}