-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCWindow.cpp
More file actions
executable file
·80 lines (56 loc) · 1.64 KB
/
CWindow.cpp
File metadata and controls
executable file
·80 lines (56 loc) · 1.64 KB
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
//
// CWindow.cpp
// Third
//
// Created by Didrik Munther on 19/04/15.
// Copyright (c) 2015 Didrik Munther. All rights reserved.
//
#include "CWindow.h"
#include "NFile.h"
CWindow::CWindow() :
_screenWidth(0), _screenHeight(0) {
}
int CWindow::onInit(std::string title, int width, int height) {
Uint32 window_flags = SDL_WINDOW_SHOWN;
Uint32 renderer_flags = SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED | SDL_RENDERER_SOFTWARE;
_window = SDL_CreateWindow(title.c_str(), 0, 0,
width, height, window_flags);
if(_window == nullptr) {
NFile::log(LogType::ERROR, "At SDL_CreateWindow: ", SDL_GetError());
return -1;
}
_renderer = SDL_CreateRenderer(_window, 0, renderer_flags);
SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_BLEND);
if(_renderer == nullptr) {
NFile::log(LogType::ERROR, "At SDL_CreateRenderer: ", SDL_GetError());
return -1;
}
_screenWidth = width;
_screenHeight = height;
return 0;
}
int CWindow::newWindow(std::string title, int width, int height) {
onCleanup();
return onInit(title, width, height);
}
void CWindow::setTitle(std::string title) {
SDL_SetWindowTitle(_window, title.c_str());
}
int CWindow::getWidth() {
return _screenWidth;
}
int CWindow::getHeight() {
return _screenHeight;
}
SDL_Window* CWindow::getWindow() {
return _window;
}
SDL_Renderer* CWindow::getRenderer() {
return _renderer;
}
void CWindow::onCleanup() {
SDL_DestroyWindow(_window);
SDL_DestroyRenderer(_renderer);
_window = nullptr;
_renderer = nullptr;
}