diff options
author | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
commit | 393b5cd1dc438872af89d334ef6e5fcc59f27d47 (patch) | |
tree | 6a14521219942a08a1b95cb2f5a923a9edd60f63 /libraries/irrlicht-1.8/source/Irrlicht/CVideoModeList.cpp | |
parent | Add a note about rasters suggested start up code. (diff) | |
download | SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.zip SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.gz SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.bz2 SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.xz |
Added Irrlicht 1.8, but without all the Windows binaries.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CVideoModeList.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CVideoModeList.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CVideoModeList.cpp new file mode 100644 index 0000000..9ae7fb2 --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CVideoModeList.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CVideoModeList.h" | ||
6 | #include "irrMath.h" | ||
7 | |||
8 | namespace irr | ||
9 | { | ||
10 | namespace video | ||
11 | { | ||
12 | |||
13 | //! constructor | ||
14 | CVideoModeList::CVideoModeList() | ||
15 | { | ||
16 | #ifdef _DEBUG | ||
17 | setDebugName("CVideoModeList"); | ||
18 | #endif | ||
19 | |||
20 | Desktop.depth = 0; | ||
21 | Desktop.size = core::dimension2d<u32>(0,0); | ||
22 | } | ||
23 | |||
24 | |||
25 | void CVideoModeList::setDesktop(s32 desktopDepth, const core::dimension2d<u32>& desktopSize) | ||
26 | { | ||
27 | Desktop.depth = desktopDepth; | ||
28 | Desktop.size = desktopSize; | ||
29 | } | ||
30 | |||
31 | |||
32 | //! Gets amount of video modes in the list. | ||
33 | s32 CVideoModeList::getVideoModeCount() const | ||
34 | { | ||
35 | return (s32)VideoModes.size(); | ||
36 | } | ||
37 | |||
38 | |||
39 | //! Returns the screen size of a video mode in pixels. | ||
40 | core::dimension2d<u32> CVideoModeList::getVideoModeResolution(s32 modeNumber) const | ||
41 | { | ||
42 | if (modeNumber < 0 || modeNumber > (s32)VideoModes.size()) | ||
43 | return core::dimension2d<u32>(0,0); | ||
44 | |||
45 | return VideoModes[modeNumber].size; | ||
46 | } | ||
47 | |||
48 | |||
49 | core::dimension2d<u32> CVideoModeList::getVideoModeResolution( | ||
50 | const core::dimension2d<u32>& minSize, | ||
51 | const core::dimension2d<u32>& maxSize) const | ||
52 | { | ||
53 | u32 best=VideoModes.size(); | ||
54 | // if only one or no mode | ||
55 | if (best<2) | ||
56 | return getVideoModeResolution(0); | ||
57 | |||
58 | u32 i; | ||
59 | for (i=0; i<VideoModes.size(); ++i) | ||
60 | { | ||
61 | if (VideoModes[i].size.Width>=minSize.Width && | ||
62 | VideoModes[i].size.Height>=minSize.Height && | ||
63 | VideoModes[i].size.Width<=maxSize.Width && | ||
64 | VideoModes[i].size.Height<=maxSize.Height) | ||
65 | best=i; | ||
66 | } | ||
67 | // we take the last one found, the largest one fitting | ||
68 | if (best<VideoModes.size()) | ||
69 | return VideoModes[best].size; | ||
70 | const u32 minArea = minSize.getArea(); | ||
71 | const u32 maxArea = maxSize.getArea(); | ||
72 | u32 minDist = 0xffffffff; | ||
73 | best=0; | ||
74 | for (i=0; i<VideoModes.size(); ++i) | ||
75 | { | ||
76 | const u32 area = VideoModes[i].size.getArea(); | ||
77 | const u32 dist = core::min_(abs(int(minArea-area)), abs(int(maxArea-area))); | ||
78 | if (dist<minDist) | ||
79 | { | ||
80 | minDist=dist; | ||
81 | best=i; | ||
82 | } | ||
83 | } | ||
84 | return VideoModes[best].size; | ||
85 | } | ||
86 | |||
87 | |||
88 | //! Returns the pixel depth of a video mode in bits. | ||
89 | s32 CVideoModeList::getVideoModeDepth(s32 modeNumber) const | ||
90 | { | ||
91 | if (modeNumber < 0 || modeNumber > (s32)VideoModes.size()) | ||
92 | return 0; | ||
93 | |||
94 | return VideoModes[modeNumber].depth; | ||
95 | } | ||
96 | |||
97 | |||
98 | //! Returns current desktop screen resolution. | ||
99 | const core::dimension2d<u32>& CVideoModeList::getDesktopResolution() const | ||
100 | { | ||
101 | return Desktop.size; | ||
102 | } | ||
103 | |||
104 | |||
105 | //! Returns the pixel depth of a video mode in bits. | ||
106 | s32 CVideoModeList::getDesktopDepth() const | ||
107 | { | ||
108 | return Desktop.depth; | ||
109 | } | ||
110 | |||
111 | |||
112 | //! adds a new mode to the list | ||
113 | void CVideoModeList::addMode(const core::dimension2d<u32>& size, s32 depth) | ||
114 | { | ||
115 | SVideoMode m; | ||
116 | m.depth = depth; | ||
117 | m.size = size; | ||
118 | |||
119 | for (u32 i=0; i<VideoModes.size(); ++i) | ||
120 | { | ||
121 | if (VideoModes[i] == m) | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | VideoModes.push_back(m); | ||
126 | VideoModes.sort(); // TODO: could be replaced by inserting into right place | ||
127 | } | ||
128 | |||
129 | |||
130 | } // end namespace video | ||
131 | } // end namespace irr | ||
132 | |||