1*11969Sslatteng /* @(#)db2.c 1.2 04/18/83
211947Sslatteng *
311947Sslatteng * Copyright -C- 1982 Barry S. Roitblat
411947Sslatteng *
511947Sslatteng * This file contains routines for implementing the database
611947Sslatteng * manipulations for the gremlin picture editor.
711947Sslatteng */
811947Sslatteng
911947Sslatteng #include "gremlin.h"
1011947Sslatteng #include "grem2.h"
1111947Sslatteng
1211947Sslatteng /* imports from undodb.c */
1311947Sslatteng
1411947Sslatteng extern UNRembAdd(), UNRembMod();
1511947Sslatteng
1611947Sslatteng /* imports from db1.c */
1711947Sslatteng
1811947Sslatteng extern ELT *DBCreateElt();
1911947Sslatteng
2011947Sslatteng /* imports from point.c */
2111947Sslatteng
2211947Sslatteng extern POINT *PTMakePoint(), *PTInit();
2311947Sslatteng
2411947Sslatteng /* imports from c */
2511947Sslatteng
2611947Sslatteng extern char *malloc();
2711947Sslatteng extern char *strcpy();
2811947Sslatteng
2911947Sslatteng ELT *DBCopy(element,transform,db)
3011947Sslatteng ELT *element, *(*db);
3111947Sslatteng float transform[3][2];
3211947Sslatteng /*
3311947Sslatteng * This routine creates a copy of the the element transformed by
3411947Sslatteng * the transformation matrix and adds the new copy to the database.
3511947Sslatteng */
3611947Sslatteng
3711947Sslatteng {
3811947Sslatteng POINT *pt, *newlist;
3911947Sslatteng char *newtext;
4011947Sslatteng
4111947Sslatteng newlist = PTInit();
4211947Sslatteng pt = element->ptlist;
4311947Sslatteng while ( !Nullpoint(pt) )
4411947Sslatteng { /* matrix multiply */
4511947Sslatteng (void) PTMakePoint(( ( (pt->x) * transform[0][0])
4611947Sslatteng + ( (pt->y) * transform[1][0])
4711947Sslatteng + transform[2][0]),
4811947Sslatteng ( ( (pt->x) * transform[0][1])
4911947Sslatteng + ( (pt->y) * transform[1][1])
5011947Sslatteng + transform[2][1]), &newlist);
5111947Sslatteng pt = pt->nextpt;
5211947Sslatteng } /* end while */;
5311947Sslatteng newtext = malloc((unsigned) strlen(element->textpt) + 1);
5411947Sslatteng (void) strcpy(newtext, element->textpt);
5511947Sslatteng return( DBCreateElt(element->type, newlist, element->brushf,
5611947Sslatteng element->size, newtext, db) );
5711947Sslatteng } /* end copy */
5811947Sslatteng
59*11969Sslatteng
DBXform(element,transform,db)6011947Sslatteng DBXform(element, transform, db)
6111947Sslatteng ELT *element;
6211947Sslatteng float transform[3][2];
6311947Sslatteng ELT *(*db);
6411947Sslatteng /*
6511947Sslatteng * This routine transforms the element by multiplying the
6611947Sslatteng * coordinates of each of the points in the element by the
6711947Sslatteng * transformation matrix.
6811947Sslatteng */
6911947Sslatteng
7011947Sslatteng {
7111947Sslatteng POINT *pt;
7211947Sslatteng float px, py;
7311947Sslatteng
7411947Sslatteng UNRembMod(element, db);
7511947Sslatteng pt = element->ptlist;
7611947Sslatteng while ( !Nullpoint(pt) )
7711947Sslatteng {
7811947Sslatteng px = ( (pt->x) * transform[0][0] )
7911947Sslatteng + ( (pt->y) * transform[1][0] )
8011947Sslatteng + transform[2][0];
8111947Sslatteng py = ( (pt->x) * transform[0][1] )
8211947Sslatteng + ( (pt->y) * transform[1][1] )
8311947Sslatteng + transform[2][1];
8411947Sslatteng pt->x = px;
8511947Sslatteng pt->y = py;
8611947Sslatteng pt = pt->nextpt;
8711947Sslatteng } /* end while */;
8811947Sslatteng } /* end Xform */
8911947Sslatteng
90*11969Sslatteng
9111947Sslatteng DBChangeBrush(element, brush, db)
9211947Sslatteng ELT *element, *(*db);
9311947Sslatteng int brush;
9411947Sslatteng /*
9511947Sslatteng * This routine changes the brush attribute of the element
9611947Sslatteng */
9711947Sslatteng
9811947Sslatteng {
9911947Sslatteng UNRembMod(element, db);
10011947Sslatteng element->brushf = brush;
10111947Sslatteng } /* end ChangeBrush */
10211947Sslatteng
10311947Sslatteng DBChangeFont(element, font, size, db)
10411947Sslatteng ELT *element, *(*db);
10511947Sslatteng int font, size;
10611947Sslatteng /*
10711947Sslatteng * This routine changes the font and size attributes of the given
10811947Sslatteng * element.
10911947Sslatteng */
11011947Sslatteng
11111947Sslatteng {
11211947Sslatteng UNRembMod(element, db);
11311947Sslatteng element->brushf = font;
11411947Sslatteng element->size = size;
11511947Sslatteng } /* end ChangeFont */
116