<commit_before>/// @file
/// @author  <NAME>
/// @author  <NAME>
/// @author  <NAME>
/// @version 2.3
/// 
/// @section LICENSE
/// 
/// This program is free software; you can redistribute it and/or modify it under
/// the terms of the BSD license: http://www.opensource.org/licenses/bsd-license.php

#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
#import <AppKit/NSApplication.h>
#import <AppKit/NSCursor.h>
#import <AppKit/NSEvent.h>
#import <AppKit/NSPanel.h>
#import <AppKit/NSScreen.h>
#import <AppKit/NSWindow.h>
#import <Foundation/NSString.h>

#include <gtypes/Vector2.h>

#include "Platform.h"
#include "RenderSystem.h"
#include "Window.h"

namespace april
{
	bool platform_CursorIsVisible()
	{
		return CGCursorIsVisible();
	}
	
	void platform_cursorVisibilityUpdate()
	{
		// mac only: extra visibility handling
		NSWindow* window = [[NSApplication sharedApplication] keyWindow];
		bool shouldShow;
		
		if (!april::window->isCursorVisible())
		{
			//NSPoint 	mouseLoc = [window convertScreenToBase:[NSEvent mouseLocation]];
			//[window frame]
			NSPoint mouseLoc;
			id hideInsideView; // either NSView or NSWindow; both implement "frame" method
			if ([window contentView])
			{
				hideInsideView = [window contentView];
				mouseLoc = [window convertScreenToBase:[NSEvent mouseLocation]];
			}
			else
			{
				hideInsideView = window;
				mouseLoc = [NSEvent mouseLocation];
			}
			
			if (hideInsideView)
			{
				shouldShow = !NSPointInRect(mouseLoc, [hideInsideView frame]);
			}
			else // no view? let's presume we are in fullscreen where we should blindly honor the requests from the game
			{
				shouldShow = false;
			}
		}
		else
		{			
			shouldShow = true;
		}
		
		if (!shouldShow && CGCursorIsVisible())
		{
			CGDisplayHideCursor(kCGDirectMainDisplay);
		}
		else if (shouldShow && !CGCursorIsVisible())
		{
			CGDisplayShowCursor(kCGDirectMainDisplay);
		}
	}
	
	SystemInfo getSystemInfo()
	{
		// TODO
		static SystemInfo info;
		if (info.locale == "")
		{
			// CPU cores
			info.cpuCores = sysconf(_SC_NPROCESSORS_ONLN);
			// RAM
			info.name = "mac";
			info.ram = 1024; // TODO
			// display resolution
			NSScreen* mainScreen = [NSScreen mainScreen];
			NSRect rect = [mainScreen frame];
			info.displayResolution.set((float)rect.size.width, (float)rect.size.height);
			// display DPI
			info.displayDpi = 72; // TODO
			info.maxTextureSize = 0;
			// locale<commit_msg>* mac - added fetching of mac system ram size<commit_after>/// @file
/// @author  <NAME>
/// @author  <NAME>
/// @author  <NAME>
/// @version 2.3
/// 
/// @section LICENSE
/// 
/// This program is free software; you can redistribute it and/or modify it under
/// the terms of the BSD license: http://www.opensource.org/licenses/bsd-license.php
#include <sys/sysctl.h>
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
#import <AppKit/NSApplication.h>
#import <AppKit/NSCursor.h>
#import <AppKit/NSEvent.h>
#import <AppKit/NSPanel.h>
#import <AppKit/NSScreen.h>
#import <AppKit/NSWindow.h>
#import <Foundation/NSString.h>

#include <gtypes/Vector2.h>

#include "Platform.h"
#include "RenderSystem.h"
#include "Window.h"

namespace april
{
	bool platform_CursorIsVisible()
	{
		return CGCursorIsVisible();
	}
	
	void platform_cursorVisibilityUpdate()
	{
		// mac only: extra visibility handling
		NSWindow* window = [[NSApplication sharedApplication] keyWindow];
		bool shouldShow;
		
		if (!april::window->isCursorVisible())
		{
			//NSPoint 	mouseLoc = [window convertScreenToBase:[NSEvent mouseLocation]];
			//[window frame]
			NSPoint mouseLoc;
			id hideInsideView; // either NSView or NSWindow; both implement "frame" method
			if ([window contentView])
			{
				hideInsideView = [window contentView];
				mouseLoc = [window convertScreenToBase:[NSEvent mouseLocation]];
			}
			else
			{
				hideInsideView = window;
				mouseLoc = [NSEvent mouseLocation];
			}
			
			if (hideInsideView)
			{
				shouldShow = !NSPointInRect(mouseLoc, [hideInsideView frame]);
			}
			else // no view? let's presume we are in fullscreen where we should blindly honor the requests from the game
			{
				shouldShow = false;
			}
		}
		else
		{			
			shouldShow = true;
		}
		
		if (!shouldShow && CGCursorIsVisible())
		{
			CGDisplayHideCursor(kCGDirectMainDisplay);
		}
		else if (shouldShow && !CGCursorIsVisible())
		{
			CGDisplayShowCursor(kCGDirectMainDisplay);
		}
	}
	
	SystemInfo getSystemInfo()
	{
		// TODO
		static SystemInfo info;
		if (info.locale == "")
		{
			// CPU cores
			info.cpuCores = sysconf(_SC_NPROCESSORS_ONLN);
			// RAM
			info.name = "mac";

			int mib [] = { CTL_HW, HW_MEMSIZE };
			int64_t value = 0;
			size_t length = sizeof(value);

			if (sysctl(mib, 2, &value, &length, NULL, 0) == -1)
				info.ram = 2048;
			else
				info.ram = value / (1024 * 1024);

			// display resolution
			NSScreen* mainScreen = [NSScreen mainScreen];
			NSRect rect = [mainScreen frame];
			info.displayResolution.set((float)rect.size.width, (float)rect.size.height);
			// display DPI
			info.displayDpi = 72; // TODO
			info.maxTextureSize = 0;
			// locale
{'fraction_non_alphanumeric': 0.13017408123791102, 'fraction_numerical': 0.0065764023210831725, 'mean_word_length': 3.400851063829787, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2068275', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1741, 'n_words': 423}