void FlatTextarea::onDocumentContentsChanged() { if (_replacingEmojis) return; if (!_insertions.isEmpty()) { if (document()->availableRedoSteps() > 0) { _insertions.clear(); } else { _replacingEmojis = true; do { Insertion i = _insertions.front(); _insertions.pop_front(); if (i.second > 0) { processDocumentContentsChange(i.first, i.second); } } while (!_insertions.isEmpty()); _replacingEmojis = false; } } QString curText(getText()); if (_oldtext != curText) { _oldtext = curText; emit changed(); } updatePlaceholder(); if (App::wnd()) App::wnd()->updateGlobalMenu(); }
void FlatTextarea::onDocumentContentsChanged() { if (_correcting) return; QString curText(getText()); _correcting = true; correctValue(_oldtext, curText); _correcting = false; if (_oldtext != curText) { _oldtext = curText; emit changed(); checkContentHeight(); } updatePlaceholder(); if (App::wnd()) App::wnd()->updateGlobalMenu(); }
void csConsoleOutput::SetPosition(int x, int y, int width, int height) { if (!font) return; if (x >= 0) size.xmin = x; if (y >= 0) size.ymin = y; if (width >= 0) size.xmax = size.xmin + width; if (height >= 0) size.ymax = size.ymin + height; // Make sure we don't go off the current screen if (size.xmax >= G2D->GetWidth ()) size.xmax = G2D->GetWidth () - 1; if (size.ymax >= G2D->GetHeight ()) size.ymax = G2D->GetHeight () - 1; // Calculate the number of lines on the console int fw, fh; font->GetMaxSize (fw, fh); buffer->SetPageSize (size.Height () / (fh + 2)); // Invalidate the entire new area of the console invalid.Set (size); // Update cursor coordinates cy = csMin (cy, buffer->GetPageSize ()); // now check how many chars do fit in the current width const csString *text = buffer->GetLine (cy); if (!text) cx = 0; else { csString curText (*text); curText.Truncate (cx); while (cx) { int fw, fh; font->GetDimensions (curText.GetData (), fw, fh); if (fw <= size.Width ()) break; curText.Truncate (--cx); } } }
void csConsoleOutput::Draw2D (csRect *area) { if (!visible || !font) return; CS::Threading::RecursiveMutexScopedLock lock (mutex); int i, height, fh; csRect line, oldrgn; const csString *text; bool dirty; invalid.Union (size); // Save old clipping region G2D->GetClipRect (oldrgn.xmin, oldrgn.ymin, oldrgn.xmax, oldrgn.ymax); G2D->SetClipRect (invalid.xmin, invalid.ymin, invalid.xmax, invalid.ymax); // Calculate the height of the text font->GetMaxSize (i, height); height += 2; // Draw the background if (!transparent) G2D->DrawBox (size.xmin, size.ymin, size.xmax, size.ymax, bg); // Make sure we redraw everything we need to if (area) area->Union (invalid); // Print all lines on the current page for (i = 0; i < buffer->GetPageSize (); i++) { // Retrieve the line from the buffer and it's dirty flag text = buffer->GetLine (i, &dirty); // A 0 line indicates it's the last printed line on the page if (text == 0) break; // Calculate the rectangle of this line line.Set (size.xmin, (i * height) + size.ymin, size.xmax, (i * height) + size.ymin + height); // See if the line changed or if the line intersects with the invalid area if (area && (dirty || line.Intersects (invalid))) area->Union (line); // draw the shadow if needed, behind the text if (has_shadow) G2D->Write (font, 1 + size.xmin + 1, (i * height) + size.ymin + 1, shadow, -1, text->GetData ()); // Write the line G2D->Write (font, 1 + size.xmin, (i * height) + size.ymin, fg, -1, text->GetData ()); } // Test for a change in the flash state if (flash_interval > 0) { csTicks cur_time = csGetTicks (); if (cur_time > flash_time + flash_interval || cur_time < flash_time) { cursor_visible = !cursor_visible; flash_time = cur_time; } } else cursor_visible = true; // See if we draw a cursor if ((cursor != csConNoCursor) && cursor_visible && (cy != -1)) { int cx_pix, cy_pix; // Get the line of text that the cursor is on text = buffer->GetLine (cy); if (text == 0) { #ifdef CS_DEBUG if (cx != 0) csPrintf ( "csConsoleOutput: Current line is empty but cursor x != 0!\n"); #endif // CS_DEBUG cx_pix = 1; } else { // Make a copy of the text csString curText (*text); curText.Truncate(cx); font->GetDimensions (curText.GetData (), cx_pix, fh); } cy_pix = (cy * height) + size.ymin; cx_pix += size.xmin; int cursor_w; font->GetDimensions ("_", cursor_w, fh); line.Set (cx_pix, cy_pix, cx_pix + cursor_w, cy_pix + height); // Draw the appropriate cursor switch (cursor) { case csConInsertCursor: G2D->DrawLine (cx_pix + 1, cy_pix + (height-3), line.xmax, cy_pix + (height-3), fg); break; case csConNormalCursor: G2D->DrawBox (cx_pix + 1, cy_pix + 1, line.xmax - 1 - (cx_pix + 1), (height - 1) - 1, fg); break; #ifdef CS_DEBUG default: csPrintf ("csConsoleOutput: Invalid cursor setting!\n"); #endif // CS_DEBUG } } // Restore the original clipping region G2D->SetClipRect (oldrgn.xmin, oldrgn.ymin, oldrgn.xmax, oldrgn.ymax); // No more invalid area invalid.MakeEmpty (); }