Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "stdafx.h"

#include "Headers/DisplayWindow.h"

#include "Core/Headers/Console.h"
#include "Core/Headers/Application.h"
#include "Core/Headers/Configuration.h"
#include "Core/Headers/PlatformContext.h"
#include "Utility/Headers/Localization.h"

#ifndef HAVE_M_PI
#define HAVE_M_PI
#endif //HAVE_M_PI

#include <SDL.h>

#include <AntTweakBar/include/AntTweakBar.h>

namespace Divide {
DisplayWindow::DisplayWindow(WindowManager& parent, PlatformContext& context)
 : GUIDWrapper(),
   _parent(parent),
   _context(context),
   _hasFocus(true),
   _minimized(false),
   _hidden(true),
   _type(WindowType::COUNT),
   _previousType(WindowType::COUNT),
   _queuedType(WindowType::COUNT),
   _mainWindow(nullptr),
   _internalMoveEvent(false),
   _externalResizeEvent(false)
{
    _windowPosition.fill(vec2<I32>(0));
    _prevDimensions.fill(vec2<U16>(1));
    _windowDimensions.fill(vec2<U16>(1));
}

DisplayWindow::~DisplayWindow() 
{
}

ErrorCode DisplayWindow::destroyWindow() {
    if (_type != WindowType::COUNT) {
        DIVIDE_ASSERT(_mainWindow != nullptr,
            "DisplayWindow::destroyWindow error: Tried to double-delete the same window!");

        SDL_DestroyWindow(_mainWindow);
        _mainWindow = nullptr;
    }

    return ErrorCode::NO_ERR;
}

ErrorCode DisplayWindow::init(U32 windowFlags,
                              WindowType initialType,
                              const ResolutionByType& initialResolutions,
                              const char* windowTitle)
{
    _type = initialType;

    _windowDimensions = initialResolutions;

    _mainWindow = SDL_CreateWindow(windowTitle,
                                   SDL_WINDOWPOS_CENTERED_DISPLAY(_parent.targetDisplay()),
                                   SDL_WINDOWPOS_CENTERED_DISPLAY(_parent.targetDisplay()),
                                   1,
                                   1,
                                   windowFlags);

    I32 positionX, positionY;
    SDL_GetWindowPosition(_mainWindow, &positionX, &positionY);
    setPosition(type(), positionX, positionY);

    // Check if we have a valid window
    if (!_mainWindow) {
        SDL_Quit();
        Console::errorfn(Locale::get(_ID("ERROR_GFX_DEVICE")),
                         Locale::get(_ID("ERROR_SDL_WINDOW")));
        Console::printfn(Locale::get(_ID("WARN_APPLICATION_CLOSE")));
        return ErrorCode::SDL_WINDOW_INIT_ERROR;
    }

    return ErrorCode::NO_ERR;
}

void DisplayWindow::update() {
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        if (Config::USE_ANT_TWEAK_BAR) {
            if (_context.config().gui.enableDebugVariableControls) {
                // send event to AntTweakBar
                if (TwEventSDL(&event, SDL_MAJOR_VERSION, SDL_MINOR_VERSION) != 0) {
                    continue;
                }
            }
        }

        switch (event.type)
        {
            case SDL_QUIT: {
                SDL_HideWindow(_mainWindow);
                Application::instance().RequestShutdown();
            } break;
            case SDL_WINDOWEVENT: {
                switch (event.window.event) {
                case SDL_WINDOWEVENT_ENTER:
                case SDL_WINDOWEVENT_FOCUS_GAINED: {
                    _parent.handleWindowEvent(WindowEvent::GAINED_FOCUS,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_LEAVE:
                case SDL_WINDOWEVENT_FOCUS_LOST: {
                    _parent.handleWindowEvent(WindowEvent::LOST_FOCUS,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_RESIZED: {
                    _externalResizeEvent = true;
                    setDimensions(type(),
                                  to_U16(event.window.data1),
                                  to_U16(event.window.data2));
                    _externalResizeEvent = false;
                }break;
                case SDL_WINDOWEVENT_SIZE_CHANGED: {
                    _parent.handleWindowEvent(WindowEvent::RESIZED_INTERNAL,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_MOVED: {
                    _parent.handleWindowEvent(WindowEvent::MOVED,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);

                    if (!_internalMoveEvent) {
                        setPosition(type(),
                                    event.window.data1,
                                    event.window.data2);
                        _internalMoveEvent = false;
                    }
                } break;
                case SDL_WINDOWEVENT_SHOWN: {
                    _parent.handleWindowEvent(WindowEvent::SHOWN,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_HIDDEN: {
                    _parent.handleWindowEvent(WindowEvent::HIDDEN,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_MINIMIZED: {
                    _parent.handleWindowEvent(WindowEvent::MAXIMIZED,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_MAXIMIZED: {
                    _parent.handleWindowEvent(WindowEvent::MAXIMIZED,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                case SDL_WINDOWEVENT_RESTORED: {
                    _parent.handleWindowEvent(WindowEvent::RESTORED,
                        getGUID(),
                        event.window.data1,
                        event.window.data2);
                } break;
                };
            } break;
        }
    }

    if (_queuedType != WindowType::COUNT) {
        //handleChangeWindowType(_queuedType);
        _queuedType = WindowType::COUNT;
    }
}

void DisplayWindow::setDimensionsInternal(U16 w, U16 h) {
    if (_externalResizeEvent && 
        (_type != WindowType::WINDOW &&
         _type != WindowType::SPLASH))
    {
        return;
    }

    if (_type == WindowType::FULLSCREEN) {
        // Should never be true, but need to be sure
        SDL_DisplayMode mode, closestMode;
        SDL_GetCurrentDisplayMode(_parent.targetDisplay(), &mode);
        mode.w = w;
        mode.h = h;
        SDL_GetClosestDisplayMode(_parent.targetDisplay(), &mode, &closestMode);
        SDL_SetWindowDisplayMode(_mainWindow, &closestMode);
    } else {
        if (_externalResizeEvent) {
            // Find a decent resolution close to our dragged dimensions
            SDL_DisplayMode mode, closestMode;
            SDL_GetCurrentDisplayMode(_parent.targetDisplay(), &mode);
            mode.w = w;
            mode.h = h;
            SDL_GetClosestDisplayMode(_parent.targetDisplay(), &mode, &closestMode);
            w = to_U16(closestMode.w);
            h = to_U16(closestMode.h);
        }

        SDL_SetWindowSize(_mainWindow, w, h);
    }
}

/// Window positioning is handled by SDL
void DisplayWindow::setPositionInternal(I32 w, I32 h) {
    _internalMoveEvent = true;
    SDL_SetWindowPosition(_mainWindow, w, h);
}

/// Centering is also easier via SDL
void DisplayWindow::centerWindowPosition() {
    _internalMoveEvent = true;

    setPosition(type(),
                SDL_WINDOWPOS_CENTERED_DISPLAY(_parent.targetDisplay()),
                SDL_WINDOWPOS_CENTERED_DISPLAY(_parent.targetDisplay()));
}

/// Mouse positioning is handled by SDL
void DisplayWindow::setCursorPosition(I32 x, I32 y) const {
    SDL_WarpMouseInWindow(_mainWindow, x, y);
}

void DisplayWindow::handleChangeWindowType(WindowType newWindowType) {
    _previousType = _type;
    _type = newWindowType;
    I32 switchState = 0;
    switch (newWindowType) {
        case WindowType::SPLASH: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, 0);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::WINDOW: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, 0);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_TRUE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::FULLSCREEN_WINDOWED: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::FULLSCREEN: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, SDL_WINDOW_FULLSCREEN);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_TRUE);
        } break;
    };

    const vec2<U16>& dimensions = getDimensions(newWindowType);
    setDimensionsInternal(dimensions.width, dimensions.height);

    centerWindowPosition();

    if (hidden()) {
        SDL_ShowWindow(_mainWindow);
        hidden(false);
    }
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/DisplayWindow.cpp

Diff revisions: vs.
Revision Author Commited Message
902 Diff Diff IonutCava picture IonutCava Sun 25 Jun, 2017 16:56:57 +0000

[Ionut]
- Rework input system a bit for easier maintenance and readability
- Toggle AntTweakBar display using CTRL+F11

900 Diff Diff IonutCava picture IonutCava Fri 23 Jun, 2017 16:00:28 +0000

[Ionut]
- Add AntTweakBar support for easier debugging

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

829 Diff Diff IonutCava picture IonutCava Tue 24 Jan, 2017 17:28:39 +0000

[IonutCava]
- Separate resourceLocation for resources into resourceLocation and resourceName.
- More XML config loading refactoring

827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

818 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

720 Diff Diff IonutCava picture IonutCava Mon 06 Jun, 2016 15:51:06 +0000

[IonutCava]
- PVS-Studio guided static analysis fixes and optimizations
- Added a flag to SceneState to bypass the Save/Load system not needed for certain types of scenes (menus, cinematics, etc)

684 IonutCava picture IonutCava Wed 20 Apr, 2016 16:27:05 +0000

[IonutCava]
- More math template code cleanup