Transparent Figure?

Post anything related to programming here.
Post Reply
jaap@jlgelling.nl
Posts: 1
Joined: Mon Dec 08, 2025 7:18 am

Transparent Figure?

Post by jaap@jlgelling.nl »

Making (happy) use of DataPlotClasses, I try to make a Figure transparent, so I can see a picture that I put on a canvas behind that Figure.
Whatever I try, the Figure keeps blocking the view to the picture behind.
What do I do wrong?

Cheers,
Jaap
User avatar
roger
Site Admin
Posts: 542
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: Transparent Figure?

Post by roger »

Hi Jaap,

The DataPlotClasses use double-buffering where the contents are first drawn to a picture and then the picture is drawn to the canvas. To make the figure transparent, the code in Figure.Draw needs to be changed to draw directly to the canvas (by removing the double-buffering code).

Here is the modified Figure.Draw method:

Code: Select all

// Draw the entire Figure contents

// if PreserveAspectRatio is true, then fit the figure into g without changing the aspect ratio
dim w as integer
dim h as integer
if PreserveAspectRatio then
  dim r1 as Double = me.Width / me.Height // the aspect ratio of the displayed figure
  dim r2 as Double = g.Width / g.Height // the aspect ratio of the passed graphics object
  if r1 > r2 then
    // the displayed figure is wider than the passed graphics, ratiometrically.
    w = g.Width
    h = w / r1
  else
    // the displayed figure is taller than the passed graphics, ratiometrically.
    h = g.Height
    w = h * r1
  end if
else
  w = g.Width
  h = g.Height
end if

ScalingFactor = 1

// Draw the frame
g.PenWidth = 1 * ScalingFactor
g.PenHeight = 1 * ScalingFactor
g.ForeColor = FrameColor
g.DrawRect 0, 0, g.Width, g.Height

// Draw all Graphs
SetGraphLocations(g.Width, g.Height)
for each gr as Graph in mGraphs
  gr.draw(g)
next
And if you also want the chart area (with the grid) to be transparent, remove the following line of code from Graph.Draw (under "Draw Box"):

Code: Select all

g.FillRect x, y, w+1, h+1
That should do it.
Post Reply