• Advertisement
  • entries
    707
  • comments
    1173
  • views
    435204

Untitled

Sign in to follow this  

82 views

The GUI is coming along nicely. I have the skin file system setup and it works pretty decently, but because of the way it's setup it's really easy to either write horrendous code (nested if's checking that class and value's exist) or write easily broken code, so I'm going to try to fix that soon. For example, this is the test code I used to load my button's skin info:

ConfigClass* ButtonClass = GetManager()->GetSkinClass("button");
if(ButtonClass)
{
ConfigValue* Value = ButtonClass->GetValue("Offset");
if(Value)
Value->ParseVector(&Offset);

Value = ButtonClass->GetValue("Source-Sizes");
if(!Value)
{
Value = ButtonClass->GetValue("Source-Left-Width");
if(Value)
SourceSizes.left = Value->ParseInteger();

Value = ButtonClass->GetValue("Source-Top-Height");
if(Value)
SourceSizes.top = Value->ParseInteger();

Value = ButtonClass->GetValue("Source-Right-Width");
if(Value)
SourceSizes.right = Value->ParseInteger();

Value = ButtonClass->GetValue("Source-Bottom-Height");
if(Value)
SourceSizes.bottom = Value->ParseInteger();
}
else
Value->ParseRect(&SourceSizes);
}







Quite ugly[sick].



I've also taken up learning some "electronics" (not quite sure if there is an exact name for it.) Obviously it's only been a day so I have gotten everything compacted into my brain, but I got a few of the basics down. Hopefully you'll be seeing pictures of my experiments soon (that's if I can ever find an available breadboard to work with. I checked like 8 online stores with no luck until I checked RadioShack.com, but they're out of stock -_-.)



I also tried my hand at generics and made a std::map like generic class (if there is a class in C# that is already like it then I missed it somewhere. I saw KeyValuePair, but it seems that you have to use it in unison with another generic (like List) and none of those support the features I want.) Anyway, here's the code for it and my test code:
(Note: I need to move my exceptions out of the class, it makes catching them a pain in the arse.)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace dftCodeLibrary
{
public class Map : IEnumerator
{
/* ItemNotFoundException */
public class ItemNotFoundException : Exception
{
public ItemNotFoundException(String Message)
{
MessageBox.Show(Message, "ItemNotFoundException");
}
}

/* ItemFoundException */
public class ItemFoundException : Exception
{
public ItemFoundException(String Message)
{
MessageBox.Show(Message, "ItemFoundException");
}
}

/* ItemNode class */
public class ItemNode
{
public KeyType Key;
public ObjectType Object;
}

/* Variables */
List Items = null;
int Position = -1;

/* MoveNext() */
public bool MoveNext()
{
if(Position < Items.Count - 1)
{
++Position;
return true;
}
return false;
}

/* Reset() */
public void Reset()
{
Position = -1;
}

/* Current */
public object Current
{
get
{
return Items[Position].Object;
}
}

/* GetEnumerator() */
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}

/* Map() */
public Map()
{
Items = new List();
}

/* Add() */
public void Add(KeyType Key, ObjectType Object)
{
if(Items == null)
throw new NullReferenceException();

foreach(ItemNode Item in Items)
{
if(Item.Key.Equals(Key))
throw new ItemFoundException(string.Format("The item \"{0}\" was found in the list.", Key));
}
ItemNode NewItem = new ItemNode();
NewItem.Key = Key;
NewItem.Object = Object;
Items.Add(NewItem);
}

/* Remove() */
public void Remove(KeyType Key)
{
if(Items == null)
throw new NullReferenceException();

foreach(ItemNode Item in Items)
{
if(Item.Key.Equals(Key))
{
Items.Remove(Item);
return;
}
}
throw new ItemNotFoundException(string.Format("The item \"{0}\" was not found in the list.", Key));
}

/* operator [] */
public ObjectType this[KeyType Key]
{
get
{
if(Items == null)
throw new NullReferenceException();

foreach(ItemNode Item in Items)
{
if(Item.Key.Equals(Key))
return Item.Object;
}
throw new ItemNotFoundException(string.Format("The item \"{0}\" was not found in the list.", Key));
}

set
{
if(Items == null)
throw new NullReferenceException();

foreach(ItemNode Item in Items)
{
if(Item.Key.Equals(Key))
{
Item.Object = value;
return;
}
}

Add(Key, value);
}
}
}
}








using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using dftCodeLibrary;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
Map MyMap = new Map();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
MyMap["First Name"] = "Donald";
MyMap["Middle Name"] = "Raymond";
MyMap["Last Name"] = "Beals";
MyMap.Remove("Middle Name");

foreach(String Item in MyMap)
MessageBox.Show(Item);
}

catch(Map.ItemNotFoundException SourceException)
{
this.Close();
}

catch(Map.ItemFoundException SourceException)
{
this.Close();
}
}
}
}







I'm still new to a lot of C#, so if I'm doing something wrong, please point it out. Thanks!

Anyway, I'm off to work. I plan on having the GUI finished in a few days. I'm going to start with scrollbars and faders to make sure that I get them implemented and done correctly (I had faders before, but they were MAJORLY broken. Well, not really broken, just incorrect.)


GUI Update


I modified the whole system to do something that I felt was missing from my other GUI: different textures and fonts for each control (each font doesn't contain an instance to it; I use a smart-pointer pool system so they just have smart pointers to the texture/font they want to use.) Anyway, here's a screenshot:


At the moment it uses ID3DXFont, but I have setup the interface in a manner that it'll work with my bitmap font system. I have the bitmap font system code "working" but I have a few small issues to work out.

This'll also allow me to use background textures which will be pretty awesome (hopefully.)


GUI Update 2


Ok, last update until I wake up later[wink]. I got background textures in and working right. They tile nicely, but I'm going to have to beware the fact that they're the same exact size as the widget, meaning they screw up my nice rounded corners and such.

Now, a little bit about the speed issues I just added in the last 30 minutes. Since each widget can essentially have a different texture, I have to assign the texture for each call to render. BUT, I should be (and I am) doing this anyway, because when I put bitmap fonts in they'll be setting a texture.

Anyway, if it becomes to much of a problem, all I have to do is remove "Background-Texture = FileNameHere;" from my skin files and background textures will be completely ignored. I originally only added them for dialogboxes, but I figured it could add some really nice effects to other controls, so why not? Especially when they can just be completely ignored.

Gah, it's almost 6am. Time for bed.

Edit: Forgot to post a new screeny with backgrounds:


The big button in the middle uses a 256x256 background texture. Also, the two buttons use two different classes.
Sign in to follow this  


2 Comments


Recommended Comments

Guest Anonymous Poster

Posted

System.Collections.Generics.Dictionary<,> is similar to your Map class and it uses the hash values of the key for retrieval, so it doesn't sequentially search.

Share this comment


Link to comment
Quote:
Original post by Anonymous Poster
System.Collections.Generics.Dictionary<,> is similar to your Map class and it uses the hash values of the key for retrieval, so it doesn't sequentially search.


Thanks! I'll look into that[smile].

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement