Skip to content

Instantly share code, notes, and snippets.

@michaelgautier
Created April 20, 2015 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelgautier/85a1203ed0321ce8539e to your computer and use it in GitHub Desktop.
Save michaelgautier/85a1203ed0321ce8539e to your computer and use it in GitHub Desktop.
/*Copyright 2015 Michael Gautier, Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Software distributed under the License is distributed on an "AS IS" BASIS,
NO WARRANTIES OR CONDITIONS OF ANY KIND, explicit or implicit.
See the License for details on permissions and limitations.*/
/*
Discussed in a WordPress Post: Exploring SFML Graphics in C++, Refactoring Wave 4
https://gautiertalkstechnology.wordpress.com/2014/09/18/exploring-sfml-graphics-in-c-refactoring-wave-4/
Full, version 4 tree:
https://github.com/michaelgautier/codeexpo/tree/master/building_cpp_with_sfml_wave_04
*/
#include "programwindow.h"
#include "visualsettings.h"
#include "visualcommon.h"
#include "colorspec.h"
using namespace Gautier::SFMLApp::VisualFundamentals;
VisualSettings& ProgramWindow::GetVisualSettings()
{
return _VisualSettings;
}
ProgramWindow::ProgramWindow()
{
Init();
return;
};
void ProgramWindow::SetVisualSettings(VisualSettings visualSettings)
{
_VisualSettings = visualSettings;
// AreaSize WindowAreaSize = _VisualSettings->GetBackgroundSize();
// const string* WindowTitleText = _VisualSettings->GetTitleText();
//
// const SFMLVector2UInt WindowSize(WindowAreaSize.GetWidth(), WindowAreaSize.GetHeight());
// WindowImplementation.RenderTarget->setTitle(*WindowTitleText);
// WindowImplementation.RenderTarget->setSize(WindowSize);
// WindowImplementation.RenderTarget->setTitle("test");
// WindowImplementation.RenderTarget->setSize(SFMLVector2UInt(100, 200));
CreateSFMLProgramWindow();
return;
}
void ProgramWindow::Init()
{
if(!_InitCalled)
{
_InitCalled = true;
auto DesktopVisualMode = SFMLVideoMode::getDesktopMode();
_DesktopModeSize = AreaSize(DesktopVisualMode.width, DesktopVisualMode.height);
_DesktopBitsPerPixel = DesktopVisualMode.bitsPerPixel;
}
return;
}
bool ProgramWindow::IsWindowOpen()
{
return WindowImplementation.RenderTarget->isOpen();
}
void ProgramWindow::CreateSFMLProgramWindow()
{
if(!_SFMLProgramWindowCreateCalled)
{
_SFMLProgramWindowCreateCalled = true;
auto WindowAreaSize = _VisualSettings.GetBackgroundSize();
SFMLVideoMode ProgramWindowVideoMode(WindowAreaSize.GetWidth(), WindowAreaSize.GetHeight());
if(!WindowImplementation.RenderTarget)
{
auto WindowTitleText = _VisualSettings.GetTitleText();
WindowImplementation.RenderTarget.reset(new SFMLWindow(ProgramWindowVideoMode, WindowTitleText));
}
}
return;
}
VisualWindow& ProgramWindow::GetVisualWindow()
{
CreateSFMLProgramWindow();
return WindowImplementation;
}
void ProgramWindow::ProcessEvent(const WindowEventModel& eventModel)
{
auto WindowEventProperties = eventModel.GetInputPropertiesWindow();
auto WindowWasResized = WindowEventProperties.GetWindowResized();
if(WindowWasResized)
{
auto WindowSize = WindowEventProperties.GetWindowSize();
Polygon VisibleArea (0, 0, WindowSize.GetWidth(), WindowSize.GetHeight());
auto ViewableArea = VisualCommon::CreateSFMLRectFloat(VisibleArea);
WindowImplementation.RenderTarget->setView(SFMLView(ViewableArea));
}
}
void ProgramWindow::DefaultWindowClear()
{
auto WindowBackgroundColorFilter = _VisualSettings.GetBackgroundColor();
SFMLColor WindowBackgroundColor;
WindowBackgroundColorFilter.ChangeSFMLColor(WindowBackgroundColor);
WindowImplementation.RenderTarget->clear(WindowBackgroundColor);
return;
}
void ProgramWindow::Draw()
{
DefaultWindowClear();
WindowImplementation.RenderTarget->display();
return;
}
void ProgramWindow::Draw(SFMLGraphicBase& drawable)
{
DefaultWindowClear();
WindowImplementation.RenderTarget->draw(drawable);
WindowImplementation.RenderTarget->display();
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment