2010-09-28 19:29:00 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
2010-09-28 19:29:00 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2010-09-28 19:29:00 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2010-09-28 19:29:00 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2010-09-28 19:29:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* A viewport to each player */
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "C4Include.h"
|
|
|
|
#include "editor/C4ViewportWindow.h"
|
2010-09-28 19:29:00 +00:00
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "game/C4Viewport.h"
|
|
|
|
#include "editor/C4Console.h"
|
|
|
|
#include "landscape/C4Landscape.h"
|
|
|
|
#include "player/C4PlayerList.h"
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
|
2016-03-26 18:03:16 +00:00
|
|
|
#ifdef WITH_QT_EDITOR
|
2016-04-03 19:06:32 +00:00
|
|
|
#include "editor/C4ConsoleQtViewport.h"
|
2016-03-26 18:03:16 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-28 20:07:43 +00:00
|
|
|
#ifdef WITH_QT_EDITOR
|
|
|
|
bool C4Viewport::ScrollBarsByViewPosition()
|
|
|
|
{
|
|
|
|
if (PlayerLock) return false;
|
|
|
|
scrollarea->ScrollBarsByViewPosition();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::TogglePlayerLock()
|
|
|
|
{
|
|
|
|
PlayerLock = !PlayerLock;
|
|
|
|
scrollarea->setScrollBarVisibility(!PlayerLock);
|
|
|
|
ScrollBarsByViewPosition();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(USE_WIN32_WINDOWS)
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
void UpdateWindowLayout(HWND hwnd)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
GetWindowRect(hwnd,&rect);
|
|
|
|
MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left-1,rect.bottom-rect.top,true);
|
|
|
|
MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::TogglePlayerLock()
|
|
|
|
{
|
|
|
|
// Disable player lock
|
|
|
|
if (PlayerLock)
|
|
|
|
{
|
|
|
|
PlayerLock=false;
|
|
|
|
SetWindowLong(pWindow->hWindow,GWL_STYLE,C4ViewportWindowStyle | WS_HSCROLL | WS_VSCROLL);
|
|
|
|
UpdateWindowLayout(pWindow->hWindow);
|
|
|
|
ScrollBarsByViewPosition();
|
|
|
|
}
|
|
|
|
// Enable player lock
|
|
|
|
else if (ValidPlr(Player))
|
|
|
|
{
|
|
|
|
PlayerLock=true;
|
|
|
|
SetWindowLong(pWindow->hWindow,GWL_STYLE,C4ViewportWindowStyle);
|
|
|
|
UpdateWindowLayout(pWindow->hWindow);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::ViewPositionByScrollBars()
|
|
|
|
{
|
|
|
|
if (PlayerLock) return false;
|
|
|
|
SCROLLINFO scroll;
|
|
|
|
scroll.cbSize=sizeof(SCROLLINFO);
|
|
|
|
// Vertical
|
|
|
|
scroll.fMask=SIF_POS;
|
|
|
|
GetScrollInfo(pWindow->hWindow,SB_VERT,&scroll);
|
2015-01-03 21:51:02 +00:00
|
|
|
SetViewY(float(scroll.nPos));
|
2010-09-28 19:29:00 +00:00
|
|
|
// Horizontal
|
|
|
|
scroll.fMask=SIF_POS;
|
|
|
|
GetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll);
|
2015-01-03 21:51:02 +00:00
|
|
|
SetViewX(float(scroll.nPos));
|
2010-09-28 19:29:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::ScrollBarsByViewPosition()
|
|
|
|
{
|
|
|
|
if (PlayerLock) return false;
|
|
|
|
SCROLLINFO scroll;
|
|
|
|
scroll.cbSize=sizeof(SCROLLINFO);
|
|
|
|
// Vertical
|
|
|
|
scroll.fMask=SIF_ALL;
|
|
|
|
scroll.nMin=0;
|
2016-04-02 15:50:49 +00:00
|
|
|
scroll.nMax = ::Landscape.GetHeight() * Zoom;
|
2010-09-28 19:29:00 +00:00
|
|
|
scroll.nPage=ViewHgt;
|
2015-01-03 21:51:02 +00:00
|
|
|
scroll.nPos=int(GetViewY() * Zoom);
|
2010-09-28 19:29:00 +00:00
|
|
|
SetScrollInfo(pWindow->hWindow,SB_VERT,&scroll,true);
|
|
|
|
// Horizontal
|
|
|
|
scroll.fMask=SIF_ALL;
|
|
|
|
scroll.nMin=0;
|
2016-04-02 15:50:49 +00:00
|
|
|
scroll.nMax=::Landscape.GetWidth() * Zoom;
|
2010-09-28 19:29:00 +00:00
|
|
|
scroll.nPage=ViewWdt;
|
2015-01-03 21:51:02 +00:00
|
|
|
scroll.nPos = int(GetViewX() * Zoom);
|
2010-09-28 19:29:00 +00:00
|
|
|
SetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll,true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-03 14:10:36 +00:00
|
|
|
#endif
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
void C4ViewportWindow::PerformUpdate()
|
|
|
|
{
|
2016-03-26 18:03:16 +00:00
|
|
|
#ifdef WITH_QT_EDITOR
|
|
|
|
if (viewport_widget)
|
|
|
|
viewport_widget->update();
|
|
|
|
#else
|
2010-12-11 18:50:38 +00:00
|
|
|
if (cvp)
|
|
|
|
{
|
|
|
|
cvp->UpdateOutputSize();
|
|
|
|
cvp->Execute();
|
|
|
|
}
|
2016-03-22 15:50:38 +00:00
|
|
|
#endif
|
2010-12-11 18:50:38 +00:00
|
|
|
}
|
2010-09-28 19:29:00 +00:00
|
|
|
|
2012-03-04 21:45:00 +00:00
|
|
|
C4Window * C4ViewportWindow::Init(int32_t Player)
|
2011-01-23 22:02:23 +00:00
|
|
|
{
|
2011-08-27 21:12:01 +00:00
|
|
|
C4Window* result;
|
2011-01-23 22:02:23 +00:00
|
|
|
const char * Title = Player == NO_OWNER ? LoadResStr("IDS_CNS_VIEWPORT") : ::Players.Get(Player)->GetName();
|
2012-08-19 19:01:54 +00:00
|
|
|
C4Rect r(0,0,800,500);
|
2012-04-01 20:16:59 +00:00
|
|
|
result = C4Window::Init(C4Window::W_Viewport, &Application, Title, &r);
|
2012-04-11 02:15:33 +00:00
|
|
|
|
2011-01-23 22:02:23 +00:00
|
|
|
if (!result) return result;
|
|
|
|
|
2012-03-04 21:45:00 +00:00
|
|
|
pSurface = new C4Surface(&Application, this);
|
2016-03-09 02:21:34 +00:00
|
|
|
#ifndef WITH_QT_EDITOR
|
2011-01-23 22:02:23 +00:00
|
|
|
// Position and size
|
|
|
|
RestorePosition(FormatString("Viewport%i", Player+1).getData(), Config.GetSubkeyPath("Console"));
|
2016-02-12 04:37:13 +00:00
|
|
|
#endif
|
2011-01-23 22:02:23 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-09-28 19:29:00 +00:00
|
|
|
void C4ViewportWindow::Close()
|
|
|
|
{
|
2010-09-29 01:44:05 +00:00
|
|
|
::Viewports.CloseViewport(cvp);
|
2010-09-28 19:29:00 +00:00
|
|
|
}
|
2012-04-23 19:45:01 +00:00
|
|
|
void C4ViewportWindow::EditCursorMove(int X, int Y, uint32_t state)
|
2010-10-10 16:45:00 +00:00
|
|
|
{
|
2016-06-17 04:07:49 +00:00
|
|
|
Console.EditCursor.Move(cvp->WindowToGameX(X), cvp->WindowToGameY(Y), cvp->GetZoom(), state);
|
2010-10-10 16:45:00 +00:00
|
|
|
}
|