first commit
This commit is contained in:
169
include/engine/ui/ui.h
Normal file
169
include/engine/ui/ui.h
Normal file
@ -0,0 +1,169 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_SCENE__
|
||||
#define __NUI_SCENE__
|
||||
|
||||
|
||||
#include "ui/ui_item.h"
|
||||
#include "ui/ui_cursor.h"
|
||||
#include "ui/ui_message.h"
|
||||
#include "ui/ui_event_handler.h"
|
||||
#include "ui/ui_window_skin.h"
|
||||
#include "ui/ui_scene_event_interface.h"
|
||||
#include "scene3d/scene_io_flag.h"
|
||||
#include "motion/scene_motion_container.h"
|
||||
#include "core/tool_mode.h"
|
||||
#include "core/clock.h"
|
||||
#include "core/ace.h"
|
||||
#include "color/color.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace GPU { class TriangleBatch; }
|
||||
namespace Render { class RasterFont; }
|
||||
namespace S2D {
|
||||
struct Group;
|
||||
struct Camera;
|
||||
class Window;
|
||||
class Widget;
|
||||
|
||||
/*!
|
||||
@short Scene 2D
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Scene : public SharedObject, public ACE::Unit
|
||||
{
|
||||
uint current_item_uid;
|
||||
|
||||
protected:
|
||||
|
||||
SharedList <Item *> item_list;
|
||||
Item *lock;
|
||||
|
||||
Matrix3 screen_to_ui, ui_to_screen;
|
||||
|
||||
SharedPtr <Camera> default_camera, current_camera;
|
||||
|
||||
Widget *RecurseWidgetBelowCursor(Window *, Widget *, int x, int y);
|
||||
void ProcessCursorEnterLeaveWidget(Cursor *, Window *, Widget *);
|
||||
|
||||
/// Execute an ACE command.
|
||||
bool ExecCommand(ACE::Command *, float dt);
|
||||
|
||||
Core::sClock clock;
|
||||
|
||||
public:
|
||||
|
||||
String name;
|
||||
|
||||
void SetClock(Core::Clock * = 0);
|
||||
|
||||
/*!
|
||||
@name Script system.
|
||||
@{
|
||||
*/
|
||||
Script::sVM vm;
|
||||
|
||||
AutoPtr <ISceneEvent> scene_event;
|
||||
AutoPtr <Script::ScriptedObject> scripted_object;
|
||||
|
||||
void SetAsScriptGlobalScene(Script::IVM * = 0);
|
||||
/*!
|
||||
@}
|
||||
@name Item list.
|
||||
@{
|
||||
*/
|
||||
const SharedList <Item *> &GetItemList() const { return item_list; }
|
||||
|
||||
/// Get item 2d from name.
|
||||
Item *ItemFromName(const char *name, Item *parent = 0) const;
|
||||
/// Get item 2d from unique identifier.
|
||||
Item *ItemFromUid(uint) const;
|
||||
|
||||
void SetupItemComponents(Item *);
|
||||
|
||||
void AddItem(Item *, bool setup_components);
|
||||
bool RemoveItem(Item *);
|
||||
|
||||
void DeleteAllItems();
|
||||
/*!
|
||||
@}
|
||||
@name Motion system.
|
||||
@{
|
||||
*/
|
||||
Core::SceneMotionContainer motion;
|
||||
|
||||
/*!
|
||||
@short Start a motion on the scene items.
|
||||
@note Request an animation source group if you need control on the
|
||||
started animation sources.
|
||||
*/
|
||||
void SetMotion(const char *name, Automation::SourceGroup ** = 0, float blend = Units::Sec(0.1), Automation::Player::AddSourceMode = Automation::Player::SourceSet, float weight = 1);
|
||||
/// @}
|
||||
|
||||
Camera *GetDefaultCamera() const { return default_camera; }
|
||||
|
||||
Camera *GetCurrentCamera() const { return current_camera; }
|
||||
void SetCurrentCamera(Camera *camera = 0);
|
||||
|
||||
/// Lock all UI events to a specific item.
|
||||
void Lock(Item *i) { lock = i; }
|
||||
void Unlock() { lock = 0; }
|
||||
|
||||
void UpdateCursor(Cursor *);
|
||||
|
||||
/// Call event handler.
|
||||
bool CallEventHandler(Cursor *, EventCode, EventTable *);
|
||||
void CallEventHandler(Cursor *, Widget *, EventCode, bool can_propagate = true);
|
||||
|
||||
void DrawProfilerText(Renderer &, Render::RasterFont *font[2], float &x, float &y);
|
||||
|
||||
sWindowSkin window_skin;
|
||||
|
||||
Matrix3 offset_matrix; ///< Global post-projection offset matrix.
|
||||
Color global_fade_color;
|
||||
|
||||
/// Normalized screen coordinates to scene coordinates in pixels.
|
||||
const Matrix3 &GetScreenToUIMatrix() const { return screen_to_ui; }
|
||||
/// Scene coordinates in pixels to normalized screen coordinates.
|
||||
const Matrix3 &GetUIToScreenMatrix() const { return ui_to_screen; }
|
||||
|
||||
float GetGlobalFadeEffect() const;
|
||||
void SetGlobalFadeEffect(float opacity = 1);
|
||||
|
||||
/// Evaluate scene.
|
||||
void Update();
|
||||
|
||||
void SetRenderMatrices(Renderer &);
|
||||
|
||||
void Render(Renderer &, GPU::TriangleBatch * = 0);
|
||||
void RenderGlobalFade(Renderer &);
|
||||
void RenderSetup(Core::ResourceFactories *);
|
||||
|
||||
void Setup();
|
||||
void Reset();
|
||||
void Clear();
|
||||
|
||||
bool IsItemToBeSaved(Item *, const Group *, uint save_flag) const;
|
||||
NML::Tag *LinkInfoAsMetaTag(Item *, const Group *, uint flag) const;
|
||||
|
||||
bool FromMetaFileStoreGroup(const char *, Group ** = 0, uint = SceneIOAll, ToolMode = NoTool, int load_level = 0);
|
||||
bool FromMetaTagStoreGroup(const NML::Tag &, Group **group = 0, uint = SceneIOAll, ToolMode = NoTool, int load_level = 0);
|
||||
bool FromMetaTag(const NML::Tag &tag, ToolMode tool = NoTool) { return FromMetaTagStoreGroup(tag, 0, SceneIOAll, tool); }
|
||||
|
||||
NML::Tag *AsMetaTag(const Group *, uint = SceneIOAll, ToolMode = NoTool) const;
|
||||
NML::Tag *AsMetaTag() const { return AsMetaTag(0); }
|
||||
|
||||
Scene(Script::IVM * = 0);
|
||||
virtual ~Scene();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUI_SCENE__
|
||||
36
include/engine/ui/ui_ace_manager.h
Normal file
36
include/engine/ui/ui_ace_manager.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UIACEMANAGER__
|
||||
#define __UIACEMANAGER__
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace ACE { class Manager; }
|
||||
namespace S2D {
|
||||
|
||||
enum
|
||||
{
|
||||
ACE_toalpha = 0,
|
||||
ACE_toposition,
|
||||
ACE_toscale,
|
||||
ACE_toangle,
|
||||
ACE_show,
|
||||
ACE_hide,
|
||||
|
||||
ACE_globalfade
|
||||
};
|
||||
|
||||
struct ACEManager
|
||||
{
|
||||
static ACE::Manager *Get();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __UIACEMANAGER__
|
||||
33
include/engine/ui/ui_camera.h
Normal file
33
include/engine/ui/ui_camera.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NCAMERA2D__
|
||||
#define __NCAMERA2D__
|
||||
|
||||
|
||||
#include "ui/ui_item.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Scene 2d camera.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct Camera : public Item
|
||||
{
|
||||
Vector2 resolution; ///< Camera virtual resolution.
|
||||
|
||||
virtual void RenderSetup(Core::ResourceFactories *) {}
|
||||
virtual void Render(Renderer &, GPU::TriangleBatch * = 0) {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NCAMERA2D__
|
||||
49
include/engine/ui/ui_cursor.h
Normal file
49
include/engine/ui/ui_cursor.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_CURSOR__
|
||||
#define __NUI_CURSOR__
|
||||
|
||||
|
||||
#include "ui/ui_item.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
// Scene 2D cursor.
|
||||
struct Cursor
|
||||
{
|
||||
int id;
|
||||
|
||||
struct State
|
||||
{
|
||||
float x, y;
|
||||
bool down;
|
||||
|
||||
SharedPtr <Item> item;
|
||||
SharedPtr <Widget> widget;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
x = y = 0;
|
||||
down = false;
|
||||
}
|
||||
|
||||
State() { Reset(); }
|
||||
};
|
||||
|
||||
State current_state,
|
||||
previous_state,
|
||||
down_state;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // __NUI_CURSOR__
|
||||
84
include/engine/ui/ui_event_handler.h
Normal file
84
include/engine/ui/ui_event_handler.h
Normal file
@ -0,0 +1,84 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIEVENTHANDLER__
|
||||
#define __NUIEVENTHANDLER__
|
||||
|
||||
|
||||
#include "script/script_vm.h"
|
||||
#include "script/script_object.h"
|
||||
#include "memory/nauto_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
enum EventCode
|
||||
{
|
||||
Event_None = 0,
|
||||
|
||||
Event_CursorDown,
|
||||
Event_CursorHit,
|
||||
Event_CursorUp,
|
||||
|
||||
Event_CursorEnter,
|
||||
Event_CursorLeave,
|
||||
Event_CursorMove,
|
||||
};
|
||||
|
||||
/// 2D event handler.
|
||||
class EventHandler
|
||||
{
|
||||
friend class EventTable;
|
||||
|
||||
protected:
|
||||
|
||||
EventCode code;
|
||||
AutoPtr <Script::Object> handler, context;
|
||||
|
||||
public:
|
||||
|
||||
EventCode GetCode() const { return code; }
|
||||
Script::Object *GetHandler() { return handler; }
|
||||
Script::Object *GetContext() { return context; }
|
||||
|
||||
EventHandler(EventCode c = Event_None) : code(c) {}
|
||||
};
|
||||
|
||||
/*!
|
||||
@short UI event table.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class EventTable
|
||||
{
|
||||
bool enabled;
|
||||
AutoList <EventHandler *> handler_list;
|
||||
|
||||
public:
|
||||
|
||||
void Reset() { handler_list.Clear(); }
|
||||
|
||||
/// Returns true if the table has any handler set.
|
||||
bool HasHandler() const { return handler_list.GetCount() > 0; }
|
||||
|
||||
EventHandler *GetHandler(EventCode) const;
|
||||
EventHandler *SetHandler(EventCode, Script::Object *handler, Script::Object *context = 0);
|
||||
void DeleteHandler(EventCode);
|
||||
|
||||
bool HasHandler(EventCode code) const { return asbool(GetHandler(code)); }
|
||||
bool HasHandlerContext(EventCode) const;
|
||||
|
||||
void Enable(bool v) { enabled = v; }
|
||||
bool IsEnabled() const { return enabled; }
|
||||
|
||||
EventTable() : enabled(true) {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUIEVENTHANDLER__
|
||||
35
include/engine/ui/ui_group.h
Normal file
35
include/engine/ui/ui_group.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_GROUP__
|
||||
#define __NUI_GROUP__
|
||||
|
||||
|
||||
#include "container/nlist.h"
|
||||
#include "nstring/nstring.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Item;
|
||||
|
||||
/*!
|
||||
@short UI Group.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct Group
|
||||
{
|
||||
String name;
|
||||
List <Item *> item_list;
|
||||
|
||||
bool IsMember(const Item *) const;
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUI_GROUP__
|
||||
142
include/engine/ui/ui_item.h
Normal file
142
include/engine/ui/ui_item.h
Normal file
@ -0,0 +1,142 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIITEM__
|
||||
#define __NUIITEM__
|
||||
|
||||
|
||||
#include "automation/automation_player.h"
|
||||
#include "ui/ui_item_event_interface.h"
|
||||
#include "script/scripted_object.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "geometry/rect.h"
|
||||
#include "container/nlist.h"
|
||||
#include "nstring/nstring.h"
|
||||
#include "memory/nshared_ptr.h"
|
||||
#include "memory/bit_field.h"
|
||||
#include "memory/nauto_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace GPU { class TriangleBatch; }
|
||||
namespace Core { struct ResourceFactories; }
|
||||
namespace Render { class Renderer; }
|
||||
|
||||
namespace S2D {
|
||||
class EventTable;
|
||||
|
||||
using Render::Renderer;
|
||||
|
||||
/*!
|
||||
@short UI Item.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Item : public SharedObject
|
||||
{
|
||||
friend class Scene;
|
||||
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
Type_None = 0,
|
||||
Type_Camera,
|
||||
Type_Sprite,
|
||||
Type_Window
|
||||
};
|
||||
|
||||
enum Flag
|
||||
{
|
||||
Flag_ItemActive = (1 << 0)
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
uint uid;
|
||||
Type type;
|
||||
|
||||
Item *parent;
|
||||
|
||||
Vector2 position, pivot, size, scale;
|
||||
float zorder, angle;
|
||||
|
||||
Matrix3 local_matrix, matrix, imatrix;
|
||||
|
||||
List <Item *> children; ///< Children list.
|
||||
|
||||
public:
|
||||
|
||||
String name;
|
||||
|
||||
BitField item_flags;
|
||||
|
||||
uint GetUid() const { return uid; }
|
||||
Type GetItemType() const { return type; }
|
||||
|
||||
virtual EventTable *GetEventTable() const { return 0; }
|
||||
|
||||
Item *GetParent() const { return parent; }
|
||||
void SetParent(Item * = 0);
|
||||
|
||||
bool Inherits(const Item *) const;
|
||||
|
||||
List <Item *> &GetChildren() { return children; }
|
||||
|
||||
void ComputeMatrix();
|
||||
|
||||
const Matrix3 &GetLocalMatrix() { return local_matrix; }
|
||||
const Matrix3 &GetMatrix() { return matrix; }
|
||||
const Matrix3 &GetInverseMatrix() { return imatrix; }
|
||||
|
||||
/// Snapshot a transformation to this sprite position, rotation and scale.
|
||||
void SnapshotTransformation(const Matrix3 &);
|
||||
|
||||
float GetZOrder() const { return zorder; }
|
||||
void SetZOrder(float z) { zorder = z; }
|
||||
Vector2 GetPosition() const { return position; }
|
||||
void SetPosition(float x, float y) { position.Set(x, y); }
|
||||
Vector2 GetPivot() const { return pivot; }
|
||||
void SetPivot(float x, float y) { pivot.Set(x, y); }
|
||||
Vector2 GetScale() const { return scale; }
|
||||
void SetScale(float x, float y) { scale.Set(x, y); }
|
||||
Vector2 GetSize() const { return size; }
|
||||
virtual void SetSize(float x, float y) { size.Set(Types::Max <float> (1, x), Types::Max <float> (1, y)); }
|
||||
|
||||
float GetRotation() const { return angle; }
|
||||
void SetRotation(float a) { angle = a; }
|
||||
|
||||
/// Rectangle in local space.
|
||||
virtual iRect GetRect() const;
|
||||
/// Rectangle in screen space.
|
||||
virtual iRect GetScreenRect() const;
|
||||
|
||||
iRect LocalToScreen(const iRect &) const;
|
||||
iRect ScreenToLocal(const iRect &) const;
|
||||
Vector2 LocalToScreen(const Vector2 &) const;
|
||||
Vector2 ScreenToLocal(const Vector2 &) const;
|
||||
|
||||
virtual void RenderSetup(Core::ResourceFactories * = 0) = 0;
|
||||
virtual void Render(Renderer &, GPU::TriangleBatch * = 0) = 0;
|
||||
|
||||
AutoPtr <IItemEvent> item_event;
|
||||
AutoPtr <Script::ScriptedObject> scripted_object;
|
||||
AutoPtr <GS::Automation::Player> automation_player;
|
||||
|
||||
void Reset();
|
||||
void Setup();
|
||||
|
||||
virtual bool FromMetaTag(NML::Tag &);
|
||||
virtual NML::Tag *AsMetaTag() const;
|
||||
|
||||
Item();
|
||||
virtual ~Item();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUIITEM__
|
||||
40
include/engine/ui/ui_item_automated_property_provider.h
Normal file
40
include/engine/ui/ui_item_automated_property_provider.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIITEMAUTOMATEDPROPERTYPROVIDER__
|
||||
#define __NUIITEMAUTOMATEDPROPERTYPROVIDER__
|
||||
|
||||
|
||||
#include "automation/automated_property_provider.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Item;
|
||||
namespace Automation {
|
||||
|
||||
/*!
|
||||
@short Item automated property provider.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct ItemPropertyProvider : public GS::Automation::IPropertyProvider
|
||||
{
|
||||
S2D::Item *item;
|
||||
|
||||
virtual bool GetProperty(Core::MotionChannel::Type, float &);
|
||||
virtual bool SetProperty(Core::MotionChannel::Type, float);
|
||||
virtual Quaternion GetRotation() const;
|
||||
virtual bool SetRotation(const Quaternion &);
|
||||
|
||||
ItemPropertyProvider(S2D::Item *i) : item(i) {}
|
||||
};
|
||||
|
||||
} // Automation
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NITEMAUTOMATEDPROPERTYPROVIDER__
|
||||
45
include/engine/ui/ui_item_event_interface.h
Normal file
45
include/engine/ui/ui_item_event_interface.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __IUIITEMEVENT__
|
||||
#define __IUIITEMEVENT__
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Item;
|
||||
|
||||
/*!
|
||||
@short Item event interface.
|
||||
Implement this class if you wish to process item events.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
struct IItemEvent
|
||||
{
|
||||
virtual void OnSetup(Item *) {}
|
||||
virtual void OnSetupDone(Item *) {}
|
||||
virtual void OnReset(Item *) {}
|
||||
|
||||
virtual void OnActivate(Item *, bool) {}
|
||||
|
||||
virtual void OnPhysicStep(Item *, bool /*step_taken*/) {}
|
||||
|
||||
virtual void OnUpdate(Item *) {}
|
||||
virtual void OnDelete(Item *) {}
|
||||
|
||||
virtual void OnRenderDone(Item *) {}
|
||||
virtual void OnRenderUser(Item *) {}
|
||||
|
||||
// virtual void OnCollision(Item *, Item * /*with*/, const nCollisionPair &) {}
|
||||
|
||||
virtual ~IItemEvent() {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __IUIITEMEVENT__
|
||||
44
include/engine/ui/ui_item_script_event.h
Normal file
44
include/engine/ui/ui_item_script_event.h
Normal file
@ -0,0 +1,44 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIITEMSCRIPTEVENT__
|
||||
#define __NUIITEMSCRIPTEVENT__
|
||||
|
||||
|
||||
#include "ui/ui_item_event_interface.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Item script event.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
struct ItemScriptEvent : public IItemEvent
|
||||
{
|
||||
virtual void OnSetup(Item *);
|
||||
virtual void OnSetupDone(Item *);
|
||||
virtual void OnReset(Item *);
|
||||
|
||||
virtual void OnActivate(Item *, bool activate);
|
||||
|
||||
virtual void OnPhysicStep(Item *, bool step_taken);
|
||||
|
||||
virtual void OnUpdate(Item *);
|
||||
virtual void OnDelete(Item *);
|
||||
|
||||
virtual void OnRenderDone(Item *);
|
||||
virtual void OnRenderUser(Item *);
|
||||
|
||||
// virtual void OnCollision(Item *, Item *with, const nCollisionPair &);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // __NUIITEMSCRIPTEVENT__
|
||||
46
include/engine/ui/ui_item_script_unit.h
Normal file
46
include/engine/ui/ui_item_script_unit.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UIITEMSCRIPTUNIT__
|
||||
#define __UIITEMSCRIPTUNIT__
|
||||
|
||||
|
||||
#include "script/script_unit.h"
|
||||
#include "script/script_object.h"
|
||||
#include "memory/nauto_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short UI item script unit.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
struct ItemScriptUnit : public Script::Unit
|
||||
{
|
||||
AutoPtr <Script::Object>
|
||||
update_callback,
|
||||
trigger_callback,
|
||||
activation_callback,
|
||||
physic_callback,
|
||||
physic_sleep_callback,
|
||||
collision_callback,
|
||||
collisionex_callback,
|
||||
render_user_callback;
|
||||
|
||||
bool Open();
|
||||
void Close();
|
||||
|
||||
ItemScriptUnit(Script::IVM *);
|
||||
~ItemScriptUnit();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __UIITEMSCRIPTUNIT__
|
||||
37
include/engine/ui/ui_item_scripted_object.h
Normal file
37
include/engine/ui/ui_item_scripted_object.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UIITEMSCRIPTEDOBJECT__
|
||||
#define __UIITEMSCRIPTEDOBJECT__
|
||||
|
||||
|
||||
#include "script/scripted_object.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Item;
|
||||
|
||||
/*!
|
||||
@short Managed item scripted object.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class ItemScriptedObject : public Script::ScriptedObject
|
||||
{
|
||||
Item *item;
|
||||
|
||||
public:
|
||||
|
||||
virtual Script::Unit *NewUnit() const;
|
||||
|
||||
ItemScriptedObject(Item *i, Script::IVM *vm = 0) : Script::ScriptedObject(vm), item(i) {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __UIITEMSCRIPTEDOBJECT__
|
||||
63
include/engine/ui/ui_message.h
Normal file
63
include/engine/ui/ui_message.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_MESSAGE__
|
||||
#define __NUI_MESSAGE__
|
||||
|
||||
|
||||
#include "messaging/messaging.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Scene;
|
||||
|
||||
/*
|
||||
@short UI message enum.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
enum Message
|
||||
{
|
||||
UIMsg_None = 0, ///< No message.
|
||||
|
||||
UIMsg_AddingItem,
|
||||
UIMsg_ItemAdded,
|
||||
UIMsg_DeletingItem,
|
||||
UIMsg_ItemDeleted,
|
||||
|
||||
UIMsg_Deleting,
|
||||
UIMsg_Deleted,
|
||||
UIMsg_Loading,
|
||||
UIMsg_Loaded,
|
||||
|
||||
UIMsg_SpriteLinkChanging,
|
||||
UIMsg_SpriteLinkChanged,
|
||||
|
||||
UIMsg_LastMessage
|
||||
};
|
||||
|
||||
/*
|
||||
@short UI message return value.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
enum ReturnValue
|
||||
{
|
||||
UIReturn_Ok = 0
|
||||
};
|
||||
|
||||
/// UI listener.
|
||||
struct Listener
|
||||
{
|
||||
virtual ReturnValue ProcessMessage(Message, const Scene *, const void *) = 0;
|
||||
};
|
||||
|
||||
extern Messaging::Broadcaster <Message, Listener, Scene *> g_ui_messenger;
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUI_MESSAGE__
|
||||
36
include/engine/ui/ui_scene_event_interface.h
Normal file
36
include/engine/ui/ui_scene_event_interface.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UISCENEEVENTINTERFACE__
|
||||
#define __UISCENEEVENTINTERFACE__
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
class Scene;
|
||||
|
||||
/*!
|
||||
@short UI scene event interface.
|
||||
|
||||
Implement this class if you wish to process script events from C++.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct ISceneEvent
|
||||
{
|
||||
virtual void OnSetup(Scene *) {}
|
||||
virtual void OnReset(Scene *) {}
|
||||
virtual void OnUpdate(Scene *) {}
|
||||
virtual void OnDelete(Scene *) {}
|
||||
|
||||
virtual ~ISceneEvent() {}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // __UISCENEEVENTINTERFACE__
|
||||
36
include/engine/ui/ui_scene_script_event.h
Normal file
36
include/engine/ui/ui_scene_script_event.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UISCENESCRIPTEVENT__
|
||||
#define __UISCENESCRIPTEVENT__
|
||||
|
||||
|
||||
#include "ui/ui_scene_event_interface.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
class Scene;
|
||||
struct ISceneEvent;
|
||||
|
||||
/*!
|
||||
@short UI scene event interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct SceneScriptEvent : public ISceneEvent
|
||||
{
|
||||
virtual void OnSetup(Scene *);
|
||||
virtual void OnReset(Scene *);
|
||||
virtual void OnUpdate(Scene *);
|
||||
virtual void OnDelete(Scene *);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // __UISCENESCRIPTEVENT__
|
||||
37
include/engine/ui/ui_scene_scripted_object.h
Normal file
37
include/engine/ui/ui_scene_scripted_object.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUISCENESCRIPTEDOBJECT__
|
||||
#define __NUISCENESCRIPTEDOBJECT__
|
||||
|
||||
|
||||
#include "script/scripted_object.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
class Scene;
|
||||
|
||||
/*!
|
||||
@short UI scene scripted object.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class SceneScriptedObject : public Script::ScriptedObject
|
||||
{
|
||||
Scene *scene;
|
||||
|
||||
public:
|
||||
|
||||
virtual Script::Unit *NewUnit() const;
|
||||
|
||||
SceneScriptedObject(Script::IVM *vm, Scene *s) : Script::ScriptedObject(vm), scene(s) {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUISCENESCRIPTEDOBJECT__
|
||||
38
include/engine/ui/ui_script_unit.h
Normal file
38
include/engine/ui/ui_script_unit.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __UISCENESCRIPTUNIT__
|
||||
#define __UISCENESCRIPTUNIT__
|
||||
|
||||
|
||||
#include "script/script_unit.h"
|
||||
#include "script/script_object.h"
|
||||
#include "memory/nauto_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short UI scene script unit.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct SceneUnit : public Script::Unit
|
||||
{
|
||||
AutoPtr <Script::Object> frame_callback;
|
||||
|
||||
bool Open();
|
||||
void Close();
|
||||
|
||||
SceneUnit(Script::IVM *);
|
||||
~SceneUnit();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __UISCENESCRIPTUNIT__
|
||||
80
include/engine/ui/ui_sprite.h
Normal file
80
include/engine/ui/ui_sprite.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NSPRITE__
|
||||
#define __NSPRITE__
|
||||
|
||||
|
||||
#include "ui/ui_event_handler.h"
|
||||
#include "ui/ui_item.h"
|
||||
#include "core/ace.h"
|
||||
#include "core/render_data.h"
|
||||
#include "core/resource_factories.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*
|
||||
@short Sprite class.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Sprite : public Item, public ACE::Unit
|
||||
{
|
||||
protected:
|
||||
|
||||
AutoPtr <EventTable> event_table;
|
||||
|
||||
public:
|
||||
|
||||
struct RenderData
|
||||
{
|
||||
Render::sTexture texture;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
FlagFlipU = (1 << 2),
|
||||
FlagFlipV = (1 << 3),
|
||||
|
||||
FlagBlendOpaque = (1 << 4),
|
||||
FlagBlendAdditive = (1 << 5),
|
||||
|
||||
FlagNonSensitive = (1 << 6),
|
||||
FlagResolutionInvariant = (1 << 7),
|
||||
FlagTransformUV = (1 << 8),
|
||||
|
||||
FlagSnapToPixel = (1 << 9)
|
||||
};
|
||||
|
||||
BitField sprite_flags;
|
||||
|
||||
String texture;
|
||||
|
||||
Vector2 uv_origin;
|
||||
Matrix3 uv_matrix;
|
||||
float opacity;
|
||||
|
||||
virtual EventTable *GetEventTable() const { return event_table; }
|
||||
|
||||
bool ExecCommand(ACE::Command *, float dt);
|
||||
|
||||
virtual void Render(Render::Renderer &, GPU::TriangleBatch * = 0);
|
||||
virtual void RenderSetup(Core::ResourceFactories * = 0);
|
||||
|
||||
AutoPtr <RenderData> render_data;
|
||||
|
||||
virtual bool FromMetaTag(NML::Tag &);
|
||||
virtual NML::Tag *AsMetaTag() const;
|
||||
|
||||
Sprite();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NSPRITE__
|
||||
87
include/engine/ui/ui_window.h
Normal file
87
include/engine/ui/ui_window.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NWINDOW__
|
||||
#define __NWINDOW__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
#include "ui/ui_sprite.h"
|
||||
#include "ui/ui_window_skin.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
struct RenderResourceFactory;
|
||||
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Window class.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Window : public Sprite
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
FlagNoDecoration = (1 << 0),
|
||||
FlagNoTitleBar = (1 << 1),
|
||||
|
||||
// Non-serializable
|
||||
FlagCacheDirty = (1 << 2),
|
||||
FlagRenderDirty = (1 << 3)
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
sWindowSkin skin;
|
||||
sPicture cache;
|
||||
|
||||
sWidget title_widget;
|
||||
sWidget base_widget;
|
||||
|
||||
BitField window_flags;
|
||||
|
||||
public:
|
||||
|
||||
Picture *GetCache() const { return cache; }
|
||||
|
||||
void Invalidate();
|
||||
|
||||
void SetSkin(WindowSkin *);
|
||||
void ComposeSkin();
|
||||
void Compose();
|
||||
|
||||
void SetSize(float w, float h);
|
||||
|
||||
sPicture background_picture;
|
||||
Color background_color;
|
||||
|
||||
Widget *GetWidget(uint id);
|
||||
|
||||
Widget *GetTitleWidget() const;
|
||||
void SetTitleWidget(Widget *);
|
||||
Widget *GetBaseWidget() const;
|
||||
void SetBaseWidget(Widget *);
|
||||
|
||||
iRect GetRect() const;
|
||||
iRect GetClientRect() const;
|
||||
|
||||
virtual void RenderSetup(Core::ResourceFactories * = 0);
|
||||
virtual void Render(Renderer &, GPU::TriangleBatch * = 0);
|
||||
|
||||
virtual bool FromMetaTag(NML::Tag &);
|
||||
virtual NML::Tag *AsMetaTag() const;
|
||||
|
||||
Window();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NWINDOW__
|
||||
38
include/engine/ui/ui_window_skin.h
Normal file
38
include/engine/ui/ui_window_skin.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __WINDOWSKIN__
|
||||
#define __WINDOWSKIN__
|
||||
|
||||
|
||||
#include "font/font_cache.h"
|
||||
#include "picture/pict.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/// UI Window skin.
|
||||
struct WindowSkin : public SharedObject
|
||||
{
|
||||
sPicture top, left, right, bottom, top_left, top_right, bottom_left, bottom_right;
|
||||
uint color;
|
||||
|
||||
sFontEx title_font;
|
||||
|
||||
int title_top,
|
||||
title_bottom,
|
||||
title_size,
|
||||
title_color;
|
||||
};
|
||||
|
||||
typedef SharedPtr <WindowSkin> sWindowSkin;
|
||||
|
||||
} //S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __WINDOWSKIN__
|
||||
128
include/engine/ui/widget.h
Normal file
128
include/engine/ui/widget.h
Normal file
@ -0,0 +1,128 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NWIDGET__
|
||||
#define __NWIDGET__
|
||||
|
||||
|
||||
#include "ui/ui_event_handler.h"
|
||||
#include "geometry/rect.h"
|
||||
#include "math/vector.h"
|
||||
#include "memory/nshared_ptr.h"
|
||||
#include "memory/nweak_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
class Picture;
|
||||
|
||||
namespace S2D {
|
||||
class Widget;
|
||||
|
||||
typedef SharedPtr <Widget> sWidget;
|
||||
|
||||
/// Widget type.
|
||||
enum WidgetType
|
||||
{
|
||||
WidgetTypeBase = 0,
|
||||
WidgetTypeSizer,
|
||||
WidgetTypeVSizer,
|
||||
WidgetTypeHSizer,
|
||||
WidgetTypeContainer,
|
||||
WidgetTypeSpacer,
|
||||
WidgetTypeText,
|
||||
WidgetTypeCanvas,
|
||||
WidgetTypeDrawable,
|
||||
WidgetTypeBitmap,
|
||||
WidgetTypeCheck
|
||||
};
|
||||
|
||||
/*!
|
||||
@short Base widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Widget : public SharedObject
|
||||
{
|
||||
public:
|
||||
|
||||
enum Align
|
||||
{
|
||||
AlignNone = 0,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
AlignMiddle,
|
||||
AlignRight,
|
||||
AlignBottom,
|
||||
AlignGrow
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
WidgetType type;
|
||||
Widget *parent;
|
||||
|
||||
AutoPtr <EventTable> event_table;
|
||||
|
||||
int object_id;
|
||||
iRect rect;
|
||||
|
||||
Align h_align, v_align;
|
||||
|
||||
bool hidden; ///< Hidden.
|
||||
bool dirty; ///< Dirty flag.
|
||||
|
||||
Vector4 border_size; ///< Border size in pixel (x->top, y->bottom, z->left, w->right).
|
||||
|
||||
SharedList <Widget *> children;
|
||||
|
||||
Vector2 format; ///< Formatting size.
|
||||
|
||||
/// Setup and align output rectangle.
|
||||
iRect FormatOutputRect(const iRect &rect, const iRect &out_rect);
|
||||
|
||||
public:
|
||||
|
||||
int GetId() const { return object_id; }
|
||||
WidgetType GetType() const { return type; }
|
||||
|
||||
void SetHidden(bool h = true);
|
||||
bool IsHidden() const { return hidden; }
|
||||
bool IsDirty() const { return dirty; }
|
||||
|
||||
void Validate() { dirty = false; }
|
||||
virtual void Invalidate();
|
||||
|
||||
virtual void Refresh() = 0;
|
||||
virtual void Compose(Picture &output, const iRect &clip_rect) = 0;
|
||||
|
||||
EventTable *GetEventTable() const { return event_table; }
|
||||
|
||||
void SetParent(Widget *w);
|
||||
Widget *GetParent() const { return parent; }
|
||||
|
||||
Widget *GetChild(int id);
|
||||
|
||||
const SharedList <Widget *> &GetChildren() const { return children; }
|
||||
|
||||
/// Return widget rect in parent window client space.
|
||||
iRect GetRect() const;
|
||||
|
||||
void SetBorderSize(float top = 2, float bottom = 2, float left = 2, float right = 2);
|
||||
void SetHAlign(Align = AlignMiddle);
|
||||
void SetVAlign(Align = AlignMiddle);
|
||||
void SetFormattingSize(const Vector2 &);
|
||||
|
||||
/// Get widget formatting size ratio.
|
||||
Vector2 GetFormat() const;
|
||||
|
||||
Widget(int id = -1);
|
||||
virtual ~Widget();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NWIDGET__
|
||||
29
include/engine/ui/widget_bitmap.h
Normal file
29
include/engine/ui/widget_bitmap.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_WIDGET_BITMAP__
|
||||
#define __NUI_WIDGET_BITMAP__
|
||||
|
||||
|
||||
#include "ui/widget_drawable.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/// Bitmap widget.
|
||||
struct BitmapWidget : public DrawableWidget
|
||||
{
|
||||
void SetPicture(Picture *);
|
||||
|
||||
BitmapWidget(int id = -1, Picture *bitmap = 0);
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUI_WIDGET_BITMAP__
|
||||
36
include/engine/ui/widget_canvas.h
Normal file
36
include/engine/ui/widget_canvas.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIWIDGETCANVAS__
|
||||
#define __NUIWIDGETCANVAS__
|
||||
|
||||
|
||||
#include "ui/widget_drawable.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Canvas widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct CanvasWidget : public DrawableWidget
|
||||
{
|
||||
/// Allocate canvas dimensions.
|
||||
bool Allocate(uint width, uint height);
|
||||
|
||||
Picture *Lock() { return picture; }
|
||||
void Unlock() { dirty = true; }
|
||||
|
||||
CanvasWidget(int id = -1, uint width = 8, uint height = 8);
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUIWIDGETCANVAS__
|
||||
66
include/engine/ui/widget_check.h
Normal file
66
include/engine/ui/widget_check.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIWIDGETCHECK__
|
||||
#define __NUIWIDGETCHECK__
|
||||
|
||||
|
||||
#include "ui/widget_bitmap.h"
|
||||
#include "ui/widget_text.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Check widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class CheckWidget : public Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
BitmapWidget check_bitmap;
|
||||
TextWidget label;
|
||||
|
||||
bool state;
|
||||
int marging;
|
||||
|
||||
public:
|
||||
|
||||
TextWidget &GetLabel() { return label; }
|
||||
|
||||
int GetMarging() const { return marging; }
|
||||
void SetMarging(int m)
|
||||
{
|
||||
if (marging == m)
|
||||
return;
|
||||
Widget::Invalidate();
|
||||
marging = m;
|
||||
}
|
||||
|
||||
bool GetState() const { return state; }
|
||||
void SetState(bool state);
|
||||
|
||||
virtual void Refresh();
|
||||
virtual void Compose(Picture &, const iRect &out_rect);
|
||||
virtual void Invalidate();
|
||||
|
||||
CheckWidget(int id = -1, const char *label = 0, FontEx *font = 0, int size = 16, bool b_state = true) :
|
||||
Widget(id), check_bitmap(-1, 0), label(-1, label, font, size)
|
||||
{
|
||||
type = WidgetTypeCheck;
|
||||
|
||||
marging = 4;
|
||||
SetState(b_state);
|
||||
}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUIWIDGETCHECK__
|
||||
45
include/engine/ui/widget_drawable.h
Normal file
45
include/engine/ui/widget_drawable.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NWIDGETDRAWABLE__
|
||||
#define __NWIDGETDRAWABLE__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
#include "picture/pict.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Drawable widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class DrawableWidget : public Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
sPicture picture;
|
||||
|
||||
public:
|
||||
|
||||
Picture *GetPicture() const { return picture; }
|
||||
|
||||
virtual void Refresh() {}
|
||||
virtual void Compose(Picture &output, const iRect &clip_rect);
|
||||
|
||||
protected:
|
||||
|
||||
DrawableWidget(int id = -1);
|
||||
virtual ~DrawableWidget() {}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NWIDGETDRAWABLE__
|
||||
53
include/engine/ui/widget_sizer.h
Normal file
53
include/engine/ui/widget_sizer.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NWIDGETSIZER__
|
||||
#define __NWIDGETSIZER__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Sizer widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct SizerWidget : public Widget
|
||||
{
|
||||
virtual void Invalidate();
|
||||
|
||||
Widget *Add(Widget *widget);
|
||||
bool Remove(Widget *widget) { return children.Remove(widget); }
|
||||
|
||||
SizerWidget(int id = -1) : Widget(id) { type = WidgetTypeSizer; }
|
||||
};
|
||||
|
||||
struct HSizerWidget : public SizerWidget
|
||||
{
|
||||
virtual void Refresh();
|
||||
virtual void Compose(Picture &output, const iRect &out_rect);
|
||||
|
||||
void SetColumnSize(int size);
|
||||
|
||||
HSizerWidget(int id = -1) : SizerWidget(id) { type = WidgetTypeHSizer; }
|
||||
};
|
||||
|
||||
struct VSizerWidget : public SizerWidget
|
||||
{
|
||||
virtual void Refresh();
|
||||
virtual void Compose(Picture &output, const iRect &out_rect);
|
||||
|
||||
VSizerWidget(int id = -1) : SizerWidget(id) { type = WidgetTypeVSizer; }
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NWIDGETSIZER__
|
||||
43
include/engine/ui/widget_spacer.h
Normal file
43
include/engine/ui/widget_spacer.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_WIDGET_SPACER__
|
||||
#define __NUI_WIDGET_SPACER__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Spacer widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct SpacerWidget : public Widget
|
||||
{
|
||||
void Invalidate() { dirty = true; }
|
||||
|
||||
virtual void Refresh() {}
|
||||
virtual void Compose(Picture &, const iRect &out_rect)
|
||||
{
|
||||
dirty = false;
|
||||
rect = out_rect;
|
||||
}
|
||||
|
||||
SpacerWidget(int id = -1) : Widget(id)
|
||||
{
|
||||
type = WidgetTypeSpacer;
|
||||
format.Set(0.5, 0.5);
|
||||
}
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUI_WIDGET_SPACER__
|
||||
54
include/engine/ui/widget_staticcontainer.h
Normal file
54
include/engine/ui/widget_staticcontainer.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUI_WIDGET_CONTAINER__
|
||||
#define __NUI_WIDGET_CONTAINER__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
//
|
||||
struct ContainerCell
|
||||
{
|
||||
iRect cell_rect; ///< Cell rect in parent coordinate frame.
|
||||
sWidget widget; ///< Cell widget.
|
||||
};
|
||||
|
||||
/*!
|
||||
@short Container widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class ContainerWidget : public Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
List <ContainerCell *> cell_list;
|
||||
|
||||
public:
|
||||
|
||||
void Invalidate();
|
||||
|
||||
virtual void Refresh();
|
||||
virtual void Compose(Picture &, const iRect &out_rect);
|
||||
|
||||
ContainerCell *GetCell(const Widget *) const;
|
||||
|
||||
Widget *Add(Widget *, const iRect &cell_rect);
|
||||
bool Remove(Widget *);
|
||||
|
||||
ContainerWidget(int id = -1) : Widget(id) { type = WidgetTypeContainer; }
|
||||
~ContainerWidget();
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NWIDGETCONTAINER__
|
||||
95
include/engine/ui/widget_text.h
Normal file
95
include/engine/ui/widget_text.h
Normal file
@ -0,0 +1,95 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NUIWIDGETTEXT__
|
||||
#define __NUIWIDGETTEXT__
|
||||
|
||||
|
||||
#include "ui/widget.h"
|
||||
#include "font/font_renderer.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D {
|
||||
|
||||
/*!
|
||||
@short Text widget.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class TextWidget : public Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
TextState state; ///< Widget text state.
|
||||
String text; ///< Widget text.
|
||||
|
||||
public:
|
||||
|
||||
const char *GetText() const { return text.c_str(); }
|
||||
void SetText(const char *);
|
||||
|
||||
/// Set text block formatting rule.
|
||||
void SetTextFormat(TextState::Format f)
|
||||
{
|
||||
if (state.format != f)
|
||||
{
|
||||
state.format = f;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
/// Get text formatting rule.
|
||||
TextState::Format GetTextFormat() const { return state.format; }
|
||||
|
||||
/// Get text alignment rule.
|
||||
TextState::Alignment GetTextAlignment() const { return state.alignment; }
|
||||
/// Set text alignment rule.
|
||||
void SetTextAlignment(TextState::Alignment align)
|
||||
{
|
||||
if (state.alignment != align)
|
||||
{
|
||||
state.alignment = align;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void SetFont(FontEx *);
|
||||
void SetFontSize(int size);
|
||||
void SetFontColor(float r, float g, float b, float a = 1.0);
|
||||
|
||||
/// Set column formatting width in character.
|
||||
void SetColumnWidth(int w)
|
||||
{
|
||||
state.column_width = w;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// Set font tracking.
|
||||
void SetTextTracking(float tracking_offset = 0)
|
||||
{
|
||||
state.SetTracking(tracking_offset);
|
||||
dirty = true;
|
||||
}
|
||||
/// Set font heading.
|
||||
void SetTextHeading(float heading_offset = 0)
|
||||
{
|
||||
state.SetLeading(heading_offset);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void SetTextState(const TextState &);
|
||||
void GetTextState(TextState &) const;
|
||||
|
||||
virtual void Refresh();
|
||||
virtual void Compose(Picture &output, const iRect &clip_rect);
|
||||
|
||||
TextWidget(int id = -1, const char * = "Text", FontEx * = 0, int size = 16);
|
||||
};
|
||||
|
||||
} // S2D
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NUIWIDGETTEXT__
|
||||
Reference in New Issue
Block a user