123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * 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?nvgRGBAf(LA_COLOR4(override_color)):nvgRGBAf(0.8,0.8,0.8,1));
- nvgFill(vg);
- }
- void tnsDrawShapeObjectShapes(tnsEvaluatedInstance* ei, la3DObjectDrawExtra* de, real* override_color){
- tnsShapeObject* so=ei->Object; NVGcontext* vg=MAIN.CurrentWindow->nvg;
- real sca[3]; tnsExtractScale44d(ei->Mat,sca);
- real rot[3]; tnsExtractXYZEuler44d(ei->Mat,rot);
- nvgSave(vg);
- if(de->Is3D){
- tnsVector4d pos; tnsApplyTransform44d(pos,de->mViewProj,&ei->Mat[12]);
- pos[0]/=pos[3]; pos[1]/=pos[3];
- nvgTranslate(vg,pos[0]*de->W/2,pos[1]*de->H/2);
- nvgScale(vg,LA_RH*sca[0],LA_RH*sca[1]); nvgRotate(vg,rot[2]);
- }else{
- nvgTranslate(vg,ei->Mat[12],-ei->Mat[13]);
- nvgScale(vg,sca[0],-sca[1]); nvgRotate(vg,rot[2]);
- }
- for(tnsShape*s=so->Shapes.pFirst;s;s=s->Item.pNext){ tns_DrawShape(s,override_color); }
- nvgRestore(vg);
- }
- void tnsDrawShapeObject(tnsEvaluatedInstance* ei, la3DObjectDrawExtra* de){
- tnsDrawShapeObjectShapes(ei,de,0);
- }
- void tnsDrawShapeObjectSelectionID(tnsEvaluatedInstance* ei, la3DObjectDrawExtra* de){
- int i=ei->InstanceSelectionID; real color[4]={0,0,0,1}; TNS_ID_TO_COLOR(color,i);
- tnsDrawShapeObjectShapes(ei,de,color);
- }
- void tnsDrawShapeObjectOverlay(tnsEvaluatedInstance* ei, la3DObjectDrawExtra* de){
- int i=ei->InstanceSelectionID; real color[4]; tnsVectorCopy4d(laAccentColor(LA_BT_ACTIVE),color);
- if(ei->Object!=ei->Object->InRoot->Active){ color[3]=0.4; }else{ color[3]=0.7; }
- tnsDrawShapeObjectShapes(ei,de,color);
- }
- void tnsEvaluateShapeObject(tnsShapeObject* so, tnsEvaluateData* ed){
- int DrawTo=TNS_EVAL_LAYER_SOLID;
- if(so->Backdrop){ DrawTo=TNS_EVAL_LAYER_BACKDROP; }
- tnsAddEvaluatedInstance(ed,so,tnsDrawShapeObject,DrawTo,0,0,0);
- if(ed->FillSelectionID){
- tnsAddEvaluatedInstance(ed,so,tnsDrawShapeObjectSelectionID,TNS_EVAL_LAYER_SELECTION,0,1,so->Base.SelectID);
- }
- if(ed->FillOutline && (!ed->OverrideID)){
- if((so->Base.Flags&TNS_OBJECT_FLAGS_SELECTED) && (so->Mode!=TNS_MESH_EDIT_MODE)){
- tnsAddEvaluatedInstance(ed,so,tnsDrawShapeObjectOverlay,TNS_EVAL_LAYER_OVERLAY,0,0,0);
- }
- }
- }
- 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;
- }
|