Skip to content

Commit 801fce5

Browse files
committed
chore: make metal graphics example content view full size
1 parent 95a73b4 commit 801fce5

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

examples/metal_graphics.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class ApplicationDelegate extends NSObject {
3535
window.title = "NativeScript for macOS";
3636
window.delegate = this;
3737
window.styleMask = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable |
38-
NSWindowStyleMask.Miniaturizable | NSWindowStyleMask.Resizable;
38+
NSWindowStyleMask.Miniaturizable | NSWindowStyleMask.Resizable |
39+
NSWindowStyleMask.FullSizeContentView;
3940

4041
window.titlebarAppearsTransparent = true;
4142
window.titleVisibility = NSWindowTitleVisibility.Hidden;
@@ -79,11 +80,28 @@ export class Renderer extends NSObject {
7980
/** @type {Uint32Array} */
8081
viewportSize;
8182

83+
/** @type {NSTextField} */
84+
fpsCounter;
85+
86+
updateIterval = 0.5;
87+
accum = 0;
88+
frames = 0;
89+
timeLeft;
90+
previousTime;
91+
92+
set fps(value) {
93+
this.fpsCounter.stringValue = `${Number(value).toFixed(2)} FPS`;
94+
}
95+
8296
/**
8397
* @param {MTKView} mtkView
98+
* @param {NSTextField} fpsCounter
8499
*/
85-
initWithMtkView(mtkView) {
100+
initWithMtkView(mtkView, fpsCounter) {
86101
this.device = mtkView.device;
102+
this.fpsCounter = fpsCounter;
103+
104+
this.updateIterval = this.timeLeft = 0.3;
87105

88106
const error = new interop.Reference();
89107
const library = this.device.newLibraryWithSourceOptionsError(
@@ -251,19 +269,36 @@ export class ViewController extends NSViewController {
251269
mtkView;
252270

253271
loadView() {
254-
this.mtkView = this.view = MTKView.alloc().initWithFrameDevice(
272+
this.mtkView = MTKView.alloc().initWithFrameDevice(
255273
{
256274
origin: { x: 0, y: 0 },
257275
size: { width: 480, height: 480 },
258276
},
259277
MTLCreateSystemDefaultDevice(),
260278
);
279+
280+
this.view = NSView.alloc().initWithFrame(this.mtkView.frame);
281+
this.view.addSubview(this.mtkView);
261282
}
262283

263284
viewDidLoad() {
264285
super.viewDidLoad();
265286

266-
this.renderer = Renderer.new().initWithMtkView(this.mtkView);
287+
const fpsCounter = NSTextField.new();
288+
fpsCounter.stringValue = "60 FPS";
289+
fpsCounter.textColor = NSColor.whiteColor;
290+
fpsCounter.backgroundColor = NSColor.blackColor;
291+
fpsCounter.isBordered = false;
292+
fpsCounter.isEditable = false;
293+
fpsCounter.isSelectable = false;
294+
fpsCounter.frame = {
295+
origin: { x: 10, y: 10 },
296+
size: { width: 60, height: 20 },
297+
};
298+
299+
this.view.addSubview(fpsCounter);
300+
301+
this.renderer = Renderer.new().initWithMtkView(this.mtkView, fpsCounter);
267302

268303
this.mtkView.delegate = this.renderer;
269304
}

0 commit comments

Comments
 (0)