| | 1 | [[PageOutline(1-5, Contents)]] |
|---|
| | 2 | = Contexts = |
|---|
| | 3 | |
|---|
| | 4 | == Interface == |
|---|
| | 5 | |
|---|
| | 6 | === Properties === |
|---|
| | 7 | |
|---|
| | 8 | || '''Python property''' || '''Brief description''' || '''Equivalent C++ functions''' || |
|---|
| | 9 | || ''dimensions'' || Gets/sets the dimensions of the context. || ''GetDimensions()'', ''SetDimensions()'' || |
|---|
| | 10 | || ''documents'' || Retrieves a document within the interface. || ''GetDocument()'', ''GetNumDocuments()'' || |
|---|
| | 11 | || ''focus_element'' || Retrieves the context's focus element. || ''GetFocusElement()'' || |
|---|
| | 12 | || ''name'' || Retrieves the context's name. || ''GetName()'' || |
|---|
| | 13 | |
|---|
| | 14 | ==== Retrieving documents ==== |
|---|
| | 15 | |
|---|
| | 16 | The ''documents'' property on the context can be referenced in several ways. For example, as an array: |
|---|
| | 17 | |
|---|
| | 18 | {{{ |
|---|
| | 19 | for document in context.documents: |
|---|
| | 20 | print document.title |
|---|
| | 21 | |
|---|
| | 22 | index = 0 |
|---|
| | 23 | while index < len(context.documents): |
|---|
| | 24 | print str(index) + ": " + context.documents[index].title |
|---|
| | 25 | }}} |
|---|
| | 26 | |
|---|
| | 27 | Or as a dictionary, looking documents up by their ID: |
|---|
| | 28 | |
|---|
| | 29 | {{{ |
|---|
| | 30 | try: |
|---|
| | 31 | document = context.documents["highscores"] |
|---|
| | 32 | except KeyError: |
|---|
| | 33 | print "No document found!" |
|---|
| | 34 | }}} |
|---|
| | 35 | |
|---|
| | 36 | Or accessing documents as attributes on the ''documents'' property itself: |
|---|
| | 37 | |
|---|
| | 38 | {{{ |
|---|
| | 39 | try: |
|---|
| | 40 | document = context.documents.highscores |
|---|
| | 41 | except AttributeError: |
|---|
| | 42 | print "No document found!" |
|---|
| | 43 | }}} |
|---|
| | 44 | |
|---|
| | 45 | === Methods === |
|---|
| | 46 | |
|---|
| | 47 | The following methods are exported from the C++ interface. |
|---|
| | 48 | |
|---|
| | 49 | || '''Python method''' || '''Brief description''' || |
|---|
| | 50 | || ''AddEventListener()'' || Attaches an inline event listener to the root of the context.|| |
|---|
| | 51 | || ''AddMouseCursor()'' || Adds a previously-loaded mouse cursor to the document. || |
|---|
| | 52 | || ''CreateDocument()'' || Creates a new document. || |
|---|
| | 53 | || ''LoadDocument()'' || Loads a document from an external RML file. || |
|---|
| | 54 | || ''LoadMouseCursor()'' || Loads a mouse cursor from an external RML file. || |
|---|
| | 55 | || ''Render()'' || Renders the context. || |
|---|
| | 56 | || ''ShowMouseCursor()'' || Shows or hides the mouse cursor. || |
|---|
| | 57 | || ''UnloadAllDocuments()'' || Unloads all loaded documents within the context. || |
|---|
| | 58 | || ''UnloadAllMouseCursors()'' || Unloads all of the context's mouse cursors. || |
|---|
| | 59 | || ''UnloadDocument()'' || Unloads one of the context's documents. || |
|---|
| | 60 | || ''UnloadMouseCursor()'' || Unloads one of the context's cursors. || |
|---|
| | 61 | || ''Update()'' || Updates the context. || |
|---|
| | 62 | |
|---|
| | 63 | == Creating contexts == |
|---|
| | 64 | |
|---|
| | 65 | Contexts can be created in Python with the ''CreateContext()'' function in the Rocket module. This function takes the name of the context as a string and the dimensions as an ''Vector2i'' type. |
|---|
| | 66 | |
|---|
| | 67 | {{{ |
|---|
| | 68 | new_context = rocket.CreateContext("hud", rocket.Vector2i(1024, 768)) |
|---|
| | 69 | }}} |
|---|
| | 70 | |
|---|
| | 71 | == Accessing contexts == |
|---|
| | 72 | |
|---|
| | 73 | Existing contexts can be accessed in Python with the ''GetContext()'' function in the Rocket module. |
|---|
| | 74 | |
|---|
| | 75 | {{{ |
|---|
| | 76 | context = rocket.GetContext("hud") |
|---|
| | 77 | }}} |