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; } } }
void Frigid::update() { while (mWindow->isOpen()) { WindowEvent e; Input::updateInput(); while (mWindow->pollEvent(e)) { switch (e.type) { case WindowEvent::Closed: { mWindow->close(); } break; case WindowEvent::Resized: { Rectf visibleArea(0, 0, staticCastf(e.size.width), staticCastf(e.size.height)); mWindow->setView(View(visibleArea)); mMainPanel.resizeEvent(e); } break; case WindowEvent::TextEntered: { //TODO: Create proper filter. if (e.text.unicode >= 32 && e.text.unicode <= 126) { mMainPanel.enterText(e.text.unicode); } } break; case WindowEvent::KeyPressed: { Input::Key k = e.key.code; checkBindings(); mMainPanel.keyPressed(e); } break; case WindowEvent::MouseWheelMoved: { mMainPanel.mouseWheelMoved(e); } break; //TODO!: Come up with a GUI system! case WindowEvent::GainedFocus: { mMainPanel.setHasFocus(true); } break; case WindowEvent::LostFocus: { mMainPanel.setHasFocus(false); } break; case WindowEvent::MouseButtonPressed: { mMainPanel.mouseButtonPressed(e); } break; } } lua_State *L = mPrefs->getLuaState(); if (L) { lua_getglobal(L, "update"); if (lua_isfunction(L, -1)) { lua_pcall(L, 0, 0, 0); } else { lua_pop(L, 1); } } uint32 w = tempHelpText.getLocalBounds().width; tempHelpText.setPosition((mWindow->getWidth() / 2) - (w / 2), 2); mWindow->clear(mClearColor); mMainPanel.update(mWindow); mWindow->draw(tempHelpText); mWindow->display(/*mWindow.hasFocus()*/); } lua_close(mPrefs->getLuaState()); }