123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /*
- * LaGUI: A graphical application framework.
- * Copyright (C) 2022-2023 Wu Yiming
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "la_5.h"
- #include <math.h>
- extern LA MAIN;
- extern tnsMain *T;
- tnsShape* tnsNewShape(tnsShapeObject* so){
- tnsShape* s=memAcquireSimple(sizeof(tnsShape));
- lstAppendItem(&so->Shapes,s); return s;
- }
- tnsSPoint* tnsNewSPoint(tnsShape* s,real x, real y,real ldx,real ldy, real rdx,real rdy){
- tnsSPoint* sp=memAcquireSimple(sizeof(tnsSPoint));
- tnsVectorSet2(sp->p,x,y); tnsVectorSet2(sp->dl,ldx,ldy); tnsVectorSet2(sp->dr,rdx,rdy);
- lstAppendItem(&s->Points,sp); return sp;
- }
- void tnsInitShapeSquare(tnsShapeObject* so, real size){
- tnsShape* s=tnsNewShape(so);
- tnsNewSPoint(s,-size,-size,0,0,0,0)->flags|=TNS_MESH_FLAG_SELECTED;
- tnsNewSPoint(s,-size,size,0,0,0,0)->flags|=TNS_MESH_FLAG_SELECTED;
- tnsNewSPoint(s,size,size,0,0,0,0)->flags|=TNS_MESH_FLAG_SELECTED;
- tnsNewSPoint(s,size,-size,0,0,0,0)->flags|=TNS_MESH_FLAG_SELECTED;
- }
- void tns_DrawShape(tnsShape* s, real* override_color){
- if(!s->Points.pFirst) return;
- NVGcontext* vg=MAIN.CurrentWindow->nvg; nvgBeginPath(vg);
- tnsSPoint* sp1=s->Points.pFirst; nvgMoveTo(vg,sp1->p[0],sp1->p[1]);
- for(tnsSPoint* sp=sp1->Item.pNext;sp;sp=sp->Item.pNext){
- nvgLineTo(vg,sp->p[0],sp->p[1]);
- }
- nvgFillColor(vg, override_color?nvgRGBA(LA_COLOR4(override_color)):nvgRGBAf(0.8,0.8,0.8,1));
- nvgFill(vg);
- }
- void tnsDrawShapeObject(tnsEvaluatedInstance* ei,la3DObjectDrawExtra* de){
- tnsShapeObject* so=ei->Object;
- for(tnsShape*s=so->Shapes.pFirst;s;s=s->Item.pNext){
- tns_DrawShape(s,0);
- }
- }
- void tnsDrawShapeObjectSelectionID(tnsEvaluatedInstance* ei, void* unused){
- tnsShapeObject* so=ei->Object;
- int i=ei->InstanceSelectionID; real color[4]={0,0,0,1}; TNS_ID_TO_COLOR(color,i);
- for(tnsShape*s=so->Shapes.pFirst;s;s=s->Item.pNext){
- tns_DrawShape(s,color);
- }
- }
- void tnsEvaluateShapeObject(tnsShapeObject* so, tnsEvaluateData* ed){
- tnsAddEvaluatedInstance(ed,so,tnsDrawShapeObject,TNS_EVAL_LAYER_SOLID,0,0,0);
- if(ed->FillSelectionID){
- tnsAddEvaluatedInstance(ed,so,tnsDrawShapeObjectSelectionID,TNS_EVAL_LAYER_SELECTION,0,1,so->Base.SelectID);
- }
- }
- tnsShapeObject *tnsCreateShapeEmpty(tnsObject *under, char *Name, real AtX, real AtY, real AtZ){
- tnsShapeObject *so = memAcquireHyper(sizeof(tnsShapeObject));
- tnsInitObjectBase(&so->Base, under, Name, TNS_OBJECT_SHAPE, AtX, AtY, AtZ, 0, 0, 0, 1.0f, TNS_ROTATION_XYZ_EULER, 1.0f);
- return so;
- }
- tnsShapeObject *tnsCreateShapeSquare(tnsObject *under, char *Name, real AtX, real AtY, real AtZ, real size){
- tnsShapeObject *so=tnsCreateShapeEmpty(under, Name, AtX, AtY, AtZ);
- tnsInitShapeSquare(so, size);
- return so;
- }
|