Git Product home page Git Product logo

transparentwindows's Introduction

Transparent Windows

This repository contains an example of how to create non-rectangular semi-transparent windows on multiple operating systems with SFML (which is only used to load the image and display the result). It loads an image with transparent parts, uses this image to set the shape of the window and draws the image on the window. The code also contains an opacity variable to set the opacity of the window.

The code works for Windows, Linux and Mac OS X.

Feel free to send pull requests to improve the code.

Compiling

Linux:

g++ Transparent.cpp -lsfml-graphics -lsfml-window -lsfml-system -lX11 -lXext

Mac OS X:

clang++ Transparent.cpp Transparent.mm -framework sfml-graphics -framework sfml-window -framework sfml-system -framework Cocoa

Windows:

No special libraries are needed for the transparency. You should just compile Transparent.cpp and link to sfml the way you do it for your own programs.

Translucent windows

This code in this project works by using a fully opaque image and then applying an alpha value over all the visible pixels, it does not support per-pixel alpha. If you want to use a transparent image and set the alpha values of the window like in the image then check the following resources:

  • Windows: I wrote an implementation for Windows using the UpdateLayeredWindow function.

  • Linux: I found this gist which can be changed to use per-pixel alpha. Adapting it to use SFML only worked when creating the sf::RenderWindow from the created Xlib Window, but not the other way around. If you manage to get it working on linux with a window created by SFML then please let me know.

  • macOS: The code in this repository already supports translucent windows for macOS! You can just replace the image with a transparent one and it will work.

transparentwindows's People

Contributors

texus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

transparentwindows's Issues

mac osx ei capitan render black background

i feel confuse about the code you write about macos

#elif defined (SFML_SYSTEM_MACOS)
    bool setShape(sf::WindowHandle handle, const sf::Image& image);
    bool setTransparency(sf::WindowHandle handle, unsigned char alpha);
#else

when those two function be call, nothing happen.And I run the code in mac, a borderless window with black background and an image in it appear like this:
2015-12-12 16 16 50

(png) alpha gradient possible?

hi!
great example!
currently I consider to enhance my old (linux) game launcher
https://github.com/frostworx/typhon-launcher
a bit and would like to make it work optionally as some "desktop HUD overlay",
so you could work on both the launcher and on the desktop, depending on where you click etc.
for that I need alpha gradient compatibility, but I haven't found a way to make it work.
all alpha gradients are cut rough, so either it is transparent or black.
(f.e. with that image: https://github.com/frostworx/typhon-launcher/blob/master/data/themedata/typhon/jewelcase1.png )
do you have a clue if that could work correctly?
would be nice if you could help.
In case I get something to work, would you mind me committing your code in my project?
of course with mentioning the source.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.