Canvas with transparent icons

  1. ‹ Older
  2. 8 weeks ago

    The icon covers the background, it is NOT transparent on Win, only on Linux

  3. Alberto D

    Jun 20 Pre-Release Testers
    Edited 8 weeks ago

    The icon is transparent, the canvas is not transparent on Windows, that's why I paint a green box on the canvas and then the icon, that way it simulates what you are trying to do with the green square.

    Edited to make it clearer. The icons are transparent.

  4. Dave S

    Jun 20 San Diego, California USA

    an icon with a properly applied mask should be transparent on all platforms without resorting to "tricks"

  5. Alberto D

    Jun 20 Pre-Release Testers

    @Dave S an icon with a properly applied mask should be transparent on all platforms without resorting to "tricks"

    The icons are transparent on all platforms. The issue is that Peter want to create a button with a canvas that show an icon and move a green square behind the canvas to make it look like a hover icon change.

    The icons are not the issue. The canvas picking up the window color behind it instead of the green square on Windows, that's the issue.

    If you download the small project, you can see that it works different on macOS, Linux and Windows.

  6. Alberto D

    Jun 20 Pre-Release Testers
    Edited 8 weeks ago

    This is how the small app looks on mac:
    -image-

    This is the same app on windows 10:
    -image-

    The green box is bigger and behind the canvas.

    Edit: this is how it looks on Windows with my changes (paint or not the green square, then the icon on Canvas Paint Event):
    -image-
    I'm sure there is a better way to code what I did. This is my first code involving canvas, icons and paint event.

  7. Good Morning Alberto.
    That is exactly what i need!
    I don't really understand what events should fire in which case.
    Can you place that in a dropbox?

  8. Emile S

    Jun 21 Europe (France, Strasbourg)

    What about using a RGBSurface to invert the icons colors ?

  9. Alberto D

    Jun 21 Pre-Release Testers
    Edited 8 weeks ago

    @Emile S What about using a RGBSurface to invert the icons colors ?

    Thank you Emile, I didn't know there is something like that in Xojo and after reading the docs it is too advanced for me.

    @Peter M Good Morning Alberto.
    That is exactly what i need!
    I don't really understand what events should fire in which case.
    Can you place that in a dropbox?

    I think is better to comment here what I did, that way experienced programmers can comment what other ways there are to do the same thing, just better.

    Having your code as a base, what I did was:

    • remove Rectangle1
    • remove MouseMove event from each canvas
    • add MouseEnter, MouseExit, Paint events to each canvas
    • add 2 boolean properties to the Window, Canvas1active, Canvas2active default to False
    • code in MouseEnter:
    Canvas1active = True // change to Canvas2active for Canvas2
    me.Invalidate

    - code in MouseExit::

    Canvas1active = False // change to Canvas2active for Canvas2
    me.Invalidate

    - code in Paint event:

    if Canvas1active Then // change to Canvas2active for Canvas2
      // paint the green square if mouse entered Canvas
      g.ForeColor = &c80fe80
      g.FillRect(0,0,me.Width,me.Height)
    End if
    // Draw the icon
    g.DrawPicture(icons8suche48,0,0) // change to (icons8obenrechts48,0,0) for Canvas2

    Hope this helps and hope others can point to better ways to do it.

  10. Emile S

    Jun 21 Europe (France, Strasbourg)

    http://docs.xojo.com/RGBSurface have cde to invert the image.

    A simple use can be to put the code in MouseEnter and MouseExit.

  11. @Alberto D;Poo
    Great it works!
    Honestly, i worked nearly one week to solve the problem with menu bar or tool bar. Now i solved the problems with the icons (in Win).
    It is really complex to make a nice icon with Xojo without a Mac.
    I will need years until my project is ready and i hope to get a lot of good help like this!

or Sign Up to reply!