ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² KNOW-HOW.GRAPHICS ²²²²²²²²²²²²²²²²²²²²²²²²²²²² ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ This text contain brief description of KNOW_HOW.GRAPHICS 6.0x, the product in the 6th version of library. It provide the following features: a) Using common code for any graphics library. It is realized now for BGI and for Windows GDI. It is not difficult to add few lines of code to use any other library, if it support basical operations (lineto, moveto etc.) b) Scrolling, Zooming, mirror reflection of image, rotations and even complex rotations of image. Saying "complex rotations" I mean drawing of the picture, rotated around x,y to alpha, then (result) around x1,y1 to beta and so on. BGI fonts could be rotated too, filled BGI fonts are also available (not all BGI font could be filled, of course). °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Additional (and very powerfull) features are available if KNOW-HOW.GRAPHICS is used together with KNOW-HOW.SLANG. SLANG is BASIC-like language, designed as CPP class. Its child classes could have additional operators, so KNOW-HOW.SLANG.GRAPHICS is the BASIC with access to drawing tools of current product. It provide to user the possibility to load graphical resourses (DOS or Windows, or other if he add some code) and interprete them in run-time. There are very many applications of this tool, like run-time changeable GUI, maketing (without stage of compilation) of BGI, GDI and so on applications, vector drawing tools (KNOW-HOW.VECTOR is the ready-to-use product of this type). Together with BASIC math. functions it could also be used for data plotting, spreadsheets and so on. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° SERVICE FILES °°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ÞÞÞÞÞÞÞ File SIMPLE.H contains some simplifications for often used names. Complete listing: Þ #ifndef __SIMPLE_H_ Þ #define __SIMPLE_H_ Þ Þ typedef unsigned char uchar; Þ typedef unsigned long ulong; Þ typedef int bool; Þ Þ #define TRUE 1 Þ #define FALSE 0 Þ #define ON TRUE Þ #define OFF FALSE Þ Þ #endif __SIMPLE_H_ °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ File GEOM.H contains geometry of KNOW-HOW. It defines geom. objects in C++ manner: loc(x, y) defines point, rect(x1, y1, x2, y2) - rectangle and so on. For example, instead of call to f(int x, int y) we could call f(loc l), where loc is defined in GEOM.H as Þ struct loc Þ { int X,Y; Þ ..... °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ Files TRIGON.H and TRIGON.CPP contains structure with the overloaded sin(int) and cos(int) functions. This functions works much faster than standart versions but are not so flexible. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ Files KH_ERROR.H and KH_ERROR.CPP are the part of KNOW-HOW error handling system. The only variable is defined: kh_error_code. Functions of KNOW-HOW or user-defined functions could change it, default value is KH_SUCCESS: Þ enum { KH_SUCCESS, KH_UNKNOWN_ERROR, KH_FILE_ERROR, KH_BGI_ERROR, Þ KH_MEMORY_ERROR, KH_USER_ERROR }; This list could be continued: Þ enum { KH_NEW_ERROR = KH_USER_ERROR + 1, ... } °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°° DRAWING MODULES °°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ÞÞÞÞÞÞÞ File ABS_GRAF.H contains empty shablons of functions. We could derivate classes from it not thinking about concrete graphics library we shell use. It provide common code for any DOS, Windows and so on libraries, if them include the same functions. This set is only part of Paint class's functions set, described in PAINT.H: Þ struct AbstractGraphics Þ { Þ virtual void moveto(int x, int y) {} Þ virtual void lineto(int x, int y) {} Þ virtual void fillpoly(int numpoints, int* polypoints) {} Þ }; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ Files BGI_FONT.H and BGI_FONT.CPP contains class, which incapsulate BGI fonts (*.chr) description. 1. BGI fonts are not documented. I use existing format. 2. Abstract (non-BGI) graphics is used for moveto, lineto, drawpoly and fillpoly operations. It should be overloaded in child classes for concrete graf. libraries like BGI, Windows GDI and so on. 3. BGI header have some fields, which are not absolutely necessary (for current class). I skip them and remarks are not complete for them. BGI font format is documented in the remarks to code in these files. So I give here only the brief explanation. BGI use two types of commands for drawing - moveto and lineto. To define non-filled fonts I use calls to the same (virtual) functions. To draw filled fonts I use fillpoly() function. In this case lineto calls are added to points array, and moveto call stop the polygon creation and begin next one. To use filled fonts you should use fonts which are drawn as group of closed polygons. Example - 'O' char: ÚÄÄÄÄÄÄÄ¿ ³²²²²²²²³ ³²ÚÄÄÄ¿²³ ³²³ ³²³ ³²ÀÄÂÄÙ²³ ³²²²³²²²³ ÀÄÄÄÁÄÄÄÙ °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ Files PAINT.H and PAINT.CPP. In the files described previously, we have incapsulated graphics primitives like lineto, moveto, drawchar and so on. Now the additional shell is included for rotation, mirror reflection, complex rotation, zooming and scrolling. All this operations are performed with abstract graphics calls, and not depend on library which you intend to use. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ------------------------- WHAT IS COMPLEX ROTATION ? ------------------------ °Rotation could be simply processed if it is single operation. To use nested °rotations we use stack of rotations info structures. Example of complex °rotation: ° ° void f1(int x, int y, int alpha) { ... perform rotation ... } ° void f2(int x, int y, int alpha) { rotate(10,10,90); f1(x, y, alpha); } °Function f2() call rotation procedure and then call f1(), which call another °rotation. We could a) cancel first rotation and b) add first and second °rotations to complex transformation. KNOW-HOW.GRAPHICS make possible both °variances. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° The structure RInfo is used to keep information about single rotation, and stack of RInfo's is used (if R_STACK variable is set to 1) to keep complex rotation information. Þ struct RInfo Þ { Þ loc center; Þ int angle; Þ }; /////////////// Þ struct Stack Þ { Þ int used, total; Þ RInfo* list; Þ Þ Stack(); Þ ~Stack(); Þ void push(RInfo* r); Þ void pop(); Þ void flash(); Þ }; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ----------------------------------------------------------------------------- Class Paint give some additional facilities for any graphics library. Class does not contain calls to the concrete drawing functions - only to abstract prototypes. functions shold be overloaded in child classes for adaptation to concrete graphic interface (BGI, GDI, and so on). The zoom and addzoom are deformation coeficients. You could use zoom in any part of program. Addzoom is used only once to set the additional deformation of the whole picture (for example if context is changed from screen to printer), for preview and so on. Þ class Paint : public BGI_Font Þ { Þ protected: Þ loc zoom; // Image deformation Þ loc add_zoom; // Additional deformation Þ loc lt; // Scroll of part of picture Þ loc add_scroll; // Left - top clip of the whole picture Þ int fill; // Fill flag Þ loc center; // Rotation center Þ int alpha; // Rotation angle Þ bool R_STACK; // Use or not stack of rotations Þ Stack* r_stack; // Stack of rotations Þ int mirror; Þ public: Þ Paint(); Þ ~Paint() { delete r_stack; } Þ Þ loc get_add_zoom() { return add_zoom; } Þ loc get_zoom() { return zoom; } Þ Þ void set_mirror(int m) { mirror = m; } // X coord. if no rotation Þ void set_stack(bool r) { R_STACK = r; r_stack->flash(); Þ rotate(loc(0, 0), 0); } Þ void set_zoom(double x, double y) { zoom.X = x * add_zoom.X; Þ zoom.Y = y * add_zoom.Y; } // No out-of-range control !!! Þ void set_add_zoom(double x, double y) { add_zoom.X = 100 * x; Þ add_zoom.Y = 100 * y; } Þ void set_scroll(int x, int y) { lt.X = x; lt.Y = y; } Þ void set_add_scroll(int x, int y) { add_scroll.X = x; Þ add_scroll.Y = y; } Þ void rotate(loc c, int a); Þ void set_fill(bool f) { fill = f; } Þ Þ // Using alpha and center returns rotated coordinates Þ loc rot(int x, int y); Þ // Return completely transformed point: rotated, zoomed and scrolled Þ loc transform(int x, int y); Þ }; ----------------------------------------------------------------------------- ÞÞÞÞÞÞÞ Files BGIPAINT.H and BGIPAINT.CPP. Classes in these files replace calls to empty graphics primitives functions to concrete calls of functions from BGI, GDI or from other drawing libraries. The #define directives set switches on one of libraries, user should unremark one of them to use it in program: As the example, lets look to the code for DOS BGI. Þ #ifdef DOS_BGI // If we define DOS_BGI Þ #include // Include GBI header The following structure do nonthing but replace calls to f() {} to calls to f() { ::f(); }, where ::f() is BGI function. Þ struct To_Paint Þ { Þ void putpixel(int x, int y) { ::putpixel(x, y, getcolor()); } Þ void line(int xstart, int ystart, int xend, int yend) Þ { line(xstart, ystart, xend, yend); } Þ Þ void moveto(int x, int y) { ::moveto(x, y); } Þ void lineto(int x, int y) { ::lineto(x, y); } Þ void fillpoly(int numpoints, int* polypoints) Þ { ::fillpoly(numpoints, polypoints); } Þ void circle(int x, int y, int radius) { ::circle(x, y, radius); } Þ void ellipse(int x, int y, int stangle, int endangle, int xr, int yr) Þ { ::ellipse(x, y, stangle, endangle, xr, yr); } Þ void drawpoly(int numpoints, int far* points) Þ { ::drawpoly(numpoints, points); } Þ }; Þ #endif DOS_BGI Then we combine Paint class possibilities to zoom, scroll, rotate (including complex rotations) and so on and To_Paint possibilities to output graphics primitives using different libraries. Þ class KH_Paint : public To_Paint, public Paint Þ { Þ public: Þ KH_Paint() : Paint() {} Þ Þ void putpixel(int x, int y); Þ void line(int xstart, int ystart, int xend, int yend); Þ void lineto(int x, int y); Þ void moveto(int x, int y); Þ void circle(int x, int y, int radius); Þ void ellipse(int x, int y, int stangle, int endangle, int xr, int yr); Þ void roundrect(int left, int top, int right, int bottom, int radius); Þ Þ void rectangle(int left, int top, int right, int bottom); Þ void drawpoly(int numpoints, int far* points); Þ void outtext(char far* str); Þ }; ®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯® ±±±±±±±±±±±±±±±±±±±±±±±±±±±± ATTENTION !!! ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± 1. The set of functions of KH_Paint class will be continued, it is possible that your version contains additional functions (setcolor() is already included, both (int color) and (Red, Green, Blue)). 2. When the Windows compatible part (class To_Paint for Windows) was designed, I find some difficulties: Windows GDI is more powerfull than DOS BGI. It is also possible that when user will try to use his graphics library he find that it have some functions which are absent in both BGI and GDI. The solution is: use KH_Paint functions if possible, I think that it is much more than enought for most cases. Another way is to add new functions to KH_Paint (KH_Paint::draw_pig() {...} and so on, and modify To_Paint for DOS and Windows), If it is not possible - use direct calls to your lovely library - and forget about the compatibility with others. 3. KH_Paint above is restricted. The real listing of 6.0 version (and of course of 6.x) is Windows GDI - oriented. It means that if BGI does not contain some of GDI features, DOS BGI version of To_Paint class try to elulate them. ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± ®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯®¯® ----------------------------------------------------------------------------- Example. I add to *.CPP files (when possible) working examples of main() functions, to run it you need only to remove remarks. In this file I illustrate only the usage of KNOW-HOW.GRAPHICS with DOS BGI, but BGIPAINT file contains also example of Windows OWL usage. Þ void main() Þ { Þ int gdriver = DETECT, gmode; // Standart BGI initialization Þ initgraph(&gdriver, &gmode, ""); // see Borland help system Þ Þ KH_Paint* paint = new KH_Paint(); // Create new KH_Paint class Þ paint->load("euro.chr"); // Load BGI font Þ setcolor(LIGHTRED); Þ setfillstyle(SOLID_FILL, LIGHTGRAY); Þ paint->set_fill(ON); // This flag acts on drawpoly Þ // but not to fonts filling. Þ paint->set_zoom(0.5, 0.8); // Set picture deformation Þ Þ for(int i = 0; i < 360; i += 15) // BGI fonts output with rotation Þ { Þ paint->rotate(loc(400, 200), i); Þ paint->outtextxy(10, 200, "Hello, World !"); Þ } Þ Þ cleardevice(); Þ Þ for(int i1 = 0; i1 < 360; i1 += 15) // Primitives output with rotation Þ { Þ paint->rotate(loc(400, 200), i1); Þ paint->roundrect(300, 100, 400, 200, 20); Þ int poly[10] = {100, 100, 200, 100, 200, 200, 100, 200, 100, 100}; Þ paint->drawpoly(5, poly); Þ } Þ Þ cleardevice(); Þ paint->set_stack(ON); // Switch complex rotations ON Þ for(i = 0; i < 360; i += 30) // First call rotate image to 30, Þ { // second to 60 and so on. Þ paint->rotate(loc(400, 200), 30); Þ paint->outtextxy(10, 200, "Hello, World !"); Þ } Þ Þ paint->set_stack(OFF); Þ for(int j = 0; j < 360; j += 15) Þ { Þ paint->rotate(loc(400, 200), j); // Ellipse rotations Þ paint->ellipse(200, 200, 0, 360, 30, 20); Þ paint->ellipse(300, 200, 50, 120, 30, 20); Þ } Þ Þ delete paint; Þ closegraph(); Þ }