Merge remote-tracking branch 'remotes/alexparlett/window-icon'
This commit is contained in:
commit
cc4c4e6a79
@ -269,6 +269,7 @@ bool Engine::Initialize(const VariantMap& parameters)
|
||||
graphics->SetExternalWindow(GetParameter(parameters, "ExternalWindow").GetPtr());
|
||||
graphics->SetForceSM2(GetParameter(parameters, "ForceSM2", false).GetBool());
|
||||
graphics->SetWindowTitle(GetParameter(parameters, "WindowTitle", "Urho3D").GetString());
|
||||
graphics->SetWindowIcon(cache->GetResource<Image>(GetParameter(parameters, "WindowIcon", "Textures/Icon.png").GetString()));
|
||||
if (!graphics->SetMode(
|
||||
GetParameter(parameters, "WindowWidth", 0).GetInt(),
|
||||
GetParameter(parameters, "WindowHeight", 0).GetInt(),
|
||||
|
@ -170,6 +170,7 @@ static unsigned depthStencilFormat = D3DFMT_D24S8;
|
||||
Graphics::Graphics(Context* context) :
|
||||
Object(context),
|
||||
impl_(new GraphicsImpl()),
|
||||
windowIcon_(0),
|
||||
externalWindow_(0),
|
||||
width_(0),
|
||||
height_(0),
|
||||
@ -267,6 +268,15 @@ void Graphics::SetWindowTitle(const String& windowTitle)
|
||||
SDL_SetWindowTitle(impl_->window_, windowTitle_.CString());
|
||||
}
|
||||
|
||||
void Graphics::SetWindowIcon(Image* windowIcon)
|
||||
{
|
||||
windowIcon_ = windowIcon;
|
||||
if (impl_->window_)
|
||||
{
|
||||
CreateWindowIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::SetWindowPosition(const IntVector2& position)
|
||||
{
|
||||
if (impl_->window_)
|
||||
@ -2201,10 +2211,35 @@ bool Graphics::OpenWindow(int width, int height, bool resizable)
|
||||
LOGERROR("Could not create window");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
CreateWindowIcon();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Graphics::CreateWindowIcon()
|
||||
{
|
||||
if (windowIcon_)
|
||||
{
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, windowIcon_->GetWidth(), windowIcon_->GetHeight(), windowIcon_->GetComponents() * BITS_PER_COMPONENT, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
|
||||
if (windowIcon_->GetMemoryUse() > 0)
|
||||
{
|
||||
SDL_LockSurface(surface);
|
||||
memcpy(surface->pixels, windowIcon_->GetData(), windowIcon_->GetMemoryUse());
|
||||
SDL_UnlockSurface(surface);
|
||||
|
||||
SDL_SetWindowIcon(impl_->window_, surface);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("Unable to load icon windowIcon_ " + windowIcon_->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen)
|
||||
{
|
||||
if (!externalWindow_)
|
||||
|
@ -83,6 +83,8 @@ public:
|
||||
void SetExternalWindow(void* window);
|
||||
/// Set window title.
|
||||
void SetWindowTitle(const String& windowTitle);
|
||||
/// Set window icon.
|
||||
void SetWindowIcon(Image* windowIcon);
|
||||
/// Set window position.
|
||||
void SetWindowPosition(const IntVector2& position);
|
||||
/// Set window position.
|
||||
@ -392,6 +394,8 @@ public:
|
||||
private:
|
||||
/// Create the application window.
|
||||
bool OpenWindow(int width, int height, bool resizable);
|
||||
/// Create the application window icon.
|
||||
void CreateWindowIcon();
|
||||
/// Adjust the window for new resolution and fullscreen mode.
|
||||
void AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen);
|
||||
/// Create the Direct3D interface.
|
||||
@ -415,6 +419,8 @@ private:
|
||||
GraphicsImpl* impl_;
|
||||
/// Window title.
|
||||
String windowTitle_;
|
||||
/// Window Icon File Name
|
||||
Image* windowIcon_;
|
||||
/// External window, null if not in use (default.)
|
||||
void* externalWindow_;
|
||||
/// Window width.
|
||||
|
@ -321,4 +321,5 @@ static const int MAX_VERTEX_STREAMS = 4;
|
||||
static const int MAX_SKIN_MATRICES = 64;
|
||||
static const int MAX_CONSTANT_REGISTERS = 256;
|
||||
|
||||
static const int BITS_PER_COMPONENT = 8;
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ bool CheckExtension(String& extensions, const String& name)
|
||||
Graphics::Graphics(Context* context_) :
|
||||
Object(context_),
|
||||
impl_(new GraphicsImpl()),
|
||||
windowIcon_(0),
|
||||
externalWindow_(0),
|
||||
width_(0),
|
||||
height_(0),
|
||||
@ -212,6 +213,15 @@ void Graphics::SetWindowTitle(const String& windowTitle)
|
||||
SDL_SetWindowTitle(impl_->window_, windowTitle_.CString());
|
||||
}
|
||||
|
||||
void Graphics::SetWindowIcon(Image* windowIcon)
|
||||
{
|
||||
windowIcon_ = windowIcon;
|
||||
if (impl_->window_)
|
||||
{
|
||||
CreateWindowIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::SetWindowPosition(const IntVector2& position)
|
||||
{
|
||||
if (impl_->window_)
|
||||
@ -356,6 +366,8 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool resizable, b
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CreateWindowIcon();
|
||||
|
||||
// Create/restore context and GPU objects and set initial renderstate
|
||||
Restore();
|
||||
@ -2386,6 +2398,29 @@ unsigned Graphics::GetFormat(const String& formatName)
|
||||
return GetRGBFormat();
|
||||
}
|
||||
|
||||
void Graphics::CreateWindowIcon()
|
||||
{
|
||||
if (windowIcon_)
|
||||
{
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, windowIcon_->GetWidth(), windowIcon_->GetHeight(), windowIcon_->GetComponents() * BITS_PER_COMPONENT, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
|
||||
if (windowIcon_->GetMemoryUse() > 0)
|
||||
{
|
||||
SDL_LockSurface(surface);
|
||||
memcpy(surface->pixels, windowIcon_->GetData(), windowIcon_->GetMemoryUse());
|
||||
SDL_UnlockSurface(surface);
|
||||
|
||||
SDL_SetWindowIcon(impl_->window_, surface);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("Unable to load icon windowIcon_ " + windowIcon_->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::CheckFeatureSupport(String& extensions)
|
||||
{
|
||||
// Check supported features: light pre-pass, deferred rendering and hardware depth texture
|
||||
|
@ -86,8 +86,10 @@ public:
|
||||
|
||||
/// Set external window handle. Only effective before setting the initial screen mode. On Windows it is necessary to set up OpenGL pixel format manually for the window.
|
||||
void SetExternalWindow(void* window);
|
||||
/// Set window title.
|
||||
void SetWindowTitle(const String& windowTitle);
|
||||
/// Set window icon.
|
||||
void SetWindowIcon(Image* windowIcon);
|
||||
/// Set window title.
|
||||
void SetWindowTitle(const String& windowTitle);
|
||||
/// Set window position.
|
||||
void SetWindowPosition(const IntVector2& position);
|
||||
/// Set window position.
|
||||
@ -411,6 +413,8 @@ public:
|
||||
static unsigned GetFormat(const String& formatName);
|
||||
|
||||
private:
|
||||
/// Create the application window icon.
|
||||
void CreateWindowIcon();
|
||||
/// Check supported rendering features.
|
||||
void CheckFeatureSupport(String& extensions);
|
||||
/// Select FBO and commit changes.
|
||||
@ -428,6 +432,8 @@ private:
|
||||
GraphicsImpl* impl_;
|
||||
/// Window title.
|
||||
String windowTitle_;
|
||||
/// Window Icon File Name
|
||||
Image* windowIcon_;
|
||||
/// External window, null if not in use (default.)
|
||||
void* externalWindow_;
|
||||
/// Window width.
|
||||
|
@ -3,6 +3,7 @@ $#include "Graphics.h"
|
||||
class Graphics : public Object
|
||||
{
|
||||
void SetWindowTitle(const String windowTitle);
|
||||
void SetWindowIcon(Image* windowIcon);
|
||||
void SetWindowPosition(const IntVector2& position);
|
||||
void SetWindowPosition(int x, int y);
|
||||
|
||||
|
@ -1195,6 +1195,7 @@ static void RegisterGraphics(asIScriptEngine* engine)
|
||||
engine->RegisterObjectMethod("Graphics", "bool TakeScreenShot(Image@+)", asMETHOD(Graphics, TakeScreenShot), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "void set_windowTitle(const String&in)", asMETHOD(Graphics, SetWindowTitle), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "const String& get_windowTitle() const", asMETHOD(Graphics, GetWindowTitle), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "void set_windowIcon(Image@+)", asMETHOD(Graphics, SetWindowIcon), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "void set_windowPosition(const IntVector2&in)", asMETHODPR(Graphics, SetWindowPosition, (const IntVector2&), void), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "IntVector2 get_windowPosition() const", asMETHOD(Graphics, GetWindowPosition), asCALL_THISCALL);
|
||||
engine->RegisterObjectMethod("Graphics", "void set_sRGB(bool)", asMETHOD(Graphics, SetSRGB), asCALL_THISCALL);
|
||||
|
Loading…
Reference in New Issue
Block a user