home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
g
/
gina15.zip
/
demos
/
mickey.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-27
|
5KB
|
174 lines
/* @(#)mickey.C 1.7 7/29/91 */
#include <Gina/Gina.h>
#ifdef INCLUDE_SRC
#include "Gina.C"
#endif
class MickeyApplication : public GnApplication {
public:
GnDocument *create_document ();
char * app_class () { return "Mickey" ; }
char * app_signature() { return "mickey" ; }
char * app_file_type() { return ".mickey" ; }
};
class MickeyView : public GnView {
public:
MickeyView (GnDocument *);
void draw (int count, int x, int y, Dimension width, Dimension height);
};
class MickeyDocument : public GnDocument {
friend void MickeyView :: draw (int count, int x, int y,
Dimension width, Dimension height);
public:
MickeyDocument();
virtual void create_windows(int new_width = 0, int new_height = 0);
void new_mickey_height(XmScaleCallbackStruct *);
void new_mickey_width(XmScaleCallbackStruct *);
// Document IO
virtual Boolean write_to_stream ( ostream & );
virtual Boolean read_from_stream ( istream & );
private:
GnScale *vScale;
GnScale *hScale;
Dimension mickeyWidth;
Dimension mickeyHeight;
};
//---------------------------------------------------------------------
GnDocument *MickeyApplication ::
create_document () { return new MickeyDocument; }
//---------------------------------------------------------------------
MickeyDocument ::
MickeyDocument()
{
mickeyWidth = 100;
mickeyHeight = 100;
}
void MickeyDocument ::
create_windows(int new_width, int new_height)
{
main_shell = new GnDocumentShell( this, new_width, new_height);
main_shell->create(GnApplication::get()->get_application_shell(), "shell");
GnForm *form = new GnForm;
form->create(main_shell, "mickeyForm");
vScale = new GnScale;
vScale->setR_processingDirection(XmMAX_ON_BOTTOM);
vScale->setR_value(mickeyHeight);
vScale->setR_maximum(500);
vScale->setR_topAttachment(XmATTACH_FORM);
vScale->setR_topOffset(17);
vScale->setR_leftAttachment(XmATTACH_FORM);
vScale->setR_bottomAttachment(XmATTACH_FORM);
vScale->create(form, "vScale");
hScale = new GnScale;
hScale->setR_orientation(XmHORIZONTAL);
hScale->setR_value(mickeyWidth);
hScale->setR_maximum(500);
hScale->setR_topAttachment(XmATTACH_FORM);
hScale->setR_leftAttachment(XmATTACH_WIDGET);
hScale->setR_leftWidget(vScale);
hScale->setR_rightAttachment(XmATTACH_FORM);
hScale->create(form, "hScale");
GnStaticScrolledWindow *scroller = new GnStaticScrolledWindow;
scroller->setR_topAttachment(XmATTACH_WIDGET);
scroller->setR_topWidget(hScale);
scroller->setR_leftAttachment(XmATTACH_WIDGET);
scroller->setR_leftWidget(vScale);
scroller->setR_rightAttachment(XmATTACH_FORM);
scroller->setR_bottomAttachment(XmATTACH_FORM);
scroller->create(form, "scrolledWindow");
main_view = new MickeyView(this);
main_view->setR_width(500);
main_view->setR_height(500);
main_view->create(scroller, "mainView");
vScale->add_dragCallback(CALLBACK(MickeyDocument,new_mickey_height,this));
vScale->add_valueChangedCallback(CALLBACK(MickeyDocument,
new_mickey_height,this));
hScale->add_dragCallback(CALLBACK(MickeyDocument,new_mickey_width,this));
hScale->add_valueChangedCallback(CALLBACK(MickeyDocument,
new_mickey_width,this));
}
void MickeyDocument ::
new_mickey_height(XmScaleCallbackStruct *new_height)
{
mickeyHeight = new_height->value;
main_view->force_redraw();
set_modified(True);
}
void MickeyDocument ::
new_mickey_width(XmScaleCallbackStruct *new_width)
{
mickeyWidth = new_width->value;
main_view->force_redraw();
set_modified(True);
}
Boolean MickeyDocument ::
write_to_stream( ostream &ofs )
{
ofs << mickeyWidth << " " << mickeyHeight << endl;
return True;
}
Boolean MickeyDocument ::
read_from_stream ( istream &ifs )
{
ifs >> mickeyWidth >> mickeyHeight;
vScale->setR_value(mickeyHeight);
vScale->SetValues();
hScale->setR_value(mickeyWidth);
hScale->SetValues();
return True;
}
//---------------------------------------------------------------------
MickeyView ::
MickeyView ( GnDocument* doc )
: GnView( doc )
{}
void MickeyView ::
draw(int count, int /*x*/, int /*y*/, Dimension /*width*/, Dimension /*height*/)
{
// if ( count ) return; // tut nicht wegen clipping
Dimension w = ((MickeyDocument*)document)->mickeyWidth;
Dimension h = ((MickeyDocument*)document)->mickeyHeight;
draw_arc(w*35/100, h*43/100, w*50/100, h*50/100, 0, 360*64); // head
draw_arc(w*30/100, h*30/100, w*20/100, h*20/100, 0, 360*64, True); // ears
draw_arc(w*70/100, h*30/100, w*20/100, h*20/100, 0, 360*64, True);
draw_arc(w*58/100, h*64/100, w* 5/100, h* 5/100, 0, 360*64, True); // nose
draw_arc(w*50/100, h*55/100, w* 5/100, h* 5/100, 0, 360*64); // eyes
draw_arc(w*65/100, h*55/100, w* 5/100, h* 5/100, 0, 360*64);
draw_arc(w*45/100, h*50/100, w*30/100, h*30/100, 234*64, 72*64); // mouth
}
//---------------------------------------------------------------------
int main (unsigned int argc, char ** argv)
{
MickeyApplication tea;
#ifdef GINA_DEBUG
tea.set_sync();
#endif
tea.run ( argc, argv );
}