2022-12-21 02:14:45 -08:00

82 lines
2.4 KiB
Objective-C

//
// AppDelegate.m
// cunnyfinder
//
// Created by Femployee on 12/16/22.
// Copyright (c) 2022 FemboyFinancial. All rights reserved.
//
#import "AppDelegate.h"
#import "libbooru/BooruClient.h"
#import "ui/ClickableImageView.h"
@implementation AppDelegate
BooruClient* booru;
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
booru = [[BooruClient alloc] init:@[@"hatsune_miku", @"kuroki_tomoko", @"monika_(doki_doki_literature_club)", @"megumin"]];
}
-(NSRect)randomPositionWithWidth:(int)width height:(int)height
{
float x = arc4random_uniform(self.window.frame.size.width - width);
float y = arc4random_uniform(self.window.frame.size.height - height);
NSRect rect = NSMakeRect(x, y, width, height);
return rect;
}
-(void)addWaifu:(id)btn
{
// find the image
BooruImage* img = [booru search];
// download and show image
NSRect frame = [self randomPositionWithWidth:[img previewWidth] height:[img previewHeight]];
ClickableImageView* imgView = [[ClickableImageView alloc] initWithFrame:frame imageUrl:[img fileUrl]];
NSURL* displayUrl;
if ([img hasSample])
{
displayUrl = [img sampleUrl];
}
else
{
displayUrl = [img fileUrl];
}
[booru downloadAndDisplayImage:displayUrl inView:imgView];
[self.window.contentView addSubview:imgView positioned:NSWindowBelow relativeTo:btn];
// cleanup
[booru reset];
}
-(IBAction)actionUohhh:(id)sender
{
/*
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:@"Uohhh!"];
[alert setInformativeText:@"Damn bratty girl, seducing an adult... correction is needed!"];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert runModal];
*/
bool brat = arc4random_uniform(20) == 0;
NSTextField *label = [[NSTextField alloc] initWithFrame:[self randomPositionWithWidth:48 height:48]];
[label setEditable:false];
[label setBezeled:false];
[label setFont:[NSFont fontWithName:@"Apple Color Emoji" size:32]];
[label setBackgroundColor:[NSColor colorWithDeviceWhite:0 alpha:0]];
[label setAlignment:NSCenterTextAlignment];
if (brat) {
[label setStringValue:@"💢"];
[self addWaifu:sender];
} else {
[label setStringValue:@"😭"];
}
[self.window.contentView addSubview:label positioned:NSWindowBelow relativeTo:sender];
}
@end