#include "library.h" struct component; const int maxw=640, maxh=480; int lastx=0, lasty=0, maxy=0; const int maxcomponents=100; component * all[maxcomponents]; int numcomponents=0; const int lightgrey=EncodeColor(0.8, 0.8, 0.8); struct component { int xpos, ypos, width, height; string text; component(int w, int h, string s=""); virtual void draw(void); }; component::component(int w, int h, string s) { width=w; height=h; if (lastx+width>=maxw) { lasty=maxy; lastx=0; } xpos=lastx; ypos=lasty; lastx=xpos+width; if (ypos+height>maxy) maxy=ypos+height; text=s; all[numcomponents]=this; numcomponents+=1; } void component::draw(void) { PenColor(lightgrey); FillRectangleXYWH(xpos, ypos, width, height); PenColor(PEN_BLACK); DrawRectangleXYWH(xpos, ypos, width, height); int w, h; MeasureText(text, w, h); MoveTo(xpos+width/2-w/2, ypos+height/2-h/2); WriteText(text); } void nextline(void) { lastx=0; lasty=maxy; } void show(void) { for (int i=0; idraw(); } void main(void) { MakeWindow(maxw, maxh); new component(100, 30, "abc"); new component(200, 100, "second"); nextline(); new component(80, 80, "hello"); new component(300, 40, "you"); show(); }