OpenTTD Source  1.11.0-beta1
cocoa_v.h
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_COCOA_H
11 #define VIDEO_COCOA_H
12 
13 #include "../video_driver.hpp"
14 #include "../../core/geometry_type.hpp"
15 
16 
17 extern bool _cocoa_video_started;
18 
20 private:
22 
23 public:
24  const char *Start(const StringList &param) override;
25 
27  void Stop() override;
28 
35  void MakeDirty(int left, int top, int width, int height) override;
36 
38  void MainLoop() override;
39 
45  bool ChangeResolution(int w, int h) override;
46 
51  bool ToggleFullscreen(bool fullscreen) override;
52 
56  bool AfterBlitterChange() override;
57 
61  void EditBoxLostFocus() override;
62 
66  const char *GetName() const override { return "cocoa"; }
67 
68  /* --- The following methods should be private, but can't be due to Obj-C limitations. --- */
69 
71  void GameLoop(); // In event.mm.
72 
73 protected:
74  Dimension GetScreenSize() const override;
75 
76 private:
77  friend class WindowQuartzSubdriver;
78 
79  void GameSizeChanged();
80 };
81 
83 public:
84  FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
85  Driver *CreateInstance() const override { return new VideoDriver_Cocoa(); }
86 };
87 
88 
95 public:
99 
102  int window_pitch;
103 
105  void *pixel_buffer;
107  CGColorSpaceRef color_space; //< Window color space
108  id window;
109 
110 # define MAX_DIRTY_RECTS 100
111  Rect dirty_rects[MAX_DIRTY_RECTS];
113  uint32 palette[256];
114 
115  bool active;
116  bool setup;
117 
119 
120  /* Separate driver vars for Quarz
121  * Needed here in order to avoid much code duplication */
122  CGContextRef cgcontext;
123 
124  /* Driver methods */
126  virtual ~CocoaSubdriver() {}
127 
131  virtual void Draw(bool force_update = false) = 0;
132 
139  virtual void MakeDirty(int left, int top, int width, int height) = 0;
140 
142  virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
143 
144  virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
145 
151  virtual bool ChangeResolution(int w, int h, int bpp) = 0;
152 
156  virtual bool IsFullscreen() = 0;
157 
161  virtual bool ToggleFullscreen(bool fullscreen) { return false; };
162 
166  virtual int GetWidth() = 0;
167 
171  virtual int GetHeight() = 0;
172 
176  virtual void *GetPixelBuffer() = 0;
177 
182  virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
183 
188  virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
189 
194  virtual bool MouseIsInsideView(NSPoint *pt) = 0;
195 
199  virtual bool IsActive() = 0;
200 
204  virtual bool WindowResized() { return false; };
205 };
206 
207 extern CocoaSubdriver *_cocoa_subdriver;
208 
209 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
210 
211 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
212 
213 #endif /* VIDEO_COCOA_H */
CocoaSubdriver::window_buffer
void * window_buffer
Colour translation from palette to screen.
Definition: cocoa_v.h:106
CocoaSubdriver::active
bool active
Whether the window is visible.
Definition: cocoa_v.h:115
fullscreen
bool fullscreen
Whether to use (true) fullscreen mode.
Definition: win32_v.cpp:52
CocoaSubdriver::device_depth
int device_depth
Colour depth of device in bit.
Definition: cocoa_v.h:98
CocoaSubdriver::MakeDirty
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark dirty a screen region.
VideoDriver_Cocoa::GetName
const char * GetName() const override
Return driver name.
Definition: cocoa_v.h:66
VideoDriver_Cocoa::AfterBlitterChange
bool AfterBlitterChange() override
Callback invoked after the blitter was changed.
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
CocoaSubdriver::num_dirty_rects
int num_dirty_rects
Number of dirty rectangles.
Definition: cocoa_v.h:112
FVideoDriver_Cocoa
Definition: cocoa_v.h:82
CocoaSubdriver::UpdatePalette
virtual void UpdatePalette(uint first_color, uint num_colors)=0
Update the palette.
VideoDriver_Cocoa::ChangeResolution
bool ChangeResolution(int w, int h) override
Change window resolution.
CocoaSubdriver
Generic display driver for cocoa On grounds to not duplicate some code, it contains a few variables w...
Definition: cocoa_v.h:94
DriverFactoryBase::DriverFactoryBase
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
Definition: driver.cpp:206
CocoaSubdriver::MouseIsInsideView
virtual bool MouseIsInsideView(NSPoint *pt)=0
Return whether the mouse is within our view.
CocoaSubdriver::GetWidth
virtual int GetWidth()=0
Return the width of the current view.
VideoDriver_Cocoa::GameLoop
void GameLoop()
Main game loop.
height
int height
Height in pixels of our display surface.
Definition: win32_v.cpp:49
CocoaSubdriver::window_width
int window_width
Current window width in pixel.
Definition: cocoa_v.h:100
CocoaSubdriver::PrivateLocalToCG
virtual CGPoint PrivateLocalToCG(NSPoint *p)=0
Convert local coordinate to window server (CoreGraphics) coordinate.
CocoaSubdriver::IsFullscreen
virtual bool IsFullscreen()=0
Are we in fullscreen mode.
CocoaSubdriver::Draw
virtual void Draw(bool force_update=false)=0
Draw window.
CocoaSubdriver::IsActive
virtual bool IsActive()=0
Return whether the window is active (visible)
CocoaSubdriver::GetHeight
virtual int GetHeight()=0
Return the height of the current view.
CocoaSubdriver::GetMouseLocation
virtual NSPoint GetMouseLocation(NSEvent *event)=0
Return the mouse location.
VideoDriver_Cocoa::Stop
void Stop() override
Stop the video driver.
CocoaSubdriver::~CocoaSubdriver
virtual ~CocoaSubdriver()
Initialize driver.
Definition: cocoa_v.h:126
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
CocoaSubdriver::GetPixelBuffer
virtual void * GetPixelBuffer()=0
Return the current pixel buffer.
CocoaSubdriver::device_height
int device_height
Height of device in pixel.
Definition: cocoa_v.h:97
CocoaSubdriver::ChangeResolution
virtual bool ChangeResolution(int w, int h, int bpp)=0
Change window resolution.
CocoaSubdriver::device_width
int device_width
Width of device in pixel.
Definition: cocoa_v.h:96
CocoaSubdriver::cocoaview
id cocoaview
Pointer to view object.
Definition: cocoa_v.h:118
VideoDriver_Cocoa::ToggleFullscreen
bool ToggleFullscreen(bool fullscreen) override
Set a new window mode.
VideoDriver_Cocoa::Start
const char * Start(const StringList &param) override
Start this driver.
CocoaSubdriver::dirty_rects
Rect dirty_rects[MAX_DIRTY_RECTS]
dirty rectangles
Definition: cocoa_v.h:111
VideoDriver_Cocoa
Definition: cocoa_v.h:19
CocoaSubdriver::cgcontext
CGContextRef cgcontext
Context reference for Quartz subdriver.
Definition: cocoa_v.h:122
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:44
CocoaSubdriver::WindowResized
virtual bool WindowResized()
Whether the window was successfully resized.
Definition: cocoa_v.h:204
VideoDriver_Cocoa::MainLoop
void MainLoop() override
Programme main loop.
width
int width
Width in pixels of our display surface.
Definition: win32_v.cpp:48
VideoDriver_Cocoa::orig_res
Dimension orig_res
Saved window size for non-fullscreen mode.
Definition: cocoa_v.h:21
CocoaSubdriver::window
id window
Pointer to window object.
Definition: cocoa_v.h:108
CocoaSubdriver::pixel_buffer
void * pixel_buffer
used for direct pixel access
Definition: cocoa_v.h:105
GameSizeChanged
void GameSizeChanged()
Size of the application screen changed.
Definition: main_gui.cpp:561
CocoaSubdriver::palette
uint32 palette[256]
Colour Palette.
Definition: cocoa_v.h:113
CocoaSubdriver::buffer_depth
int buffer_depth
Colour depth of used frame buffer.
Definition: cocoa_v.h:104
FVideoDriver_Cocoa::CreateInstance
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: cocoa_v.h:85
Driver
A driver for communicating with the user.
Definition: driver.h:23
CocoaSubdriver::window_height
int window_height
Current window height in pixel.
Definition: cocoa_v.h:101
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
DriverFactoryBase
Base for all driver factories.
Definition: driver.h:59
VideoDriver_Cocoa::EditBoxLostFocus
void EditBoxLostFocus() override
An edit box lost the input focus.
CocoaSubdriver::ToggleFullscreen
virtual bool ToggleFullscreen(bool fullscreen)
Toggle between fullscreen and windowed mode.
Definition: cocoa_v.h:161
VideoDriver_Cocoa::MakeDirty
void MakeDirty(int left, int top, int width, int height) override
Mark dirty a screen region.