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 >
C/C++ Source or Header  |  1992-02-27  |  5KB  |  174 lines

  1. /* @(#)mickey.C    1.7 7/29/91 */
  2.  
  3. #include <Gina/Gina.h>
  4.  
  5. #ifdef INCLUDE_SRC
  6. #include "Gina.C"
  7. #endif
  8.  
  9. class MickeyApplication : public GnApplication {
  10.   public:
  11.     GnDocument *create_document ();
  12.  
  13.     char * app_class () { return "Mickey" ; }
  14.     char * app_signature() { return "mickey" ; }
  15.     char * app_file_type() { return ".mickey" ; }
  16. };
  17.  
  18. class MickeyView : public GnView {
  19.   public:
  20.     MickeyView (GnDocument *);
  21.     void draw (int count, int x, int y, Dimension width, Dimension height);
  22. };
  23.  
  24. class MickeyDocument : public GnDocument {
  25.     friend void MickeyView :: draw (int count, int x, int y,
  26.                     Dimension width, Dimension height);
  27.   public:
  28.     MickeyDocument();
  29.     virtual void create_windows(int new_width = 0, int new_height = 0);
  30.     void new_mickey_height(XmScaleCallbackStruct *);
  31.     void new_mickey_width(XmScaleCallbackStruct *);
  32.  
  33.     // Document IO
  34.     virtual Boolean write_to_stream ( ostream & );
  35.     virtual Boolean read_from_stream ( istream & );
  36.  
  37.   private:
  38.     GnScale *vScale;
  39.     GnScale *hScale;
  40.     Dimension mickeyWidth;
  41.     Dimension mickeyHeight;
  42. };
  43.  
  44. //---------------------------------------------------------------------
  45.  
  46. GnDocument *MickeyApplication ::
  47. create_document () { return new MickeyDocument; }
  48.  
  49. //---------------------------------------------------------------------
  50.  
  51. MickeyDocument ::
  52. MickeyDocument()
  53. {
  54.     mickeyWidth = 100;
  55.     mickeyHeight = 100;
  56. }
  57.  
  58. void MickeyDocument ::
  59. create_windows(int new_width, int new_height)
  60. {
  61.     main_shell = new GnDocumentShell( this, new_width, new_height);
  62.     main_shell->create(GnApplication::get()->get_application_shell(), "shell");
  63.  
  64.     GnForm *form = new GnForm;
  65.     form->create(main_shell, "mickeyForm");
  66.  
  67.     vScale = new GnScale;
  68.     vScale->setR_processingDirection(XmMAX_ON_BOTTOM);
  69.     vScale->setR_value(mickeyHeight);
  70.     vScale->setR_maximum(500);
  71.     vScale->setR_topAttachment(XmATTACH_FORM);
  72.     vScale->setR_topOffset(17);
  73.     vScale->setR_leftAttachment(XmATTACH_FORM);
  74.     vScale->setR_bottomAttachment(XmATTACH_FORM);
  75.     vScale->create(form, "vScale");
  76.  
  77.     hScale = new GnScale;
  78.     hScale->setR_orientation(XmHORIZONTAL);
  79.     hScale->setR_value(mickeyWidth);
  80.     hScale->setR_maximum(500);
  81.     hScale->setR_topAttachment(XmATTACH_FORM);
  82.     hScale->setR_leftAttachment(XmATTACH_WIDGET);
  83.     hScale->setR_leftWidget(vScale);
  84.     hScale->setR_rightAttachment(XmATTACH_FORM);
  85.     hScale->create(form, "hScale");
  86.  
  87.     GnStaticScrolledWindow *scroller = new GnStaticScrolledWindow;
  88.     scroller->setR_topAttachment(XmATTACH_WIDGET);
  89.     scroller->setR_topWidget(hScale);
  90.     scroller->setR_leftAttachment(XmATTACH_WIDGET);
  91.     scroller->setR_leftWidget(vScale);
  92.     scroller->setR_rightAttachment(XmATTACH_FORM);
  93.     scroller->setR_bottomAttachment(XmATTACH_FORM);
  94.     scroller->create(form, "scrolledWindow");
  95.  
  96.     main_view = new MickeyView(this);
  97.     main_view->setR_width(500);
  98.     main_view->setR_height(500);
  99.     main_view->create(scroller, "mainView");
  100.  
  101.     vScale->add_dragCallback(CALLBACK(MickeyDocument,new_mickey_height,this));
  102.     vScale->add_valueChangedCallback(CALLBACK(MickeyDocument,
  103.                           new_mickey_height,this));
  104.     hScale->add_dragCallback(CALLBACK(MickeyDocument,new_mickey_width,this));
  105.     hScale->add_valueChangedCallback(CALLBACK(MickeyDocument,
  106.                           new_mickey_width,this));
  107. }
  108.  
  109. void MickeyDocument ::
  110. new_mickey_height(XmScaleCallbackStruct *new_height)
  111. {
  112.     mickeyHeight = new_height->value;
  113.     main_view->force_redraw();
  114.     set_modified(True);
  115. }
  116.  
  117. void MickeyDocument ::
  118. new_mickey_width(XmScaleCallbackStruct *new_width)
  119. {
  120.     mickeyWidth = new_width->value;
  121.     main_view->force_redraw();
  122.     set_modified(True);
  123. }
  124.  
  125. Boolean MickeyDocument ::
  126. write_to_stream( ostream &ofs )
  127. {
  128.     ofs << mickeyWidth << " " << mickeyHeight << endl;
  129.     return True;
  130. }
  131.  
  132. Boolean MickeyDocument ::
  133. read_from_stream ( istream &ifs )
  134. {
  135.     ifs >> mickeyWidth >> mickeyHeight;
  136.     vScale->setR_value(mickeyHeight);
  137.     vScale->SetValues();
  138.     hScale->setR_value(mickeyWidth);
  139.     hScale->SetValues();
  140.     return True;
  141. }
  142.  
  143. //---------------------------------------------------------------------
  144. MickeyView ::
  145. MickeyView ( GnDocument* doc )
  146. : GnView( doc )
  147. {}
  148.  
  149. void MickeyView ::
  150. draw(int count, int /*x*/, int /*y*/, Dimension /*width*/, Dimension /*height*/)
  151. {
  152. //    if ( count ) return; // tut nicht wegen clipping
  153.  
  154.     Dimension w = ((MickeyDocument*)document)->mickeyWidth;
  155.     Dimension h = ((MickeyDocument*)document)->mickeyHeight;
  156.     draw_arc(w*35/100, h*43/100, w*50/100, h*50/100, 0, 360*64); // head
  157.     draw_arc(w*30/100, h*30/100, w*20/100, h*20/100, 0, 360*64, True); // ears
  158.     draw_arc(w*70/100, h*30/100, w*20/100, h*20/100, 0, 360*64, True);
  159.     draw_arc(w*58/100, h*64/100, w* 5/100, h* 5/100, 0, 360*64, True); // nose
  160.     draw_arc(w*50/100, h*55/100, w* 5/100, h* 5/100, 0, 360*64); // eyes
  161.     draw_arc(w*65/100, h*55/100, w* 5/100, h* 5/100, 0, 360*64);
  162.     draw_arc(w*45/100, h*50/100, w*30/100, h*30/100, 234*64, 72*64); // mouth
  163. }
  164.  
  165. //---------------------------------------------------------------------
  166. int main (unsigned int argc, char ** argv)
  167. {
  168.     MickeyApplication tea;
  169. #ifdef GINA_DEBUG
  170.     tea.set_sync();
  171. #endif
  172.     tea.run ( argc, argv );
  173. }
  174.