コード例 #1
0
ファイル: text_area.cpp プロジェクト: toholio/epsilon
bool TextArea::handleEventWithText(const char * text, bool indentation, bool forceCursorRightOfText) {
  int nextCursorLocation = cursorLocation();

  size_t cursorIndexInCommand = TextInputHelpers::CursorIndexInCommand(text);

  size_t eventTextSize = strlen(text) + 1;
  char buffer[eventTextSize];
  size_t bufferIndex = 0;

  // Remove EmptyChars
  for (size_t i = bufferIndex; i < eventTextSize; i++) {
    if (text[i] != Ion::Charset::Empty) {
      buffer[bufferIndex++] = text[i];
    } else if (i < cursorIndexInCommand) {
      cursorIndexInCommand--;
    }
  }

  if ((indentation && insertTextWithIndentation(buffer, cursorLocation())) || insertTextAtLocation(buffer, cursorLocation())) {
    if (forceCursorRightOfText) {
      nextCursorLocation += strlen(buffer);
    } else {
      nextCursorLocation += cursorIndexInCommand;
    }
  }
  setCursorLocation(nextCursorLocation);
  return true;
}
コード例 #2
0
ファイル: text_field.cpp プロジェクト: toholio/epsilon
void TextField::setText(const char * text) {
  reloadScroll();
  m_contentView.setText(text);
  if (isEditing()) {
    setCursorLocation(draftTextLength());
  }
}
コード例 #3
0
void MeshEditorInstance::setSelectedLocation(float x, float y, float z)
{
    if(m_selectedVolume)
    {
        m_selectedVolume->location = glm::vec3(x, y, z);
        setCursorLocation(m_selectedVolume->location);
    }
}
コード例 #4
0
void MeshEditorInstance::setSelectedShapeInternal(SPhysVolume* volume)
{
    m_selectedVolume = volume;

    if(m_selectedVolume)
    {
        setCursorLocation(m_selectedVolume->location);
        setCursorRotation(m_selectedVolume->rotation);
        setCursorScale(m_selectedVolume->scale);
    }
    else
    {
        setCursorLocation(glm::vec3(0.f));
        setCursorRotation(glm::vec3(0.f));
        setCursorScale(glm::vec3(1.f));
    }

    m_editorEventDispatcher->call(EEditorEvent::SelectionChanged);
}
コード例 #5
0
ファイル: text_field.cpp プロジェクト: toholio/epsilon
bool TextField::handleEventWithText(const char * eventText, bool indentation, bool forceCursorRightOfText) {
  size_t previousTextLength = strlen(text());

  size_t eventTextSize = strlen(eventText) + 1;
  char buffer[eventTextSize];
  size_t bufferIndex = 0;

  /* DIRTY
   * We use the notation "_{}" to indicate a subscript layout. In a text field,
   * such a subscript should be written using parentheses. For instance: "u_{n}"
   * should be inserted as "u(n)".
   * We thus remove underscores and changes brackets into parentheses. */
  bool specialUnderScore = false;
  for (size_t i = bufferIndex; i < eventTextSize; i++) {
    if (eventText[i] == '_') {
      specialUnderScore = ((i < eventTextSize - 1) && (eventText[i+1] == '{')) ? true : false;
      if (!specialUnderScore) {
         buffer[bufferIndex++] = '_';
      }
    } else if (eventText[i] == '{' && specialUnderScore) {
      buffer[bufferIndex++] = '(';
    } else if (eventText[i] == '}' && specialUnderScore) {
      buffer[bufferIndex++] = ')';
      specialUnderScore = false;
    } else {
      buffer[bufferIndex++] = eventText[i];
    }
  }

  int cursorIndexInCommand = TextInputHelpers::CursorIndexInCommand(buffer);

  int newBufferIndex = 0;
  // Remove EmptyChars
  for (size_t i = newBufferIndex; i < bufferIndex; i++) {
    if (buffer[i] != Ion::Charset::Empty) {
      buffer[newBufferIndex++] = buffer[i];
    }
  }

  if (!isEditing()) {
    setEditing(true);
  }
  int nextCursorLocation = draftTextLength();
  if (insertTextAtLocation(buffer, cursorLocation())) {
    /* The cursor position depends on the text as we sometimes want to position
     * the cursor at the end of the text and sometimes after the first
     * parenthesis. */
    nextCursorLocation = cursorLocation() + (forceCursorRightOfText? strlen(buffer) : cursorIndexInCommand);
  }
  setCursorLocation(nextCursorLocation);
  return m_delegate->textFieldDidHandleEvent(this, true, strlen(text()) != previousTextLength);
}
コード例 #6
0
ファイル: text_area.cpp プロジェクト: toholio/epsilon
bool TextArea::ContentView::removeStartOfLine() {
  if (cursorLocation() <= 0) {
    return false;
  }
  size_t removedLine = m_text.removeRemainingLine(cursorLocation()-1, -1);
  if (removedLine > 0) {
    assert(m_cursorIndex >= removedLine);
    setCursorLocation(cursorLocation()-removedLine);
    reloadRectFromCursorPosition(cursorLocation(), false);
    return true;
  }
  return false;
}
コード例 #7
0
ファイル: text_area.cpp プロジェクト: toholio/epsilon
bool TextArea::handleEvent(Ion::Events::Event event) {
  if (m_delegate != nullptr && m_delegate->textAreaDidReceiveEvent(this, event)) {
    return true;
  } else if (Responder::handleEvent(event)) {
    // The only event Responder handles is 'Toolbox' displaying.
    return true;
  } else if (event == Ion::Events::Left) {
    return setCursorLocation(cursorLocation()-1);
  } else if (event == Ion::Events::Right) {
    return setCursorLocation(cursorLocation()+1);
  } else if (event == Ion::Events::Up) {
    contentView()->moveCursorGeo(0, -1);
  } else if (event == Ion::Events::Down) {
    contentView()->moveCursorGeo(0, 1);
  } else if (event == Ion::Events::ShiftLeft) {
    contentView()->moveCursorGeo(-INT_MAX/2, 0);
  } else if (event == Ion::Events::ShiftRight) {
    contentView()->moveCursorGeo(INT_MAX/2, 0);
  } else if (event == Ion::Events::Backspace) {
    return removeChar();
  } else if (event.hasText()) {
    return handleEventWithText(event.text());
  } else if (event == Ion::Events::EXE) {
    return handleEventWithText("\n");
  } else if (event == Ion::Events::Clear) {
    if (!contentView()->removeEndOfLine()) {
      contentView()->removeStartOfLine();
    }
  } else if (event == Ion::Events::Paste) {
    return handleEventWithText(Clipboard::sharedClipboard()->storedText());
  } else {
    return false;
  }
  scrollToCursor();
  return true;
}
コード例 #8
0
ファイル: text_field.cpp プロジェクト: toholio/epsilon
bool TextField::ContentView::removeChar() {
  if (cursorLocation() <= 0) {
    return false;
  }
  m_currentDraftTextLength--;
  if (m_horizontalAlignment > 0.0f) {
    reloadRectFromCursorPosition(0);
  }
  setCursorLocation(cursorLocation()-1);
  if( m_horizontalAlignment == 0.0f) {
    reloadRectFromCursorPosition(cursorLocation());
  }
  for (size_t k = cursorLocation(); k < m_currentDraftTextLength; k++) {
    m_draftTextBuffer[k] = m_draftTextBuffer[k+1];
  }
  m_draftTextBuffer[m_currentDraftTextLength] = 0;
  layoutSubviews();
  return true;
}
コード例 #9
0
ファイル: text_field.cpp プロジェクト: toholio/epsilon
void TextField::ContentView::reinitDraftTextBuffer() {
  setCursorLocation(0);
  m_draftTextBuffer[0] = 0;
  m_currentDraftTextLength = 0;
}
コード例 #10
0
ファイル: text_field.cpp プロジェクト: toholio/epsilon
bool TextField::privateHandleEvent(Ion::Events::Event event) {
  if (Responder::handleEvent(event)) {
    /* The only event Responder handles is 'Toolbox' displaying. In that case,
     * the text field is forced into editing mode. */
    if (!isEditing()) {
      setEditing(true);
    }
    return true;
  }
  if (event == Ion::Events::Left && isEditing() && cursorLocation() > 0) {
    return setCursorLocation(cursorLocation()-1);
  }
  if (event == Ion::Events::ShiftLeft && isEditing()) {
    return setCursorLocation(0);
  }
  if (event == Ion::Events::Right && isEditing() && cursorLocation() < draftTextLength()) {
    return setCursorLocation(cursorLocation()+1);
  }
  if (event == Ion::Events::ShiftRight && isEditing()) {
    return setCursorLocation(draftTextLength());
  }
  if (isEditing() && textFieldShouldFinishEditing(event)) {
    char bufferText[ContentView::k_maxBufferSize];
    strlcpy(bufferText, m_contentView.textBuffer(), ContentView::k_maxBufferSize);
    strlcpy(m_contentView.textBuffer(), m_contentView.draftTextBuffer(), m_contentView.bufferSize());
    int cursorLoc = cursorLocation();
    setEditing(false, m_hasTwoBuffers);
    if (m_delegate->textFieldDidFinishEditing(this, text(), event)) {
      /* We allow overscroll to avoid calling layoutSubviews twice because the
       * content might have changed. */
      reloadScroll(true);
      return true;
    }
    /* if the text was refused (textInputDidFinishEditing returned false, we
     * reset the textfield in the same state as before */
    char bufferDraft[ContentView::k_maxBufferSize];
    strlcpy(bufferDraft, m_contentView.textBuffer(), ContentView::k_maxBufferSize);
    setText(bufferText);
    setEditing(true);
    setText(bufferDraft);
    setCursorLocation(cursorLoc);
    return true;
  }
  if (event == Ion::Events::Backspace && isEditing()) {
    return removeChar();
  }
  if (event == Ion::Events::Back && isEditing()) {
    setEditing(false);
    reloadScroll();
    m_delegate->textFieldDidAbortEditing(this);
    return true;
  }
  if (event == Ion::Events::Clear && isEditing()) {
    if (!removeEndOfLine()) {
      setEditing(true, true);
    }
    return true;
  }
  if (event == Ion::Events::Copy && !isEditing()) {
    Clipboard::sharedClipboard()->store(text());
    return true;
  }
  if (event == Ion::Events::Cut && !isEditing()) {
    Clipboard::sharedClipboard()->store(text());
    setEditing(true, true);
    return true;
  }
  return false;
}
コード例 #11
0
ファイル: qibusengine.cpp プロジェクト: ascetic85/ibus-qt
void
Engine::SetCursorLocation(int x, int y, int w, int h)
{
    setCursorLocation(x, y, w, h);
}
コード例 #12
0
ファイル: text_area.cpp プロジェクト: toholio/epsilon
void TextArea::ContentView::moveCursorGeo(int deltaX, int deltaY) {
  Text::Position p = m_text.positionAtIndex(m_cursorIndex);
  setCursorLocation(m_text.indexAtPosition(Text::Position(p.column() + deltaX, p.line() + deltaY)));
}