1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2021, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17/* A viewport to each player */
18
19#pragma once
20
21#include "C4ForwardDeclarations.h"
22#include "C4Rect.h"
23#include <C4Region.h>
24#include "Fixed.h"
25#include "StdColors.h"
26#include <StdWindow.h>
27
28#ifdef WITH_DEVELOPER_MODE
29#include <StdGtkWindow.h>
30typedef CStdGtkWindow C4ViewportBase;
31#else
32typedef CStdWindow C4ViewportBase;
33#endif
34
35class C4Viewport;
36
37class C4ViewportWindow : public C4ViewportBase
38{
39#ifdef _WIN32
40public:
41 static constexpr auto WindowStyle = WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
42#endif
43public:
44 C4Viewport *cvp;
45 C4ViewportWindow(C4Viewport *cvp) : cvp(cvp) {}
46#ifdef _WIN32
47 std::pair<DWORD, DWORD> GetWindowStyle() const override { return {WindowStyle, WS_EX_ACCEPTFILES}; }
48 WNDCLASSEX GetWindowClass(HINSTANCE instance) const override;
49 bool GetPositionData(std::string &id, std::string &subKey, bool &storeSize) const override;
50#elif defined(WITH_DEVELOPER_MODE)
51 virtual GtkWidget *InitGUI() override;
52
53 static gboolean OnKeyPressStatic(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
54 static gboolean OnKeyReleaseStatic(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
55 static gboolean OnScrollStatic(GtkWidget *widget, GdkEventScroll *event, gpointer user_data);
56 static gboolean OnButtonPressStatic(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
57 static gboolean OnButtonReleaseStatic(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
58 static gboolean OnMotionNotifyStatic(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
59 static gboolean OnConfigureStatic(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data);
60 static void OnRealizeStatic(GtkWidget *widget, gpointer user_data);
61 static gboolean OnExposeStatic(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
62 static void OnDragDataReceivedStatic(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data);
63
64 static gboolean OnConfigureDareaStatic(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data);
65
66 static void OnVScrollStatic(GtkAdjustment *adjustment, gpointer user_data);
67 static void OnHScrollStatic(GtkAdjustment *adjustment, gpointer user_data);
68
69 GtkWidget *h_scrollbar;
70 GtkWidget *v_scrollbar;
71 GtkWidget *drawing_area;
72#elif defined(USE_X11) && !defined(WITH_DEVELOPER_MODE)
73 bool HideCursor() const override { return true; }
74 virtual void HandleMessage(XEvent &) override;
75#endif
76 virtual void Close() override;
77
78#ifdef _WIN32
79 static LRESULT APIENTRY WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
80#endif
81};
82
83class C4Viewport
84{
85 friend class C4GraphicsSystem;
86 friend class C4MouseControl;
87
88public:
89 C4Viewport();
90 ~C4Viewport();
91 C4RegionList Regions;
92 C4Fixed dViewX, dViewY;
93 int32_t ViewX, ViewY, ViewWdt, ViewHgt;
94 int32_t BorderLeft, BorderTop, BorderRight, BorderBottom;
95 int32_t ViewOffsX, ViewOffsY;
96 int32_t DrawX, DrawY;
97 bool fIsNoOwnerViewport; // this viewport is found for searches of NO_OWNER-viewports; even if it has a player assigned (for network obs)
98 void Default();
99 void Clear();
100 void Execute();
101 void ClearPointers(C4Object *pObj);
102 void SetOutputSize(int32_t iDrawX, int32_t iDrawY, int32_t iOutX, int32_t iOutY, int32_t iOutWdt, int32_t iOutHgt);
103 void UpdateViewPosition(); // update view position: Clip properly; update border variables
104 bool Init(int32_t iPlayer, bool fSetTempOnly);
105 bool Init(CStdWindow *pParent, CStdApp *pApp, int32_t iPlayer);
106#ifdef _WIN32
107 bool DropFiles(HANDLE hDrop);
108#endif
109 bool TogglePlayerLock();
110 void NextPlayer();
111 C4Rect GetOutputRect() { return C4Rect(OutX, OutY, ViewWdt, ViewHgt); }
112 bool IsViewportMenu(class C4Menu *pMenu);
113 int32_t GetPlayer() { return Player; }
114 void CenterPosition();
115
116protected:
117 int32_t Player;
118 bool PlayerLock;
119 int32_t OutX, OutY;
120 bool ResetMenuPositions;
121 C4RegionList *SetRegions;
122 CStdGLCtx *pCtx; // rendering context for OpenGL
123 C4ViewportWindow *pWindow;
124 CClrModAddMap ClrModMap; // color modulation map for viewport drawing
125 void DrawMouseButtons(C4FacetEx &cgo);
126 void DrawPlayerStartup(C4FacetEx &cgo);
127 void Draw(C4FacetEx &cgo, bool fDrawOverlay);
128 void DrawOverlay(C4FacetEx &cgo);
129 void DrawMenu(C4FacetEx &cgo);
130 void DrawCursorInfo(C4FacetEx &cgo);
131 void DrawPlayerInfo(C4FacetEx &cgo);
132 void DrawPlayerControls(C4FacetEx &cgo);
133 void BlitOutput();
134 void AdjustPosition();
135 bool UpdateOutputSize();
136 bool ViewPositionByScrollBars();
137 bool ScrollBarsByViewPosition();
138
139 friend class C4ViewportWindow;
140};
141