📄 guicontrol.h
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _GUICONTROL_H_
#define _GUICONTROL_H_
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _MPOINT_H_
#include "math/mPoint.h"
#endif
#ifndef _MRECT_H_
#include "math/mRect.h"
#endif
#ifndef _COLOR_H_
#include "core/color.h"
#endif
#ifndef _SIMBASE_H_
#include "console/simBase.h"
#endif
#ifndef _GUITYPES_H_
#include "gui/core/guiTypes.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#ifndef _LANG_H_
#include "i18n/lang.h"
#endif
class GuiCanvas;
class GuiEditCtrl;
/// Root class for all GUI controls in Torque.
///
/// @see GUI for an overview of the Torque GUI system.
///
/// @section GuiControl_Intro Introduction
///
/// GuiControl is the base class for GUI controls in Torque. It provides these
/// basic areas of functionality:
/// - Inherits from SimGroup, so that controls can have children.
/// - Interfacing with a GuiControlProfile.
/// - An abstraction from the details of handling user input
/// and so forth, providing friendly hooks like onMouseEnter(), onMouseMove(),
/// and onMouseLeave(), onKeyDown(), and so forth.
/// - An abstraction from the details of rendering and resizing.
/// - Helper functions to manipulate the mouse (mouseLock and
/// mouseUnlock), and convert coordinates (localToGlobalCoord() and
/// globalToLocalCoord()).
///
/// @ref GUI has an overview of the GUI system.
///
/// @nosubgrouping
class GuiControl : public SimGroup
{
private:
typedef SimGroup Parent;
public:
/// @name Control State
/// @{
GuiControlProfile *mProfile;
GuiControlProfile *mTooltipProfile;
#ifdef TGE_RPG_UI
Point2I m_marginTopLeft;
Point2I m_marginBottomRight;
bool m_bAutoSize;
#endif
bool mVisible;
bool mActive;
bool mAwake;
bool mSetFirstResponder;
S32 mLayer;
RectI mBounds;
Point2I mMinExtent;
StringTableEntry mLangTableName;
LangTable *mLangTable;
static bool smDesignTime; ///< static GuiControl boolean that specifies if the GUI Editor is active
/// @}
/// @name Design Time Editor Access
/// @{
static GuiEditCtrl *smEditorHandle; ///< static GuiEditCtrl pointer that gives controls access to editor-NULL if editor is closed
/// @}
/// @name Keyboard Input
/// @{
GuiControl *mFirstResponder;
static GuiControl *smPrevResponder;
static GuiControl *smCurResponder;
/// @}
enum horizSizingOptions
{
horizResizeRight = 0, ///< fixed on the left and width
horizResizeWidth, ///< fixed on the left and right
horizResizeLeft, ///< fixed on the right and width
horizResizeCenter,
horizResizeRelative ///< resize relative
};
enum vertSizingOptions
{
vertResizeBottom = 0, ///< fixed on the top and in height
vertResizeHeight, ///< fixed on the top and bottom
vertResizeTop, ///< fixed in height and on the bottom
vertResizeCenter,
vertResizeRelative ///< resize relative
};
protected:
/// @name Control State
/// @{
S32 mHorizSizing; ///< Set from horizSizingOptions.
S32 mVertSizing; ///< Set from vertSizingOptions.
StringTableEntry mConsoleVariable;
StringTableEntry mConsoleCommand;
StringTableEntry mAltConsoleCommand;
StringTableEntry mAcceleratorKey;
StringTableEntry mTooltip;
/// @}
/// @name Console
/// The console variable collection of functions allows a console variable to be bound to the GUI control.
///
/// This allows, say, an edit field to be bound to '$foo'. The value of the console
/// variable '$foo' would then be equal to the text inside the text field. Changing
/// either changes the other.
/// @{
/// Sets the value of the console variable bound to this control
/// @param value String value to assign to control's console variable
void setVariable(const char *value);
/// Sets the value of the console variable bound to this control
/// @param value Integer value to assign to control's console variable
void setIntVariable(S32 value);
/// Sets the value of the console variable bound to this control
/// @param value Float value to assign to control's console variable
void setFloatVariable(F32 value);
const char* getVariable(); ///< Returns value of control's bound variable as a string
S32 getIntVariable(); ///< Returns value of control's bound variable as a integer
F32 getFloatVariable(); ///< Returns value of control's bound variable as a float
public:
/// Set the name of the console variable which this GuiObject is bound to
/// @param variable Variable name
void setConsoleVariable(const char *variable);
/// Set the name of the console function bound to, such as a script function
/// a button calls when clicked.
/// @param newCmd Console function to attach to this GuiControl
void setConsoleCommand(const char *newCmd);
const char * getConsoleCommand(); ///< Returns the name of the function bound to this GuiControl
LangTable *getGUILangTable(void);
const UTF8 *getGUIString(S32 id);
/// @}
/// @name Editor
/// These functions are used by the GUI Editor
/// @{
/// Sets the size of the GuiControl
/// @param horz Width of the control
/// @param vert Height of the control
void setSizing(S32 horz, S32 vert);
/// @}
public:
/// @name Initialization
/// @{
DECLARE_CONOBJECT(GuiControl);
GuiControl();
virtual ~GuiControl();
static void initPersistFields();
/// @}
/// @name Accessors
/// @{
const Point2I& getPosition() { return mBounds.point; } ///< Returns position of the control
const Point2I& getExtent() { return mBounds.extent; } ///< Returns extents of the control
const Point2I& getMinExtent() { return mMinExtent; } ///< Returns minimum size the control can be
const S32 getLeft() { return mBounds.point.x; } ///< Returns the X position of the control
const S32 getTop() { return mBounds.point.y; } ///< Returns the Y position of the control
const S32 getWidth() { return mBounds.extent.x; } ///< Returns the width of the control
const S32 getHeight() { return mBounds.extent.y; } ///< Returns the height of the control
#ifdef TGE_RPG
const S32 getRight() { return mBounds.point.x + mBounds.extent.x; } ///< Returns the X right position of the control
const S32 getBottom() { return mBounds.point.y + mBounds.extent.y; } ///< Returns the Y bottom position of the control
Point2I getGlobalPos() ; ///< Returns position of the control
#endif
#ifdef TGE_RPG_UI
virtual void ToggleVH(bool bVertical,GuiControl *pDispatch);
virtual void autoSizeToContent();
#endif
/// @}
/// @name Flags
/// @{
/// Sets the visibility of the control
/// @param value True if object should be visible
virtual void setVisible(bool value);
inline bool isVisible() { return mVisible; } ///< Returns true if the object is visible
/// Sets the status of this control as active and responding or inactive
/// @param value True if this is active
void setActive(bool value);
bool isActive() { return mActive; } ///< Returns true if this control is active
bool isAwake() { return mAwake; } ///< Returns true if this control is awake
/// @}
/// Get information about the size of a scroll line.
///
/// @param rowHeight The height, in pixels, of a row
/// @param columnWidth The width, in pixels, of a column
virtual void getScrollLineSizes(U32 *rowHeight, U32 *columnWidth);
/// Get information about the cursor.
/// @param cursor Cursor information will be stored here
/// @param showCursor Will be set to true if the cursor is visible
/// @param lastGuiEvent GuiEvent containing cursor position and modifyer keys (ie ctrl, shift, alt etc)
virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
/// @name Children
/// @{
/// Adds an object as a child of this object.
/// @param obj New child object of this control
void addObject(SimObject *obj);
/// Removes a child object from this control.
/// @param obj Object to remove from this control
void removeObject(SimObject *obj);
GuiControl *getParent(); ///< Returns the control which owns this one.
GuiCanvas *getRoot(); ///< Returns the root canvas of this control.
/// @}
/// @name Coordinates
/// @{
/// Translates local coordinates (wrt this object) into global coordinates
///
/// @param src Local coordinates to translate
Point2I localToGlobalCoord(const Point2I &src);
/// Returns global coordinates translated into local space
///
/// @param src Global coordinates to translate
Point2I globalToLocalCoord(const Point2I &src);
/// @}
/// @name Resizing
/// @{
/// Changes the size and/or position of this control
/// @param newPosition New position of this control
/// @param newExtent New size of this control
virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
/// Changes the position of this control
/// @param newPosition New position of this control
virtual void setPosition( const Point2I &newPosition );
/// Changes the size of this control
/// @param newExtent New size of this control
virtual void setExtent( const Point2I &newExtent );
#ifdef TGE_RPG
/// Changes the X right position of this control
/// @param newXPosition New X Position of this control
virtual void setRight( S32 newRight);
virtual void setRightBy( S32 newRight);
/// Changes the Y bottom position of this control
/// @param newYPosition New Y Position of this control
virtual void setBottom( S32 newBottom);
virtual void setBottomBy( S32 newBottom);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -