Kaynağa Gözat

Isolate window methods

Define create window prototype in header.
master
TheoryOfNekomata 1 yıl önce
ebeveyn
işleme
81e96bb4f6
2 değiştirilmiş dosya ile 51 ekleme ve 15 silme
  1. +27
    -10
      src/main.h
  2. +24
    -5
      src/main.m

+ 27
- 10
src/main.h Dosyayı Görüntüle

@@ -1,16 +1,33 @@
//
// main.h
// cerberus
//
// Created by Allan Crisostomo on 2023-01-06.
//

#ifndef main_h
#define main_h
#ifndef MAIN_H
#define MAIN_H

#define WINDOW_X 0
#define WINDOW_Y 0
#define WINDOW_WIDTH 350
#define WINDOW_HEIGHT 250

#endif /* main_h */
typedef enum {
CBR_WINDOW_STYLE_FLAG_BORDERLESS = 0,
CBR_WINDOW_STYLE_FLAG_TITLED = 1 << 0,
CBR_WINDOW_STYLE_FLAG_CLOSABLE = 1 << 1,
CBR_WINDOW_STYLE_FLAG_MINIATURIZABLE = 1 << 2,
CBR_WINDOW_STYLE_FLAG_RESIZABLE = 1 << 3,
CBR_WINDOW_STYLE_FLAG_FULL_SCREEN = 1 << 14,
} CBR_WindowStyleFlag;

typedef struct {
float x;
float y;
float width;
float height;
} CBR_Rect;

typedef struct {
CBR_Rect rect;
CBR_WindowStyleFlag style_flags;
const char* title;
} CBR_CreateWindowParams;

void* CBR_CreateWindow(CBR_CreateWindowParams);

#endif

+ 24
- 5
src/main.m Dosyayı Görüntüle

@@ -1,15 +1,34 @@
#import <Cocoa/Cocoa.h>
#import "main.h"

void* CBR_CreateWindow(CBR_CreateWindowParams params) {
id window = [
[NSWindow alloc] initWithContentRect:NSMakeRect(params.rect.x, params.rect.y, params.rect.width, params.rect.height)
styleMask: (NSWindowStyleMask)params.style_flags
backing:NSBackingStoreBuffered
defer:NO
];
[window cascadeTopLeftFromPoint:NSMakePoint(0,0)];
[window setTitle: [NSString stringWithUTF8String:(params.title)]];
[window makeKeyAndOrderFront:nil];
return (__bridge void *)(window);
}

int main() {
@autoreleasepool{
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
id applicationName = [[NSProcessInfo processInfo] processName];
id window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 120, 120)
styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:NO];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window setTitle: applicationName];
[window makeKeyAndOrderFront:nil];
void* window = CBR_CreateWindow((CBR_CreateWindowParams) {
.rect = {
.x = WINDOW_X,
.y = WINDOW_Y,
.width = WINDOW_WIDTH,
.height = WINDOW_HEIGHT
},
.style_flags = CBR_WINDOW_STYLE_FLAG_TITLED,
.title = [applicationName cStringUsingEncoding:NSUTF8StringEncoding]
});
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
}


Yükleniyor…
İptal
Kaydet