Mercurial > projects > mde
view mde/gui/content/Content.d @ 61:7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Also some changes to debug statements, in particular a new drawGlyphCache debug version.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 25 Jun 2008 17:25:48 +0100 |
parents | |
children | 891211f034f2 |
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(). */ // Don't include dimension/drawing stuff because it's renderer specific and content should not be! // NOTE: an interface or a class? alias IContent Content; // use either name until it's settled... /** ditto */ interface IContent { /** 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 /** Every Content should be convertible to a string, which, if possible, should be a sensible * conversion of its content. */ char[] toString (); } /** 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 : Content { this () { // NOTE: testing text_ = "\"a@b\" − an example"; } 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 : Content { this () { // NOTE: testing int_ = -496; } 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_; }