Browse Source

Extended Sample with ability to set window title and icon and take screenshots

Mike3D 12 years ago
parent
commit
75321c632d
1 changed files with 25 additions and 1 deletions
  1. 25 1
      Source/Samples/Sample.inl

+ 25 - 1
Source/Samples/Sample.inl

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2013 the Urho3D project.
+// Copyright (c) 2008-2014 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -24,11 +24,13 @@
 #include "Console.h"
 #include "DebugHud.h"
 #include "Engine.h"
+#include "Graphics.h"
 #include "InputEvents.h"
 #include "Renderer.h"
 #include "ResourceCache.h"
 #include "Sprite.h"
 #include "Texture2D.h"
+#include "Timer.h"
 #include "UI.h"
 #include "XMLFile.h"
 
@@ -51,6 +53,9 @@ void Sample::Start()
     // Create logo
     CreateLogo();
 
+    // Set custom window Title & Icon
+    SetWindowTitleAndIcon();
+
     // Create console and debug HUD
     CreateConsoleAndDebugHud();
 
@@ -101,6 +106,15 @@ void Sample::CreateLogo()
     logoSprite_->SetPriority(-100);
 }
 
+void Sample::SetWindowTitleAndIcon()
+{
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+    Graphics* graphics = GetSubsystem<Graphics>();
+    Image* icon = cache->GetResource<Image>("Textures/LogoLarge.png");
+    graphics->SetWindowIcon(icon);
+    graphics->SetWindowTitle("Urho3D Sample");
+}
+
 void Sample::CreateConsoleAndDebugHud()
 {
     // Get default style
@@ -204,5 +218,15 @@ void Sample::HandleKeyDown(StringHash eventType, VariantMap& eventData)
         // Instancing
         else if (key == '8')
             renderer->SetDynamicInstancing(!renderer->GetDynamicInstancing());
+        
+        // Take screenshot
+        else if (key == '9')
+        {
+            Graphics* graphics = GetSubsystem<Graphics>();
+            Image screenshot(context_);
+            graphics->TakeScreenShot(screenshot);
+            screenshot.FlipVertical();
+            screenshot.SavePNG("Data/" + Time::GetTimeStamp() + "Screenshot.png"); // Here we save in the Data folder with date and time appended
+	    }
     }
 }