Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Introductions

Introductions

nerd_boy
nerd_boy's journal · · 4 min read
1,110 2
First post! Woot! Etc!

Firstly, introductions. I'm nerd_boy. Sadly, I've never really coded anything bigger/better/greater than Asteroids(DirectX 8, I believe). I've spent perhaps the past year not doing much coding at all, starting to for a couple of hours then stopping. I've told benryves countless times that I was finally starting on my hopeful code editor. Usually I'd code a couple hundred lines, find something I didn't like, and wipe the whole thing. Something I'll have to stop doing. [disturbed] Anyway, since I don't like my current situation of working at Wal*Mart, not having been to college for two semesters, and still living with my parents(fun times, I can tell you), I really need to start doing something. Like coding.

Enough emoing.

I've decided to have a go at a lite weight editor control for the .NET platform, aptly named CodeLite. There seems to be a huge lack of these unless you want to shell out a couple hundred dollars. The main features it will include, hopefully, are:

  • Line Numbering
  • Syntax Highlighting
  • Basic Code Suggestion
  • Line Color Strip
  • Line Icon


The line color strip and line icon are whatever the heck those things in Visual Studio's gutter are. The icon is easy to describe, being the same height as the line and is pictured before the line numbers in my copy of VS. The line color strip is between the actual text and the line numbers in my copy as well. Green if its been saved and not edited, yellow if its been edited, etc. Functionality for it wouldn't be built in, though, just methods to change the color and icon.

So anyway, I've been focusing on the actual Text portion of the control. As many times as I've wiped it and redone it, you'd think I'd have something wonderful, but meh. The Text portion is going to be set aside from the CodeLite and be part of the 'core' system for the RNFN namespace. Currently just that, though I might throw some components of the syntax highlighter engine in there as well, depending on the final design. Currently, the nodes of the text linked list, RNFN.Collections.Text.TextLine, look like this:
		public class TextLine		{			public String data;			public T extradata;			public TextLine nextNode;			public TextLine prevNode;			public TextLine()			{				QuickSetup("",default(T),null,null);			}			public TextLine(String text)			{				QuickSetup(text,default(T),null,null);			}			public TextLine(T data)			{				QuickSetup("",data,null,null);			}			public TextLine(String text,T data)			{				QuickSetup(text,data,null,null);			}			public TextLine(TextLine previous,TextLine next)			{				QuickSetup("",default(T),previous,next);			}			public TextLine(String text,TextLine previous,TextLine next)			{				QuickSetup(text,default(T),previous,next);			}			public TextLine(T data,TextLine previous,TextLine next)			{				QuickSetup("",data,previous,next);			}			public TextLine(String text,T data,TextLine previous,TextLine next)			{				QuickSetup(text,data,previous,next);			}			protected void QuickSetup(String text,T data,TextLine previous,TextLine next)			{				this.data=text;				this.extradata=data;				if(previous!=null)					previous.nextNode=this;				this.prevNode=previous;				this.nextNode=next;				if(next!=null)					next.prevNode=this;			}		}

As is probably obvious, the T bit is for extra data of the text that must be kept track of per line(in the case of CodeLite, line numbers, line strip and icon, etc.) Now the main odd thing about this, that I'd really like to have critiqued to death as I want CodeLite to be pretty decent, is having the nodes linked when they're created. (Note: The reason I have the TextLine a class instead of a struct(like most nodes I've ever seen) is so I don't have to mark the bloody thing unsafe and use pointers and possibly fudge something up.) This is remarkably unsafe, but I figure that anything that if anything other than RNFN.Collections.Text uses it, it would/should have the root node protected, and not really give anything other than a copy away in an accessor. It also allows for some unusual code:
		protected void SetupText(String defaultString,T defaultT)		{			// Setup default value of T			this.defaultValue=defaultT;			roottextline=new TextLine(":root:",defaultT);			currenttextline=roottextline;			// Setup the string			String[] text=defaultString.Split("\n".ToCharArray());			foreach(String line in text)			{				new TextLine(line,defaultValue,currenttextline,null);				currenttextline=currenttextline.nextNode;				lines++;			}		}


Again, please critique this to death so I can make it better. But something just seems good about having the node linked with what it is supposed to the moment I create it.

----------
Edit 1:
Just occurred to me to add a destructor to the node that automagically unlinks it and links the prevNode and nextNode to each other. Now just deleting a node takes care of linking too. Yay.

---------
Edit 2:
And apparently C# doesn't have a delete keyword. Drat these languages that are so similiar to others that I feel I don't need to buy a book on the subject only to get bitten by my ignorance. Trial by fire. Time to change that Deconstructor to a deleteor.

Discussion

Loading comments...