Ejemplo 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;
}
Ejemplo n.º 2
0
//main function to get values out of the timeline, operates on the given value range
bool ofxTLFlags::mousePressed(ofMouseEventArgs& args, long millis){
	
    //if we aren't entering text and someone has the shift key held down don't let us go into modal
//    if(!enteringText && ofGetModifierSelection()){
//        return ofxTLBangs::mousePressed(args, millis);
//    }
        
    clickedTextField = NULL;    
    //look at each element to see if a text field was clicked
    for(int i = 0; i < keyframes.size(); i++){
        ofxTLFlag* key = (ofxTLFlag*)keyframes[i];
		if(key->display.inside(args.x, args.y)){
            clickedTextField = key;
            break;
        }
    }

//	cout << "text field? " << (clickedTextField == NULL ? "NULL" : clickedTextField->textField.text) << endl;
    //if so, select that text field and key and present modally
    //so that keyboard input all goes to the text field.
    //selection model is designed so that you can type into
    //mulitple fields at once
    if(clickedTextField != NULL){
        timeline->presentedModalContent(this);
        if(!ofGetModifierSelection()){
            timeline->unselectAll();
        }
		if(ofGetModifierSelection() && clickedTextField->textField.isEditing()){
			clickedTextField->textField.endEditing();
		}
		else{
			clickedTextField->textField.beginEditing();
			enteringText = true;
			//make sure this key is selected
			selectKeyframe(clickedTextField);
		}
        return false;
    }
	else{
		if(enteringText && !isHovering()){
			for(int i = 0; i < selectedKeyframes.size(); i++){
				((ofxTLFlag*)selectedKeyframes[i])->textField.endEditing();
			}
			enteringText = false;
			timeline->dismissedModalContent();
		}
	}
	
	if(!enteringText){
		//if we get all the way here we didn't click on a text field and we aren't
		//currently entering text so proceed as normal
		return ofxTLBangs::mousePressed(args, millis);
	}
	return false;
}
Ejemplo n.º 3
0
void ofxTLPage::mouseReleased(ofMouseEventArgs& args, long millis){
	if(draggingInside){
		for(int i = 0; i < headers.size(); i++){
			headers[i]->mouseReleased(args);
			tracks[headers[i]->name]->_mouseReleased(args, millis);
		}		
		draggingInside = false;
        timeline->setHoverTime(millis);
	}

	if(draggingSelectionRectangle && selectionRectangle.getArea() != 0){
		if(!ofGetModifierSelection() ){
			timeline->unselectAll();
		}

		draggingSelectionRectangle = false;
        ofLongRange timeRange = ofLongRange(timeline->screenXToMillis(selectionRectangle.x),
                                            timeline->screenXToMillis(selectionRectangle.x+selectionRectangle.width));
		for(int i = 0; i < headers.size(); i++){
            ofRectangle trackBounds = tracks[headers[i]->name]->getDrawRect();
			ofRange valueRange = ofRange(ofMap(selectionRectangle.y, trackBounds.y, trackBounds.y+trackBounds.height, 0.0, 1.0, true),
                                         ofMap(selectionRectangle.y+selectionRectangle.height, trackBounds.y, trackBounds.y+trackBounds.height, 0.0, 1.0, true));
            if(valueRange.min != valueRange.max){
				tracks[headers[i]->name]->regionSelected(timeRange, valueRange);
			}
		}		        
    }
}
Ejemplo n.º 4
0
//if we didn't click on a text field and we are entering txt
//take off the typing mode. Hitting enter will also do this
void ofxTLFlags::mouseReleased(ofMouseEventArgs& args, long millis){
	if(enteringText){
		//if we clicked outside of the rect, definitely deslect everything
		if(clickedTextField == NULL && !ofGetModifierSelection()){
			for(int i = 0; i < selectedKeyframes.size(); i++){
				((ofxTLFlag*)selectedKeyframes[i])->textField.endEditing();
			}
			enteringText = false;
		}
		//otherwise check if still have a selection
		else{
			enteringText = false;
			for(int i = 0; i < selectedKeyframes.size(); i++){
				enteringText = enteringText || ((ofxTLFlag*)selectedKeyframes[i])->textField.isEditing();
			}
		}

		if(!enteringText){
			timeline->dismissedModalContent();
			timeline->flagTrackModified(this);
		}
	}
	else {
		ofxTLBangs::mouseReleased(args, millis);
	}
}
Ejemplo n.º 5
0
void ofxTLPage::mouseReleased(ofMouseEventArgs& args, long millis){
	if(draggingInside){
		for(int i = 0; i < headers.size(); i++){
			headers[i]->mouseReleased(args);
			tracks[headers[i]->name]->_mouseReleased(args, millis);
		}		
		draggingInside = false;
        timeline->setHoverTime(millis);
	}

	if(draggingSelectionRectangle && selectionRectangle.getArea() != 0){
		if(!ofGetModifierSelection() ){
			timeline->unselectAll();
		}

        ofLongRange timeRange = ofLongRange(timeline->screenXToMillis(selectionRectangle.x),
                                            timeline->screenXToMillis(selectionRectangle.x+selectionRectangle.width));
		for(int i = 0; i < headers.size(); i++){
            ofRectangle trackBounds = tracks[headers[i]->name]->getDrawRect();
			ofRange valueRange;
			//if we have a collapsed track
			if(trackBounds.height == 0){
				//and the selection rect actual is over the track
				if(selectionRectangle.getMinY() < trackBounds.y && selectionRectangle.getMaxY() > trackBounds.y){
					valueRange = ofRange(0,1.0);
				}
				else{
					continue;
				}
			}
			else{
				valueRange = ofRange(ofMap(selectionRectangle.getMinY(), trackBounds.y, trackBounds.y+trackBounds.height, 0.0, 1.0, true),
									 ofMap(selectionRectangle.getMaxY(), trackBounds.y, trackBounds.y+trackBounds.height, 0.0, 1.0, true));
			}
			
            if(valueRange.min != valueRange.max){
				tracks[headers[i]->name]->regionSelected(timeRange, valueRange);
			}
		}		        
    }
	draggingSelectionRectangle = false;
}
//if we didn't click on a text field and we are entering txt
//take off the typing mode. Hitting enter will also do this
void ofxTLFileSelectFlags::mouseReleased(ofMouseEventArgs& args, long millis){

    if(false)
//        if(enteringText)
    {
        //if we clicked outside of the rect, definitely deslect everything
        if(clickedKey == NULL && !ofGetModifierSelection()){
            for(int i = 0; i < selectedKeyframes.size(); i++)
            {
                //((ofxTLDropDownFlag*)selectedKeyframes[i])->textField.endEditing();
            }
            enteringText = false;
        }
        //otherwise check if still have a selection
        else{
            //enteringText = false;
            //for(int i = 0; i < selectedKeyframes.size(); i++)
            {
                //enteringText = enteringText || ((ofxTLDropDownFlag*)selectedKeyframes[i])->textField.getIsEditing();
            }
        }
        
        if(!enteringText){
            timeline->dismissedModalContent();
            timeline->flagTrackModified(this);
        }
    }
    else {
        
//        if(aChildrenIsFocused!=-1)
//        {
//            save();
//            cout << "track saved" << endl;
//        }
        
        ofxTLBangs::mouseReleased(args, millis);
    }
}
Ejemplo n.º 7
0
bool ofxTLSwitches::mousePressed(ofMouseEventArgs& args, long millis){
    
	if(placingSwitch != NULL){
		if(isActive() && args.button == 0){
			placingSwitch->timeRange.max = millis;
			updateTimeRanges();
		}
		else {
			deleteKeyframe(placingSwitch);
		}
		placingSwitch = NULL;
		return false;
	}
	
	keysAreDraggable = !ofGetModifierSelection();
	
    //check to see if we are close to any edges, if so select them
    bool startSelected = false;
    bool endSelected = false;
    int selectedKeyframeIndex;
    if(isActive() && args.button == 0){
        for(int i = 0; i < keyframes.size(); i++){
            
            ofxTLSwitch* switchKey = (ofxTLSwitch*)keyframes[i];
            //unselect everything else if we just clicked this edge without shift held down
            startSelected = abs(switchKey->display.x - args.x) < 10.0;
            if (startSelected && !switchKey->startSelected && !ofGetModifierSelection()) {
                timeline->unselectAll();
            }
            //Deselect the key if we clicked it already selected with shift held down
            if(ofGetModifierSelection() && ((startSelected && switchKey->startSelected) || isKeyframeSelected(switchKey))){
                switchKey->startSelected = false;    
            }
            else {
                switchKey->startSelected |= startSelected;
            }
            float endEdge = switchKey->display.x+switchKey->display.width;
            endSelected = abs(endEdge - args.x) < 10.0;
            //don't let them both be selected in one click!
            if(!startSelected && endSelected && !switchKey->endSelected && !ofGetModifierSelection()){
                timeline->unselectAll();
            }
            //Deselect the key if we clicked it already selected with shift held down
            if(ofGetModifierSelection() && ((endSelected && switchKey->endSelected) || isKeyframeSelected(switchKey))){
                switchKey->endSelected = false;    
            }
            else{
                switchKey->endSelected |= endSelected && !startSelected;
            }
            
            if(startSelected || endSelected){
				selectedKeyframeIndex = i;
                break;
            }        
        }
    }
    
    //update dragging and snapping if we clicked an edge
    updateEdgeDragOffsets(millis);
    if(endSelected || startSelected){
        ofxTLSwitch* selectedSwitch = (ofxTLSwitch*)keyframes[selectedKeyframeIndex];
        timeline->setDragTimeOffset(selectedSwitch->edgeDragOffset);
    }
	
    if(!endSelected && !startSelected){
    	//normal selection from above

	    ofxTLKeyframes::mousePressed(args, millis);
        if(isActive()){
	        timeline->cancelSnapping(); //don't snap when dragging the whole switch
        }
    }
    
    //move through the keyframes, if both the start and the end have been selected
    //count it as completely selected and let the super class take care of it
    //otherwise if just one of the edges are selected make sure it's unselected
    for(int i = 0; i < keyframes.size(); i++){
        ofxTLSwitch* switchKey = (ofxTLSwitch*)keyframes[i];
        if (switchKey->startSelected && switchKey->endSelected) {
            switchKey->startSelected = switchKey->endSelected = false;
            selectKeyframe(switchKey);
        }
        //make sure that if just one of the edges is clicked that the keyframe is *not* selected
		//also make sure it wasn't *just* selected in the last click by checking that it's not 'the' selected key
        else if( (switchKey->startSelected || switchKey->endSelected) && isKeyframeSelected(switchKey)){
			if(selectedKeyframe == switchKey){
				switchKey->startSelected = switchKey->endSelected = false;
			}
			else{
	            deselectKeyframe(switchKey);
			}
        }
    }
	return false;
}
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;
}