home *** CD-ROM | disk | FTP | other *** search
- #include "rb_plugin.h"
-
- // An original (but useless) creation by:
- // Shane Blackburn © 1998
-
-
- extern struct REALcontrol boilerplate_Control;
-
- //*************************************
- //* PROPERTIES STRUCT *
- //*************************************
-
- struct boilerplate_Data
- {
- int backColour;
- int rivetFace;
- int rivetShadow;
- int xRivets;
- int yRivets;
- int spacing;
- int xMargin;
- int yMargin;
- int diam;
- Boolean rivets;
- Boolean outerFrame;
- Boolean innerFrame;
- };
-
- //*************************************
- //* SUPPORT ROUTINES *
- //*************************************
-
- //----------------------------------------------------------------
-
- RGBColor faceCol,shadowCol;
- int dx,dy;
-
- //----------------------------------------------------------------
- int setRGB(int r,int g,int b)
- {
- return r*(256*256)+g*256+b;
- }
- //----------------------------------------------------------------
- RGBColor getRGB(int c)
- {
- RGBColor col;
-
- col.red=(c >> 16) *257;
- col.green=((c >> 8) & 0xFF) *257;
- col.blue=(c & 0xFF) *257;
-
- return col;
- }
- //----------------------------------------------------------------
- void drawRivet(int x,int y,int d,int xMargin,int yMargin)
- {
- Rect r;
-
- SetRect(&r,
- x+xMargin/2-d/2+dx,y+yMargin/2-d/2+dy,
- x+xMargin/2+(d-d/2)+dx,y+yMargin/2+(d-d/2)+dy);
- RGBForeColor(&shadowCol);
- PaintOval(&r);
- SetRect(&r,
- x+xMargin/2-d/2,y+yMargin/2-d/2,
- x+xMargin/2+(d-d/2),y+yMargin/2+(d-d/2));
- RGBForeColor(&faceCol);
- PaintOval(&r);
- }
- //----------------------------------------------------------------
-
- //*************************************
- //* METHODS IMPLEMENTATION *
- //*************************************
-
- //----------------------------------------------------------------
- static int boilerplate_xRivets(REALcontrolInstance instance)
- {
- ControlData(boilerplate_Control, instance, boilerplate_Data, data);
-
- return data->xRivets+1;
- }
- //----------------------------------------------------------------
- static int boilerplate_yRivets(REALcontrolInstance instance)
- {
- ControlData(boilerplate_Control, instance, boilerplate_Data, data);
-
- return data->yRivets+1;
- }
- //----------------------------------------------------------------
- static void boilerplate_Init(REALcontrolInstance instance)
- {
- ControlData(boilerplate_Control, instance, boilerplate_Data, data);
- //default settings
- data->diam=2;
- data->xMargin=10;
- data->yMargin=10;
- data->spacing=30;
- data->rivets=false;
- data->innerFrame=false;
- data->outerFrame=true;
- data->backColour=setRGB(180,180,180);
- data->rivetFace=setRGB(230,230,230);
- data->rivetShadow=setRGB(128,128,128);
- }
- //----------------------------------------------------------------
- static void boilerplate_Paint(REALcontrolInstance instance)
- {
- Rect b;
- RGBColor fillCol,old;
- int i,width,height;
- float w,h,x,y;
-
- ControlData(boilerplate_Control, instance, boilerplate_Data, data);
- REALGetControlBounds(instance, &b);
-
- GetForeColor(&old);
-
- if (data->rivets)
- {dx=1; dy=1;}
- else
- {dx=-1; dy=-1;}
-
- width=b.right-b.left- data->xMargin;
- height=b.bottom-b.top- data->yMargin;
- data->xRivets=width/ data->spacing; w=width/ data->xRivets;
- data->yRivets=height/ data->spacing; h=height/ data->yRivets;
-
- fillCol=getRGB(data->backColour);
- shadowCol=getRGB(data->rivetShadow);
- faceCol=getRGB(data->rivetFace);
-
- RGBForeColor(&fillCol);
- PaintRect(&b);
-
- x=b.left; y=b.top;
- for (i=0;i<data->xRivets;i++)
- {
- drawRivet(x,b.top, data->diam, data->xMargin, data->yMargin);
- drawRivet(x,b.bottom, data->diam, data->xMargin, -data->yMargin);
- x=x+w;
- }
-
- drawRivet(b.right,b.top, data->diam, -data->xMargin, data->yMargin);
- drawRivet(b.right,b.bottom, data->diam, -data->xMargin, -data->yMargin);
-
- for (i=1;i< data->yRivets;i++)
- {
- y=y+h;
- drawRivet(b.left,y, data->diam, data->xMargin, data->yMargin);
- drawRivet(b.right,y, data->diam, -data->xMargin, data->yMargin);
- }
-
- RGBForeColor(&shadowCol);
-
- if (data->outerFrame) FrameRect(&b);
-
- if (data->innerFrame)
- {
- InsetRect(&b,1,1);
- width+=data->xMargin-2; height+=data->yMargin-2;
- MoveTo(b.left+data->xMargin,b.top); Line(0,height);
- MoveTo(b.right-data->xMargin,b.top); Line(0,height);
- MoveTo(b.left,b.top+data->yMargin); Line(width,0);
- MoveTo(b.left,b.bottom-data->yMargin); Line(width,0);
-
- RGBForeColor(&faceCol);
- MoveTo(b.left+data->xMargin-dx,b.top); Line(0,height);
- MoveTo(b.right-data->xMargin-dx,b.top); Line(0,height);
- MoveTo(b.left,b.top+data->yMargin-dy); Line(width,0);
- MoveTo(b.left,b.bottom-data->yMargin-dy); Line(width,0);
- }
- RGBForeColor(&old);
- }
- //-------------------------------------------------------------
-
- //*************************************
- //* EXPORT TABLE *
- //*************************************
- REALexport pluginExports[] = {
- { nil, boilerplate_Init},
- { nil, boilerplate_Paint},
- { nil, boilerplate_xRivets},
- { nil, boilerplate_yRivets},
- };
-
- short pluginExportCode = sizeof(pluginExports) / sizeof(REALexport);
-
-
-
- //*************************************
- //* PLUGIN DEFINITION *
- //*************************************
-
- REALproperty boilerplate_Properties[] = {
- { "Colouring", "FillColour", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, backColour) },
- { "Colouring", "RivetFace", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivetFace) },
- { "Colouring", "RivetShadow", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivetShadow) },
- { "Appearance", "MinSpacing", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, spacing) },
- { "Appearance", "xMargin", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, xMargin) },
- { "Appearance", "yMargin", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, yMargin) },
- { "Appearance", "Diameter", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, diam) },
- { "Appearance", "Rivet", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivets) },
- { "Appearance", "OuterFrame", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, outerFrame) },
- { "Appearance", "InnerFrame", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, innerFrame) }
- };
-
- //seem to need at least one event defined here,
- //so this is it...
- REALevent boilerplate_Events[] = {
- {"Action" }
- };
-
- //having no methods seems to cause a problem, so here are
- //some getter functions of dubious importance
- REALmethodDefinition boilerplate_Methods[] = {
- {2,REALnoImplementation,"xRivets as integer"},
- {3,REALnoImplementation,"yRivets as integer"},
- };
-
- REALcontrolBehaviour boilerplate_Behaviour = {
- &pluginExports[0],
- nil,
- &pluginExports[1],
- nil,
- nil,
- nil,
- };
-
- REALcontrol boilerplate_Control = {
- kCurrentREALControlVersion,
- "BoilerPlate",
- sizeof(boilerplate_Data),
- 0,
- 169,
- 170,
- 64, 64,
- boilerplate_Properties,
- sizeof(boilerplate_Properties) / sizeof(REALproperty),
- boilerplate_Methods,
- sizeof(boilerplate_Methods) / sizeof(REALmethodDefinition),
- boilerplate_Events,
- sizeof(boilerplate_Events) / sizeof(REALevent),
- &boilerplate_Behaviour
- };
-
- void PluginEntry(void)
- {
- REALRegisterControl(&boilerplate_Control);
- }
-