Setting a color from NativeInterface

Topics: Developer Forum, User Forum
Dec 29, 2011 at 6:48 PM

I'm trying to use NativeInterface.SetFoldMarginColour(Boolean, Integer) to set the fold margin color. I'm a bit of a noob and don't know how to get the color I want via a single integer value. How do I calculate the color value from R,G,B to a single integer?

Developer
Dec 29, 2011 at 9:48 PM
Edited Dec 29, 2011 at 9:49 PM

A simple method to get you on the right track:

public static int ConvertToIntFromRGBA(byte red, byte green, byte blue, byte alpha)
{
    return ((red << 24) | (green << 16) | (blue << 8) | (alpha) );
}

 

also, that's assuming RGBA is the target color format, if it's ABGR, or ARGB, then that method will have to be changed slightly.

Coordinator
Dec 30, 2011 at 12:14 AM

Native Scintilla uses RGB Format only. In places where alpha is supported it is set separately. ScintillaNet (2x) uses a couple of static methods ColorToRgb and RgbToColor to do the translation but there are in fact standard Framework methods to do this:

System.Drawing.ColorTranslator.FromWin32
System.Drawing.ColorTranslator.ToWin32

Dec 30, 2011 at 2:20 AM

Thanks Chris and blah38621. Works great.

One other question on this subject: Is it possible to change the color of the fold lines and symbols? Folding was a last-minute addition to my current project, and everything is dark-themed. I'd like to have the symbol color match the color of the line numbers. Thanks again for a quick and helpful response.

Coordinator
Dec 30, 2011 at 4:14 PM

SetFoldMarginColour and SetFoldMarginHiColour

Dec 31, 2011 at 2:01 AM

I tried this earlier but both commands affect the background color. There was no effect on the forecolor. I've uploaded a screen capture so you can see what it looks like along with the code: http://www.alanburkhart.com/ScintillaNetFoldingIssue.html

Developer
Jan 2, 2012 at 2:56 AM
neverhome wrote:

I tried this earlier but both commands affect the background color. There was no effect on the forecolor. I've uploaded a screen capture so you can see what it looks like along with the code: http://www.alanburkhart.com/ScintillaNetFoldingIssue.html

This was an issue with the released version, the repo version has this issue fixed in all of the branches (I know I fixed it in 2.0, 2.2, and 4.0, not sure if I fixed it in 3.0 (or if it's even an issue in 3.0) )