Skip to content

Commit

Permalink
WindowMac::move, WindowMac::resize
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed May 20, 2021
1 parent 6e363ba commit 661e241
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions examples/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public Example() {
_window = App.makeWindow();
_window.setEventListener(this);
changeLayer();
var scale = _window.getScale();
_window.move((int) (100 * scale), (int) (100 * scale));
_window.resize((int) (800 * scale), (int) (600 * scale));
_window.show();
_window.requestFrame();
}
Expand Down
2 changes: 2 additions & 0 deletions macos/cc/WindowMac.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace jwm {
void show();
void reconfigure();
float getScale() const;
void move(int left, int top);
void resize(int width, int height);
void requestFrame();
void close();

Expand Down
27 changes: 26 additions & 1 deletion macos/cc/WindowMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
return (fNSWindow.screen ?: [NSScreen mainScreen]).backingScaleFactor;
}

void jwm::WindowMac::move(int left, int top) {
auto screen = fNSWindow.screen ?: [NSScreen mainScreen];
auto scale = screen.backingScaleFactor;
NSPoint point {(CGFloat) left / scale, screen.frame.size.height - (CGFloat) top / scale};
[fNSWindow setFrameTopLeftPoint:point];
}

void jwm::WindowMac::resize(int width, int height) {
auto scale = getScale();
NSSize size {(CGFloat) width / scale, (CGFloat) height / scale};
[fNSWindow setContentSize:size];
}

void jwm::WindowMac::requestFrame() {
fFrameRequested = true;
if (!CVDisplayLinkIsRunning(fDisplayLink))
Expand Down Expand Up @@ -149,10 +162,22 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
return instance->getScale();
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_WindowMac_move
(JNIEnv* env, jobject obj, int left, int top) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
instance->move(left, top);
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_WindowMac_resize
(JNIEnv* env, jobject obj, int width, int height) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
instance->resize(width, height);
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_WindowMac_requestFrame
(JNIEnv* env, jobject obj) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
return instance->requestFrame();
instance->requestFrame();
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_WindowMac__1nClose
Expand Down
8 changes: 2 additions & 6 deletions macos/java/WindowMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ public WindowMac() {
public native float getScale();

@Override
public void move(int left, int top) {
throw new UnsupportedOperationException("Not implemented");
}
public native void move(int left, int top);

@Override
public void resize(int width, int height) {
throw new UnsupportedOperationException("Not implemented");
}
public native void resize(int width, int height);

@Override
public native void requestFrame();
Expand Down

0 comments on commit 661e241

Please sign in to comment.