sung@rigel.csc.ti.com ("Helen Chang ", sung@csc.ti.com) (05/10/91)
I'd like to display a Composition contains Labels, and update
this display when new Labels are added. Could someone help me
identify where is wrong and how to make it work?
Thanks a lot.
----------------------------------------
#include <stream.h>
#include <string.h>
#include <InterViews/arraycomp.h>
#include <InterViews/character.h>
#include <InterViews/color.h>
#include <InterViews/composition.h>
#include <InterViews/deck.h>
#include <InterViews/discretion.h>
#include <InterViews/font.h>
#include <InterViews/glyph.h>
#include <InterViews/handler.h>
#include <InterViews/label.h>
#include <InterViews/listener.h>
#include <InterViews/monoglyph.h>
#include <InterViews/patch.h>
#include <InterViews/sensor.h>
#include <InterViews/strut.h>
#include <InterViews/window.h>
#include <InterViews/world.h>
class TestViewer : public MonoGlyph, public Handler {
public:
TestViewer(Font*, Color*);
virtual void event() {}
void item_append(Glyph* );
void update();
private:
Listener* _listener;
Composition* _lines;
Patch* _textPatch;
};
TestViewer::TestViewer(Font* f, Color* fg)
: MonoGlyph(nil), Handler()
{
_lines=new TBComposition(
new Deck(),
new ArrayCompositor(1),
new Discretionary(
100,
new Character(0216, f, fg)
),
8, 5);
_textPatch = new Patch(_lines);
_listener = new Listener(_textPatch, this);
_listener->sensor()->button(true, Event::any);
_listener->sensor()->key(true);
body(_listener);
}
void TestViewer::item_append(Glyph* g)
{ _lines->append(g);
}
void TestViewer::update()
{ _lines->repair();
_textPatch->reallocate();
}
static PropertyData props[] = {
{ nil }
};
static OptionDesc options[] = {
{ nil }
};
int main(int argc, char** argv)
{
World world("Test", argc, argv, options, props);
Font* f = world.font();
Color* fg = world.foreground();
TestViewer* viewer = new TestViewer(f, fg);
// the original display in unreadable
instead of blank.
// Next 3 lines are supposed to put one line there.
/* Glyph* g = new Label("first line", f, fg);
viewer->item_append(g);
viewer->update();
*/
ApplicationWindow window(viewer);
window.map();
world.run();
return 0;
}calder@uluru.stanford.edu (Paul Calder) (05/11/91)
Helen Chang asks about updating Compositions and offers some sample
code.
Compositions take a list of glyphs and break it into smaller pieces.
Then they build composite glyphs for each of the pieces. This
functionality is usually associated with formatting text; breaking
paragraphs into lines and lines into columns are classic applications
of Compositions.
Helen, I can't see why your example needs a Composition at all. If
you just want to display a column of Labels (and have the display
update when you add new items) then a simpler arrangement will
suffice. Something like this, perhaps...
========
class TestViewer : public MonoGlyph, public Handler {
public:
TestViewer(Font*, Color*);
virtual void event() {}
void item_append(Glyph* );
void update();
private:
Listener* _listener;
TBBox* _lines;
Patch* _textPatch;
};
TestViewer::TestViewer(Font* f, Color* fg)
: MonoGlyph(nil), Handler()
{
_lines = new TBBox();
_textPatch = new Patch(_lines);
_listener = new Listener(_textPatch, this);
_listener->sensor()->button(true, Event::any);
_listener->sensor()->key(true);
body(_listener);
}
void TestViewer::item_append(Glyph* g)
{ _lines->append(g);
}
void TestViewer::update()
{ _textPatch->reallocate();
}
--
Paul Calder
Computer Systems Lab
Stanford University
calder@lurch.stanford.edusung@rigel.csc.ti.com ("Helen Chang ", sung@csc.ti.com) (05/11/91)
Paul, > Compositions take a list of glyphs and break it into smaller pieces. > Then they build composite glyphs for each of the pieces. This > functionality is usually associated with formatting text; breaking > paragraphs into lines and lines into columns are classic applications > of Compositions. > Helen, I can't see why your example needs a Composition at all. If > you just want to display a column of Labels (and have the display > update when you add new items) then a simpler arrangement will > suffice. Something like this, perhaps... Thanks for the reply and codes. However, I would like to arrange those label in a form like texts (but the contents are all Labels of text string intead of individual characters). I reduced codes to one layer of composite glyph hoping to find out why was the display blurred. The TBBox version also produces a similar image consists of look-like randon green/blue/white spots (instead of readable text such as "first line"). Why is it? Thanks in advance. Helen Chang
calder@ULURU.STANFORD.EDU (Paul Calder) (05/11/91)
Helen,
The 'random' window happens because you haven't defined a background
(the colored dots come from an unitialized pixmap). You need to
put the top-level glyph inside a Background.
int main(int argc, char** argv)
{
Color* bg = world.background();
...
ApplicationWindow window(new Background(viewer, bg));
window.map();
world.run();
return 0;
}