나는 (SDL을 사용하고 있습니다.) 잘 작동하는 크로스 플랫폼 게임 엔진에서 일하고 있습니다. 그러나 SDL 또는 OpenGL (화면에 렌더링)을 사용하지 않고도 사용자에게 메시지 상자를 표시하는 간단한 방법이 필요합니다. 화면이 파괴되었거나 아직 생성되지 않은 경우 화면에 메시지를 렌더링 할 수 없습니다.Linux 용 SDL 크로스 플랫폼 메시지 상자
각 플랫폼에 대해 여러 구현으로 된 메시지 상자 기능을 구현했습니다. Windows 구현은 MessageBox를 사용하고 Mac OS X 구현은 Cocoa의 NSAlert를 사용하며 Linux 구현에 사용할 수있는 것을 모르겠습니다. X11은 SDL이 리눅스에서 윈도우 잉 (windowing)을 위해 사용하기 때문에 생각했습니다.
나는 다른 답변을 시도했지만 너무 애매하거나 X11 등으로 전체 게임 엔진을 다시 조작해야합니다. 콘솔 응용 프로그램에서 사용할 수있는 Windows MessageBox 함수와 같은 응용 프로그램과 독립적 인 솔루션을 찾으려고합니다.
참고 : Mac 및 Windows 구현 코드는 모두 잘 작동합니다. 도움이 필요한 Linux 구현 일뿐입니다.
오, Mac OS X에서 컴파일 할 때 Objective-C++를 활용하므로 C++ msgbox() 함수와 함께 Cocoa (Objective-C)를 혼합 할 수 있습니다.
msgbox.h
#ifndef MSGBOX_H
#define MSGBOX_H
//Cross-platform message box method.
#include "platform.h"
#include "string.h"
//This is my own cross platform enum for message boxes.
//This enumeration 'overlaps' with some declarations in windows.h but that is fine.
enum //Message box values.
{
MB_OK, //For OK message box and return value.
MB_OKCANCEL,
MB_YESNO,
MB_RETRYCANCEL,
MB_YESNOCANCEL,
MB_ABORTRETRYIGNORE,
MB_CANCELTRYCONTINUE,
MB_CANCEL,
MB_YES,
MB_NO,
MB_RETRY,
MB_IGNORE,
MB_TRYAGAIN,
MB_CONTINUE,
MB_ABORT,
};
//The message box function (multiple implementations for each platform).
int msgbox(string msg, string title, int buttons);
#endif // MSGBOX_H
msgbox.cpp
#include "msgbox.h"
#if CURRENT_PLATFORM == PLATFORM_WINDOWS //We can use the windows API for our messagebox.
#include <windows.h> //For the message box function.
#define IDTRYAGAIN 10 //Some fixes to help this application compile.
#define IDCONTINUE 11
int msgbox(string msg, string title, int buttons)
{
//Display the mesagebox.
int retval = MessageBox(NULL, msg.c_str(), title.c_str(), buttons | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
//Map the windows return value to ours.
switch(retval)
{
case IDOK: return MB_OK;
case IDCANCEL: return MB_CANCEL;
case IDYES: return MB_YES;
case IDNO: return MB_NO;
case IDRETRY: return MB_RETRY;
case IDIGNORE: return MB_IGNORE;
case IDTRYAGAIN:return MB_TRYAGAIN;
case IDCONTINUE:return MB_CONTINUE;
}
}
#elif CURRENT_PLATFORM == PLATFORM_MACOSX //Use Cocoa to display the message box.
int msgbox(string msg, string title, int buttons)
{
NSString* defbutton = nil;
NSString* altbutton = nil;
NSString* otherbutton = nil;
switch(buttons)
{
default:
case MB_OK:
defbutton = @"Ok";
break;
case MB_OKCANCEL:
defbutton = @"Ok";
altbutton = @"Cancel";
break;
case MB_RETRYCANCEL:
defbutton = @"Retry";
altbutton = @"Cancel";
break;
case MB_YESNO:
defbutton = @"Yes";
altbutton = @"No";
break;
case MB_YESNOCANCEL:
defbutton = @"Yes";
altbutton = @"No";
otherbutton = @"Cancel";
break;
case MB_ABORTRETRYIGNORE:
defbutton = @"Abort";
altbutton = @"Retry";
otherbutton = @"Ignore";
break;
case MB_CANCELTRYCONTINUE:
defbutton = @"Cancel";
altbutton = @"Try Again";
otherbutton = @"Continue";
break;
}
NSAlert* alert = [NSAlert alertWithMessageText:[NSString stringWithCString:title.c_str() encoding:[NSString defaultCStringEncoding]]
defaultButton:defbutton
alternateButton:altbutton
otherButton:otherbutton
informativeTextWithFormat:@"%s", msg.c_str()];
//brings this 'application' to the front.
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
NSInteger retval = [alert runModal];
//Convert the NSAlert return values into my MB_* return values.
if(retval == NSAlertDefaultReturn)
{
switch(buttons)
{
case MB_OK:
case MB_OKCANCEL:
return MB_OK;
case MB_YESNO:
case MB_YESNOCANCEL:
return MB_YES;
case MB_ABORTRETRYIGNORE:
return MB_ABORT;
case MB_CANCELTRYCONTINUE:
return MB_CANCEL;
case MB_RETRYCANCEL:
return MB_RETRY;
}
} else if(retval == NSAlertAlternateReturn)
{
switch(buttons)
{
case MB_OKCANCEL:
case MB_RETRYCANCEL:
return MB_CANCEL;
case MB_YESNO:
case MB_YESNOCANCEL:
return MB_NO;
case MB_ABORTRETRYIGNORE:
return MB_RETRY;
case MB_CANCELTRYCONTINUE:
return MB_TRYAGAIN;
}
} else if(retval == NSAlertOtherReturn)
{
switch(buttons)
{
case MB_YESNOCANCEL:
return MB_CANCEL;
case MB_ABORTRETRYIGNORE:
return MB_IGNORE;
case MB_CANCELTRYCONTINUE:
return MB_CONTINUE;
}
}
return NULL;
}
#else
int msgbox(string msg, string title, int buttons)
{
//WHAT DO I DO??????
return 0;
}
//#error No implementation of message boxes on current platform!
#endif // CURRENT_PLATFORM
편집 : 내가하지 않으려는 여기
내가 윈도우 & 맥 구현을 위해 지금까지 가지고있는 코드입니다 몇 가지 이유로 Qt를 사용하십시오 : 너무 무거워서 내 컴퓨터에서 작동하지 않습니다 & i 이 프로그램에 대한 충분한 통제권을주지 못합니다. 어쨌든 다른 게임 라이브러리에 의존하지 않고 취미 프로젝트로 처음부터이 게임 엔진을 만들려고합니다. 결국 SDL을 내 코드로 대체하려고합니다.
왜 여기
코드입니다 대신 Qt와 같은 크로스 플랫폼 GUI 툴킷을 사용 하시겠습니까? 그렇다면 이것에 대해 걱정할 필요가 없습니다. –Qt의 지원을 넘어 더 많은 플랫폼을 목표로 삼을 것입니다. 또한 Qt는 내 마음에 들기에 너무 무거워서 메시지 루프 등을 제어하지 못합니다. Qt를 이미 사용해 보았고 내 주요 개발 컴퓨터에서 작동하지 않습니다. – hddh
실제 질문은 무엇입니까? 예를 들어 Xlib 또는 OpenMotif를 사용하여 비 대한 라이브러리가없는 Linux에서 메시지 상자를 표시하는 데는 여러 가지 방법이 있습니다. – scai