Skip to content

Commit

Permalink
Implement window transparency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apprentice-Alchemist committed Aug 4, 2022
1 parent 88b4fdf commit 1c8c6c1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 1 deletion.
2 changes: 2 additions & 0 deletions project/include/ui/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace lime {
virtual void SetTextInputRect (Rectangle *rect) = 0;
virtual const char* SetTitle (const char* title) = 0;
virtual void WarpMouse (int x, int y) = 0;
virtual float GetOpacity();
virtual void SetOpacity(float opacity);

Application* currentApplication;
int flags;
Expand Down
26 changes: 26 additions & 0 deletions project/src/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,28 @@ namespace lime {

}

double lime_window_get_opacity (value window) {
Window* targetWindow = (Window*)val_data (window);
return (float)targetWindow->GetOpacity ();
}


HL_PRIM double HL_NAME(hl_window_get_opacity) (HL_CFFIPointer* window) {
Window* targetWindow = (Window*)window->ptr;
return (float)targetWindow->GetOpacity ();
}

void lime_window_set_opacity (value window, double opacity) {
Window* targetWindow = (Window*)val_data (window);
targetWindow->SetOpacity((float)opacity);
}


HL_PRIM void HL_NAME(hl_window_set_opacity) (HL_CFFIPointer* window, double opacity) {
Window* targetWindow = (Window*)window->ptr;
targetWindow->SetOpacity ((float)opacity);
}


value lime_zlib_compress (value buffer, value bytes) {

Expand Down Expand Up @@ -3951,6 +3973,8 @@ namespace lime {
DEFINE_PRIME2v (lime_window_set_text_input_rect);
DEFINE_PRIME2 (lime_window_set_title);
DEFINE_PRIME3v (lime_window_warp_mouse);
DEFINE_PRIME1 (lime_window_get_opacity);
DEFINE_PRIME2v (lime_window_set_opacity);
DEFINE_PRIME2 (lime_zlib_compress);
DEFINE_PRIME2 (lime_zlib_decompress);

Expand Down Expand Up @@ -4135,6 +4159,8 @@ namespace lime {
DEFINE_HL_PRIM (_VOID, hl_window_set_text_input_rect, _TCFFIPOINTER _TRECTANGLE);
DEFINE_HL_PRIM (_STRING, hl_window_set_title, _TCFFIPOINTER _STRING);
DEFINE_HL_PRIM (_VOID, hl_window_warp_mouse, _TCFFIPOINTER _I32 _I32);
DEFINE_HL_PRIM (_F64, hl_window_get_opacity, _TCFFIPOINTER);
DEFINE_HL_PRIM (_VOID, hl_window_set_opacity, _TCFFIPOINTER _F64);
DEFINE_HL_PRIM (_TBYTES, hl_zlib_compress, _TBYTES _TBYTES);
DEFINE_HL_PRIM (_TBYTES, hl_zlib_decompress, _TBYTES _TBYTES);

Expand Down
11 changes: 11 additions & 0 deletions project/src/backend/sdl/SDLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,17 @@ namespace lime {

}

float SDLWindow::GetOpacity() {
float opacity = 1.0;
if(SDL_GetWindowOpacity(sdlWindow, &opacity) != 0) {
return 1.0;
}
return opacity;
}

void SDLWindow::SetOpacity(float opacity) {
SDL_SetWindowOpacity(sdlWindow, opacity);
}

Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) {

Expand Down
3 changes: 2 additions & 1 deletion project/src/backend/sdl/SDLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace lime {
virtual void SetTextInputRect (Rectangle *rect);
virtual const char* SetTitle (const char* title);
virtual void WarpMouse (int x, int y);

virtual float GetOpacity();
virtual void SetOpacity(float opacity);
SDL_Renderer* sdlRenderer;
SDL_Texture* sdlTexture;
SDL_Window* sdlWindow;
Expand Down
7 changes: 7 additions & 0 deletions src/lime/_internal/backend/flash/FlashWindow.hx
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,11 @@ class FlashWindow
}

public function warpMouse(x:Int, y:Int):Void {}

public function getOpacity():Float
{
return 1.0;
}

public function setOpacity(value:Float):Void {}
}
4 changes: 4 additions & 0 deletions src/lime/_internal/backend/html5/HTML5Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,4 +1291,8 @@ class HTML5Window
}

public function warpMouse(x:Int, y:Int):Void {}

public function getOpacity():Float { return 1.0; }

public function setOpacity(value:Float):Void {}
}
15 changes: 15 additions & 0 deletions src/lime/_internal/backend/native/NativeCFFI.hx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ class NativeCFFI

@:cffi private static function lime_window_warp_mouse(handle:Dynamic, x:Int, y:Int):Void;

@:cffi private static function lime_window_get_opacity(handle:Dynamic):Float;

@:cffi private static function lime_window_set_opacity(handle:Dynamic, value:Float):Void;

@:cffi private static function lime_window_event_manager_register(callback:Dynamic, eventObject:Dynamic):Void;

@:cffi private static function lime_zlib_compress(data:Dynamic, bytes:Dynamic):Dynamic;
Expand Down Expand Up @@ -601,6 +605,11 @@ class NativeCFFI
false));
private static var lime_window_warp_mouse = new cpp.Callable<cpp.Object->Int->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_window_warp_mouse",
"oiiv", false));
private static var lime_window_get_opacity = new cpp.Callable<cpp.Object->Float>(cpp.Prime._loadPrime("lime", "lime_window_get_opacity", "od", false));
private static var lime_window_set_opacity = new cpp.Callable<cpp.Object->Float->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_opacity", "odv",
false));

private static var lime_window_set_opacity(handle:Dynamic, value:Float):Void;
private static var lime_window_event_manager_register = new cpp.Callable<cpp.Object->cpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime",
"lime_window_event_manager_register", "oov", false));
private static var lime_zlib_compress = new cpp.Callable<cpp.Object->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_zlib_compress", "ooo",
Expand Down Expand Up @@ -754,6 +763,8 @@ class NativeCFFI
private static var lime_window_set_text_input_rect = CFFI.load("lime", "lime_window_set_text_input_rect", 2);
private static var lime_window_set_title = CFFI.load("lime", "lime_window_set_title", 2);
private static var lime_window_warp_mouse = CFFI.load("lime", "lime_window_warp_mouse", 3);
private static var lime_window_get_opacity = CFFI.load("lime", "lime_window_get_opacity", 1);
private static var lime_window_set_opacity = CFFI.load("lime", "lime_window_set_opacity", 2);
private static var lime_window_event_manager_register = CFFI.load("lime", "lime_window_event_manager_register", 2);
private static var lime_zlib_compress = CFFI.load("lime", "lime_zlib_compress", 2);
private static var lime_zlib_decompress = CFFI.load("lime", "lime_zlib_decompress", 2);
Expand Down Expand Up @@ -1357,6 +1368,10 @@ class NativeCFFI

@:hlNative("lime", "hl_window_warp_mouse") private static function lime_window_warp_mouse(handle:CFFIPointer, x:Int, y:Int):Void {}

@:hlNative("lime", "hl_window_get_opacity") private static function lime_window_get_opacity(handle:CFFIPointer):Float;

@:hlNative("lime", "hl_window_set_opacity") private static function lime_window_set_opacity(handle:CFFIPointer, value:Float):Void;

@:hlNative("lime", "hl_window_event_manager_register") private static function lime_window_event_manager_register(callback:Void->Void,
eventObject:WindowEventInfo):Void {}

Expand Down
21 changes: 21 additions & 0 deletions src/lime/_internal/backend/native/NativeWindow.hx
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,27 @@ class NativeWindow
NativeCFFI.lime_window_warp_mouse(handle, x, y);
#end
}

public function getOpacity():Float
{
if (handle != null)
{
#if (!macro && lime_cffi)
return NativeCFFI.lime_window_get_opacity(handle);
#end
}
return 1.0;
}

public function setOpacity(value:Float):Void
{
if (handle != null)
{
#if (!macro && lime_cffi)
NativeCFFI.lime_window_set_opacity(handle, value);
#end
}
}
}

@:enum private abstract MouseCursorType(Int) from Int to Int
Expand Down
8 changes: 8 additions & 0 deletions src/lime/ui/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ class Window
__backend.warpMouse(x, y);
}

public function getOpacity():Float {
return __backend.getOpacity();
}

public function setOpacity(opacity:Float):Void {
__backend.setOpacity(opacity);
}

// Get & Set Methods
@:noCompletion private function get_cursor():MouseCursor
{
Expand Down

0 comments on commit 1c8c6c1

Please sign in to comment.