1 /* @(#)db2.c 1.2 04/18/83 2 * 3 * Copyright -C- 1982 Barry S. Roitblat 4 * 5 * This file contains routines for implementing the database 6 * manipulations for the gremlin picture editor. 7 */ 8 9 #include "gremlin.h" 10 #include "grem2.h" 11 12 /* imports from undodb.c */ 13 14 extern UNRembAdd(), UNRembMod(); 15 16 /* imports from db1.c */ 17 18 extern ELT *DBCreateElt(); 19 20 /* imports from point.c */ 21 22 extern POINT *PTMakePoint(), *PTInit(); 23 24 /* imports from c */ 25 26 extern char *malloc(); 27 extern char *strcpy(); 28 29 ELT *DBCopy(element,transform,db) 30 ELT *element, *(*db); 31 float transform[3][2]; 32 /* 33 * This routine creates a copy of the the element transformed by 34 * the transformation matrix and adds the new copy to the database. 35 */ 36 37 { 38 POINT *pt, *newlist; 39 char *newtext; 40 41 newlist = PTInit(); 42 pt = element->ptlist; 43 while ( !Nullpoint(pt) ) 44 { /* matrix multiply */ 45 (void) PTMakePoint(( ( (pt->x) * transform[0][0]) 46 + ( (pt->y) * transform[1][0]) 47 + transform[2][0]), 48 ( ( (pt->x) * transform[0][1]) 49 + ( (pt->y) * transform[1][1]) 50 + transform[2][1]), &newlist); 51 pt = pt->nextpt; 52 } /* end while */; 53 newtext = malloc((unsigned) strlen(element->textpt) + 1); 54 (void) strcpy(newtext, element->textpt); 55 return( DBCreateElt(element->type, newlist, element->brushf, 56 element->size, newtext, db) ); 57 } /* end copy */ 58 59 60 DBXform(element, transform, db) 61 ELT *element; 62 float transform[3][2]; 63 ELT *(*db); 64 /* 65 * This routine transforms the element by multiplying the 66 * coordinates of each of the points in the element by the 67 * transformation matrix. 68 */ 69 70 { 71 POINT *pt; 72 float px, py; 73 74 UNRembMod(element, db); 75 pt = element->ptlist; 76 while ( !Nullpoint(pt) ) 77 { 78 px = ( (pt->x) * transform[0][0] ) 79 + ( (pt->y) * transform[1][0] ) 80 + transform[2][0]; 81 py = ( (pt->x) * transform[0][1] ) 82 + ( (pt->y) * transform[1][1] ) 83 + transform[2][1]; 84 pt->x = px; 85 pt->y = py; 86 pt = pt->nextpt; 87 } /* end while */; 88 } /* end Xform */ 89 90 91 DBChangeBrush(element, brush, db) 92 ELT *element, *(*db); 93 int brush; 94 /* 95 * This routine changes the brush attribute of the element 96 */ 97 98 { 99 UNRembMod(element, db); 100 element->brushf = brush; 101 } /* end ChangeBrush */ 102 103 DBChangeFont(element, font, size, db) 104 ELT *element, *(*db); 105 int font, size; 106 /* 107 * This routine changes the font and size attributes of the given 108 * element. 109 */ 110 111 { 112 UNRembMod(element, db); 113 element->brushf = font; 114 element->size = size; 115 } /* end ChangeFont */ 116