view mde/gui/content/Content.d @ 91:4d5d53e4f881

Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too. Some debugging improvements. When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 16 Oct 2008 17:43:48 +0100
parents b525ff28774b
children 9520cc0448e5
line wrap: on
line source

/* LICENSE BLOCK
Part of mde: a Modular D game-oriented Engine
Copyright © 2007-2008 Diggory Hardy

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/** The content system − type agnostic part.
 */
module mde.gui.content.Content;

import Int = tango.text.convert.Integer;

/** Content − universal part.
 *
 * Services like copy/paste could work on universal content. However, they would need to run a
 * conversion to the appropriate type (or try next-oldest item on clipboard?).
 *
 * Currently Content instances can only have their data set on creation.
 * Each Content class should provide a method to get it's content, e.g. the method text().
 *
 * Extensions to content:
 * 
 * These extensions require that a content can notify any dependants of changes.
 * 
 * Use as a state switch (one option from an enumeration). E.g. a button/selection box could set a
 * state, and a tabbed box could show a tab based on this. Or could represent an option.
 */
//TODO - write a generic IContent displaying widget. Also a generic editable?
// Don't include dimension/drawing stuff because it's renderer specific and content should not be!
// NOTE: an interface or a class?
interface IContent
{
    /+ NOTE: None of this is really used yet, but was (mostly) intended for clipboard copying.
    /** Return a copy of self. */
    IContent dup ();
    
    /** Attempt to convert the content to a specific type (may simply return this if appropriate).
     *
     * Annoyingly we can't use cast because overloading by return type isn't supported. */
    // FIXME: throw or return null on error or unsupported conversion?
    ContentText	toText ();
    ContentInt	toInt ();	/// ditto
    +/
    
    
    
    /** Generically return strings.
     *
     * Every Content should return a string for i == 0; preferably its value. Other values of i
     * can be used to return other strings. For unsupported values of i, null should be returned.
     */
    char[] toString (uint i);
}
/+
/** Extension to interface providing text-specific tools. */
interface IContentText : IContent
{
    char[] text ();            /// Get/set the value.
    void text (char[] v);      /// ditto
}
+/
/+ FIXME - use content lists or drop?
/** Get a content from the list (what list?). */
ContentText getContentText (char[] id) {
    return new ContentText (id);	// forget the list for now
}

/** ditto */
ContentInt getContentInt (char[] id) {
    return new ContentInt (42);	// forget the list for now
}
+/

/+FIXME - currently unused
/** Text content. */
/* May end up extending a universal content type.
 *  Services like copy/paste could work on universal content.
 *
 * NOTE: Needs to be a reference type really.
 *  Could alternately be:
 *      alias ContentTextStruct* ContentText
 *  where ContentTextStruct is a struct. */
class ContentText : IContent
{
    this () {}
    this (char[] text) {
        text_ = text;
    }
    
    ContentText dup () {
        return new ContentText (text_);
    }
    
    ContentText toText () {
        return this;
    }
    ContentInt  toInt () {
        // FIXME: convert
        return null;
    }
    
    alias toString text;
    
    /// Get the text.
    char[] toString () {
        return text_;
    }
    
protected:
    //NOTE: need to allow cache-invalidating when text changes!
    char[] text_;
}

/** Integer content. */
class ContentInt : IContent
{
    this () {}
    this (int integer) {
        int_ = integer;
    }
    
    ContentInt dup () {
        return new ContentInt (int_);
    }
    
    ContentText toText () {
        return new ContentText(toString);
    }
    ContentInt  toInt () {
        return this;
    }
    
    /// Get the integer.
    int integer () {
        return int_;
    }
    
    char[] toString () {
        return Int.toString (int_);
    }
    
protected:
    int int_;
}
+/