Example #1
0
void CodeEditor::keyPressed(WindowEvent e) {
	Input::Key k = e.key.code;

	checkBindings();
	
	bool control = Input::isKeyDown(Input::Control);
	bool shift = Input::isKeyDown(Input::Shift);

	if (k == Input::Up) {
		moveCursorUpOne();
	} else if (k == Input::Down) {
		moveCursorDownOne();
	} else if (k == Input::Left) {
		resetBlink();

		if (mLineIndex > getLineLength(mCurrentLine)) {
			mLineIndex = getLineLength(mCurrentLine);
		}

		if (mLineIndex == 0 && mCurrentLine != 0) {
			--mCurrentLine;
			mLineIndex = getLineLength(mCurrentLine);
			
			if (mText[mCurrentLine].getPosition().y < mPos.y) {
				scrollUpOne();
			}
		} else if (mLineIndex > 0) {
			if (mLineIndex > mUpperBound) {
				mLineIndex = mUpperBound;
			}

			--mLineIndex;
		}
	} else if (k == Input::Right) {
		resetBlink();

		if (mLineIndex > getLineLength(mCurrentLine)) {
			mLineIndex = getLineLength(mCurrentLine);
		}

		if (mLineIndex == getLineLength(mCurrentLine) && ((mCurrentLine + 1) < getLineCount())) {
			++mCurrentLine;
			mLineIndex = 0;

			if (mText[mCurrentLine].getPosition().y > (mPos.y + mSize.y - (mFontSize * 2))) {
				scrollDownOne();
			}
		} else if (mLineIndex < getLineLength(mCurrentLine)) {
			++mLineIndex;
		}
	}
}
Example #2
0
void CodeEditor::doDelete() {
	if (mUpperBound == getLineLength(mCurrentLine) && mCurrentLine == mText.size() - 1) {
		return;
	}

	resetBlink();

	if (mUpperBound == getLineLength(mCurrentLine)) {

		String str = mText[mCurrentLine + 1].getString();
		mText[mCurrentLine].append(str);

		mText.erase(mText.begin() + mCurrentLine + 1);
		removeLineNumber();

		if (mCurrentLine < (mText.size() - 1)) {
			for (int i = mCurrentLine + 1; i < mText.size(); ++i) {
				mText[i].setPosition(mPos.x + mLineNumberAreaWidth, mText[i].getPosition().y - mFontSize - 2);
			}
		}

		return;
	}

	String str = mText[mCurrentLine].getString();
	str.erase(mUpperBound, 1);
	mText[mCurrentLine].setString(str);
}
Example #3
0
void CodeEditor::moveCursorToLineBegin() {
	if (mUpperBound == getLine(mCurrentLine).firstCharIndex()) {
		return;
	}

	mLineIndex = getLine(mCurrentLine).firstCharIndex();
	mUpperBound = mLineIndex;
	resetBlink();
}
Example #4
0
void CodeEditor::enterText(uint32 k) {
	//TODO: Maybe don't ignore alt?
	if (Input::isKeyDown(Input::Control) || Input::isKeyDown(Input::Alt)) {
		return;
	}

	mText[mCurrentLine].insert(incUpperBound(), String(k));
	resetBlink();
}
Example #5
0
void CodeEditor::moveCursorToLineEnd() {
	if (mUpperBound == getLineLength(mCurrentLine)) {
		return;
	}

	mLineIndex = getLineLength(mCurrentLine);
	mUpperBound = mLineIndex;
	resetBlink();
}
Example #6
0
void CodeEditor::moveCursorToMark() {
	mLineIndex = mMarkIndex;
	mUpperBound = mLineIndex;
	mCurrentLine = mMarkLine;

	moveViewToCursor();

	resetBlink();
}
Example #7
0
void CodeEditor::moveCursorDownOne() {
	if ((mCurrentLine + 1) < mText.size()) {
		++mCurrentLine;
		resetBlink();

		if (mText[mCurrentLine].getPosition().y > (mPos.y + mSize.y - (mFontSize * 2))) {
			scrollDownOne();
		}
	}
}
Example #8
0
void CodeEditor::moveCursorUpOne() {
	if (mCurrentLine > 0) {
		--mCurrentLine;
		resetBlink();

		if (mText[mCurrentLine].getPosition().y < mPos.y) {
			scrollUpOne();
		}
	}
}
Example #9
0
void CodeEditor::doTab() {
	resetBlink();
	if (mUseTabs) {
		mText[mCurrentLine].insert(incUpperBound(), "\t");
	} else {
		for (int i = 0; i < mTabWidth; ++i) {
			mText[mCurrentLine].insert(incUpperBound(), " ");
		}
	}
}
Example #10
0
void CodeEditor::mouseButtonPressed(WindowEvent e) {
	if (!Preferences::instance()->useMouseClick() || e.mouseButton.button != Input::MouseLeft) {
		return;
	}
	
	int x = e.mouseButton.x;
	int y = e.mouseButton.y;
	int index = 0;

	if (y < mPos.y) {
		return;
	}

	if (mShowLineNumbers) {
		x -= mLineNumberAreaWidth;
	}

	//TODO: The stupid way. Fixme later.
	for (uint32 i = 0; i < mText.size(); ++i) {
		if (y >= mText[i].getPosition().y && y <= mText[i].getPosition().y + mFontSize + 2) {
			index = i;
			break;
		}
	}

	mCurrentLine = index;
	int xx = 0;
	uint32 lineIndex = 0;

	for (int j = 0; j < getLineLength(mCurrentLine); ++j) {
		uint32 c = getLine(mCurrentLine)[j];

		uint32 charWidth = 0;

		if (c == '\t') {
			charWidth = (getCharWidth(L'') * mTabWidth);
		} else {
			charWidth = getCharWidth(c);
		}

		if (xx + charWidth >= x) {
			break;
		}

		xx += charWidth;
		++lineIndex;
	}

	mLineIndex = lineIndex;
	mUpperBound = mLineIndex;
	resetBlink();
}
Example #11
0
void CodeEditor::moveCursorToDocumentEnd() {
	if (mCurrentLine == mText.size() - 1) {
		return;
	}

	mCurrentLine = mText.size() - 1;
	mLineIndex = 0;
	mUpperBound = mLineIndex;

	while (cursorBelowView()) {
		scrollDownOne();
	}

	resetBlink();
}
Example #12
0
void CodeEditor::moveCursorToDocumentBegin() {
	if (mCurrentLine == 0) {
		return;
	}
	
	mCurrentLine = 0;
	mLineIndex = 0;
	mUpperBound = mLineIndex;

	while (cursorAboveView()) {
		scrollUpOne();
	}

	resetBlink();
}
Example #13
0
void CodeEditor::swapCursorAndMark() {
	mMarkRect.setPosition(mCursorRect.getPosition());
	
	uint32 tempIndex = mUpperBound;
	uint32 tempLine = mCurrentLine;

	mLineIndex = mMarkIndex;
	mUpperBound = mLineIndex;
	mCurrentLine = mMarkLine;

	mMarkIndex = tempIndex;
	mMarkLine = tempLine;

	moveViewToCursor();

	resetBlink();
}
Example #14
0
void CodeEditor::mouseWheelMoved(WindowEvent e) {
	if (mText.size() == 1) {
		return;
	}

	int dir = e.mouseWheel.delta > 0 ? 1 : -1; 

	//std::cerr << e.mouseWheel.delta * 250 << "\n";
	//std::cerr << ((mFontSize + 2) * 16) << "\n";

	for (uint32 i = 0; i < mText.size(); ++i) {
		mText[i].move(0, mScrollSpeed * dir);
		mLineNumbers[i].move(0, mScrollSpeed * dir);
	}

	resetBlink();
}
Example #15
0
void CodeEditor::moveCursorDownToBlank() {
	if (mCurrentLine == mText.size() - 1) {
		return;
	}

	resetBlink();

	for (uint32 i = mCurrentLine + 1; i < mText.size(); ++i) {
		if (mText[i].allWhiteSpace()) {
			mCurrentLine = i - 1;
			//mLineIndex = 0;
			//mUpperBound = mLineIndex;

			while (cursorBelowView()) {
				scrollDownOne();
			}
			return;
		}
	}
}
Example #16
0
void CodeEditor::moveCursorUpToBlank() {
	if (mCurrentLine == 0) {
		return;
	}

	resetBlink();

	for (int64 i = mCurrentLine - 1; i >= 0; --i) {
		if (mText[i].allWhiteSpace()) {
			mCurrentLine = i + 1;
			//mLineIndex = 0;
			//mUpperBound = mLineIndex;

			while (cursorAboveView()) {
				scrollUpOne();
			}

			return;
		}
	}
}
Example #17
0
void CodeEditor::doBackspace() {
	if (mUpperBound == 0 && mCurrentLine == 0) {
		return;
	}

	resetBlink();

	if ((mUpperBound == 0 || mText[mCurrentLine].isEmpty()) && mCurrentLine > 0) {
		--mCurrentLine;

		if (!mText[mCurrentLine + 1].isEmpty()) {
			mLineIndex = getLineLength(mCurrentLine);
			mText[mCurrentLine].append(mText[mCurrentLine + 1].getString());
		} else {
			mLineIndex = getLineLength(mCurrentLine);
		}

		//Remove the line.
		mText.erase(mText.begin() + mCurrentLine + 1);
		removeLineNumber();

		if (mCurrentLine < (mText.size() - 1)) {
			for (int i = mCurrentLine + 1; i < mText.size(); ++i) {
				mText[i].setPosition(mPos.x + mLineNumberAreaWidth, mText[i].getPosition().y - mFontSize - 2);
			}
		}

		return;
	}

	String str = mText[mCurrentLine].getString();
	str.erase(mUpperBound - 1, 1);
	mText[mCurrentLine].setString(str);
	if (mUpperBound > 0) {
		if (mLineIndex <= mUpperBound) {
			--mLineIndex;
		}
		--mUpperBound;
	}
}
Example #18
0
void MenuStateMachine(void){
    uint8_t u8ExitWithoutSavingFlag = TRUE;
    uint8_t u8MemCommand;
    static uint32_t u32defaultSettingsInitialValue;
    static uint8_t u8checkForDefaultSettings = FALSE;
    uint32_t u32TickCount;

    //Check to see if the encoder moved
    if(i8MenuChangeFlag != 0 && i8SubMenuState == SUBMENU_NOT_SELECTED){
        changeMainMenuState();
        resetBlink();
    }

    //Check to see if the encoder switch is held down for 3 seconds. This is
    //the mechanism for defaulting the menu.
    if(u8MenuKeyPressFlag == TRUE){
        //Start the timer.
        u32TickCount = xTaskGetTickCount();
        u32defaultSettingsInitialValue = u32TickCount;
        u8checkForDefaultSettings = TRUE;
    }else{
        //If the switch continues to be held down for 3 seconds, default the settings and exit the menu.
        if(u8checkForDefaultSettings == TRUE){
            if(!READ_ENC_SWITCH){//Switch is held down.
                //Increment the timer
                u32TickCount = xTaskGetTickCount();
                if((u32TickCount - u32defaultSettingsInitialValue) > DEFAULT_SETTINGS_TIME_LENGTH){
                    defaultSettings();
                    u8ExitWithoutSavingFlag = FALSE;
                    u8MenuExitFlag = TRUE;
                    u8checkForDefaultSettings = FALSE;
                }
            }else{
                u8checkForDefaultSettings = FALSE;
            }
        }
    }

    switch(i8MainMenuState){
        case X_MENU:
        case Y_MENU:
        case Z_MENU:
            //Handle the encoder switch press
            if(u8MenuKeyPressFlag == TRUE){
                u8MenuKeyPressFlag = FALSE;
                //If no submenu has been selected, enter submenu mode
                if(i8SubMenuState == SUBMENU_NOT_SELECTED){
                    i8SubMenuState = RANGE;
                    setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON);
                    setLEDState(u8XYZSubMenuMapping[i8SubMenuState-1], BLINK);
                }
                else if(u8ParameterEditModeFlag == FALSE){
                    //Enter the submenu and modify the parameter
                    u8ParameterEditModeFlag = TRUE;
                    setLEDState(u8XYZSubMenuMapping[i8SubMenuState-1], ON);
                    initializeXYZParameterMode();
                }
                else{
                    //Lock in the selection and exit the menu.
                    u8ExitWithoutSavingFlag = FALSE;
                    u8MenuExitFlag = TRUE;
                }
            }

            //If it made it this far, then it's changing submenus
            if(i8MenuChangeFlag != 0){
                //If we're not in parameter edit mode
                if(u8ParameterEditModeFlag == FALSE){
                    changeXYZSubMenuState();
                    resetBlink();
                }
                else{
                    editXYZParameter(i8SubMenuState);
                }
            }  
            break;
        case RECORD_MENU:
        case OVERDUB_MENU:
        case PLAYBACK_MENU:
            //Handle the encoder switch press
            if(u8MenuKeyPressFlag == TRUE){
                u8MenuKeyPressFlag = FALSE;
                //If no submenu has been selected, enter submenu mode
                if(i8SubMenuState == SUBMENU_NOT_SELECTED){
                    i8SubMenuState = SOURCE;
                    setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON);
                    setLEDState(u8PlaySubMenuMapping[i8SubMenuState-1], BLINK);
                }
                else if(u8ParameterEditModeFlag == FALSE){
                    //Enter the submenu and modify the parameter
                    u8ParameterEditModeFlag = TRUE;
                    setLEDState(u8PlaySubMenuMapping[i8SubMenuState-1], ON);
                    initializeRecParameterMode(i8MainMenuState-RECORD_MENU);
                }
                else{
                    //Locking in the change and exiting the menu.
                    u8ExitWithoutSavingFlag = FALSE;
                    u8MenuExitFlag = TRUE;
                }
            }

            //If it made it this far, then it's changing submenus
            if(i8MenuChangeFlag != 0){
                //If we're not in parameter edit mode
                if(u8ParameterEditModeFlag == FALSE){
                    changeRecSubMenuState();
                    resetBlink();
                }
                else{
                    editRecParameter(i8MainMenuState-RECORD_MENU);
                }
            }
            break;
        case LOAD_MENU:
        case STORE_MENU:
            //Store a sequence
            /*The first key press enters the mode. The next one issues a store
             * command*/
            if(u8MenuKeyPressFlag == TRUE){
                u8MenuKeyPressFlag = FALSE;
                if(i8MainMenuState == LOAD_MENU){
                    if(u8LoadModeFlag == FALSE){
                        //u8LoadModeFlag = TRUE;
                        /*Set the LEDs on for locations which have a stored sequence. Flash 
                         the currently selected LED.*/
                        u8LoadModeFlag = initializeLoadStoreMode();
                        if(u8LoadModeFlag == 1){
                            i8SubMenuState = 1;
                        }
                    }
                    else{
                        //Load the sequence
                        flashLoadSequence(u8LoadStoreParameter);
                        u8LoadModeFlag = FALSE;
                        u8MenuExitFlag = TRUE;
                    }
                }else{
                    if(u8StoreModeFlag == FALSE){
                        //u8StoreModeFlag = TRUE;
                        u8StoreModeFlag = initializeLoadStoreMode();
                        if(u8StoreModeFlag == 1){
                            i8SubMenuState = 1;
                        }
                    }
                    else{
                        //Store the sequence
                        flashStoreSequence(u8LoadStoreParameter, getLengthOfRecording());
                        u8StoreModeFlag = FALSE;
                        u8MenuExitFlag = TRUE;
                    }
                }
            }

            //Handle the encoder
            if(u8StoreModeFlag == TRUE || u8LoadModeFlag == TRUE){
                if(i8MenuChangeFlag != 0){
                    editLoadStoreParameter();
                }
            }
            else{
                i8MenuChangeFlag = 0;
            }

            break;
        case EFFECT_MENU:
            if(u8MenuKeyPressFlag == TRUE){
                u8MenuKeyPressFlag = FALSE;

                if(u8EffectModeFlag == FALSE){
                    i8SubMenuState = 1;
                    u8EffectModeFlag = TRUE;
                    setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON);
                    initializeEffectMode();
                }
                else{
                    //Set the effect mode
                    u8EffectModeFlag = FALSE;
                    //Locking in the change and exiting the menu.
                    u8ExitWithoutSavingFlag = FALSE;
                    u8MenuExitFlag = TRUE;
                }

            }

            //Handle the encoder
            if(u8EffectModeFlag == TRUE){
                if(i8MenuChangeFlag != 0){
                    editEffectParameter();
                }
            }
            else{
                i8MenuChangeFlag = 0;
            }
            break;
        case CLOCK_MENU:
            if(u8MenuKeyPressFlag == TRUE){
                u8MenuKeyPressFlag = FALSE;

                if(i8SubMenuState == SUBMENU_NOT_SELECTED){
                    u8ClockModeFlag = TRUE;
                    i8SubMenuState = SYNC;
                    setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON);
                    setLEDState(u8LEDMainMenuMapping[i8SubMenuState-1], BLINK);
                }
                else if(u8ParameterEditModeFlag == FALSE){
                    //Enter the submenu and modify the parameter
                    u8ParameterEditModeFlag = TRUE;
                    setLEDState(u8LEDMainMenuMapping[i8SubMenuState-1], ON);
                    initializeClockMode();
                }
                else{
                    //Set the effect mode
                    u8ClockModeFlag = FALSE;
                    //Locking in the change and exiting the menu.
                    u8ExitWithoutSavingFlag = FALSE;
                    u8MenuExitFlag = TRUE;
                }

            }

            //If it made it this far, then it's changing submenus
            if(i8MenuChangeFlag != 0){
                //If we're not in parameter edit mode
                if(u8ParameterEditModeFlag == FALSE){
                    changeClockSubMenuState();
                    resetBlink();
                }
                else{
                    editClockParameter();
                }
            }
            break;
        default:
            break;   
    }


    /*When we exit the menu, we have to reset the LIVE PLAY INTERACTION stuff or
     we could end up in a weird state.*/

    if(u8MenuExitFlag == TRUE){
        /*If the main switch is pressed, then we exit without saving the change and
         need to reset the parameter.*/
        if(u8ExitWithoutSavingFlag == TRUE){
            resetMenuParameter();
        }
        else{
            //Write the file table with the stored settings.
            copyCurrentSettingsToFileTable(0);
            u8MemCommand = WRITE_FLASH_FILE_TABLE;
            xQueueSend(xMemInstructionQueue, &u8MemCommand, 0);
        }
        resetEncoderLiveInteraction();//Encoder turning needs to be reset to not get spurious changes.
        i8SubMenuState = SUBMENU_NOT_SELECTED;
        u8MenuExitFlag = FALSE;
        setLEDAlternateFuncFlag(FALSE);//LEDs back to indicating position
        turnOffAllLEDs();//Reset the LEDs state
        setRedLEDs(HALF_BRIGHTNESS);
        setMenuModeFlag(FALSE);//Master control knows menu is over
        u8ParameterEditModeFlag = FALSE;
        u8LoadModeFlag = FALSE;
        u8StoreModeFlag = FALSE;
    }
}