Context.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCORECONTEXT_H
00029 #define ROCKETCORECONTEXT_H
00030
00031 #include <Rocket/Core/Header.h>
00032 #include <Rocket/Core/Types.h>
00033 #include <Rocket/Core/ReferenceCountable.h>
00034 #include <Rocket/Core/ElementReference.h>
00035 #include <Rocket/Core/Input.h>
00036 #include <Rocket/Core/String.h>
00037 #include <Rocket/Core/ScriptInterface.h>
00038
00039 namespace Rocket {
00040 namespace Core {
00041
00042 class Stream;
00043 class Dictionary;
00044
00045 }
00046 }
00047
00048 namespace Rocket {
00049 namespace Core {
00050
00051 class ContextInstancer;
00052 class ElementDocument;
00053 class EventListener;
00054 class RenderInterface;
00055
00062 class ROCKETCORE_API Context : public ScriptInterface
00063 {
00064 public:
00068 Context(const String& name);
00070 virtual ~Context();
00071
00074 const String& GetName() const;
00075
00078 void SetDimensions(const Vector2i& dimensions);
00081 const Vector2i& GetDimensions() const;
00082
00084 bool Update();
00086 bool Render();
00087
00091 ElementDocument* CreateDocument(const String& tag = "body");
00095 ElementDocument* LoadDocument(const String& document_path);
00099 ElementDocument* LoadDocument(Stream* document_stream);
00103 ElementDocument* LoadDocumentFromMemory(const String& string);
00106 void UnloadDocument(ElementDocument* document);
00108 void UnloadAllDocuments();
00109
00113 void AddMouseCursor(ElementDocument* cursor_document);
00117 ElementDocument* LoadMouseCursor(const String& cursor_document_path);
00120 void UnloadMouseCursor(const String& cursor_name);
00122 void UnloadAllMouseCursors();
00126 bool SetMouseCursor(const String& cursor_name);
00129 void ShowMouseCursor(bool show);
00130
00134 ElementDocument* GetDocument(const String& id);
00138 ElementDocument* GetDocument(int index);
00141 int GetNumDocuments() const;
00142
00145 Element* GetHoverElement();
00146
00149 Element* GetFocusElement();
00150
00153 Element* GetRootElement();
00154
00157 void PullDocumentToFront(ElementDocument* document);
00160 void PushDocumentToBack(ElementDocument* document);
00161
00166 void AddEventListener(const String& event, EventListener* listener, bool in_capture_phase = false);
00171 void RemoveEventListener(const String& event, EventListener* listener, bool in_capture_phase = false);
00172
00177 bool ProcessKeyDown(Input::KeyIdentifier key_identifier, int key_modifier_state);
00182 bool ProcessKeyUp(Input::KeyIdentifier key_identifier, int key_modifier_state);
00183
00187 bool ProcessTextInput(word character);
00191 bool ProcessTextInput(const String& string);
00192
00197 void ProcessMouseMove(int x, int y, int key_modifier_state);
00201 void ProcessMouseButtonDown(int button_index, int key_modifier_state);
00205 void ProcessMouseButtonUp(int button_index, int key_modifier_state);
00210 bool ProcessMouseWheel(int wheel_delta, int key_modifier_state);
00211
00214 RenderInterface* GetRenderInterface() const;
00215
00218 void SetInstancer(ContextInstancer* instancer);
00219
00220 protected:
00221 virtual void OnReferenceDeactivate();
00222
00223 private:
00224 String name;
00225 Vector2i dimensions;
00226
00227 ContextInstancer* instancer;
00228
00229 typedef std::set< ElementReference > ElementSet;
00230 typedef std::vector< ElementReference > ElementList;
00231
00232 ElementSet hover_chain;
00233
00234 ElementList active_chain;
00235
00236 ElementList document_focus_history;
00237
00238
00239 ElementList unloaded_documents;
00240
00241
00242 Element* root;
00243
00244 ElementReference focus;
00245
00246 ElementReference hover;
00247
00248 ElementReference active;
00249
00250
00251 Element* last_click_element;
00252
00253 float last_click_time;
00254
00255 typedef std::map< String, ElementDocument* > CursorMap;
00256 CursorMap cursors;
00257 ElementReference default_cursor;
00258 ElementReference active_cursor;
00259 bool show_cursor;
00260
00261 ElementDocument* cursor_proxy;
00262
00263
00264 ElementReference drag;
00265
00266 bool drag_started;
00267
00268 bool drag_verbose;
00269
00270 Element* drag_clone;
00271
00272
00273
00274 ElementReference drag_hover;
00275
00276
00277 ElementSet drag_hover_chain;
00278
00279
00280 Vector2i mouse_position;
00281
00282
00283 RenderInterface* render_interface;
00284
00285
00286 void OnElementRemove(Element* element);
00287
00288 bool OnFocusChange(Element* element);
00289
00290
00291 void GenerateClickEvent(Element* element);
00292
00293
00294 void UpdateHoverChain(const Dictionary& parameters, const Dictionary& drag_parameters, const Vector2i& old_mouse_position);
00295
00296
00297
00298
00299
00300 Element* GetElementAtPoint(const Vector2f& point, const Element* ignore_element = NULL, Element* element = NULL);
00301
00302
00303
00304
00305 void CreateDragClone(Element* element);
00306
00307 void ReleaseDragClone();
00308
00309
00310 void GenerateKeyEventParameters(Dictionary& parameters, Input::KeyIdentifier key_identifier);
00311
00312 void GenerateMouseEventParameters(Dictionary& parameters, int button_index = -1);
00313
00314 void GenerateKeyModifierEventParameters(Dictionary& parameters, int key_modifier_state);
00315
00316 void GenerateDragEventParameters(Dictionary& parameters);
00317
00318
00319 void ReleaseUnloadedDocuments();
00320
00321
00322 static void SendEvents(const ElementSet& old_items, const ElementSet& new_items, const String& event, const Dictionary& parameters, bool interruptible);
00323
00324 friend class Element;
00325 friend ROCKETCORE_API Context* CreateContext(const String&, const Vector2i&, RenderInterface*);
00326 };
00327
00328 }
00329 }
00330
00331 #endif