Transparent background/paper - is it possible?

102 views
Skip to first unread message

in...@xavierriley.co.uk

unread,
Oct 21, 2015, 5:38:43 PM10/21/15
to scintilla-interest
Hi,

We're using Scintilla (via QScintilla) in our open source software project Sonic Pi with great success! Thanks to everyone involved for the hard work. It's helped over 100k people to learn to code and is pre installed on every Raspberry Pi.

My question relates to styling the editor to have a transparent background. We'd ideally like to use it from QScintilla (Qt) and overlay it onto an OpenGL pane for doing visualisations. Ideally that would be a 100% transparent background/paper with opaque text.

The effect is something like this: https://vimeo.com/51993089 (WARNING: some mild flashing imagery in that video)

We asked over on the QScintilla mailing list and they seemed to think it would require some work on Scintilla itself - https://www.riverbankcomputing.com/pipermail/qscintilla/2015-October/thread.html#1077

Could anyone give us an idea of the issue involved with doing this and whether it is possible at all?

Many thanks,

Xavier Riley

Jason Haslam

unread,
Oct 21, 2015, 7:27:01 PM10/21/15
to scintilla...@googlegroups.com
I think that the only thing that’s really missing from core Scintilla is a way to set and draw the background with alpha. I tested it with the built-in Qt port and got it to work by just disabling drawing of the background. The attached image shows the gray background showing through. You can see the margins are still drawn in the default style background color. I did have to make a couple of tweaks to the Qt platform layer, but they were trivial.

Jason


--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-inter...@googlegroups.com.
To post to this group, send email to scintilla...@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.

Jason Haslam

unread,
Oct 21, 2015, 7:29:15 PM10/21/15
to scintilla...@googlegroups.com
Well, the screenshot was badly scaled. Attaching again at actual size.

Jason



On Oct 21, 2015, at 5:26 PM, Jason Haslam <jason....@gmail.com> wrote:

I think that the only thing that’s really missing from core Scintilla is a way to set and draw the background with alpha. I tested it with the built-in Qt port and got it to work by just disabling drawing of the background. The attached image shows the gray background showing through. You can see the margins are still drawn in the default style background color. I did have to make a couple of tweaks to the Qt platform layer, but they were trivial.

Jason

<screencap.png>

Neil Hodgson

unread,
Oct 21, 2015, 8:02:35 PM10/21/15
to scintilla...@googlegroups.com
Jason Hallam:

> I think that the only thing that’s really missing from core Scintilla is a way to set and draw the background with alpha.

There are multiple features that currently change the background (see TextBackground): the current style, whether the text is in a selection, whether it to the right of the edge, and whether it is a highlighted brace. A model with a shared alpha for these or where the alpha is the winner of these factors wouldn’t be that bad. Trying to handle allowing each of these to have an alpha which layers with the others would be more complex. It may be possible to calculate a combined colour+alpha from each of these features.

> I tested it with the built-in Qt port and got it to work by just disabling drawing of the background.

To make this work without removing features, drawBack could be omitted from the set of phases based on an option or parameter.

> The attached image shows the gray background showing through. You can see the margins are still drawn in the default style background color. I did have to make a couple of tweaks to the Qt platform layer, but they were trivial.

The margin drawing is much simpler then the main text part so doesn’t support features like phases.

Another case for transparent drawing is to support OS X-style transparent drag and drop which currently drags a translucent white background box around with the text.

Neil

Jason Haslam

unread,
Oct 21, 2015, 9:00:13 PM10/21/15
to scintilla...@googlegroups.com
Yeah, I think a single global alpha value for all of the background stuff that doesn’t already have an alpha setting (selection, indicators, markers, and caret line) would be ideal. That way you could set the background to fully transparent but still show those things translucent.

Skipping drawing the background phase would okay for the OS X drag-and-drop case, but for the original use case you probably at least want a translucent selection.

Jason

Neil Hodgson

unread,
Oct 21, 2015, 9:13:35 PM10/21/15
to scintilla...@googlegroups.com
Jason Hallam:

> Skipping drawing the background phase would okay for the OS X drag-and-drop case, but for the original use case you probably at least want a translucent selection.

There is a translucent mode for selections which draws after text and thus over it. This is the drawSelectionTranslucent phase. There are clarity and visibility benefits and costs here and drawing a translucent selection below text may be preferable to some.

Neil

Jason Haslam

unread,
Oct 21, 2015, 11:33:21 PM10/21/15
to scintilla...@googlegroups.com
Okay, I see. That is different from what I thought. So just skipping the background draw phase basically already works.

Jason

in...@xavierriley.co.uk

unread,
Oct 22, 2015, 6:02:30 AM10/22/15
to scintilla-interest
This looks very promising! Just having the background be translucent would be a great start for us, especially if it's not too difficult to implement.

> I tested it with the built-in Qt port and got it to work by just disabling drawing of the background.

Just so I know, does "the built-in Qt port" refer to the qt/ folder in the Scintilla source? (as opposed to the QScintilla project)

Also, "disabling drawing of the background" - could you point me at where this is handled? I've looked in the qt/ folder and the ScintillaBase.cxx file and I can't see where to make the change.

Thanks for your help with this,

Xavier

Jason Haslam

unread,
Oct 22, 2015, 11:41:45 AM10/22/15
to scintilla...@googlegroups.com
> On Oct 22, 2015, at 3:17 AM, in...@xavierriley.co.uk wrote:
>
> This looks very promising! Just having the background be translucent would be a great start for us, especially if it's not too difficult to implement.
>
>> I tested it with the built-in Qt port and got it to work by just disabling drawing of the background.
>
> Just so I know, does "the built-in Qt port" refer to the qt/ folder in the Scintilla source? (as opposed to the QScintilla project)

Yes.

> Also, "disabling drawing of the background" - could you point me at where this is handled? I've looked in the qt/ folder and the ScintillaBase.cxx file and I can't see where to make the change.

The changes I made for testing are inline below. Neil, disabling autoFillBackground on the viewport is probably good in any case.

Jason


diff -r 29b245e02df8 qt/ScintillaEditBase/ScintillaEditBase.cpp
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp Mon Oct 19 21:52:08 2015 +1100
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp Thu Oct 22 09:36:03 2015 -0600
@@ -47,7 +47,8 @@
setFrameStyle(QFrame::NoFrame);
setFocusPolicy(Qt::StrongFocus);
setAttribute(Qt::WA_StaticContents);
- viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
+ viewport()->setAutoFillBackground(false);
+ //viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_KeyCompression);
setAttribute(Qt::WA_InputMethodEnabled);

diff -r 29b245e02df8 src/EditView.cxx
--- a/src/EditView.cxx Mon Oct 19 21:52:08 2015 +1100
+++ b/src/EditView.cxx Thu Oct 22 09:36:03 2015 -0600
@@ -1697,12 +1697,14 @@
xStart += static_cast<int>(ll->wrapIndent);
}

+#if 0
if ((phasesDraw != phasesOne) && (phase & drawBack)) {
DrawBackground(surface, model, vsDraw, ll, rcLine, lineRange, posLineStart, xStart,
subLine, background);
DrawEOL(surface, model, vsDraw, ll, rcLine, line, lineRange.end,
xStart, subLine, subLineStart, background);
}
+#endif

if (phase & drawIndicatorsBack) {
DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRange.end, true, model.hoverIndicatorPos);

Neil Hodgson

unread,
Oct 26, 2015, 9:45:37 PM10/26/15
to scintilla...@googlegroups.com
Jason Hallam:

> Neil, disabling autoFillBackground on the viewport is probably good in any case.
> …
> setAttribute(Qt::WA_StaticContents);
> - viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
> + viewport()->setAutoFillBackground(false);
> + //viewport()->setAttribute(Qt::WA_OpaquePaintEvent);


Committed as
http://sourceforge.net/p/scintilla/code/ci/3174a07dd6a313975fa0234200ea532539e8b531/

Neil

Reply all
Reply to author
Forward
0 new messages