home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / TitleBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  5.3 KB  |  206 lines

  1.  
  2. #include "parms.h" /* added for proper prototyping -- EDB */
  3. #include "GraphicObject.h"
  4. #include "GraphicObjectClass.h"
  5. #include "TitleBox.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "minmax.h"
  9. #include <graphics/gfxmacros.h>
  10. #ifndef __GNUC__
  11. #include <clib/exec_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/graphics_protos.h>
  14. #endif
  15. #ifdef __GNUC__
  16. #include <proto/exec.h>
  17. #include <proto/intuition.h>
  18. #include <proto/graphics.h>
  19. #endif
  20. #ifdef __SASC
  21. #include <proto/exec.h>
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24. #endif
  25. #include "amigamem.h"
  26.  
  27. Point TitleBox_Location( TitleBox *self )
  28. {
  29.    return self->Location;
  30. }
  31.  
  32.  
  33. Point TitleBox_SetLocation( TitleBox *self,
  34.                              PIXELS    LeftEdge,
  35.                              PIXELS    TopEdge )
  36. {
  37.    self->Location.x = LeftEdge;
  38.    self->Location.y = TopEdge;
  39.    return self->Location;
  40. }
  41.  
  42. Point TitleBox_Size( TitleBox *self )
  43. {
  44.    return self->Size;
  45. }
  46.  
  47. Point TitleBox_AskSize( TitleBox      *self,
  48.                          PIXELS         Width,
  49.                          PIXELS         Height )
  50. {
  51.    Point size;
  52.  
  53.    size.x = MAX( Width, 6 );
  54.    size.y = MAX( Height, 6 );
  55.    return size;
  56. }
  57.  
  58.  
  59. Point TitleBox_SetSize( TitleBox *self,
  60.                          PIXELS    Width,
  61.                          PIXELS    Height )
  62. {
  63.    Point size;
  64.  
  65.    size = AskSize( (GraphicObject *)self, Width, Height );
  66.    self->Size.x = size.x;
  67.    self->Size.y = size.y;
  68.  
  69.    pcg_Init3DBox( &self->BoxBorder, 0,0, size.x, size.y,
  70.       self->Pens.BrightPen, self->Pens.DarkPen, NULL );
  71.  
  72.    AlignText( &self->ptext, size );
  73.    return size;
  74. }
  75.  
  76. USHORT TitleBox_DitherPattern[] = { 0x5555, 0xAAAA };
  77.  
  78.  
  79.  
  80. void TitleBox_Render( TitleBox *self,
  81.                       RastPort *RPort )
  82. {
  83.    PIXELS xmin, xmax, ymin, ymax;
  84.  
  85.    xmin = self->Location.x;
  86.    xmax = xmin + self->Size.x - 1;
  87.    ymin = self->Location.y;
  88.    ymax = ymin + self->Size.y - 1;
  89.  
  90.    SetAfPt( RPort, TitleBox_DitherPattern, 1 );
  91.    SetAPen( RPort, self->Pens.BackPen );
  92.    SetBPen( RPort, self->Pens.DarkPen );
  93.    SetDrMd( RPort, JAM2 );
  94.    RectFill( RPort, xmin, ymin, xmax, ymax );
  95.    SetAfPt( RPort, NULL, 0 );
  96.  
  97.  
  98.    DrawBorder( RPort, &self->BoxBorder.TopLeft, xmin, ymin );
  99.  
  100.    SetDrMd( RPort, JAM1 );
  101.    SetAPen( RPort, self->Pens.BrightPen );
  102.  
  103.    PrintIText( RPort, (struct IntuiText *)&self->ptext, xmin, ymin  );
  104. }
  105.  
  106. char *TitleBox_Title( TitleBox *self )
  107. {
  108.    return (char *)self->ptext.IText;
  109. }
  110.  
  111. BOOL TitleBox_SetTitle( TitleBox *self, char *title )
  112. {
  113.    Afree(self->ptext.IText);
  114.    self->ptext.IText = Astrdup(title);
  115.    AlignText( &self->ptext, Size( (GraphicObject *)self ) );
  116.  
  117.    return TRUE;
  118. }
  119.  
  120. AlignInfo *TitleBox_TextAlignment( TitleBox *self )
  121. {
  122.    return( &(self->ptext.alignment) );
  123. }
  124.  
  125. BOOL TitleBox_SetTextAlignment( TitleBox *self,
  126.                                      UBYTE     Flags,
  127.                                      BYTE      Xpad,
  128.                                      BYTE      Ypad )
  129. {
  130.    self->ptext.alignment.Flags = Flags;
  131.    self->ptext.alignment.Xpad  = Xpad;
  132.    self->ptext.alignment.Ypad  = Ypad;
  133.    AlignText( &self->ptext, Size( (GraphicObject *)self ) );
  134.    return TRUE;
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141. BOOL TitleBox_elaborated = FALSE;
  142.  
  143. struct GraphicObjectClass TitleBox_Class;
  144.  
  145.  
  146. void TitleBoxClass_Init( struct GraphicObjectClass *class )
  147. {
  148.    GraphicObjectClass_Init( class );
  149.    class->isa         = GraphicObjectClass();
  150.    class->ClassName   = "TitleBox";
  151.    class->CleanUp     = NULL;
  152.    class->Location    = (Point(*)(GraphicObject *))TitleBox_Location;
  153.    class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))TitleBox_SetLocation;
  154.    class->Size        = (Point(*)(GraphicObject *))TitleBox_Size;
  155.    class->AskSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))TitleBox_AskSize;
  156.    class->SetSize     = (Point(*)(GraphicObject *, PIXELS,PIXELS))TitleBox_SetSize;
  157.    class->SizeFlags   = GraphicObject_SizeFlagsAll;
  158.    class->Render      = (void(*)(GraphicObject *, RastPort *))TitleBox_Render;
  159.    class->SetTitle    = (BOOL(*)(GraphicObject *, char *))TitleBox_SetTitle;
  160.    class->Title       = (char*(*)(GraphicObject *))TitleBox_Title;
  161.    class->TextAlignment = (AlignInfo*(*)(GraphicObject *))TitleBox_TextAlignment;
  162.    class->SetTextAlignment = (BOOL(*)(GraphicObject *,UBYTE, BYTE, BYTE))TitleBox_SetTextAlignment;
  163.  
  164. }
  165.  
  166.  
  167. struct GraphicObjectClass *TitleBoxClass( void )
  168. {
  169.    if( ! TitleBox_elaborated )
  170.    {
  171.       TitleBoxClass_Init( &TitleBox_Class );
  172.       TitleBox_elaborated = TRUE;
  173.    }
  174.  
  175.    return &TitleBox_Class;
  176. }
  177.  
  178. void TitleBox_Init( TitleBox    *self,
  179.                     PIXELS       LeftEdge,
  180.                     PIXELS       TopEdge,
  181.                     PIXELS       Width,
  182.                     PIXELS       Height,
  183.                     pcg_3DPens   Pens,
  184.                     char        *Label )
  185. {
  186.    GraphicObject_Init( (GraphicObject *)self );
  187.  
  188.    self->isa         = TitleBoxClass();
  189.    self->Pens        = Pens;
  190.  
  191.    self->ptext.FrontPen  = Pens.BrightPen;
  192.    self->ptext.BackPen   = Pens.BackPen;
  193.    self->ptext.DrawMode  = JAM1;
  194.    self->ptext.ITextFont = &pcg_Topaz80;
  195.    self->ptext.IText     = NULL;
  196.    self->ptext.NextText  = NULL;
  197.  
  198.    self->ptext.alignment.Flags = tx_XCENTER | tx_YCENTER | tx_INSIDE;
  199.    self->ptext.alignment.Xpad  = STD_XPAD;
  200.    self->ptext.alignment.Ypad  = STD_YPAD;
  201.  
  202.    SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
  203.    SetSize( (GraphicObject *)self, Width, Height );
  204.    SetTitle( (GraphicObject *)self, Label );
  205. }
  206.