Skip to content

Commit

Permalink
Add some more window manip methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Speak2Erase committed Aug 15, 2024
1 parent 0850bb2 commit 405ae5e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
28 changes: 28 additions & 0 deletions binding/modshot-window-binding.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "SDL3/SDL_video.h"
#include "oneshot.h"
#include "sharedstate.h"
#include "binding-util.h"
Expand Down Expand Up @@ -72,6 +73,30 @@ RB_METHOD(SetWindowOpacity) {
return Qnil;
}

RB_METHOD(SetAlwaysOnTop) {
bool top;
rb_get_args(argc, argv, "b", &top);
SDL_SetWindowAlwaysOnTop(shState->rtData().window, top);
return Qnil;
}

RB_METHOD(FlashWindow) {
int state;
rb_get_args(argc, argv, "i", &state);

if (state < SDL_FLASH_CANCEL || state > SDL_FLASH_UNTIL_FOCUSED)
rb_raise(rb_eArgError, "Invalid flash state");

SDL_FlashWindow(shState->rtData().window, (SDL_FlashOperation) state);
return Qnil;
}

RB_METHOD(WindowRaise) {
RB_UNUSED_PARAM;
SDL_RaiseWindow(shState->rtData().window);
return Qnil;
}

void modshotwindowBindingInit()
{
VALUE module = rb_define_module("ModWindow");
Expand All @@ -80,5 +105,8 @@ void modshotwindowBindingInit()
_rb_define_module_function(module, "SetTitle", SetTitle);
_rb_define_module_function(module, "SetIcon", SetIcon);
_rb_define_module_function(module, "setWindowOpacity", SetWindowOpacity);
_rb_define_module_function(module, "setAlwaysOnTop", SetAlwaysOnTop);
_rb_define_module_function(module, "flashWindow", FlashWindow);
_rb_define_module_function(module, "raiseWindow", WindowRaise);
//_rb_define_module_function(module, "setWindowChromaKey", SetTransparentColor);
}
41 changes: 41 additions & 0 deletions binding/osfm-screen-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,44 @@ RB_METHOD(monitorWindowHide) {
return Qnil;
}

RB_METHOD(monitorSetAlwaysOnTop) {
MonitorWindow* window = getPrivateData<MonitorWindow>(self);

GUARD_DISPOSED(window);

bool top;
rb_get_args(argc, argv, "b", &top);

SDL_SetWindowAlwaysOnTop(window->window, top);

return Qnil;
}

RB_METHOD(monitorFlashWindow) {
MonitorWindow* window = getPrivateData<MonitorWindow>(self);

GUARD_DISPOSED(window);

int state;
rb_get_args(argc, argv, "i", &state);

if (state < SDL_FLASH_CANCEL || state > SDL_FLASH_UNTIL_FOCUSED)
rb_raise(rb_eArgError, "Invalid flash state");

SDL_FlashWindow(window->window, (SDL_FlashOperation) state);
return Qnil;
}

RB_METHOD(monitorWindowRaise) {
MonitorWindow* window = getPrivateData<MonitorWindow>(self);

GUARD_DISPOSED(window);

SDL_RaiseWindow(window->window);

return Qnil;
}

void osfmBindingInit() {

VALUE klass = rb_define_class("MonitorWindow", rb_cObject);
Expand All @@ -475,6 +513,9 @@ void osfmBindingInit() {
_rb_define_method(klass, "position", monitorWindowPos);
_rb_define_method(klass, "show", monitorWindowShow);
_rb_define_method(klass, "hide", monitorWindowHide);
_rb_define_method(klass, "set_always_on_top", monitorSetAlwaysOnTop);
_rb_define_method(klass, "flash", monitorFlashWindow);
_rb_define_method(klass, "raise", monitorWindowRaise);

rb_define_const(klass, "UNDEFINED_POS", INT2NUM(SDL_WINDOWPOS_UNDEFINED));
rb_define_const(klass, "CENTERED_POS", INT2NUM(SDL_WINDOWPOS_CENTERED));
Expand Down

0 comments on commit 405ae5e

Please sign in to comment.