{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorRenderableDesktop**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorRenderableDesktop ======
Behavior element behavior adding a renderable Desktop widget.
This behavior is useful for models with a complex dynamic texture where the content of the texture is provided by a #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@# widget. Multiple other behaviors can add their content #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Window.html,Window~@# to the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@# separating logic for reuse. Using **ECBehaviorRenderableDesktop** instead of [[behavior_renderablecanvas|ECBehaviorRenderableCanvas]] allows to use the full power of the GUI ToolKit including using [[dragengine:modules:dragonscript:guitheme|Gui Themes]] to create complex content easily.
The default layout for the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@# is #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Layouts_1_1StackLayout.html,StackLayout~@#]. The default gui theme is //"/shareddata/guithemes/modern/modern.guitheme.xml"//. The default #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@# designer selector is //"RenderableDesktop"//.
To use this behavior add an [[behavior_dynamicskin|ECBehaviorDynamicSkin]] to the element class before adding this behavior. Create **ECBehaviorRenderableDesktop** behavior and set the dynamic skin and designer selector and #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1GuiTheme.html,GuiTheme~@# for the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@#. Now you can add other behaviors targeting the ECBehaviorRenderableDesktop to add #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Widget.html,Widget~@# resources to.
The #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Desktop.html,Desktop~@# is created with a default size of 1024x1024 . You can change the size using the element property to fit the texture requirements.
====== Instance Counts ======
Multiple instances of **ECBehaviorRenderableDesktop** can be added to affect individual dynamic skin textures. The example below uses one component with one dynamic skin to two individual renderables named //"content1"// and //"content2"// each allowing to be individiaully filled with content by different behaviors.
class MyElement extends BehaviorElementClass
public func new()
ECBehaviorComponent.new(this)
ECBehaviorDynamicSkin.new(this)
ECBehaviorCanvas.new(this)
ECBehaviorCanvas.new(this, "canvas2")
var ECBehaviorRenderableDesktop behavior = ECBehaviorRenderableDesktop.new(this)
behavior.getRenderable().setValue("content1")
behavior.getGuiTheme().setPath("/content/renderable.guitheme.xml")
behavior.getDesignerSelector().setValue("Desktop.MyElement")
behavior = ECBehaviorRenderableDesktop.new(this, "renderableDesktop2")
behavior.setBackgroundColor(Color.blue)
behavior.getRenderable().setValue("intensity2")
behavior.getGuiTheme().setPath("/content/renderable.guitheme.xml")
behavior.getDesignerSelector().setValue("Desktop.MyElement")
end
end
====== Element Class Properties ======
Element class properties have the prefix **renderableDesktop.** or **renderableDesktop(id).** if id is not empty.
===== renderable =====
Name of the [[gamedev:renderables|renderable]] in the component skin to modify.
* Full name: "renderableDesktop.renderable" or "renderableDesktop(id).renderable"
* Type: string
* Default Value: "" (empty string)
* Example (*.deeclass): monitor content
===== size =====
Size of desktop in pixels.
* Full name: "renderableDesktop.size" or "renderableDesktop(id).size"
* Type: #@LinkApiDocDEDS2_HTML~classDragengine_1_1Gui_1_1Point.html,Point~@#
* Default value: (1024, 1024)
* Example (*.deeclass):
===== guiTheme =====
Path to gui theme (*.guitheme.xml) to load. If the same gui theme is used in multiple elements it is loaded only once and shared.
* Full name: "renderableDesktop.guiTheme" or "renderableDesktop(id).guiTheme"
* Type: Path (*.guitheme.xml)
* Default value: "/shareddata/guithemes/modern/modern.guitheme.xml"
* Example (*.deeclass): /content/ui/ingame.guitheme.xml
===== designerSelector =====
Name of designer selector to use from gui theme specified in //guiTheme// property for desktop widget. Allows to define multiple desktops in one gui theme potentially sharing definitions.
* Full name: "renderableDesktop.designerSelector" or "renderableDesktop(id).designerSelector"
* Type: string
* Default Value: "RenderableDesktop"
* Example (*.deeclass): RenderableDesktop.CockpitMonitor.Center
====== Required Behaviors ======
* [[behavior_dynamicskin|ECBehaviorDynamicSkin]]
====== Optional Behaviors ======
This behavior does not support optional behaviors.
====== Persistency ======
This behavior does not use persistency.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorRenderableDesktop.html,ECBehaviorRenderableDesktop~@#.
Since DragonScript Module Version **1.3**
====== Use Cases ======
* Create displays and monitors showing dynamic content like a digital wall clock or a train station time table. The element has one renderable used (typically [[gamedev:textureproperties:emissivity|emissivity]] to show the content. For each dynamic content to show add behavior providing the content.
* Generate textures with randomized content during game loading. Same as previous use case but content typically is static.
* Create dynamic skin content which is difficult to create using skin properties only. This can be individual moving and changing content like advertize board or shop signs.
====== Element Class Example ======
class ExampleElementClass extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorDynamicSkin dynamicSkin
public var ECBehaviorRenderableDesktop renderableDesktop
public func new() super("ExampleElement")
// add required behaviors component and collider
component = ECBehaviorComponent.new(this)
collider = ECBehaviorCollider.new(this, component)
// add dynamic skin to modify component
dynamicSkin = ECBehaviorDynamicSkin.new(this, component)
// create renderable desktop. the skin has to use a renderable named "board".
// the panel has a size of 1024x1024 and uses gui theme loaded from "adboard.guitheme.xml".
// the desktop uses by default a stack layout hence all widgets added fill the
// entire desktop space and are layered ontop of each other. any behavior can
// change the layout used for the desktop if required
renderableDesktop = ECBehaviorRenderableDesktop.new(this, dynamicSkin)
renderableDesktop.getRenderable().setValue("board")
renderableDesktop.getSize().setPoint(Point.new(512, 256))
renderableDesktop.getGuiTheme().setPath("/content/ui/adboard.guitheme.xml")
// here you could now add behaviors adding content to the renderable.
// the simply have to create (during their init(StubElement) call) one or more widgets
// adding them to the renderable. using behavior makes this a reusable process
//
// MyContentBehavior.new(this, renderableDesktop)
end
// another way is adding widgets yourself. this can be useful for prototyping
// and situations where you have a simple gui widget
protected func Element createElement()
var BehaviorElement element = super.createElement()
var Desktop desktop = renderableDesktop.instance(element).getDesktop()
// add some content to it. this example adds two labels against the top
// and bottom edge with an image stretched between them. each can be
// designed using a respective designer selector like adding borders,
// changing background, changing padding, font and color
var Window window = Window.new(Point.new(20, 50), Point.new(600, 500))
window.setLayout(BorderLayout.new(5))
window.addWidget(Label.new("Top-Side", "Label.TopSide"), BorderLayout.Area.top)
window.addWidget(DisplayImage.new("/content/adEatMorePears.png", RepeatMode.stretch, "Image.AdEatMorePears"), BorderLayout.Area.content)
window.addWidget(Label.new("Bottom-Side", "Label.BottomSide"), BorderLayout.Area.bottom)
desktop.addWindow(window)
// later on in the game you could use a WidgetInputProcessor to direct
// player input to the desktop widget to allow the player to interact
// with the content as if it is the regular UI
return element
end
end