Files @ r24161:6a03a2a7db69
Branch filter:

Location: cpp/openttd-patchpack/source/src/video/cocoa/cocoa_v.h - annotation

frosch
Fix: OpenGFX download link did no longer work. (#8105)
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r9111:983de9c5a848
r9111:983de9c5a848
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r21028:e5db3f83cafa
r7939:523d421f9d0c
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r12935:993da883d0df
r18160:133e96e28508
r18160:133e96e28508
r18160:133e96e28508
r23497:a0ab44ebd2fa
r18160:133e96e28508
r20648:393668109c79
r20648:393668109c79
r20648:393668109c79
r23497:a0ab44ebd2fa
r20648:393668109c79
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r7939:523d421f9d0c
r21027:e87e97e6befd
r7939:523d421f9d0c
r21027:e87e97e6befd
r23497:a0ab44ebd2fa
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r16830:bc75a402323c
r16830:bc75a402323c
r16830:bc75a402323c
r16830:bc75a402323c
r16830:bc75a402323c
r7939:523d421f9d0c
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r16830:bc75a402323c
r18063:14deaddcaab9
r18063:14deaddcaab9
r16830:bc75a402323c
r16830:bc75a402323c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r24136:d54bcc7ae848
r18063:14deaddcaab9
r16830:bc75a402323c
r16830:bc75a402323c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r16830:bc75a402323c
r18063:14deaddcaab9
r16830:bc75a402323c
r16830:bc75a402323c
r18063:14deaddcaab9
r16830:bc75a402323c
r16830:bc75a402323c
r16830:bc75a402323c
r18063:14deaddcaab9
r16830:bc75a402323c
r16830:bc75a402323c
r18063:14deaddcaab9
r7939:523d421f9d0c
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r13274:e64ba38458c3
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r7939:523d421f9d0c
r10647:62911ec68e89
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18160:133e96e28508
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r19944:25a78576fb5e
r18063:14deaddcaab9
r18062:17f95a9d533f
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r10647:62911ec68e89
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r7939:523d421f9d0c
r18063:14deaddcaab9
r18063:14deaddcaab9
r18063:14deaddcaab9
r7939:523d421f9d0c
r16833:b0f3f5af4293
r18063:14deaddcaab9
r16833:b0f3f5af4293
r18063:14deaddcaab9
r18063:14deaddcaab9
r19944:25a78576fb5e
r18063:14deaddcaab9
r16833:b0f3f5af4293
r7939:523d421f9d0c
r7939:523d421f9d0c
r10647:62911ec68e89
r7939:523d421f9d0c
r8092:2ffef7ba3a2b
r7943:5b6755474854
r7984:4e4b70ff8d8e
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r7939:523d421f9d0c
r10647:62911ec68e89
r8156:a6b6768b0508
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16833:b0f3f5af4293
r16834:1d03199cc9a5
r24152:75abc58338b6
r20655:3309c8d19a22
r16832:6e9e2c7ea4c7
r16834:1d03199cc9a5
r16832:6e9e2c7ea4c7
r16832:6e9e2c7ea4c7
r16832:6e9e2c7ea4c7
r16832:6e9e2c7ea4c7
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16834:1d03199cc9a5
r16832:6e9e2c7ea4c7
r16832:6e9e2c7ea4c7
r16831:c3943d3ad2de
r24152:75abc58338b6
r22778:81fef1b7f626
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r20617:4bc8f7289621
r23830:9b27a286997b
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r16831:c3943d3ad2de
r7939:523d421f9d0c
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file cocoa_v.h The Cocoa video driver. */

#ifndef VIDEO_COCOA_H
#define VIDEO_COCOA_H

#include "../video_driver.hpp"

class VideoDriver_Cocoa : public VideoDriver {
public:
	const char *Start(const char * const *param) override;

	/** Stop the video driver */
	void Stop() override;

	/** Mark dirty a screen region
	 * @param left x-coordinate of left border
	 * @param top  y-coordinate of top border
	 * @param width width or dirty rectangle
	 * @param height height of dirty rectangle
	 */
	void MakeDirty(int left, int top, int width, int height) override;

	/** Programme main loop */
	void MainLoop() override;

	/** Change window resolution
	 * @param w New window width
	 * @param h New window height
	 * @return Whether change was successful
	 */
	bool ChangeResolution(int w, int h) override;

	/** Set a new window mode
	 * @param fullscreen Whether to set fullscreen mode or not
	 * @return Whether changing the screen mode was successful
	 */
	bool ToggleFullscreen(bool fullscreen) override;

	/** Callback invoked after the blitter was changed.
	 * @return True if no error.
	 */
	bool AfterBlitterChange() override;

	/**
	 * An edit box lost the input focus. Abort character compositing if necessary.
	 */
	void EditBoxLostFocus() override;

	/** Return driver name
	 * @return driver name
	 */
	const char *GetName() const override { return "cocoa"; }
};

class FVideoDriver_Cocoa : public DriverFactoryBase {
public:
	FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
	Driver *CreateInstance() const override { return new VideoDriver_Cocoa(); }
};


/**
 * Generic display driver for cocoa
 * On grounds to not duplicate some code, it contains a few variables
 * which are not used by all device drivers.
 */
class CocoaSubdriver {
public:
	int device_width;     ///< Width of device in pixel
	int device_height;    ///< Height of device in pixel
	int device_depth;     ///< Colour depth of device in bit

	int window_width;     ///< Current window width in pixel
	int window_height;    ///< Current window height in pixel
	int window_pitch;

	int buffer_depth;     ///< Colour depth of used frame buffer
	void *pixel_buffer;   ///< used for direct pixel access
	void *window_buffer;  ///< Colour translation from palette to screen
	CGColorSpaceRef color_space; //< Window color space
	id window;            ///< Pointer to window object

#	define MAX_DIRTY_RECTS 100
	Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
	int num_dirty_rects;  ///< Number of dirty rectangles
	uint32 palette[256];  ///< Colour Palette

	bool active;          ///< Whether the window is visible
	bool setup;

	id cocoaview;         ///< Pointer to view object

	/* Separate driver vars for Quarz
	 * Needed here in order to avoid much code duplication */
	CGContextRef cgcontext;    ///< Context reference for Quartz subdriver

	/* Driver methods */
	/** Initialize driver */
	virtual ~CocoaSubdriver() {}

	/** Draw window
	 * @param force_update Whether to redraw unconditionally
	 */
	virtual void Draw(bool force_update = false) = 0;

	/** Mark dirty a screen region
	 * @param left x-coordinate of left border
	 * @param top  y-coordinate of top border
	 * @param width width or dirty rectangle
	 * @param height height of dirty rectangle
	 */
	virtual void MakeDirty(int left, int top, int width, int height) = 0;

	/** Update the palette */
	virtual void UpdatePalette(uint first_color, uint num_colors) = 0;

	virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;

	/** Change window resolution
	 * @param w New window width
	 * @param h New window height
	 * @return Whether change was successful
	 */
	virtual bool ChangeResolution(int w, int h, int bpp) = 0;

	/** Are we in fullscreen mode
	 * @return whether fullscreen mode is currently used
	 */
	virtual bool IsFullscreen() = 0;

	/** Toggle between fullscreen and windowed mode
	 * @return whether switch was successful
	 */
	virtual bool ToggleFullscreen() { return false; };

	/** Return the width of the current view
	 * @return width of the current view
	 */
	virtual int GetWidth() = 0;

	/** Return the height of the current view
	 * @return height of the current view
	 */
	virtual int GetHeight() = 0;

	/** Return the current pixel buffer
	 * @return pixelbuffer
	 */
	virtual void *GetPixelBuffer() = 0;

	/** Convert local coordinate to window server (CoreGraphics) coordinate
	 * @param p local coordinates
	 * @return window driver coordinates
	 */
	virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;

	/** Return the mouse location
	 * @param event UI event
	 * @return mouse location as NSPoint
	 */
	virtual NSPoint GetMouseLocation(NSEvent *event) = 0;

	/** Return whether the mouse is within our view
	 * @param pt Mouse coordinates
	 * @return Whether mouse coordinates are within view
	 */
	virtual bool MouseIsInsideView(NSPoint *pt) = 0;

	/** Return whether the window is active (visible)
	 * @return whether the window is visible or not
	 */
	virtual bool IsActive() = 0;

	/** Makes the *game region* of the window 100% opaque. */
	virtual void SetPortAlphaOpaque() { return; };

	/** Whether the window was successfully resized
	 * @return whether the window was successfully resized
	 */
	virtual bool WindowResized() { return false; };
};

extern CocoaSubdriver *_cocoa_subdriver;

#ifdef ENABLE_COCOA_QUARTZ
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
#endif

void QZ_GameSizeChanged();

void QZ_GameLoop();

uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);

/** Category of NSCursor to allow cursor showing/hiding */
@interface NSCursor (OTTD_QuickdrawCursor)
+ (NSCursor *) clearCocoaCursor;
@end

/** Subclass of NSWindow to cater our special needs */
@interface OTTD_CocoaWindow : NSWindow {
	CocoaSubdriver *driver;
}

- (void)setDriver:(CocoaSubdriver*)drv;

- (void)miniaturize:(id)sender;
- (void)display;
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
- (void)appDidHide:(NSNotification*)note;
- (void)appWillUnhide:(NSNotification*)note;
- (void)appDidUnhide:(NSNotification*)note;
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
@end

/** Subclass of NSView to fix Quartz rendering and mouse awareness */
@interface OTTD_CocoaView : NSView <NSTextInputClient>
{
	CocoaSubdriver *driver;
	NSTrackingRectTag trackingtag;
}
- (void)setDriver:(CocoaSubdriver*)drv;
- (void)drawRect:(NSRect)rect;
- (BOOL)isOpaque;
- (BOOL)acceptsFirstResponder;
- (BOOL)becomeFirstResponder;
- (void)setTrackingRect;
- (void)clearTrackingRect;
- (void)resetCursorRects;
- (void)viewWillMoveToWindow:(NSWindow *)win;
- (void)viewDidMoveToWindow;
- (void)mouseEntered:(NSEvent *)theEvent;
- (void)mouseExited:(NSEvent *)theEvent;
@end

/** Delegate for our NSWindow to send ask for quit on close */
@interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
{
	CocoaSubdriver *driver;
}

- (void)setDriver:(CocoaSubdriver*)drv;

- (BOOL)windowShouldClose:(id)sender;
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
- (void)windowDidChangeScreenProfile:(NSNotification *)aNotification;
@end


#endif /* VIDEO_COCOA_H */