Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Non-rectangular semi-transparent window  (Read 8630 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Non-rectangular semi-transparent window
« on: June 07, 2015, 01:12:35 am »
This is just some code that I wanted to share.
It loads an image from a file and will give the window the shape of that image. You can also set the opacity of the window.

I only wrote code for Windows and Linux. I will try to have a look at OS X next month. In case I update the code you can find it on github.

Edit: The code now works on Windows, Linux and Mac.
On mac you have to compile both files, on windows and linux just Transparent.cpp.
On windows you only need the sfml libraries, on linux you also have to add "-lX11 -lXext" to the linker flags and on mac you should add "-framework Cocoa".

Transparent.cpp:
(click to show/hide)

Transparent.mm (only needed on mac)
(click to show/hide)

Result:
« Last Edit: June 08, 2015, 12:17:16 am by texus »
TGUI: C++ SFML GUI

zmertens

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Non-rectangular semi-transparent window
« Reply #1 on: June 07, 2015, 01:18:49 am »
That's pretty neat!
The truth will set you free but first it will piss you off.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Non-rectangular semi-transparent window
« Reply #2 on: June 07, 2015, 10:17:24 am »
You should split that code, one for the non-rectangular shape, one for alpha transparency.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Non-rectangular semi-transparent window
« Reply #3 on: June 07, 2015, 12:30:00 pm »
Good idea. While developing I needed them together on linux while I was trying various methods to get it working, but in this finished version they have indeed became independent.
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Non-rectangular semi-transparent window
« Reply #4 on: June 07, 2015, 10:51:43 pm »
I found some time already to add support for Mac OS X. Check github for the updated code.

There is one problem though. In order to make the non-rectangular window work I also had to make a change inside SFML. I had to add the following function in the SFOpenGLView class:
-(BOOL)isOpaque {
    return NO;
}

Without that change the window can only be semi-transparent and will not get the custom shape on mac.
TGUI: C++ SFML GUI

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Non-rectangular semi-transparent window
« Reply #5 on: June 07, 2015, 11:09:23 pm »
Can you try adding in your .mm file something like that:

@implementation SFOpenGLView (Opaque)
-(BOOL)isOpaque { return NO; }
@end

Does it work?

Override a method via ObjC Category
SFML / OS X developer

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Non-rectangular semi-transparent window
« Reply #6 on: June 07, 2015, 11:32:35 pm »
No, it just gives me the error that no interface declaration can be found for 'SFOpenGLView'.
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Non-rectangular semi-transparent window
« Reply #7 on: June 07, 2015, 11:51:32 pm »
I got it working. Instead of overriding the function of SFOpenGLView like that (for which the declaration isn't public), I could just override the one in NSOpenGLView. Thanks for the advice.
TGUI: C++ SFML GUI

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Non-rectangular semi-transparent window
« Reply #8 on: June 08, 2015, 07:51:38 am »
Brilliant!  :)
SFML / OS X developer

dwarfman78

  • Full Member
  • ***
  • Posts: 228
  • I'm bietzsche, Nietzsche !
    • MSN Messenger - cd4c@hotmail.com
    • View Profile
    • Email
Re: Non-rectangular semi-transparent window
« Reply #9 on: June 08, 2015, 10:35:40 am »
Is it possible to add it to SFML as a standard feature in the next release ?
@dwarfman78
github.com/dwarfman78