TextEdit Documentation Vs. 1 (10/26/2002) Written By: Andy Stone
TextEdit By: Andy Stone (astone42@attbi.com) Visit: http://loreandlutes.sourceforge.net for more information. See copying.txt or copying for licensing information.


What TextEdit is:

Textedit is the self-described text editor used by L&L. It's built on top of ASFC so it only depends on that module and will support any Operating System SDL runs on. Textedit is simple, it contains of only two objects! A Text object that stores data and a TextEditor object that views or edits data. If you've downloaded Lore And Lutes you can see examples of TextEdit in action by running the editor (lledit) and pressing 'h' or 'j'.

What you should know before using textedit:

Since TextEdit uses and depends on several ASFC classes its best if you know how to use ASFC.

How to use textedit:

First make sure you have an ASFC_Screen object, an ASFC_FontPalette object, a font registered in the font palette, and an ASFC_Console object:

//Create a sample screen 640x480x16

ASFC_Screen screen(640, 480, 16); //Setup the console, use the normal font

        ASFC_Font oConFont("./fonts/normal_console_font.png",
                                8, 14, COLOR_BLUE);
        ASFC_FontPalette myoFonts;
        myoFonts.Push(oConFont);
        ASFC_Console oCon;
        oCon.SetFontPalette(&myoFonts);
        oCon.SetSurface(&screen);
        oCon.SetConsolePosition(0, 0);
        oCon.SetViewport(0, 0);
        oCon.SetViewportSize(52, 29);
        oCon.SetConsoleSize (52, 29);

If you want to see what fonts you can use with TextEdit open the fonts sub directory and look. See the ASFC section for more information about how fonts and consoles work.

Once that's done create a TE_Text object to store your textual data and a TE_TextEditor object to view\edit it. Link the editor to the console you want to display the text by using the SetConsole() member.

        TE_Text oText;
        TE_TextEditor oEdit;
        oEdit.SetConsole(&oCon);

If you don't want to start editting with blank document you can load a textfile by passing the path location of the text file you want to view\edit.

oText.Load("test.txt");

Next simply edit or view the text, text edit handles the rest.

        oEdit.EditText(&oText);
        oEdit.ViewText(&oText);

If you're editing text you can also set "boundries". The boundaries are line #s that tell TextEdit what it can edit. Anything out of the boundaries won't be viewed by the editor and can't be edited. You pass two ints for the start and end rows of the boundaries; the end row will be updated if the user adds new lines to the file.

        //Only edit lines 0 - 5
                int iStart = 0;
                int iEnd = 5;
                Edit.EditText(&oText, &iStart, &iEnd);
        /*If the user enters a new line iEnd will now be 6, or if
          he deletes a line it'll be 4*/

Adding to this documentation

Currently there's a lot of information that could be added to this doc but hasn't been mostly because I'm busy coding :-). But if you have something that you think should be added, or if you use TextEdit and know just what this doc needs feel free to help me. E-Mail me, Andy Stone, at astone42@attbi.com. Also if you notice any dumb spelling or grammar mistakes that just stand out and bug you e-mail me where the are and I'll try to fix those too. Thanks.

Errors, Bugs, Questions, Comments?


E-Mail me Andy Stone (astone42@attbi.com)