mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
Added native startup window for OS X
This commit is contained in:
parent
673e1b4faf
commit
3af95e0aea
8 changed files with 808 additions and 16 deletions
|
@ -591,8 +591,7 @@ set( PLAT_WIN32_SOURCES
|
|||
set( PLAT_POSIX_SOURCES
|
||||
posix/i_cd.cpp
|
||||
posix/i_movie.cpp
|
||||
posix/i_steam.cpp
|
||||
posix/st_start.cpp )
|
||||
posix/i_steam.cpp )
|
||||
set( PLAT_SDL_SOURCES
|
||||
posix/sdl/crashcatcher.c
|
||||
posix/sdl/hardware.cpp
|
||||
|
@ -602,7 +601,8 @@ set( PLAT_SDL_SOURCES
|
|||
posix/sdl/i_main.cpp
|
||||
posix/sdl/i_system.cpp
|
||||
posix/sdl/i_timer.cpp
|
||||
posix/sdl/sdlvideo.cpp )
|
||||
posix/sdl/sdlvideo.cpp
|
||||
posix/sdl/st_start.cpp )
|
||||
set( PLAT_OSX_SOURCES
|
||||
posix/osx/iwadpicker_cocoa.mm
|
||||
posix/osx/zdoom.icns )
|
||||
|
@ -613,7 +613,9 @@ set( PLAT_COCOA_SOURCES
|
|||
posix/cocoa/i_main.mm
|
||||
posix/cocoa/i_system.mm
|
||||
posix/cocoa/i_timer.cpp
|
||||
posix/cocoa/i_video.mm )
|
||||
posix/cocoa/i_video.mm
|
||||
posix/cocoa/st_console.mm
|
||||
posix/cocoa/st_start.mm )
|
||||
|
||||
if( WIN32 )
|
||||
set( SYSTEM_SOURCES_DIR win32 )
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "i_system.h"
|
||||
#include "m_argv.h"
|
||||
#include "s_sound.h"
|
||||
#include "st_console.h"
|
||||
#include "version.h"
|
||||
|
||||
#undef Class
|
||||
|
@ -125,18 +126,7 @@ void Mac_I_FatalError(const char* const message)
|
|||
{
|
||||
I_SetMainWindowVisible(false);
|
||||
|
||||
const CFStringRef errorString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
|
||||
message, kCFStringEncodingASCII, kCFAllocatorNull);
|
||||
|
||||
if (NULL != errorString)
|
||||
{
|
||||
CFOptionFlags dummy;
|
||||
|
||||
CFUserNotificationDisplayAlert( 0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL,
|
||||
CFSTR("Fatal Error"), errorString, CFSTR("Exit"), NULL, NULL, &dummy);
|
||||
|
||||
CFRelease(errorString);
|
||||
}
|
||||
FConsoleWindow::GetInstance().ShowFatalError(message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -315,6 +305,9 @@ ApplicationController* appCtrl;
|
|||
[[NSRunLoop currentRunLoop] addTimer:timer
|
||||
forMode:NSDefaultRunLoopMode];
|
||||
|
||||
FConsoleWindow::CreateInstance();
|
||||
atterm(FConsoleWindow::DeleteInstance);
|
||||
|
||||
exit(OriginalMain(s_argc, s_argv));
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "gameconfigfile.h"
|
||||
#include "i_sound.h"
|
||||
#include "i_system.h"
|
||||
#include "st_console.h"
|
||||
#include "v_text.h"
|
||||
#include "x86.h"
|
||||
|
||||
|
@ -184,6 +185,8 @@ void I_SetIWADInfo()
|
|||
|
||||
void I_PrintStr(const char* const message)
|
||||
{
|
||||
FConsoleWindow::GetInstance().AddText(message);
|
||||
|
||||
// Strip out any color escape sequences before writing to output
|
||||
char* const copy = new char[strlen(message) + 1];
|
||||
const char* srcp = message;
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "m_argv.h"
|
||||
#include "r_renderer.h"
|
||||
#include "r_swrenderer.h"
|
||||
#include "st_console.h"
|
||||
#include "stats.h"
|
||||
#include "textures.h"
|
||||
#include "v_palette.h"
|
||||
|
@ -445,6 +446,8 @@ CocoaVideo::CocoaVideo(const int multisample)
|
|||
[[glView openGLContext] makeCurrentContext];
|
||||
|
||||
[m_window setContentView:glView];
|
||||
|
||||
FConsoleWindow::GetInstance().Show(false);
|
||||
}
|
||||
|
||||
void CocoaVideo::StartModeIterator(const int bits, const bool fullscreen)
|
||||
|
|
95
src/posix/cocoa/st_console.h
Normal file
95
src/posix/cocoa/st_console.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
** st_console.h
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2015 Alexey Lysiuk
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef COCOA_ST_CONSOLE_INCLUDED
|
||||
#define COCOA_ST_CONSOLE_INCLUDED
|
||||
|
||||
@class NSButton;
|
||||
@class NSProgressIndicator;
|
||||
@class NSScrollView;
|
||||
@class NSTextField;
|
||||
@class NSTextView;
|
||||
@class NSView;
|
||||
@class NSWindow;
|
||||
|
||||
struct PalEntry;
|
||||
|
||||
|
||||
class FConsoleWindow
|
||||
{
|
||||
public:
|
||||
static FConsoleWindow& GetInstance();
|
||||
|
||||
static void CreateInstance();
|
||||
static void DeleteInstance();
|
||||
|
||||
void Show(bool visible);
|
||||
void ShowFatalError(const char* message);
|
||||
|
||||
void AddText(const char* message);
|
||||
|
||||
void SetTitleText();
|
||||
void SetProgressBar(bool visible);
|
||||
|
||||
// FStartupScreen functionality
|
||||
void Progress(int current, int maximum);
|
||||
void NetInit(const char* message, int playerCount);
|
||||
void NetProgress(int count);
|
||||
void NetDone();
|
||||
|
||||
private:
|
||||
NSWindow* m_window;
|
||||
NSTextView* m_textView;
|
||||
NSScrollView* m_scrollView;
|
||||
NSProgressIndicator* m_progressBar;
|
||||
|
||||
NSView* m_netView;
|
||||
NSTextField* m_netMessageText;
|
||||
NSTextField* m_netCountText;
|
||||
NSProgressIndicator* m_netProgressBar;
|
||||
NSButton* m_netAbortButton;
|
||||
|
||||
unsigned int m_characterCount;
|
||||
|
||||
int m_netCurPos;
|
||||
int m_netMaxPos;
|
||||
|
||||
FConsoleWindow();
|
||||
~FConsoleWindow();
|
||||
|
||||
void ExpandTextView(float height);
|
||||
|
||||
void AddText(const PalEntry& color, const char* message);
|
||||
};
|
||||
|
||||
#endif // COCOA_ST_CONSOLE_INCLUDED
|
506
src/posix/cocoa/st_console.mm
Normal file
506
src/posix/cocoa/st_console.mm
Normal file
|
@ -0,0 +1,506 @@
|
|||
/*
|
||||
** st_console.mm
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2015 Alexey Lysiuk
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include "i_common.h"
|
||||
|
||||
#include "d_main.h"
|
||||
#include "i_system.h"
|
||||
#include "st_console.h"
|
||||
#include "v_text.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
static NSColor* RGB(const BYTE red, const BYTE green, const BYTE blue)
|
||||
{
|
||||
return [NSColor colorWithCalibratedRed:red / 255.0f
|
||||
green:green / 255.0f
|
||||
blue:blue / 255.0f
|
||||
alpha:1.0f];
|
||||
}
|
||||
|
||||
static NSColor* RGB(const PalEntry& color)
|
||||
{
|
||||
return RGB(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
static NSColor* RGB(const DWORD color)
|
||||
{
|
||||
return RGB(PalEntry(color));
|
||||
}
|
||||
|
||||
|
||||
static const CGFloat PROGRESS_BAR_HEIGHT = 18.0f;
|
||||
static const CGFloat NET_VIEW_HEIGHT = 88.0f;
|
||||
|
||||
|
||||
FConsoleWindow::FConsoleWindow()
|
||||
: m_window([NSWindow alloc])
|
||||
, m_textView([NSTextView alloc])
|
||||
, m_scrollView([NSScrollView alloc])
|
||||
, m_progressBar(nil)
|
||||
, m_netView(nil)
|
||||
, m_netMessageText(nil)
|
||||
, m_netCountText(nil)
|
||||
, m_netProgressBar(nil)
|
||||
, m_netAbortButton(nil)
|
||||
, m_characterCount(0)
|
||||
, m_netCurPos(0)
|
||||
, m_netMaxPos(0)
|
||||
{
|
||||
const CGFloat initialWidth = 512.0f;
|
||||
const CGFloat initialHeight = 384.0f;
|
||||
const NSRect initialRect = NSMakeRect(0.0f, 0.0f, initialWidth, initialHeight);
|
||||
|
||||
[m_textView initWithFrame:initialRect];
|
||||
[m_textView setEditable:NO];
|
||||
[m_textView setBackgroundColor:RGB(70, 70, 70)];
|
||||
[m_textView setMinSize:NSMakeSize(0.0f, initialHeight)];
|
||||
[m_textView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
|
||||
[m_textView setVerticallyResizable:YES];
|
||||
[m_textView setHorizontallyResizable:NO];
|
||||
[m_textView setAutoresizingMask:NSViewWidthSizable];
|
||||
|
||||
NSTextContainer* const textContainer = [m_textView textContainer];
|
||||
[textContainer setContainerSize:NSMakeSize(initialWidth, FLT_MAX)];
|
||||
[textContainer setWidthTracksTextView:YES];
|
||||
|
||||
[m_scrollView initWithFrame:NSMakeRect(0.0f, 0.0f, initialWidth, initialHeight)];
|
||||
[m_scrollView setBorderType:NSNoBorder];
|
||||
[m_scrollView setHasVerticalScroller:YES];
|
||||
[m_scrollView setHasHorizontalScroller:NO];
|
||||
[m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[m_scrollView setDocumentView:m_textView];
|
||||
|
||||
NSString* const title = [NSString stringWithFormat:@"%s %s - Console", GAMESIG, GetVersionString()];
|
||||
|
||||
[m_window initWithContentRect:initialRect
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
[m_window setMinSize:[m_window frame].size];
|
||||
[m_window setTitle:title];
|
||||
[m_window center];
|
||||
[m_window exitAppOnClose];
|
||||
|
||||
[[m_window contentView] addSubview:m_scrollView];
|
||||
|
||||
[m_window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
FConsoleWindow::~FConsoleWindow()
|
||||
{
|
||||
[m_window close];
|
||||
}
|
||||
|
||||
|
||||
static FConsoleWindow* s_instance;
|
||||
|
||||
|
||||
void FConsoleWindow::CreateInstance()
|
||||
{
|
||||
assert(NULL == s_instance);
|
||||
s_instance = new FConsoleWindow;
|
||||
}
|
||||
|
||||
void FConsoleWindow::DeleteInstance()
|
||||
{
|
||||
assert(NULL != s_instance);
|
||||
delete s_instance;
|
||||
s_instance = NULL;
|
||||
}
|
||||
|
||||
FConsoleWindow& FConsoleWindow::GetInstance()
|
||||
{
|
||||
assert(NULL != s_instance);
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::Show(const bool visible)
|
||||
{
|
||||
if (visible)
|
||||
{
|
||||
[m_window orderFront:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[m_window orderOut:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void FConsoleWindow::ShowFatalError(const char* const message)
|
||||
{
|
||||
SetProgressBar(false);
|
||||
NetDone();
|
||||
|
||||
const CGFloat textViewWidth = [m_scrollView frame].size.width;
|
||||
|
||||
ExpandTextView(-32.0f);
|
||||
|
||||
NSButton* quitButton = [[NSButton alloc] initWithFrame:NSMakeRect(textViewWidth - 76.0f, 0.0f, 72.0f, 30.0f)];
|
||||
[quitButton setAutoresizingMask:NSViewMinXMargin];
|
||||
[quitButton setBezelStyle:NSRoundedBezelStyle];
|
||||
[quitButton setTitle:@"Quit"];
|
||||
[quitButton setKeyEquivalent:@"\r"];
|
||||
[quitButton setTarget:NSApp];
|
||||
[quitButton setAction:@selector(terminate:)];
|
||||
|
||||
NSView* quitPanel = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, textViewWidth, 32.0f)];
|
||||
[quitPanel setAutoresizingMask:NSViewWidthSizable];
|
||||
[quitPanel addSubview:quitButton];
|
||||
|
||||
[[m_window contentView] addSubview:quitPanel];
|
||||
[m_window orderFront:nil];
|
||||
|
||||
AddText(PalEntry(255, 0, 0), "\nExecution could not continue.\n");
|
||||
AddText(PalEntry(255, 255, 170), message);
|
||||
AddText("\n");
|
||||
|
||||
// It's impossible to restore minimized window in modal loop
|
||||
[m_window setStyleMask:[m_window styleMask] & ~NSMiniaturizableWindowMask];
|
||||
|
||||
[NSApp runModalForWindow:m_window];
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::AddText(const char* message)
|
||||
{
|
||||
PalEntry color(223, 223, 223);
|
||||
|
||||
char buffer[1024] = {};
|
||||
size_t pos = 0;
|
||||
bool reset = false;
|
||||
|
||||
while (*message != '\0')
|
||||
{
|
||||
if ((TEXTCOLOR_ESCAPE == *message && 0 != pos)
|
||||
|| (pos == sizeof buffer - 1)
|
||||
|| reset)
|
||||
{
|
||||
buffer[pos] = '\0';
|
||||
pos = 0;
|
||||
reset = false;
|
||||
|
||||
AddText(color, buffer);
|
||||
}
|
||||
|
||||
#define CHECK_BUFFER_SPACE \
|
||||
if (pos >= sizeof buffer - 3) { reset = true; continue; }
|
||||
|
||||
if (TEXTCOLOR_ESCAPE == *message)
|
||||
{
|
||||
const BYTE* colorID = reinterpret_cast<const BYTE*>(message) + 1;
|
||||
if ('\0' == colorID)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const EColorRange range = V_ParseFontColor(colorID, CR_UNTRANSLATED, CR_YELLOW);
|
||||
|
||||
if (range != CR_UNDEFINED)
|
||||
{
|
||||
color = V_LogColorFromColorRange(range);
|
||||
}
|
||||
|
||||
message += 2;
|
||||
}
|
||||
else if (0x1d == *message) // Opening bar character
|
||||
{
|
||||
CHECK_BUFFER_SPACE;
|
||||
|
||||
// Insert BOX DRAWINGS LIGHT LEFT AND HEAVY RIGHT
|
||||
buffer[pos++] = '\xe2';
|
||||
buffer[pos++] = '\x95';
|
||||
buffer[pos++] = '\xbc';
|
||||
++message;
|
||||
}
|
||||
else if (0x1e == *message) // Middle bar character
|
||||
{
|
||||
CHECK_BUFFER_SPACE;
|
||||
|
||||
// Insert BOX DRAWINGS HEAVY HORIZONTAL
|
||||
buffer[pos++] = '\xe2';
|
||||
buffer[pos++] = '\x94';
|
||||
buffer[pos++] = '\x81';
|
||||
++message;
|
||||
}
|
||||
else if (0x1f == *message) // Closing bar character
|
||||
{
|
||||
CHECK_BUFFER_SPACE;
|
||||
|
||||
// Insert BOX DRAWINGS HEAVY LEFT AND LIGHT RIGHT
|
||||
buffer[pos++] = '\xe2';
|
||||
buffer[pos++] = '\x95';
|
||||
buffer[pos++] = '\xbe';
|
||||
++message;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[pos++] = *message++;
|
||||
}
|
||||
|
||||
#undef CHECK_BUFFER_SPACE
|
||||
}
|
||||
|
||||
if (0 != pos)
|
||||
{
|
||||
buffer[pos] = '\0';
|
||||
|
||||
AddText(color, buffer);
|
||||
}
|
||||
|
||||
if ([m_window isVisible])
|
||||
{
|
||||
[m_textView scrollRangeToVisible:NSMakeRange(m_characterCount, 0)];
|
||||
|
||||
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
}
|
||||
|
||||
void FConsoleWindow::AddText(const PalEntry& color, const char* const message)
|
||||
{
|
||||
NSString* const text = [NSString stringWithUTF8String:message];
|
||||
|
||||
NSDictionary* const attributes = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSFont systemFontOfSize:14.0f], NSFontAttributeName,
|
||||
RGB(color), NSForegroundColorAttributeName,
|
||||
nil];
|
||||
|
||||
NSAttributedString* const formattedText =
|
||||
[[NSAttributedString alloc] initWithString:text
|
||||
attributes:attributes];
|
||||
[[m_textView textStorage] appendAttributedString:formattedText];
|
||||
|
||||
m_characterCount += [text length];
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::SetTitleText()
|
||||
{
|
||||
static const CGFloat TITLE_TEXT_HEIGHT = 32.0f;
|
||||
|
||||
NSRect textViewFrame = [m_scrollView frame];
|
||||
textViewFrame.size.height -= TITLE_TEXT_HEIGHT;
|
||||
[m_scrollView setFrame:textViewFrame];
|
||||
|
||||
const NSRect titleTextRect = NSMakeRect(
|
||||
0.0f,
|
||||
textViewFrame.origin.y + textViewFrame.size.height,
|
||||
textViewFrame.size.width,
|
||||
TITLE_TEXT_HEIGHT);
|
||||
|
||||
NSTextField* titleText = [[NSTextField alloc] initWithFrame:titleTextRect];
|
||||
[titleText setStringValue:[NSString stringWithUTF8String:DoomStartupInfo.Name]];
|
||||
[titleText setAlignment:NSCenterTextAlignment];
|
||||
[titleText setTextColor:RGB(DoomStartupInfo.FgColor)];
|
||||
[titleText setBackgroundColor:RGB(DoomStartupInfo.BkColor)];
|
||||
[titleText setFont:[NSFont fontWithName:@"Trebuchet MS Bold" size:18.0f]];
|
||||
[titleText setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
|
||||
[titleText setSelectable:NO];
|
||||
[titleText setBordered:NO];
|
||||
|
||||
[[m_window contentView] addSubview:titleText];
|
||||
}
|
||||
|
||||
void FConsoleWindow::SetProgressBar(const bool visible)
|
||||
{
|
||||
if ( (!visible && nil == m_progressBar)
|
||||
|| (visible && nil != m_progressBar))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (visible)
|
||||
{
|
||||
ExpandTextView(-PROGRESS_BAR_HEIGHT);
|
||||
|
||||
m_progressBar = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(2.0f, 0.0f, 508.0f, 16.0f)];
|
||||
[m_progressBar setIndeterminate:NO];
|
||||
[m_progressBar setAutoresizingMask:NSViewWidthSizable];
|
||||
|
||||
[[m_window contentView] addSubview:m_progressBar];
|
||||
}
|
||||
else
|
||||
{
|
||||
ExpandTextView(PROGRESS_BAR_HEIGHT);
|
||||
|
||||
[m_progressBar removeFromSuperview];
|
||||
[m_progressBar release];
|
||||
m_progressBar = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::ExpandTextView(const float height)
|
||||
{
|
||||
NSRect textFrame = [m_scrollView frame];
|
||||
textFrame.origin.y -= height;
|
||||
textFrame.size.height += height;
|
||||
[m_scrollView setFrame:textFrame];
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::Progress(const int current, const int maximum)
|
||||
{
|
||||
if (nil == m_progressBar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned int previousTime = I_MSTime();
|
||||
unsigned int currentTime = I_MSTime();
|
||||
|
||||
if (currentTime - previousTime > 33) // approx. 30 FPS
|
||||
{
|
||||
previousTime = currentTime;
|
||||
|
||||
[m_progressBar setMaxValue:maximum];
|
||||
[m_progressBar setDoubleValue:current];
|
||||
|
||||
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FConsoleWindow::NetInit(const char* const message, const int playerCount)
|
||||
{
|
||||
if (nil == m_netView)
|
||||
{
|
||||
SetProgressBar(false);
|
||||
ExpandTextView(-NET_VIEW_HEIGHT);
|
||||
|
||||
// Message like 'Waiting for players' or 'Contacting host'
|
||||
m_netMessageText = [[NSTextField alloc] initWithFrame:NSMakeRect(12.0f, 64.0f, 400.0f, 16.0f)];
|
||||
[m_netMessageText setAutoresizingMask:NSViewWidthSizable];
|
||||
[m_netMessageText setDrawsBackground:NO];
|
||||
[m_netMessageText setSelectable:NO];
|
||||
[m_netMessageText setBordered:NO];
|
||||
|
||||
// Text with connected/total players count
|
||||
m_netCountText = [[NSTextField alloc] initWithFrame:NSMakeRect(428.0f, 64.0f, 72.0f, 16.0f)];
|
||||
[m_netCountText setAutoresizingMask:NSViewMinXMargin];
|
||||
[m_netCountText setAlignment:NSRightTextAlignment];
|
||||
[m_netCountText setDrawsBackground:NO];
|
||||
[m_netCountText setSelectable:NO];
|
||||
[m_netCountText setBordered:NO];
|
||||
|
||||
// Connection progress
|
||||
m_netProgressBar = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(12.0f, 40.0f, 488.0f, 16.0f)];
|
||||
[m_netProgressBar setAutoresizingMask:NSViewWidthSizable];
|
||||
[m_netProgressBar setMaxValue:playerCount];
|
||||
|
||||
if (0 == playerCount)
|
||||
{
|
||||
// Joining game
|
||||
[m_netProgressBar setIndeterminate:YES];
|
||||
[m_netProgressBar startAnimation:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hosting game
|
||||
[m_netProgressBar setIndeterminate:NO];
|
||||
}
|
||||
|
||||
// Cancel network game button
|
||||
m_netAbortButton = [[NSButton alloc] initWithFrame:NSMakeRect(432.0f, 8.0f, 72.0f, 28.0f)];
|
||||
[m_netAbortButton setAutoresizingMask:NSViewMinXMargin];
|
||||
[m_netAbortButton setBezelStyle:NSRoundedBezelStyle];
|
||||
[m_netAbortButton setTitle:@"Cancel"];
|
||||
[m_netAbortButton setKeyEquivalent:@"\r"];
|
||||
[m_netAbortButton setTarget:NSApp];
|
||||
[m_netAbortButton setAction:@selector(terminate:)];
|
||||
|
||||
// Panel for controls above
|
||||
m_netView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 512.0f, NET_VIEW_HEIGHT)];
|
||||
[m_netView setAutoresizingMask:NSViewWidthSizable];
|
||||
[m_netView addSubview:m_netMessageText];
|
||||
[m_netView addSubview:m_netCountText];
|
||||
[m_netView addSubview:m_netProgressBar];
|
||||
[m_netView addSubview:m_netAbortButton];
|
||||
|
||||
NSRect windowRect = [m_window frame];
|
||||
windowRect.origin.y -= NET_VIEW_HEIGHT;
|
||||
windowRect.size.height += NET_VIEW_HEIGHT;
|
||||
|
||||
[m_window setFrame:windowRect display:YES];
|
||||
[[m_window contentView] addSubview:m_netView];
|
||||
}
|
||||
|
||||
[m_netMessageText setStringValue:[NSString stringWithUTF8String:message]];
|
||||
|
||||
m_netCurPos = 0;
|
||||
m_netMaxPos = playerCount;
|
||||
|
||||
NetProgress(1); // You always know about yourself
|
||||
}
|
||||
|
||||
void FConsoleWindow::NetProgress(const int count)
|
||||
{
|
||||
if (0 == count)
|
||||
{
|
||||
++m_netCurPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_netCurPos = count;
|
||||
}
|
||||
|
||||
if (nil == m_netView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_netMaxPos > 1)
|
||||
{
|
||||
[m_netCountText setStringValue:[NSString stringWithFormat:@"%d / %d", m_netCurPos, m_netMaxPos]];
|
||||
[m_netProgressBar setDoubleValue:MIN(m_netCurPos, m_netMaxPos)];
|
||||
}
|
||||
}
|
||||
|
||||
void FConsoleWindow::NetDone()
|
||||
{
|
||||
if (nil != m_netView)
|
||||
{
|
||||
ExpandTextView(NET_VIEW_HEIGHT);
|
||||
|
||||
[m_netView removeFromSuperview];
|
||||
[m_netView release];
|
||||
m_netView = nil;
|
||||
|
||||
// Released by m_netView
|
||||
m_netMessageText = nil;
|
||||
m_netCountText = nil;
|
||||
m_netProgressBar = nil;
|
||||
m_netAbortButton = nil;
|
||||
}
|
||||
}
|
190
src/posix/cocoa/st_start.mm
Normal file
190
src/posix/cocoa/st_start.mm
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
** st_start.mm
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2015 Alexey Lysiuk
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#import <Foundation/NSRunLoop.h>
|
||||
|
||||
#include "c_cvars.h"
|
||||
#include "st_console.h"
|
||||
#include "st_start.h"
|
||||
#include "v_text.h"
|
||||
|
||||
|
||||
FStartupScreen *StartScreen;
|
||||
|
||||
|
||||
CUSTOM_CVAR(Int, showendoom, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (self < 0)
|
||||
{
|
||||
self = 0;
|
||||
}
|
||||
else if (self > 2)
|
||||
{
|
||||
self = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class FBasicStartupScreen : public FStartupScreen
|
||||
{
|
||||
public:
|
||||
FBasicStartupScreen(int maxProgress, bool showBar);
|
||||
~FBasicStartupScreen();
|
||||
|
||||
virtual void Progress();
|
||||
|
||||
virtual void NetInit(const char* message, int playerCount);
|
||||
virtual void NetProgress(int count);
|
||||
virtual void NetMessage(const char *format, ...);
|
||||
virtual void NetDone();
|
||||
virtual bool NetLoop(bool (*timerCallback)(void*), void* userData);
|
||||
};
|
||||
|
||||
|
||||
FBasicStartupScreen::FBasicStartupScreen(int maxProgress, bool showBar)
|
||||
: FStartupScreen(maxProgress)
|
||||
{
|
||||
FConsoleWindow& consoleWindow = FConsoleWindow::GetInstance();
|
||||
consoleWindow.SetProgressBar(true);
|
||||
consoleWindow.SetTitleText();
|
||||
|
||||
#if 0
|
||||
// Testing code, please do not remove
|
||||
consoleWindow.AddText("----------------------------------------------------------------\n");
|
||||
consoleWindow.AddText("1234567890 !@#$%^&*() ,<.>/?;:'\" [{]}\\| `~-_=+ "
|
||||
"This is very very very long message needed to trigger word wrapping...\n\n");
|
||||
consoleWindow.AddText("Multiline...\n\tmessage...\n\t\twith...\n\t\t\ttabs.\n\n");
|
||||
|
||||
consoleWindow.AddText(TEXTCOLOR_BRICK "TEXTCOLOR_BRICK\n" TEXTCOLOR_TAN "TEXTCOLOR_TAN\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_GRAY "TEXTCOLOR_GRAY & TEXTCOLOR_GREY\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_GREEN "TEXTCOLOR_GREEN\n" TEXTCOLOR_BROWN "TEXTCOLOR_BROWN\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_GOLD "TEXTCOLOR_GOLD\n" TEXTCOLOR_RED "TEXTCOLOR_RED\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_BLUE "TEXTCOLOR_BLUE\n" TEXTCOLOR_ORANGE "TEXTCOLOR_ORANGE\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_WHITE "TEXTCOLOR_WHITE\n" TEXTCOLOR_YELLOW "TEXTCOLOR_YELLOW\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_UNTRANSLATED "TEXTCOLOR_UNTRANSLATED\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_BLACK "TEXTCOLOR_BLACK\n" TEXTCOLOR_LIGHTBLUE "TEXTCOLOR_LIGHTBLUE\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_CREAM "TEXTCOLOR_CREAM\n" TEXTCOLOR_OLIVE "TEXTCOLOR_OLIVE\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_DARKGREEN "TEXTCOLOR_DARKGREEN\n" TEXTCOLOR_DARKRED "TEXTCOLOR_DARKRED\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_DARKBROWN "TEXTCOLOR_DARKBROWN\n" TEXTCOLOR_PURPLE "TEXTCOLOR_PURPLE\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_DARKGRAY "TEXTCOLOR_DARKGRAY\n" TEXTCOLOR_CYAN "TEXTCOLOR_CYAN\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_NORMAL "TEXTCOLOR_NORMAL\n" TEXTCOLOR_BOLD "TEXTCOLOR_BOLD\n");
|
||||
consoleWindow.AddText(TEXTCOLOR_CHAT "TEXTCOLOR_CHAT\n" TEXTCOLOR_TEAMCHAT "TEXTCOLOR_TEAMCHAT\n");
|
||||
consoleWindow.AddText("----------------------------------------------------------------\n");
|
||||
#endif // _DEBUG
|
||||
}
|
||||
|
||||
FBasicStartupScreen::~FBasicStartupScreen()
|
||||
{
|
||||
FConsoleWindow::GetInstance().SetProgressBar(false);
|
||||
}
|
||||
|
||||
|
||||
void FBasicStartupScreen::Progress()
|
||||
{
|
||||
if (CurPos < MaxPos)
|
||||
{
|
||||
++CurPos;
|
||||
}
|
||||
|
||||
FConsoleWindow::GetInstance().Progress(CurPos, MaxPos);
|
||||
}
|
||||
|
||||
|
||||
void FBasicStartupScreen::NetInit(const char* const message, const int playerCount)
|
||||
{
|
||||
FConsoleWindow::GetInstance().NetInit(message, playerCount);
|
||||
}
|
||||
|
||||
void FBasicStartupScreen::NetProgress(const int count)
|
||||
{
|
||||
FConsoleWindow::GetInstance().NetProgress(count);
|
||||
}
|
||||
|
||||
void FBasicStartupScreen::NetMessage(const char* const format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
FString message;
|
||||
message.VFormat(format, args);
|
||||
va_end(args);
|
||||
|
||||
Printf("%s\n", message.GetChars());
|
||||
}
|
||||
|
||||
void FBasicStartupScreen::NetDone()
|
||||
{
|
||||
FConsoleWindow::GetInstance().NetDone();
|
||||
}
|
||||
|
||||
bool FBasicStartupScreen::NetLoop(bool (*timerCallback)(void*), void* const userData)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (timerCallback(userData))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
|
||||
|
||||
// Do not poll to often
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
FStartupScreen *FStartupScreen::CreateInstance(const int maxProgress)
|
||||
{
|
||||
return new FBasicStartupScreen(maxProgress, true);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
void ST_Endoom()
|
||||
{
|
||||
extern void I_ShutdownJoysticks();
|
||||
I_ShutdownJoysticks();
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in a new issue