home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / precg105.lha / source / GraphicObject.c < prev    next >
C/C++ Source or Header  |  1992-12-24  |  6KB  |  284 lines

  1. /* ==========================================================================
  2. **
  3. **                          GraphicObject.c
  4. **
  5. **   ©1991 WILLISoft
  6. **
  7. ** ==========================================================================
  8. */
  9. #include "GraphicObject.h"
  10. #include "GraphicObjectClass.h"
  11.  
  12. void
  13. GraphicObject_CleanUp( GraphicObject *self )
  14. {
  15.    SetTitle( self, NULL );
  16. }
  17.  
  18.  
  19. BOOL GraphicObject_elaborated = FALSE;
  20.  
  21. struct GraphicObjectClass GraphicObject_Class;
  22.  
  23. void GraphicObjectClass_Init( struct GraphicObjectClass *class )
  24. {
  25.    PObjectClass_Init( (struct PObjectClass *) class );
  26.    class->isa            = PObjectClass();
  27.    class->ClassName      = "GraphicObject";
  28.    class->CleanUp        = GraphicObject_CleanUp;
  29.    class->Location       = NULL;
  30.    class->SetLocation    = NULL;
  31.    class->Size           = NULL;
  32.    class->AskSize        = NULL;
  33.    class->SetSize        = NULL;
  34.    class->SizeFlags      = GraphicObject_SizeFlagsAll;
  35.                            /* default to sizeable on both axis. */
  36.    class->Render           = NULL;
  37.    class->SetTitle         = NULL;
  38.    class->Title            = NULL;
  39.    class->BuilderMethods   = NULL;
  40.    class->TextAlignment    = NULL;
  41.    class->SetTextAlignment = NULL;
  42. }
  43.  
  44.  
  45. struct GraphicObjectClass *GraphicObjectClass( void )
  46. {
  47.    if (! GraphicObject_elaborated)
  48.    {
  49.       GraphicObjectClass_Init( &GraphicObject_Class );
  50.       GraphicObject_elaborated = TRUE;
  51.    }
  52.  
  53.    return &GraphicObject_Class;
  54. }
  55.  
  56.  
  57.  
  58. Point Point_ZeroZero = {0,0};
  59.  
  60.  
  61. Point Location( GraphicObject *self )
  62. /* Returns the LeftEdge, TopEdge of 'self'. */
  63. {
  64.    Point                     pos;
  65.    struct GraphicObjectClass *class;
  66.  
  67.    pos = Point_ZeroZero;
  68.  
  69.    if (class = (struct GraphicObjectClass *) self->isa)
  70.    {
  71.       if (class->Location)
  72.          pos = (*class->Location)( self );
  73.    }
  74.    return pos;
  75. }
  76.  
  77.  
  78. Point SetLocation( GraphicObject *self,
  79.                    PIXELS         LeftEdge,
  80.                    PIXELS         TopEdge )
  81. /* Sets the LeftEdge, TopEdge of 'self'.
  82.  * Returns the LeftEdge, TopEdge.
  83.  */
  84. {
  85.    Point                     pos;
  86.    struct GraphicObjectClass *class;
  87.  
  88.    pos = Point_ZeroZero;
  89.  
  90.    if (class = (struct GraphicObjectClass *) self->isa)
  91.    {
  92.       if (class->SetLocation)
  93.          pos = (*class->SetLocation)( self, LeftEdge, TopEdge );
  94.    }
  95.    return pos;
  96. }
  97.  
  98.  
  99. Point Size( GraphicObject *self )
  100. /* Returns the Width, Height of 'self'.
  101.  */
  102. {
  103.    Point                      size;
  104.    struct GraphicObjectClass *class;
  105.  
  106.    size = Point_ZeroZero;
  107.  
  108.    if (class = (struct GraphicObjectClass *) self->isa)
  109.    {
  110.       if (class->Size)
  111.          size = (*class->Size)( self );
  112.    }
  113.    return size;
  114. }
  115.  
  116.  
  117. Point AskSize( GraphicObject *self,
  118.                PIXELS         Width,
  119.                PIXELS         Height )
  120. /* Given a (Width, Height), returns the nearest (Width, Height)
  121.  * that 'self' modify itself to be.  Does NOT actually change
  122.  * the dimensions of 'self'.
  123.  */
  124. {
  125.    Point                       size;
  126.    struct GraphicObjectClass *class;
  127.  
  128.    size = Point_ZeroZero;
  129.  
  130.    if (class = (struct GraphicObjectClass *) self->isa)
  131.    {
  132.       if (class->AskSize)
  133.          size = (*class->AskSize)( self, Width, Height );
  134.    }
  135.    return size;
  136. }
  137.  
  138.  
  139. Point SetSize( GraphicObject *self,
  140.                 PIXELS         Width,
  141.                 PIXELS         Height )
  142. /* Sets 'self's size to be as near (Width, Height) as possible,
  143.  * returns the actual (Width, Height).
  144.  */
  145. {
  146.    Point                       size;
  147.    struct GraphicObjectClass *class;
  148.  
  149.    size = Point_ZeroZero;
  150.  
  151.    if (class = (struct GraphicObjectClass *) self->isa)
  152.    {
  153.       if (class->SetSize)
  154.          size = (*class->SetSize)( self, Width, Height );
  155.    }
  156.    return size;
  157. }
  158.  
  159.  
  160. UWORD SizeFlags( GraphicObject *self )
  161. {
  162.    struct GraphicObjectClass *class;
  163.    UWORD flags;
  164.  
  165.    if (class = (struct GraphicObjectClass *) self->isa)
  166.    {
  167.       if (class->SizeFlags)
  168.          flags = (*class->SizeFlags)( self );
  169.    }
  170.    return flags;
  171. }
  172.  
  173.  
  174.  
  175. void Render( GraphicObject *self,
  176.              RastPort      *RPort )
  177. {
  178.    struct GraphicObjectClass *class;
  179.  
  180.  
  181.    if (class = (struct GraphicObjectClass *) self->isa)
  182.    {
  183.       if (class->Render)
  184.          (*class->Render)( self, RPort );
  185.    }
  186. }
  187.  
  188.  
  189.  
  190. UWORD GraphicObject_SizeFlagsNone( GraphicObject *self )
  191. {
  192.    return 0;
  193. }
  194.  
  195. UWORD GraphicObject_SizeFlagsX( GraphicObject *self )
  196. {
  197.    return OBJSIZE_X;
  198. }
  199.  
  200. UWORD GraphicObject_SizeFlagsY( GraphicObject *self )
  201. {
  202.    return OBJSIZE_Y;
  203. }
  204.  
  205. UWORD GraphicObject_SizeFlagsAll( GraphicObject *self )
  206. {
  207.    return OBJSIZE_X | OBJSIZE_Y;
  208. }
  209.  
  210.  
  211. BOOL SetTitle( GraphicObject *self, char *title )
  212. {
  213.    struct GraphicObjectClass *class;
  214.  
  215.  
  216.    if (class = (struct GraphicObjectClass *) self->isa)
  217.    {
  218.       if (class->SetTitle)
  219.          return (*class->SetTitle)( self, title );
  220.       else
  221.          return FALSE;
  222.    }
  223.    return FALSE;
  224.  
  225. }
  226.  
  227.  
  228. char *Title( GraphicObject *self )
  229. /* Returns a pointer to the title of an object, or NULL if none. */
  230. {
  231.    struct GraphicObjectClass *class;
  232.  
  233.  
  234.    if (class = (struct GraphicObjectClass *) self->isa)
  235.    {
  236.       if (class->Title)
  237.          return (*class->Title)( self );
  238.       else
  239.          return NULL;
  240.    }
  241.    return NULL;
  242. }
  243.  
  244. AlignInfo go_DefaultAlignment = { 0xFF, 0, 0, };
  245.  
  246. AlignInfo TextAlignment( GraphicObject *self )
  247. {
  248.    struct GraphicObjectClass *class;
  249.  
  250.    if (class = (struct GraphicObjectClass *) self->isa)
  251.    {
  252.       if (class->TextAlignment)
  253.          return (*class->TextAlignment)(self);
  254.       else
  255.          return go_DefaultAlignment;
  256.    }
  257. }
  258.  
  259. AlignInfo SetTextAlignment( GraphicObject *self,
  260.                             UBYTE         Flags,
  261.                             BYTE          Xpad,
  262.                             BYTE          Ypad )
  263. {
  264.    struct GraphicObjectClass *class;
  265.  
  266.    if (class = (struct GraphicObjectClass *) self->isa)
  267.    {
  268.       if (class->SetTextAlignment)
  269.          return (*class->SetTextAlignment)(self, Flags, Xpad, Ypad);
  270.       else
  271.          return go_DefaultAlignment;
  272.    }
  273. }
  274.  
  275.  
  276.  
  277. void GraphicObject_Init( GraphicObject *self )
  278. {
  279.    PObject_Init( self );
  280.  
  281.    self->isa = GraphicObjectClass();
  282.    self->Next = NULL;
  283. }
  284.