📄 agg_platform_support.h
字号:
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG 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; either version 2
// of the License, or (at your option) any later version.
//
// AGG 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 AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
//
// class platform_support
//
// It's not a part of the AGG library, it's just a helper class to create
// interactive demo examples. Since the examples should not be too complex
// this class is provided to support some very basic interactive graphical
// funtionality, such as putting the rendered image to the window, simple
// keyboard and mouse input, window resizing, setting the window title,
// and catching the "idle" events.
//
// The idea is to have a single header file that does not depend on any
// platform (I hate these endless #ifdef/#elif/#elif.../#endif) and a number
// of different implementations depending on the concrete platform.
// The most popular platforms are:
//
// Windows-32 API
// X-Window API
// SDL library (see http://www.libsdl.org/)
// MacOS C/C++ API
//
// This file does not include any system dependent .h files such as
// windows.h or X11.h, so, your demo applications do not depend on the
// platform. The only file that can #include system dependend headers
// is the implementation file agg_platform_support.cpp. Different
// implementations are placed in different directories, such as
// ~/agg/src/platform/win32
// ~/agg/src/platform/sdl
// ~/agg/src/platform/X11
// and so on.
//
// All the system dependent stuff sits in the platform_specific
// class which is forward-declared here but not defined.
// The platform_support class has just a pointer to it and it's
// the responsibility of the implementation to create/delete it.
// This class being defined in the implementation file can have
// any platform dependent stuff such as HWND, X11 Window and so on.
//
//----------------------------------------------------------------------------
#ifndef AGG_PLATFORM_SUPPORT_INCLUDED
#define AGG_PLATFORM_SUPPORT_INCLUDED
#include "agg_basics.h"
#include "agg_rendering_buffer.h"
#include "agg_trans_viewport.h"
#include "agg_ctrl.h"
namespace agg
{
//----------------------------------------------------------window_flag_e
// These are flags used in method init(). Not all of them are
// applicable on different platforms, for example the win32_api
// cannot use a hardware buffer (window_hw_buffer).
// The implementation should simply ignore unsupported flags.
enum window_flag_e
{
window_resize = 1,
window_hw_buffer = 2,
window_keep_aspect_ratio = 4,
window_process_all_keys = 8
};
//-----------------------------------------------------------pix_format_e
// Possible formats of the rendering buffer. Initially I thought that it's
// reasonable to create the buffer and the rendering functions in
// accordance with the native pixel format of the system because it
// would have no overhead for pixel format conersion.
// But eventually I came to a conclusion that having a possibility to
// convert pixel formats on demand is a good idea. First, it was X11 where
// there lots of different formats and visuals and it would be great to
// render everything in, say, RGB-24 and display it automatically without
// any additional efforts. The second reason is to have a possibility to
// debug renderers for different pixel formats and colorspaces having only
// one computer and one system.
//
// This stuff is not included into the basic AGG functionality because the
// number of supported pixel formats (and/or colorspaces) can be great and
// if one needs to add new format it would be good only to add new
// rendering files without having to modify any existing ones (a general
// principle of incapsulation and isolation).
//
// Using a particular pixel format doesn't obligatory mean the necessity
// of software conversion. For example, win32 API can natively display
// gray8, 15-bit RGB, 24-bit BGR, and 32-bit BGRA formats.
// This list can be (and will be!) extended in future.
enum pix_format_e
{
pix_format_undefined = 0, // By default. No conversions are applied
pix_format_bw, // 1 bit per color B/W
pix_format_gray8, // Simple 256 level grayscale
pix_format_gray16, // Simple 65535 level grayscale
pix_format_rgb555, // 15 bit rgb. Depends on the byte ordering!
pix_format_rgb565, // 16 bit rgb. Depends on the byte ordering!
pix_format_rgbAAA, // 30 bit rgb. Depends on the byte ordering!
pix_format_rgbBBA, // 32 bit rgb. Depends on the byte ordering!
pix_format_bgrAAA, // 30 bit bgr. Depends on the byte ordering!
pix_format_bgrABB, // 32 bit bgr. Depends on the byte ordering!
pix_format_rgb24, // R-G-B, one byte per color component
pix_format_bgr24, // B-G-R, native win32 BMP format.
pix_format_rgba32, // R-G-B-A, one byte per color component
pix_format_argb32, // A-R-G-B, native MAC format
pix_format_abgr32, // A-B-G-R, one byte per color component
pix_format_bgra32, // B-G-R-A, native win32 BMP format
pix_format_rgb48, // R-G-B, 16 bits per color component
pix_format_bgr48, // B-G-R, native win32 BMP format.
pix_format_rgba64, // R-G-B-A, 16 bits byte per color component
pix_format_argb64, // A-R-G-B, native MAC format
pix_format_abgr64, // A-B-G-R, one byte per color component
pix_format_bgra64, // B-G-R-A, native win32 BMP format
end_of_pix_formats
};
//-------------------------------------------------------------input_flag_e
// Mouse and keyboard flags. They can be different on different platforms
// and the ways they are obtained are also different. But in any case
// the system dependent flags should be mapped into these ones. The meaning
// of that is as follows. For example, if kbd_ctrl is set it means that the
// ctrl key is pressed and being held at the moment. They are also used in
// the overridden methods such as on_mouse_move(), on_mouse_button_down(),
// on_mouse_button_dbl_click(), on_mouse_button_up(), on_key().
// In the method on_mouse_button_up() the mouse flags have different
// meaning. They mean that the respective button is being released, but
// the meaning of the keyboard flags remains the same.
// There's absolut minimal set of flags is used because they'll be most
// probably supported on different platforms. Even the mouse_right flag
// is restricted because Mac's mice have only one button, but AFAIK
// it can be simulated with holding a special key on the keydoard.
enum input_flag_e
{
mouse_left = 1,
mouse_right = 2,
kbd_shift = 4,
kbd_ctrl = 8
};
//--------------------------------------------------------------key_code_e
// Keyboard codes. There's also a restricted set of codes that are most
// probably supported on different platforms. Any platform dependent codes
// should be converted into these ones. There're only those codes are
// defined that cannot be represented as printable ASCII-characters.
// All printable ASCII-set can be used in a regular C/C++ manner:
// ' ', 'A', '0' '+' and so on.
// Since the class is used for creating very simple demo-applications
// we don't need very rich possibilities here, just basic ones.
// Actually the numeric key codes are taken from the SDL library, so,
// the implementation of the SDL support does not require any mapping.
enum key_code_e
{
// ASCII set. Should be supported everywhere
key_backspace = 8,
key_tab = 9,
key_clear = 12,
key_return = 13,
key_pause = 19,
key_escape = 27,
// Keypad
key_delete = 127,
key_kp0 = 256,
key_kp1 = 257,
key_kp2 = 258,
key_kp3 = 259,
key_kp4 = 260,
key_kp5 = 261,
key_kp6 = 262,
key_kp7 = 263,
key_kp8 = 264,
key_kp9 = 265,
key_kp_period = 266,
key_kp_divide = 267,
key_kp_multiply = 268,
key_kp_minus = 269,
key_kp_plus = 270,
key_kp_enter = 271,
key_kp_equals = 272,
// Arrow-keys and stuff
key_up = 273,
key_down = 274,
key_right = 275,
key_left = 276,
key_insert = 277,
key_home = 278,
key_end = 279,
key_page_up = 280,
key_page_down = 281,
// Functional keys. You'd better avoid using
// f11...f15 in your applications if you want
// the applications to be portable
key_f1 = 282,
key_f2 = 283,
key_f3 = 284,
key_f4 = 285,
key_f5 = 286,
key_f6 = 287,
key_f7 = 288,
key_f8 = 289,
key_f9 = 290,
key_f10 = 291,
key_f11 = 292,
key_f12 = 293,
key_f13 = 294,
key_f14 = 295,
key_f15 = 296,
// The possibility of using these keys is
// very restricted. Actually it's guaranteed
// only in win32_api and win32_sdl implementations
key_numlock = 300,
key_capslock = 301,
key_scrollock = 302,
// Phew!
end_of_key_codes
};
//------------------------------------------------------------------------
// A predeclaration of the platform dependent class. Since we do not
// know anything here the only we can have is just a pointer to this
// class as a data member. It should be created and destroyed explicitly
// in the constructor/destructor of the platform_support class.
// Although the pointer to platform_specific is public the application
// cannot have access to its members or methods since it does not know
// anything about them and it's a perfect incapsulation :-)
class platform_specific;
//----------------------------------------------------------ctrl_container
// A helper class that contains pointers to a number of controls.
// This class is used to ease the event handling with controls.
// The implementation should simply call the appropriate methods
// of this class when appropriate events occur.
class ctrl_container
{
enum max_ctrl_e { max_ctrl = 64 };
public:
//--------------------------------------------------------------------
ctrl_container() : m_num_ctrl(0), m_cur_ctrl(-1) {}
//--------------------------------------------------------------------
void add(ctrl& c)
{
if(m_num_ctrl < max_ctrl)
{
m_ctrl[m_num_ctrl++] = &c;
}
}
//--------------------------------------------------------------------
bool in_rect(double x, double y)
{
unsigned i;
for(i = 0; i < m_num_ctrl; i++)
{
if(m_ctrl[i]->in_rect(x, y)) return true;
}
return false;
}
//--------------------------------------------------------------------
bool on_mouse_button_down(double x, double y)
{
unsigned i;
for(i = 0; i < m_num_ctrl; i++)
{
if(m_ctrl[i]->on_mouse_button_down(x, y)) return true;
}
return false;
}
//--------------------------------------------------------------------
bool on_mouse_button_up(double x, double y)
{
unsigned i;
bool flag = false;
for(i = 0; i < m_num_ctrl; i++)
{
if(m_ctrl[i]->on_mouse_button_up(x, y)) flag = true;
}
return flag;
}
//--------------------------------------------------------------------
bool on_mouse_move(double x, double y, bool button_flag)
{
unsigned i;
for(i = 0; i < m_num_ctrl; i++)
{
if(m_ctrl[i]->on_mouse_move(x, y, button_flag)) return true;
}
return false;
}
//--------------------------------------------------------------------
bool on_arrow_keys(bool left, bool right, bool down, bool up)
{
if(m_cur_ctrl >= 0)
{
return m_ctrl[m_cur_ctrl]->on_arrow_keys(left, right, down, up);
}
return false;
}
//--------------------------------------------------------------------
bool set_cur(double x, double y)
{
unsigned i;
for(i = 0; i < m_num_ctrl; i++)
{
if(m_ctrl[i]->in_rect(x, y))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -