Mercurial > projects > mde
changeset 59:672b6b162a36
Added very basic (and currently useless) content support.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 14 Jun 2008 17:52:22 +0100 |
parents | d43523ed4b62 |
children | 23a1d2b1ec5f |
files | mde/gui/IGui.d mde/gui/content/ContentText.d mde/gui/widget/TextWidget.d mde/gui/widget/createWidget.d mde/gui/widget/miscWidgets.d |
diffstat | 5 files changed, 116 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/mde/gui/IGui.d Sat Jun 14 17:15:06 2008 +0100 +++ b/mde/gui/IGui.d Sat Jun 14 17:52:22 2008 +0100 @@ -31,7 +31,10 @@ alias wdim wdrel; /// ditto alias wdim wdsize; /// ditto -/// A pair of wdim variables, and strictly no other data (methods may be added if deemed useful). +/** A pair of wdim variables, and strictly no other data (methods may be added if deemed useful). + * + * Potentially usable to return two wdim variables, e.g. width and height, from a function. + * However, the current usage of out variables looks like it's better. */ struct wdimPair { wdim x, y; /// data }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mde/gui/content/ContentText.d Sat Jun 14 17:52:22 2008 +0100 @@ -0,0 +1,39 @@ +/* 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 − text. + */ +module mde.gui.content.ContentText; + +/** 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 +/ +{ + + /// Get the text. + char[] text () { + return text_; + } + +protected: + //NOTE: need to allow cache-invalidating when text changes! + const char[] text_ = "\"a@b\" − an example"; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mde/gui/widget/TextWidget.d Sat Jun 14 17:52:22 2008 +0100 @@ -0,0 +1,72 @@ +/* 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/>. */ + +/** Basic text widget and supporting code for widgets containing text. */ +module mde.gui.widget.TextWidget; + +import mde.gui.widget.Widget; +import mde.gui.exception; +import mde.gui.renderer.IRenderer; +import mde.gui.content.ContentText; + +import mde.resource.font; + +import tango.io.Stdout; + +/// Adapter to ease use of ContentText +struct AdapterText { + void set (int col) { + if (font is null) font = FontStyle.get("default"); + + content = new ContentText; + colour = Colour (cast(ubyte) (col >> 16u), + cast(ubyte) (col >> 8u), + cast(ubyte) col ); + } + + void getDimensions (out wdsize w, out wdsize h) { + font.updateBlock (content.text, textCache); + w = cast(wdim) textCache.w; + h = cast(wdim) textCache.h; + } + + void draw (wdabs x, wdabs y) { + font.textBlock (x,y, content.text, textCache, colour); + } + + ContentText content; + TextBlock textCache; + Colour colour; + static FontStyle font; +} + +/// Basic text widget +class TextWidget : Widget +{ + this (IWindow wind, int[] data) { + if (data.length != 2) throw new WidgetDataException; + text.set (data[1]); + text.getDimensions (mw, mh); + super (wind,data); + } + + void draw () { + super.draw(); + text.draw (x,y); + } + +protected: + AdapterText text; +}
--- a/mde/gui/widget/createWidget.d Sat Jun 14 17:15:06 2008 +0100 +++ b/mde/gui/widget/createWidget.d Sat Jun 14 17:52:22 2008 +0100 @@ -22,6 +22,7 @@ // Widgets to create: import mde.gui.widget.layout; import mde.gui.widget.miscWidgets; +import mde.gui.widget.TextWidget; /** Create a widget of type data[0] (see enum WIDGET_TYPES) for _window window, with initialisation * data [1..$]. */
--- a/mde/gui/widget/miscWidgets.d Sat Jun 14 17:15:06 2008 +0100 +++ b/mde/gui/widget/miscWidgets.d Sat Jun 14 17:52:22 2008 +0100 @@ -20,8 +20,6 @@ import mde.gui.exception; import mde.gui.renderer.IRenderer; -import mde.resource.font; - import tango.io.Stdout; @@ -101,30 +99,3 @@ window.requestRedraw; } } - -/// Basic text widget -class TextWidget : Widget -{ - this (IWindow wind, int[] data) { - if (data.length != 2) throw new WidgetDataException; - if (font is null) font = FontStyle.get("default"); - font.updateBlock (str, textCache); - mw = cast(wdim) textCache.w; - mh = cast(wdim) textCache.h; - colour = Colour (cast(ubyte) (data[1] >> 16u), - cast(ubyte) (data[1] >> 8u), - cast(ubyte) data[1] ); - super (wind,data); - } - - void draw () { - super.draw(); - font.textBlock (x,y, str, textCache, colour); // test new-lines and unicode characters - } - -protected: - const str = "Text Widget\nαβγ − ΑΒΓ"; - TextBlock textCache; - Colour colour; - static FontStyle font; -}