FillColor not same as window background

Hi,

I have transparent canvas on top of window without custom color.
In paint event of canvas I have:

g.ForeColor = FillColor g.FillRect(0,0,me.Width,me.Height)
And color of rectangle is different than window background.
What am I doing wrong?
(mac 10.11, xojo 2015v3)

Thanks

Jukka

On OS X the window background is an API call that results in neither a color, pattern or gradient

A Xojo color cannot represent what OS X does for the window back ground

When you ask for the fill color you get something “reasonable” as far as a Xojo color but its not what the OS will use

[quote=222669:@Jukka Leino]Hi,

I have transparent canvas on top of window without custom color.
In paint event of canvas I have:

g.ForeColor = FillColor g.FillRect(0,0,me.Width,me.Height)
And color of rectangle is different than window background.
What am I doing wrong?
(mac 10.11, xojo 2015v3)

Thanks

Jukka[/quote]

Set the window backcolor to &ececec and use

Sub Paint(g As Graphics, areas() As REALbasic.Rect) g.ForeColor = self.BackColor g.fillrect(0,0,me.width,me.height) End Sub

On OS X thought this does make your window “not system standard”

Don’t tell me we need to do some obscure declares to get the system standard grey in case a future version of Mac OS X changes it :wink:

Since OS X isn’t using just a plain solid color, pattern or gradient i’m not sure you can represent it in anything other than an NSColor
And that will mean a declare

NSColors represent a much broader range of things than Xojo’s “color”.
Even the color space they represent is much larger.
They use a CGFloat, a single or double precision floating point value, to represent individual components.
We use an 8 bit value for each of R, G, B, and A
So an NSColor can quite literally represent a grey that has no exact match in Xojo

I can live with this solution. I tryed to make gray dashed line around canvas to represent You can drop something.
First I draw round rectangle and then make it dashed by adding spaces with background color.
Here’s my code from canvas paint event if someone knows better way of doing it :slight_smile:

[code] Dim l_length As Integer = 40 // line length
Dim l_space As Integer = 20 // space between lines
Dim l_thick As Integer = 10 // line thickness
Dim l_curve As Integer = 40 // corner roundness
Dim l_color As Color = &CCCCCCC // line color

Dim xkpl As Integer = (me.Width - 2l_length) / (l_length + l_space) // count of lines to fit horizontally
Dim ykpl As Integer = (me.Height - 2
l_length) / (l_length + l_space) // count of lines to fit vertically

Dim x_width As Integer = (me.Width - 2*l_length - (xkpl+1)l_space) / xkpl // actual length of this line
Dim y_width As Integer = (me.Height - 2
l_length - (ykpl+1)*l_space) / ykpl // actual length of this line

g.PenWidth = l_thick
g.PenHeight = l_thick
g.ForeColor = l_color

g.DrawRoundRect(0,0,me.Width,me.Height,l_curve,l_curve) // draw round rectangle

g.ForeColor = self.BackColor // this has to be same as window backcolor

For i As Integer = 0 To xkpl // add horizontal spaces
g.FillRect(ix_width + il_space + l_length, 0, l_space, l_thick)
g.FillRect(ix_width + il_space + l_length, me.Height-l_thick, l_space, me.Height)
Next i

For i As Integer = 0 To ykpl // add vertical spaces
g.FillRect(0,iy_width + il_space + l_length, l_thick, l_space)
g.FillRect(me.Width-l_thick,iy_width + il_space + l_length, me.Width, l_space)
Next i[/code]

If you’re looking to have “blank” spaces, use clearrect to allow the window background to show through.

[code] For i As Integer = 0 To xkpl // add horizontal spaces
g.ClearRect(ix_width + il_space + l_length, 0, l_space, l_thick)
g.ClearRect(ix_width + il_space + l_length, me.Height-l_thick, l_space, me.Height)
Next i

For i As Integer = 0 To ykpl // add vertical spaces
g.ClearRect(0,iy_width + il_space + l_length, l_thick, l_space)
g.ClearRect(me.Width-l_thick,iy_width + il_space + l_length, me.Width, l_space)
Next i[/code]

Wow, didn’t even know that ClearRect exist :slight_smile:
That really solves it, don’t need to make any colors.

Thanks

Jukka

Amazingly, RB/RS/Xojo can’t get a window’s native background color on Mac, even up through IDE version 2015.
In my testing, Window.DrawInto, FillColor, Window.Graphics.Pixel, and System.Pixel all fail to do what they should.
So here’s a workaround using the third-party MBS plugin suite, if you need the color value (versus Graphics.ClearRect).

Const HasMBSPlugins = True
Function GetBackgroundColor( W as Window ) as Color
    If W.HasBackColor Then Return W.BackColor
    #If HasMBSPlugins Then
        App.DoEvents // So the function will work from a Window.Open event
        Static P as Picture = W.ScreenshotWindowRectMBS( 0, 0, 1, 1 ) // Static to cache the result
        Return P.RGBSurface.Pixel( 0, 0 )
    #Else
        Return FillColor
    #EndIf
End Function

Yup!

[quote=297036:@Adam Bjornson]Amazingly, RB/RS/Xojo can’t get a window’s native background color on Mac, even up through IDE version 2015.
In my testing, Window.DrawInto, FillColor, Window.Graphics.Pixel, and System.Pixel all fail to do what they should.
So here’s a workaround using the third-party MBS plugin suite, if you need the color value (versus Graphics.ClearRect).[/quote]
Over the years I noticed that more and more system colors are not exactly colors any more, as @Norman Palardy says, a lot of them actually hold something else, so trying to rasterize them down to a color that can be used with Xojo’s framework results in the wrong values.

To draw system colors, you have to use NS functions with a NSColor. Heck even trying to convert some of these colors into a CGColor or CIColor can fail (even crash your app).

Window.Graphics is deprecated, and strongly discouraged. You should use g in the Paint event instead. System.pixel is deprecated as well, and not even listed anymore in the LR.

I do use ScreenshotWindowRectMBS as well, but on Mac one can also simply shell to ScreenCapture http://osxdaily.com/2010/07/11/take-a-screen-capture-from-the-command-line/