OpenTTD Source  1.11.0-beta1
video_driver.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef VIDEO_VIDEO_DRIVER_HPP
11 #define VIDEO_VIDEO_DRIVER_HPP
12 
13 #include "../driver.h"
14 #include "../core/geometry_type.hpp"
15 #include "../core/math_func.hpp"
16 #include <vector>
17 
18 extern std::string _ini_videodriver;
19 extern std::vector<Dimension> _resolutions;
21 extern bool _rightclick_emulate;
22 
24 class VideoDriver : public Driver {
25  const uint DEFAULT_WINDOW_WIDTH = 640u;
26  const uint DEFAULT_WINDOW_HEIGHT = 480u;
27 
28 public:
36  virtual void MakeDirty(int left, int top, int width, int height) = 0;
37 
41  virtual void MainLoop() = 0;
42 
49  virtual bool ChangeResolution(int w, int h) = 0;
50 
56  virtual bool ToggleFullscreen(bool fullscreen) = 0;
57 
63  virtual bool AfterBlitterChange()
64  {
65  return true;
66  }
67 
72  virtual void AcquireBlitterLock() { }
73 
78  virtual void ReleaseBlitterLock() { }
79 
80  virtual bool ClaimMousePointer()
81  {
82  return true;
83  }
84 
93  virtual bool HasGUI() const
94  {
95  return true;
96  }
97 
101  virtual void EditBoxLostFocus() {}
102 
106  virtual void EditBoxGainedFocus() {}
107 
113  }
114 
115 protected:
116  /*
117  * Get the resolution of the main screen.
118  */
119  virtual Dimension GetScreenSize() const { return { DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT }; }
120 
125  {
126  if (_cur_resolution.width == 0 || _cur_resolution.height == 0) {
127  /* Auto-detect a good resolution. We aim for 75% of the screen size.
128  * Limit width times height times bytes per pixel to fit a 32 bit
129  * integer, This way all internal drawing routines work correctly. */
130  Dimension res = this->GetScreenSize();
131  _cur_resolution.width = ClampU(res.width * 3 / 4, DEFAULT_WINDOW_WIDTH, UINT16_MAX / 2);
132  _cur_resolution.height = ClampU(res.height * 3 / 4, DEFAULT_WINDOW_HEIGHT, UINT16_MAX / 2);
133  }
134  }
135 };
136 
137 #endif /* VIDEO_VIDEO_DRIVER_HPP */
fullscreen
bool fullscreen
Whether to use (true) fullscreen mode.
Definition: win32_v.cpp:52
DriverFactoryBase::GetActiveDriver
static Driver ** GetActiveDriver(Driver::Type type)
Get the active driver for the given type.
Definition: driver.h:86
VideoDriver
The base of all video drivers.
Definition: video_driver.hpp:24
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
VideoDriver::MakeDirty
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
VideoDriver::ToggleFullscreen
virtual bool ToggleFullscreen(bool fullscreen)=0
Change the full screen setting.
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:23
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
VideoDriver::ReleaseBlitterLock
virtual void ReleaseBlitterLock()
Release any lock(s) required to be held when changing blitters.
Definition: video_driver.hpp:78
VideoDriver::HasGUI
virtual bool HasGUI() const
Whether the driver has a graphical user interface with the end user.
Definition: video_driver.hpp:93
height
int height
Height in pixels of our display surface.
Definition: win32_v.cpp:49
VideoDriver::DEFAULT_WINDOW_HEIGHT
const uint DEFAULT_WINDOW_HEIGHT
Default window height.
Definition: video_driver.hpp:26
_rightclick_emulate
bool _rightclick_emulate
Whether right clicking is emulated.
Definition: driver.cpp:24
VideoDriver::AcquireBlitterLock
virtual void AcquireBlitterLock()
Acquire any lock(s) required to be held when changing blitters.
Definition: video_driver.hpp:72
VideoDriver::ChangeResolution
virtual bool ChangeResolution(int w, int h)=0
Change the resolution of the window.
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:111
VideoDriver::UpdateAutoResolution
void UpdateAutoResolution()
Apply resolution auto-detection and clamp to sensible defaults.
Definition: video_driver.hpp:124
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:44
width
int width
Width in pixels of our display surface.
Definition: win32_v.cpp:48
_ini_videodriver
std::string _ini_videodriver
The video driver a stored in the configuration file.
Definition: driver.cpp:21
VideoDriver::MainLoop
virtual void MainLoop()=0
Perform the actual drawing.
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:101
VideoDriver::DEFAULT_WINDOW_WIDTH
const uint DEFAULT_WINDOW_WIDTH
Default window width.
Definition: video_driver.hpp:25
Driver
A driver for communicating with the user.
Definition: driver.h:23
_resolutions
std::vector< Dimension > _resolutions
List of resolutions.
Definition: driver.cpp:22
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:106
VideoDriver::AfterBlitterChange
virtual bool AfterBlitterChange()
Callback invoked after the blitter was changed.
Definition: video_driver.hpp:63