void Cursor::replaceAtCursor(const QByteArray &data) { //if (m_selection_valid ) { // if (current_cursor_new_y() >= m_selection_start.new_y() && current_cursor_new_y() <= m_selection_end.new_y()) // //don't need to schedule as event since it will only happen once // setSelectionEnabled(false); //} const QString text = m_gl_text_codec->toUnicode(data); if (new_x() + text.size() <= m_screen->width()) { Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(), text, m_current_text_style); new_rx() += text.size(); } else if (m_wrap_around) { Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(), text, m_current_text_style); int line_feeds = (new_x() + text.size()) / m_screen->width(); new_rx() = (new_x() + text.size()) % m_screen->width(); for (int i = 0; i < line_feeds; i++) { lineFeed(); } }else { const int size = m_document_width - new_x(); QString toBlock = text.mid(0,size); toBlock.replace(toBlock.size() - 1, 1, text.at(text.size()-1)); Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(),toBlock, m_current_text_style); new_rx() += toBlock.size(); } if (new_x() >= m_document_width) new_rx() = m_document_width - 1; notifyChanged(); }
void Cursor::setDocumentHeight(int height, int currentCursorBlock, int currentScrollBackHeight) { Q_UNUSED(currentCursorBlock); resetScrollArea(); if (m_document_height > height) { const int to_remove = m_document_height - height; const int removeLinesBelowCursor = std::min(m_document_height - new_y(), to_remove); const int removeLinesAtTop = to_remove - removeLinesBelowCursor; if (!removeLinesAtTop) { new_ry() -= removeLinesAtTop; notifyChanged(); } } else { int height_diff = height - m_document_height; if (currentScrollBackHeight >= height_diff) { new_ry() += height_diff; } else if (currentScrollBackHeight > 0) { const int move = height_diff - currentScrollBackHeight; new_ry() += move; } } m_document_height = height; if (new_y() >= height) { new_ry() = height - 1; notifyChanged(); } if (new_y() <= 0) { new_ry() = 0; } }
void Cursor::scrollDown(int lines) { if (new_y() < top() || new_y() > bottom()) return; for (int i = 0; i < lines; i++) { screen_data()->moveLine(top(), bottom()); } }
void Cursor::setScreenWidthAboutToChange(int width) { Q_UNUSED(width); auto it = m_screen->currentScreenData()->it_for_row(new_y()); if (m_screen->currentScreenData()->it_is_end(it)) return; m_resize_block = *it; int line_diff = new_y() - m_resize_block->screenIndex(); m_current_pos_in_block = (line_diff * m_screen_width) + new_x(); }
void Cursor::moveDown(int lines) { int bottom = adjusted_bottom(); if (new_y() == bottom || !lines) return; if (new_y() + lines <= bottom) { new_ry() += lines; } else { new_ry() = bottom; } notifyChanged(); }
void Cursor::scrollDown(int lines) { if (m_scroll_margins_set) { if (new_y() < m_top_margin || new_y() > m_bottom_margin) return; for (int i = 0; i < lines; i++) { screen_data()->moveLine(m_top_margin, m_bottom_margin); } } else { for (int i = 0; i < lines; i++) { screen_data()->moveLine(0,m_document_height - 1); } } }
/* Choose a place to start growing an island from */ static int place_island(int c, int *xp, int *yp) { int d, sx, sy; int ssy = roll0(WORLD_Y); int ssx = new_x(roll0(WORLD_X / 2) * 2 + ssy % 2); if (ssx > WORLD_X - 2) ssx = new_x(ssx + 2); for (d = di + id; d >= id; --d) { sx = ssx; sy = ssy; *xp = new_x(sx + 2); for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) { if (*xp >= WORLD_X) { *yp = new_y(*yp + 1); *xp = *yp % 2; if (*xp == sx && *yp == sy) break; } if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d)) return 1; } } return 0; }
/* Generic function for finding the distance to the closest sea, land, or mountain */ static int distance_to_what(int x, int y, int flag) { int j, d, px, py; for (d = 1; d < 5; ++d) { for (j = 0; j < d; ++j) vector[j] = 0; do { px = x; py = y; for (j = 0; j < d; ++j) { px = new_x(px + dirx[vector[j]]); py = new_y(py + diry[vector[j]]); } switch (flag) { case 0: /* distance to sea */ if (own[px][py] == -1) return d; break; case 1: /* distance to land */ if (own[px][py] != -1) return d; break; case 2: /* distance to mountain */ if (elev[px][py] == INFINITY) return d; break; } } while (next_vector(d)); } return d; }
void Cursor::clearToEndOfScreen() { clearToEndOfLine(); if (new_y() < m_screen->height() -1) { screen_data()->clearToEndOfScreen(m_new_position.y()+1); } }
/* Test to see if we're allowed to grow there: the arguments di and id */ static int try_to_grow(int c, int newx, int newy, int d) { int i, j, px, py; for (i = 1; i <= d; ++i) { for (j = 0; j < i; ++j) vector[j] = 0; do { px = newx; py = newy; for (j = 0; j < i; ++j) { px = new_x(px + dirx[vector[j]]); py = new_y(py + diry[vector[j]]); } if (own[px][py] != -1 && own[px][py] != c && (DISTINCT_ISLANDS || own[px][py] < nc)) return 0; } while (next_vector(i)); } sectx[c][secs] = newx; secty[c][secs] = newy; own[newx][newy] = c; return 1; }
void Cursor::lineFeed() { if(new_y() >= bottom()) { screen_data()->insertLine(bottom(), top()); } else { new_ry()++; notifyChanged(); } }
void Cursor::reverseLineFeed() { if (new_y() == top()) { scrollUp(1); } else { new_ry()--; notifyChanged(); } }
static int grow_one_sector(int c) { int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy; spike = roll0(100) < sp; if ((try1 = new_try(c)) == -1) return 0; x = sx = sectx[c][try1]; y = sy = secty[c][try1]; coast_search = 0; done = 0; do { if (spike) { for (i = roll0(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) { newx = new_x(x + dirx[i]); newy = new_y(y + diry[i]); if (own[newx][newy] == -1 && (n > 5 || (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 && own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1))) if (try_to_grow(c, newx, newy, c < nc ? di : id)) done = 1; } } else for (i = roll0(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) { newx = new_x(x + dirx[i]); newy = new_y(y + diry[i]); if (own[newx][newy] == -1) if (try_to_grow(c, newx, newy, c < nc ? di : id)) done = 1; } next_coast(c, x, y, &x, &y); ++coast_search; } while (!done && coast_search < COAST_SEARCH_MAX && (secs == 1 || x != sx || y != sy)); if (!done && c < nc) { qprint("fairland: error -- continent %c had no room to grow!\n", numletter[c % 62]); fl_status |= STATUS_NO_ROOM; } return done; }
void Cursor::setScreenHeight(int newHeight, int removedBeginning, int reclaimed) { resetScrollArea(); m_screen_height = newHeight; new_ry() -= removedBeginning; new_ry() += reclaimed; if (new_y() <= 0) { new_ry() = 0; } }
void Cursor::insertAtCursor(const QByteArray &data, bool only_latin) { const QString text = m_gl_text_codec->toUnicode(data); auto diff = screen_data()->insert(m_new_position, text, m_current_text_style, only_latin); new_rx() += diff.character; new_ry() += diff.line; if (new_y() >= m_screen_height) new_ry() = m_screen_height - 1; if (new_x() >= m_screen_width) new_rx() = m_screen_width - 1; }
static void find_coast(int c) { int i, j; for (i = 0; i < secs; ++i) { sectc[c][i] = 0; for (j = 0; j < 6; ++j) if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1) sectc[c][i] = 1; } }
void Cursor::reverseLineFeed() { int top = m_scroll_margins_set ? m_top_margin : 0; if (new_y() == top) { //m_selection_start.new_ry()++; //m_selection_end.new_ry()++; //m_selection_moved = true; scrollUp(1); } else { new_ry()--; notifyChanged(); } }
void Cursor::insertAtCursor(const QByteArray &data) { //if (m_selection_valid) { // if (current_cursor_new_y() >= m_selection_start.new_y() && current_cursor_new_y() <= m_selection_end.new_y()) // //don't need to schedule as event since it will only happen once // setSelectionEnabled(false); //} const QString text = m_gl_text_codec->toUnicode(data); Block *line = screen_data()->blockContainingLine(new_y()); line->insertAtPos(new_x(), text, m_screen->defaultTextStyle()); new_rx() += text.size(); }
void Cursor::lineFeed() { int bottom = m_scroll_margins_set ? m_bottom_margin : m_document_height - 1; if(new_y() >= bottom) { //m_selection_start.new_ry()--; //m_selection_end.new_ry()--; //m_selection_moved = true; screen_data()->insertLine(bottom); } else { new_ry()++; notifyChanged(); } }
void Cursor::moveToLine(int line) { const int height = m_screen->height(); if (line < adjusted_top()) { line = 0; } else if (line > adjusted_bottom()) { line = height -1; } if (line != new_y()) { new_rx() = line; notifyChanged(); } }
static void fl_move(int j) { int i, n, newx, newy; for (i = roll0(6), n = 0; n < 6; i = (i + 1) % 6, ++n) { newx = new_x(capx[j] + dirx[i]); newy = new_y(capy[j] + diry[i]); if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) { capx[j] = newx; capy[j] = newy; return; } } }
void Cursor::replaceAtCursor(const QByteArray &data, bool only_latin) { const QString text = m_gl_text_codec->toUnicode(data); if (!m_wrap_around && new_x() + text.size() > m_screen->width()) { const int size = m_screen_width - new_x(); QString toBlock = text.mid(0,size); toBlock.replace(toBlock.size() - 1, 1, text.at(text.size()-1)); screen_data()->replace(m_new_position, toBlock, m_current_text_style, only_latin); new_rx() += toBlock.size(); } else { auto diff = screen_data()->replace(m_new_position, text, m_current_text_style, only_latin); new_rx() += diff.character; new_ry() += diff.line; } if (new_y() >= m_screen_height) { new_ry() = m_screen_height - 1; } notifyChanged(); }
static void next_coast(int c, int x, int y, int *xp, int *yp) { int i, nx, ny, wat = 0; if (secs == 1) { *xp = x; *yp = y; return; } for (i = 0; i < 12; ++i) { nx = new_x(x + dirx[i % 6]); ny = new_y(y + diry[i % 6]); if (own[nx][ny] == -1) wat = 1; if (wat && own[nx][ny] == c) { *xp = nx; *yp = ny; return; } } }
void next_y(){ new_y( y + 1 ); }
void Cursor::clearToEndOfLine() { screen_data()->clearToEndOfLine(new_y(), new_x()); }
void Cursor::clearToEndOfScreen() { clearToEndOfLine(); if (new_y() < m_screen->height() -1) screen_data()->clearToEndOfScreen(new_y() + 1); }
void Cursor::clearLine() { screen_data()->clearLine(new_y()); }
void Cursor::clearToBeginningOfLine() { screen_data()->clearToBeginningOfLine(new_y(),new_x()); }
void Cursor::deleteCharacters(int characters) { screen_data()->deleteCharacters(new_y(), new_x(), new_x() + characters -1); }
void Cursor::clearToBeginningOfScreen() { clearToBeginningOfLine(); if (new_y() > 0) screen_data()->clearToBeginningOfScreen(m_new_position.y()-1); }