Rangi42 / tilemap-studio

A tilemap editor for Game Boy, Color, Advance, DS, and SNES projects. Written in C++ with FLTK.
https://hax.iimarckus.org/topic/7691/
Other
381 stars 30 forks source link

Option to make the window transparent #53

Closed Rangi42 closed 3 years ago

Rangi42 commented 3 years ago
void Main_Window::transparent_cb(Fl_Menu_ *m, Main_Window *mw) {
    double alpha = !!m->mvalue()->value() ? 0.75 : 1.0;
#ifdef _WIN32
    HWND hwnd = fl_xid(mw);
    LONG_PTR exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
    if (!(exstyle & WS_EX_LAYERED)) {
        SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle | WS_EX_LAYERED);
    }
    SetLayeredWindowAttributes(hwnd, 0, (BYTE)(alpha * 0xFF), LWA_ALPHA);
#else
    Atom atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
    uint32_t opacity = (uint32_t)(UINT32_MAX * alpha);
    XChangeProperty(fl_display, fl_xid(mw), atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1);
#endif
}