OpenTTD Source  12.0-beta2
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 @class OTTD_CocoaWindow;
21 @class OTTD_CocoaView;
22 
24 private:
26 
27 public:
28  bool setup;
29 
32  CGColorSpaceRef color_space;
33 
35 
36 public:
38 
39  void Stop() override;
40  void MainLoop() override;
41 
42  void MakeDirty(int left, int top, int width, int height) override;
43  bool AfterBlitterChange() override;
44 
45  bool ChangeResolution(int w, int h) override;
46  bool ToggleFullscreen(bool fullscreen) override;
47 
48  void EditBoxLostFocus() override;
49 
50  std::vector<int> GetListOfMonitorRefreshRates() override;
51 
52  /* --- The following methods should be private, but can't be due to Obj-C limitations. --- */
53 
54  void MainLoopReal();
55 
56  virtual void AllocateBackingStore(bool force = false) = 0;
57 
58 protected:
61 
62  Dimension GetScreenSize() const override;
63  float GetDPIScale() override;
64  void InputLoop() override;
65  bool LockVideoBuffer() override;
66  void UnlockVideoBuffer() override;
67  bool PollEvent() override;
68 
69  void GameSizeChanged();
70 
71  const char *Initialize();
72 
73  void UpdateVideoModes();
74 
75  bool MakeWindow(int width, int height);
76 
77  virtual NSView* AllocateDrawView() = 0;
78 
80  virtual void *GetVideoPointer() = 0;
82  virtual void ReleaseVideoPointer() {}
83 
84 private:
85  bool IsFullscreen();
86 };
87 
89 private:
91  void *pixel_buffer;
92  void *window_buffer;
93 
96  int window_pitch;
97 
98  uint32 palette[256];
99 
100  void BlitIndexedToView32(int left, int top, int right, int bottom);
101  void UpdatePalette(uint first_color, uint num_colors);
102 
103 public:
104  CGContextRef cgcontext;
105 
107 
108  const char *Start(const StringList &param) override;
109  void Stop() override;
110 
112  const char *GetName() const override { return "cocoa"; }
113 
114  void AllocateBackingStore(bool force = false) override;
115 
116 protected:
117  void Paint() override;
118  void CheckPaletteAnim() override;
119 
120  NSView* AllocateDrawView() override;
121 
122  void *GetVideoPointer() override { return this->buffer_depth == 8 ? this->pixel_buffer : this->window_buffer; }
123 };
124 
126 public:
127  FVideoDriver_CocoaQuartz() : DriverFactoryBase(Driver::DT_VIDEO, 8, "cocoa", "Cocoa Video Driver") {}
128  Driver *CreateInstance() const override { return new VideoDriver_CocoaQuartz(); }
129 };
130 
131 #endif /* VIDEO_COCOA_H */
VideoDriver_Cocoa::GetVideoPointer
virtual void * GetVideoPointer()=0
Get a pointer to the video buffer.
VideoDriver_CocoaQuartz::buffer_depth
int buffer_depth
Colour depth of used frame buffer.
Definition: cocoa_v.h:90
VideoDriver_CocoaQuartz::GetVideoPointer
void * GetVideoPointer() override
Get a pointer to the video buffer.
Definition: cocoa_v.h:122
VideoDriver_CocoaQuartz::window_width
int window_width
Current window width in pixel.
Definition: cocoa_v.h:94
VideoDriver_Cocoa::AfterBlitterChange
bool AfterBlitterChange() override
Callback invoked after the blitter was changed.
VideoDriver
The base of all video drivers.
Definition: video_driver.hpp:35
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
VideoDriver_Cocoa::InputLoop
void InputLoop() override
Handle input logic, is CTRL pressed, should we fast-forward, etc.
FVideoDriver_CocoaQuartz::CreateInstance
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: cocoa_v.h:128
VideoDriver_Cocoa::ChangeResolution
bool ChangeResolution(int w, int h) override
Change the resolution of the window.
VideoDriver_CocoaQuartz::cgcontext
CGContextRef cgcontext
Context reference for Quartz subdriver.
Definition: cocoa_v.h:104
DriverFactoryBase::DriverFactoryBase
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
Definition: driver.cpp:216
OTTD_CocoaWindowDelegate
Delegate for our NSWindow to send ask for quit on close.
Definition: cocoa_wnd.h:47
VideoDriver_CocoaQuartz
Definition: cocoa_v.h:88
VideoDriver_CocoaQuartz::window_height
int window_height
Current window height in pixel.
Definition: cocoa_v.h:95
VideoDriver_CocoaQuartz::palette
uint32 palette[256]
Colour Palette.
Definition: cocoa_v.h:98
VideoDriver_Cocoa::GetDPIScale
float GetDPIScale() override
Get DPI scaling factor of the screen OTTD is displayed on.
VideoDriver_Cocoa::cocoaview
OTTD_CocoaView * cocoaview
Pointer to view object.
Definition: cocoa_v.h:31
VideoDriver_Cocoa::ReleaseVideoPointer
virtual void ReleaseVideoPointer()
Hand video buffer back to the drawing backend.
Definition: cocoa_v.h:82
VideoDriver_CocoaQuartz::pixel_buffer
void * pixel_buffer
used for direct pixel access
Definition: cocoa_v.h:91
VideoDriver_Cocoa::buffer_locked
bool buffer_locked
Video buffer was locked by the main thread.
Definition: cocoa_v.h:60
VideoDriver_CocoaQuartz::GetName
const char * GetName() const override
Return driver name.
Definition: cocoa_v.h:112
VideoDriver_Cocoa::GetScreenSize
Dimension GetScreenSize() const override
Get the resolution of the main screen.
VideoDriver_CocoaQuartz::Paint
void Paint() override
Paint the window.
VideoDriver_Cocoa::dirty_rect
Rect dirty_rect
Region of the screen that needs redrawing.
Definition: cocoa_v.h:59
VideoDriver_Cocoa::PollEvent
bool PollEvent() override
Process a single system event.
VideoDriver_Cocoa::Stop
void Stop() override
Stop this driver.
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
VideoDriver_Cocoa::window
OTTD_CocoaWindow * window
Pointer to window object.
Definition: cocoa_v.h:30
VideoDriver_CocoaQuartz::Stop
void Stop() override
Stop this driver.
VideoDriver_CocoaQuartz::Start
const char * Start(const StringList &param) override
Start this driver.
VideoDriver_CocoaQuartz::window_buffer
void * window_buffer
Colour translation from palette to screen.
Definition: cocoa_v.h:92
VideoDriver_Cocoa::setup
bool setup
Window is currently being created.
Definition: cocoa_v.h:28
FVideoDriver_CocoaQuartz
Definition: cocoa_v.h:125
VideoDriver_Cocoa::UnlockVideoBuffer
void UnlockVideoBuffer() override
Unlock a previously locked video buffer.
OTTD_CocoaView
Subclass of NSView to support mouse awareness and text input.
Definition: cocoa_wnd.h:39
VideoDriver_Cocoa::ToggleFullscreen
bool ToggleFullscreen(bool fullscreen) override
Change the full screen setting.
VideoDriver_Cocoa
Definition: cocoa_v.h:23
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:44
VideoDriver_Cocoa::delegate
OTTD_CocoaWindowDelegate * delegate
Window delegate object.
Definition: cocoa_v.h:34
OTTD_CocoaWindow
Subclass of NSWindow to cater our special needs.
Definition: cocoa_wnd.h:32
VideoDriver_Cocoa::MainLoop
void MainLoop() override
Perform the actual drawing.
VideoDriver_CocoaQuartz::CheckPaletteAnim
void CheckPaletteAnim() override
Process any pending palette animation.
VideoDriver_Cocoa::orig_res
Dimension orig_res
Saved window size for non-fullscreen mode.
Definition: cocoa_v.h:25
VideoDriver_Cocoa::LockVideoBuffer
bool LockVideoBuffer() override
Make sure the video buffer is ready for drawing.
Driver
A driver for communicating with the user.
Definition: driver.h:23
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
VideoDriver_Cocoa::color_space
CGColorSpaceRef color_space
Window color space.
Definition: cocoa_v.h:32
VideoDriver_Cocoa::GetListOfMonitorRefreshRates
std::vector< int > GetListOfMonitorRefreshRates() override
Get a list of refresh rates of each available monitor.
DriverFactoryBase
Base for all driver factories.
Definition: driver.h:59
VideoDriver_Cocoa::EditBoxLostFocus
void EditBoxLostFocus() override
An edit box lost the input focus.
VideoDriver_Cocoa::MakeDirty
void MakeDirty(int left, int top, int width, int height) override
Mark a particular area dirty.