Skip to content

Commit

Permalink
[#17] : Fixed issue with window resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jul 12, 2020
1 parent cdfa374 commit 87ac1b0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion engines/basic/src/delta_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ysError dbasic::DeltaEngine::CreateGameWindow(const GameEngineSettings &settings

m_initialized = true;

SetWindowSize(m_gameWindow->GetScreenWidth(), m_gameWindow->GetScreenHeight());
m_windowHandler.OnResizeWindow(m_gameWindow->GetWidth(), m_gameWindow->GetHeight());

return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}
Expand Down
6 changes: 3 additions & 3 deletions engines/basic/src/window_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ dbasic::WindowHandler::~WindowHandler() {
}

void dbasic::WindowHandler::OnResizeWindow(int width, int height) {
//m_engine->SetWindowSize(width, height);
//m_device->UpdateRenderingContext(m_context);
//m_engine->GetConsole()->ResetScreenPosition();
m_engine->SetWindowSize(width, height);
m_device->UpdateRenderingContext(m_context);
m_engine->GetConsole()->ResetScreenPosition();
}

void dbasic::WindowHandler::Initialize(ysDevice *device, ysRenderingContext *context, DeltaEngine *engine) {
Expand Down
2 changes: 1 addition & 1 deletion src/yds_opengl_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ ysError ysOpenGLDevice::SetRenderTarget(ysRenderTarget *target) {
ysError ysOpenGLDevice::DestroyRenderTarget(ysRenderTarget *&target) {
YDS_ERROR_DECLARE("DestroyRenderTarget");

if (target == NULL) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER);
if (target == nullptr) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER);

if (target == m_activeRenderTarget) {
YDS_NESTED_ERROR_CALL(SetRenderTarget(NULL));
Expand Down
6 changes: 3 additions & 3 deletions src/yds_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ void ysWindow::OnMoveWindow(int x, int y) {
m_locationx = x + m_frameOriginXOffset;
m_locationy = y + m_frameOriginYOffset;

if (m_eventHandler) m_eventHandler->OnMoveWindow(x, y);
if (m_eventHandler != nullptr) m_eventHandler->OnMoveWindow(x, y);
}

void ysWindow::OnResizeWindow(int w, int h) {
m_width = w + m_frameWidthOffset;
m_height = h + m_frameHeightOffset;

if (m_eventHandler) m_eventHandler->OnResizeWindow(w, h);
if (m_eventHandler != nullptr) m_eventHandler->OnResizeWindow(w, h);
}

void ysWindow::OnActivate() {
m_active = true;

if (m_eventHandler) m_eventHandler->OnActivate();
if (m_eventHandler != nullptr) m_eventHandler->OnActivate();
}

void ysWindow::OnDeactivate() {
Expand Down
15 changes: 9 additions & 6 deletions src/yds_windows_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ ysError ysWindowsWindow::InitializeWindow(ysWindow *parent, const char *title, W
m_instance,
NULL);

m_width = width;
m_height = height;

m_locationx = x;
m_locationy = y;

m_frameOriginXOffset = rc.left;
m_frameOriginYOffset = rc.top;

m_frameWidthOffset = rc.right - rc.left - width;
m_frameHeightOffset = rc.bottom - rc.top - height;

RECT rect;
GetClientRect(m_hwnd, &rect);

m_width = rect.right - rect.left + m_frameWidthOffset;
m_height = rect.bottom - rect.top + m_frameHeightOffset;

m_locationx = x;
m_locationy = y;

SetWindowPos(m_hwnd, NULL, m_locationx, m_locationy, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion src/yds_windows_window_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ LRESULT WINAPI ysWindowsWindowSystem::WinProc(HWND hWnd, UINT msg, WPARAM wParam
PAINTSTRUCT ps;
HDC hdc;

if (target) {
if (target != nullptr) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
Expand Down

0 comments on commit 87ac1b0

Please sign in to comment.