background-aware painting in editor dumb mode (2)

This commit is contained in:
Gregory.Shrago
2017-10-25 21:20:41 +03:00
parent f15a1dd13a
commit 789ee1b8a8
2 changed files with 19 additions and 8 deletions
@@ -1670,8 +1670,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
*/
public void startDumb() {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
if (!Registry.is("editor.dumb.mode.available")) return;
putUserData(BUFFER, null);
Rectangle rect = ((JViewport)myEditorComponent.getParent()).getViewRect();
BufferedImage image = UIUtil.createImage(myEditorComponent, rect.width, rect.height, BufferedImage.TYPE_INT_ARGB);
// The LCD text loop is enabled only for opaque images
BufferedImage image = UIUtil.createImage(myEditorComponent, rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = JBSwingUtilities.runGlobalCGTransform(myEditorComponent, image.createGraphics());
graphics.translate(-rect.x, -rect.y);
graphics.setClip(rect.x, rect.y, rect.width, rect.height);
@@ -1680,6 +1683,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
putUserData(BUFFER, image);
}
public boolean isDumb() {
return getUserData(BUFFER) != null;
}
void paint(@NotNull Graphics2D g) {
Rectangle clip = g.getClipBounds();
@@ -1687,13 +1694,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
return;
}
if (Registry.is("editor.dumb.mode.available")) {
final BufferedImage buffer = getUserData(BUFFER);
if (buffer != null) {
final Rectangle rect = getContentComponent().getVisibleRect();
UIUtil.drawImage(g, buffer, null, rect.x, rect.y);
return;
}
BufferedImage buffer = Registry.is("editor.dumb.mode.available") ? getUserData(BUFFER) : null;
if (buffer != null) {
Rectangle rect = getContentComponent().getVisibleRect();
UIUtil.drawImage(g, buffer, null, rect.x, rect.y);
return;
}
if (isReleased) {
@@ -30,6 +30,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.ex.EditorGutterComponentEx;
import com.intellij.openapi.editor.impl.EditorComponentImpl;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter;
import com.intellij.openapi.fileEditor.impl.EditorsSplitters;
@@ -209,6 +210,10 @@ public class IdeBackgroundUtil {
return new MyGraphics(gg != null ? gg.myDelegate : g, helper, helper.computeOffsets(g, component), gg != null ? gg.preserved : null);
}
static Graphics2D unwrap(Graphics g) {
return g instanceof MyGraphics ? ((MyGraphics)g).getDelegate() : (Graphics2D)g;
}
MyGraphics(Graphics g, PaintersHelper helper, int[] offsets, Set<Color> preserved) {
super((Graphics2D)g);
this.helper = helper;
@@ -352,6 +357,7 @@ public class IdeBackgroundUtil {
c instanceof EditorGutterComponentEx ? CommonDataKeys.EDITOR.getData((DataProvider)c) : null;
if (editor != null) {
if (!(g instanceof MyGraphics) && Boolean.TRUE.equals(EditorTextField.SUPPLEMENTARY_KEY.get(editor))) return g;
if (c instanceof EditorComponentImpl && ((EditorImpl)editor).isDumb()) return MyGraphics.unwrap(g);
Graphics2D gg = withEditorBackground(g, c);
if (gg instanceof MyGraphics) {
EditorColorsScheme scheme = editor.getColorsScheme();