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-01-22 19:05:43 +00:00
|
|
|
#ifdef USE_GTK
|
2010-09-28 19:29:00 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-23 21:53:56 +00:00
|
|
|
#ifdef 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-01-22 19:05:43 +00:00
|
|
|
#elif defined(USE_GTK)
|
2010-09-28 19:29:00 +00:00
|
|
|
bool C4Viewport::TogglePlayerLock()
|
|
|
|
{
|
|
|
|
if (PlayerLock)
|
|
|
|
{
|
|
|
|
PlayerLock = false;
|
|
|
|
gtk_widget_show(pWindow->h_scrollbar);
|
|
|
|
gtk_widget_show(pWindow->v_scrollbar);
|
|
|
|
ScrollBarsByViewPosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayerLock = true;
|
|
|
|
gtk_widget_hide(pWindow->h_scrollbar);
|
|
|
|
gtk_widget_hide(pWindow->v_scrollbar);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::ScrollBarsByViewPosition()
|
|
|
|
{
|
|
|
|
if (PlayerLock) return false;
|
|
|
|
|
|
|
|
GtkAllocation allocation;
|
2012-04-08 23:15:30 +00:00
|
|
|
gtk_widget_get_allocation(GTK_WIDGET(pWindow->render_widget), &allocation);
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->h_scrollbar));
|
2011-01-23 22:04:40 +00:00
|
|
|
|
|
|
|
gtk_adjustment_configure(adjustment,
|
2015-01-03 21:51:02 +00:00
|
|
|
GetViewX(), // value
|
2011-01-23 22:04:40 +00:00
|
|
|
0, // lower
|
2016-04-02 15:50:49 +00:00
|
|
|
::Landscape.GetWidth(), // upper
|
2011-01-23 22:04:40 +00:00
|
|
|
ViewportScrollSpeed, // step_increment
|
2011-01-25 19:21:49 +00:00
|
|
|
allocation.width / Zoom, // page_increment
|
|
|
|
allocation.width / Zoom // page_size
|
2011-01-23 22:04:40 +00:00
|
|
|
);
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->v_scrollbar));
|
2011-01-23 22:04:40 +00:00
|
|
|
gtk_adjustment_configure(adjustment,
|
2015-01-03 21:51:02 +00:00
|
|
|
GetViewY(), // value
|
2011-01-23 22:04:40 +00:00
|
|
|
0, // lower
|
2016-04-02 15:50:49 +00:00
|
|
|
::Landscape.GetHeight(), // upper
|
2011-01-23 22:04:40 +00:00
|
|
|
ViewportScrollSpeed, // step_increment
|
2011-01-25 19:21:49 +00:00
|
|
|
allocation.height / Zoom, // page_increment
|
|
|
|
allocation.height / Zoom // page_size
|
2011-01-23 22:04:40 +00:00
|
|
|
);
|
2010-09-28 19:29:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Viewport::ViewPositionByScrollBars()
|
|
|
|
{
|
|
|
|
if (PlayerLock) return false;
|
|
|
|
|
|
|
|
GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->h_scrollbar));
|
2015-01-04 11:13:48 +00:00
|
|
|
SetViewX(gtk_adjustment_get_value(adjustment));
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->v_scrollbar));
|
2015-01-04 11:13:48 +00:00
|
|
|
SetViewY(gtk_adjustment_get_value(adjustment));
|
2010-09-28 19:29:00 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-22 19:05:43 +00:00
|
|
|
#endif // USE_GTK
|
2010-12-11 18:50:38 +00:00
|
|
|
|
|
|
|
void C4ViewportWindow::PerformUpdate()
|
|
|
|
{
|
|
|
|
if (cvp)
|
|
|
|
{
|
|
|
|
cvp->UpdateOutputSize();
|
|
|
|
cvp->Execute();
|
|
|
|
}
|
|
|
|
}
|
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);
|
2011-01-23 22:02:23 +00:00
|
|
|
// Position and size
|
|
|
|
RestorePosition(FormatString("Viewport%i", Player+1).getData(), Config.GetSubkeyPath("Console"));
|
|
|
|
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
|
|
|
{
|
2015-01-03 21:51:02 +00:00
|
|
|
Console.EditCursor.Move(cvp->GetViewX() + X / cvp->Zoom, cvp->GetViewY() + Y / cvp->Zoom, state);
|
2010-10-10 16:45:00 +00:00
|
|
|
}
|