• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineGame.UI: Custom controlGame.UI: Custom control
Previous
 
Next
New Post
8/30/2011 11:50 PM
 
jkachhad
No Ranking

Joined: 8/14/2011
Posts: 14
Game.UI: Custom control 

Hello,

I don't think there are any blog or forum posts about making a custom control. I'm sure there will eventually be a real helpful one, but I wanted to make sure I was doing it properly. Here's the control I've designed for a vertical health bar. The texture is rendered with a height related to the (value / maximum).

I wasn't sure if this was the intended way to implement custom controls, as the existing controls use styles.


      public class TexturedProgressBar : RangeBase
    {
        private Texture2D _texture;
 
        public Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }
 
        public TexturedProgressBar()
        {
             
        }
 
        protected override void OnRender(float deltaTime)
        {
            if (IsVisualValid)
                return;
 
            SpriteBatch spriteBatch = Screen.Renderer.SpriteBatch;
 
            if (_texture == null)
                return;
 
            float drawWidth = _texture.Width;
            float drawHeight = (Value / Maximum) * _texture.Height;
 
            int originX = 0;
            int originY = (int)(_texture.Height - drawHeight);
 
            Vector2 position = new Vector2(ActualX, ActualY + originY);
            Rectangle source = new Rectangle(originX, originY, (int)drawWidth, (int)drawHeight);
 
            spriteBatch.Draw(_texture, position, source, Color.White);
 
            base.OnRender(deltaTime);
        }
    }

 
New Post
8/31/2011 10:36 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 568
Re: Game.UI: Custom control 

Hi,
I will try to write a really helpful blog post ;-). Here are few tips in advance off the top of my head:

In the constructor always set a style name

public TexturedProgressBar()
{
 Style = "TexturedProgressBar";
}

 

This is only needed if you want to style the control in the Theme.xml. Nevertheless it is good practice to always set a unique style name.

In OnRender the control has to be drawn everytime - no matter what IsVisualValid says. In OnRender you can cache information and you can assume that this information is valid as long as IsVisualValid is true. For example:

protected override void OnRender(float deltaTime)
{
  if (!IsVisualValid)
  {
    //Do complex precomputation and cache results.
    ...
  }
   
  // Render using cached information.
  …
}

 

IsVisualValid is automatically reset when a control property is changed that influences the visual appearance. IsVisualValid is automatically set to true after OnRender() was called.
If you have a very complex control, you could, for example, draw you control into a texture if IsVisualValid is false - but you still have to copy this cached texture to the screen every time OnRender() is called.

base.OnRender() calls the normal Screen.Renderer.Render() method which draws the control based on its style. If you do all the dawing yourself, then you should skip this call.

If you want to be able to animate your control (using properties like control.RenderTranslation, as in the UIAnimationSample), then you also have to consider the RenderTransform of your control - but I would ignore this for now.

When creating a new custom control, overriding OnRender() is the simplest method, and I would start this way.

A more advanced way to implement custom drawing is to not override OnRender and instead to add a new RenderCallback for the style "TexturedProgresBar" to the  UIRenderer. If you are interested in this method, check out UIRenderer_Render.cs in the DigitalRune.Game.UI source code - or wait for the blog posts ;-)

I will write blog posts with more details. Maybe I will show how to develop a new control step-by-step. Any suggestions which type of control I should develop? Is there a missing control type desperately needed by anyone?

 
New Post
9/16/2011 1:23 AM
 
pfisch
No Ranking

Joined: 9/16/2011
Posts: 11
Re: Game.UI: Custom control  Modified By pfisch  on 9/16/2011 1:34:41 AM

I desperately need an onscreen keyboard control that can be controlled via gamepad and mouse.  I'm going to be trying to make one in the next few days.  A blog post detailing making a new control would be incredibly helpful.

 

I know xbox has a built in keyboard, but that one is not at all versatile.

 
New Post
9/16/2011 9:59 AM
 
Laurentius
No Ranking

Joined: 7/30/2011
Posts: 64
Re: Game.UI: Custom control  Modified By Laurentius  on 9/16/2011 10:01:19 AM

"Any suggestions which type of control I should develop? Is there a missing control type desperately needed by anyone?"

For me a treeview like control type would be great.

I currently use a mix of Winform editor and ingame editor (digitalrune) so a corresponding treeview control type like winforms treeview for digitalrune makes things much smarter for displaying hirarchical data (e.g. ragdoll bodies/limits/bonestructure - I use a button array for that - not very usable as you have many! items).

Thanks, Lars.

 
New Post
9/19/2011 10:09 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 568
Re: Game.UI: Custom control 
I hope this week I will finally get to the promised blog posts. The tree control is a good idea. I will probably implement this one as an example. Stay tuned and let me know if there are any specific Game UI questions that I should address.
 
New Post
9/19/2011 11:51 AM
 
Trent
No Ranking

Joined: 9/19/2011
Posts: 10
Re: Game.UI: Custom control 
Laurentius wrote:

"Any suggestions which type of control I should develop? Is there a missing control type desperately needed by anyone?"

For me a treeview like control type would be great.


 

Just started my eval today.. but if you're taking suggestions, a Grid component would be most excellent. :)


 
New Post
9/19/2011 12:31 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 568
Re: Game.UI: Custom control 
Do you mean a Grid panel control (to position elements) or a DataGrid control (to view a table of data)?
 
New Post
9/19/2011 6:44 PM
 
Trent
No Ranking

Joined: 9/19/2011
Posts: 10
Re: Game.UI: Custom control 

By grid component, I mean the variety used to organize tables of data in an interface. Building a strategy game that's data-heavy. Need to have scroll-able grids for things such as inventory, etc.

Doesn't need anything TOO fancy. Wouldn't need to do any data entry in to the grid directly, just display text, images, and buttons. 

Alternate row formatting would be nice, and perhaps a a rollover/highlight style.

Having something that could bind to an IList would be awesome, but I don't think the reflection namespace is available in XNA on all platforms. (Could be wrong, I haven't done any phone or XBox coding yet, just PC)


 
New Post
9/22/2011 6:56 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 568
Re: Game.UI: Custom control 

The first article is online: http://www.digitalrune.com/Support/Bl... 
And more will follow.

I have decided to discuss some core Game UI concepts first. Later we will add some exemplary custom controls (TreeView and/or DataGrid).

 
New Post
10/7/2011 7:44 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 568
Re: Game.UI: Custom control 

Finally, a tree view control sample is here:

http://www.digitalrune.com/Support/Bl...

 
 Page 1 of 1
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineGame.UI: Custom controlGame.UI: Custom control


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement