123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224 |
- #include "KEDModel2DEditor.h"
- #include <Rahmen.h>
- #include <MausEreignis.h>
- #include <Text.h>
- #include <Schrift.h>
- #include <Scroll.h>
- #include <Globals.h>
- #include <TastaturEreignis.h>
- #include "../../../../Global/Initialisierung.h"
- #include "../../../../Global/Variablen.h"
- using namespace Model2DEditor;
- // Inhalt der VertexData Klasse aus KEDModel2DEditor.h
- // Konstruktor
- VertexData::VertexData( Vec2< float > v, Vertex t )
- {
- vertex = v;
- textur = t;
- selected = 0;
- sichtbar = 1;
- ref = 1;
- }
- // nicht constant
- void VertexData::nachLinks( float num )
- {
- if( selected )
- vertex.x -= num;
- }
- void VertexData::nachOben( float num )
- {
- if( selected )
- vertex.y -= num;
- }
- void VertexData::setTextur( Vertex tp )
- {
- textur = tp;
- }
- void VertexData::setPosition( Vertex p )
- {
- vertex = p;
- }
- void VertexData::saveTextur( Punkt tPos, Punkt tGr )
- {
- textur = vertex - tPos;
- textur.x /= tGr.x;
- textur.y /= tGr.y;
- }
- void VertexData::select( Punkt p1, Punkt p2 )
- {
- selected |= vertex.istInRegion( p1, p2 ) && sichtbar;
- }
- void VertexData::deSelect()
- {
- selected = 0;
- }
- void VertexData::setAuswahl( bool ausw )
- {
- selected = ausw;
- }
- void VertexData::setSichtbar( bool s )
- {
- sichtbar = s;
- selected &= sichtbar;
- }
- // constant
- bool VertexData::istSichtbar() const
- {
- return sichtbar;
- }
- bool VertexData::istAusgewählt() const
- {
- return selected;
- }
- Vec2< float > VertexData::getPos() const
- {
- return vertex;
- }
- Vertex VertexData::getTPos() const
- {
- return textur;
- }
- // Reference Counting
- VertexData *VertexData::getThis()
- {
- ref++;
- return this;
- }
- VertexData *VertexData::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
- // Inhalt der PolygonData Klasse aus KEDModel2DEditor.h
- // Konstruktor
- PolygonData::PolygonData( Polygon2D & pg )
- {
- name = pg.name->getText();
- vd = new RCArray< VertexData >();
- transparent = pg.transparent;
- sichtbar = 1;
- ref = 1;
- int anz = pg.vertex->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- Vec2< float > v( 0, 0 );
- Vertex t( 0, 0 );
- if( pg.vertex->hat( i ) )
- v = pg.vertex->get( i );
- if( pg.tKordinaten &&pg.tKordinaten->hat( i ) )
- t = pg.tKordinaten->get( i );
- vd->add( new VertexData( v, t ) );
- }
- }
- // Destruktor
- PolygonData::~PolygonData()
- {
- vd->release();
- }
- // nicht constant
- void PolygonData::addVertex( Vec2< float >v, Vertex t )
- {
- vd->add( new VertexData( v, t ) );
- }
- void PolygonData::removeVertex( int num )
- {
- vd->remove( num );
- }
- void PolygonData::nachLinks( float num )
- {
- for( auto i = vd->getIterator(); i; i++ )
- i->nachLinks( num );
- }
- void PolygonData::nachOben( float num )
- {
- for( auto i = vd->getIterator(); i; i++ )
- i->nachOben( num );
- }
- void PolygonData::saveTextur( Punkt tPos, Punkt tGr )
- {
- for( auto i = vd->getIterator(); i; i++ )
- i->saveTextur( tPos, tGr );
- }
- void PolygonData::select( Punkt p1, Punkt p2 )
- {
- for( auto i = vd->getIterator(); i; i++ )
- i->select( p1, p2 );
- }
- void PolygonData::deSelect()
- {
- for( auto i = vd->getIterator(); i; i++ )
- i->deSelect();
- }
- void PolygonData::setSichtbar( bool s )
- {
- sichtbar = s;
- }
- void PolygonData::setTransparent( bool t )
- {
- transparent = t;
- }
- void PolygonData::setName( const char *name )
- {
- this->name = name;
- }
- // constant
- const char *PolygonData::getName() const
- {
- return name;
- }
- bool PolygonData::istSichtbar() const
- {
- return sichtbar;
- }
- VertexData *PolygonData::zVertex( int num ) const
- {
- return vd->z( num );
- }
- int PolygonData::getVertexAnzahl() const
- {
- return vd->getEintragAnzahl();
- }
- void PolygonData::getM2( Polygon2D & pd, bool textur ) const
- {
- int anz = vd->getEintragAnzahl();
- if( !pd.name )
- pd.name = new Text( name );
- if( !pd.vertex )
- pd.vertex = new Array< Vertex >();
- if( !pd.tKordinaten )
- pd.tKordinaten = new Array< Vertex >();
- for( int i = 0; i < anz; i++ )
- {
- pd.vertex->add( this->vd->z( i )->getPos() );
- if( textur )
- pd.tKordinaten->add( this->vd->z( i )->getTPos() );
- }
- }
- bool PolygonData::istTransparent() const
- {
- return transparent;
- }
- // Reference Counting
- PolygonData *PolygonData::getThis()
- {
- ref++;
- return this;
- }
- PolygonData *PolygonData::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
- // Inhalt der Data Klasse aus KEDModel2DEditor.h
- // Konstruktor
- Data::Data( Model2DData * mdl )
- {
- pd = new RCArray< PolygonData >();
- tPos.x = 0;
- tPos.y = 0;
- textur = 0;
- rTextur = 0;
- sp = -1;
- ref = 1;
- int anz = ( mdl && mdl->polygons ) ? mdl->polygons->getEintragAnzahl() : 0;
- for( int i = 0; i < anz; i++ )
- {
- if( mdl->polygons->hat( i ) )
- {
- pd->add( new PolygonData( mdl->polygons->get( i ) ) );
- }
- }
- if( mdl )
- mdl->release();
- }
- // Destruktor
- Data::~Data()
- {
- pd->release();
- if( textur )
- textur->release();
- }
- // nicht constant
- void Data::addPolygon()
- {
- Polygon2D p;
- p.name = new Text();
- p.vertex = new Array< Vertex >();
- pd->add( new PolygonData( p ) );
- p.vertex->release();
- p.name->release();
- }
- void Data::removePolygon( int num )
- {
- pd->remove( num );
- if( sp == num )
- sp = -1;
- }
- void Data::selectPolygon( int num )
- {
- sp = num;
- }
- void Data::nachLinks( float num )
- {
- for( auto i = pd->getIterator(); i; i++ )
- i->nachLinks( num );
- }
- void Data::nachOben( float num )
- {
- for( auto i = pd->getIterator(); i; i++ )
- i->nachOben( num );
- }
- void Data::tNachLinks( int num )
- {
- if( !rTextur )
- return;
- tPos.x -= num;
- }
- void Data::tNachOben( int num )
- {
- if( !rTextur )
- return;
- tPos.y -= num;
- }
- void Data::setRTextur( bool rt )
- {
- rTextur = rt;
- if( rt && !textur )
- {
- textur = new Bild();
- textur->neuBild( 500, 500, 0xFF505000 );
- }
- }
- void Data::saveTextur()
- {
- if( !rTextur )
- return;
- for( auto i = pd->getIterator(); i; i++ )
- i->saveTextur( tPos, textur->getSize() );
- }
- void Data::setTextur( Bild * t )
- {
- if( textur )
- textur->release();
- textur = t;
- if( pd->getEintragAnzahl() > 0 && pd->z( 0 )->zVertex( 0 ) )
- {
- Vertex p = pd->z( 0 )->zVertex( 0 )->getPos();
- Vertex tp = pd->z( 0 )->zVertex( 0 )->getTPos();
- tp.x *= t->getBreite();
- tp.y *= t->getHeight();
- tPos = p - tp;
- }
- }
- void Data::select( Punkt p1, Punkt p2 )
- {
- for( auto i = pd->getIterator(); i; i++ )
- i->select( p1, p2 );
- }
- void Data::deSelect()
- {
- for( auto i = pd->getIterator(); i; i++ )
- i->deSelect();
- }
- // constant
- PolygonData *Data::zPolygon( int num ) const
- {
- return pd->z( num );
- }
- int Data::getPolygonAnzahl() const
- {
- return pd->getEintragAnzahl();
- }
- int Data::getSelectedPolygon() const
- {
- return sp;
- }
- Model2DData *Data::getM2() const
- {
- int anz = pd->getEintragAnzahl();
- Array< Polygon2D > *polygons = new Array< Polygon2D >();
- for( int i = 0; i < anz; i++ )
- {
- Polygon2D pd = { 0, 0, 0, 0, 0 };
- this->pd->z( i )->getM2( pd, 1 );
- pd.transparent = this->pd->z( i )->istTransparent();
- polygons->add( pd );
- }
- Model2DData *ret = new Model2DData();
- ret->erstelleModell( polygons );
- return ret;
- }
- Bild *Data::zTextur() const
- {
- return rTextur ? textur : 0;
- }
- Punkt Data::getTPos() const
- {
- return tPos;
- }
- // Reference Counting
- Data *Data::getThis()
- {
- ref++;
- return this;
- }
- Data *Data::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
- // Inhalt der EditorListe Klasse aus KEDModel2DEditor.h
- // Konstruktor
- EditorListe::EditorListe( Schrift * zSchrift )
- : Zeichnung()
- {
- ram = new LRahmen();
- ram->setRamenBreite( 1 );
- ram->setFarbe( 0xFFFFFFFF );
- ram->setSize( 150, 480 );
- ram->setPosition( 720, 10 );
- scroll = new VScrollBar();
- schrift = zSchrift->getThis();
- tr = new TextRenderer( schrift ? schrift->getThis() : 0 );
- pName = initTextFeld( 0, 0, 70, 20, schrift, TextFeld::Style::TextFeld, "" );
- koordF = initFenster( 10, 10, 150, 140, zSchrift, ( Fenster::Style::normal | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund ) & ~Fenster::Style::Sichtbar, "Koordinaten" );
- koordF->setKBgFarbe( 0xFF000000 );
- koordF->setTBgFarbe( 0xFF000000 );
- koordF->setClosingMe( _closeFensterME );
- kxT = initTextFeld( 10, 10, 30, 20, zSchrift, TextFeld::Style::Text, "x:" );
- kyT = initTextFeld( 10, 40, 30, 20, zSchrift, TextFeld::Style::Text, "y:" );
- kx = initTextFeld( 40, 10, 90, 20, zSchrift, TextFeld::Style::TextFeld, "" );
- ky = initTextFeld( 40, 40, 90, 20, zSchrift, TextFeld::Style::TextFeld, "" );
- tkxT = initTextFeld( 10, 70, 30, 20, zSchrift, TextFeld::Style::Text, "tx:" );
- tkyT = initTextFeld( 10, 100, 30, 20, zSchrift, TextFeld::Style::Text, "ty:" );
- tkx = initTextFeld( 40, 70, 90, 20, zSchrift, TextFeld::Style::TextFeld, "" );
- tky = initTextFeld( 40, 100, 90, 20, zSchrift, TextFeld::Style::TextFeld, "" );
- int *polIP = &polI, *verIP = &verI;
- TextFeld * kxTmp = kx;
- TextFeld * kyTmp = ky;
- auto saveK = [ polIP, verIP, kxTmp, kyTmp ]( void *p, void *o, TastaturEreignis te )
- {
- Data *data = (Data *)p;
- data->zPolygon( *polIP )->zVertex( *verIP )->setPosition( Vertex( (float)(double)* kxTmp->zText(), (float)(double)* kyTmp->zText() ) );
- return 1;
- };
- kx->setNTastaturEreignis( saveK );
- ky->setNTastaturEreignis( saveK );
- TextFeld * tkxTmp = tkx;
- TextFeld * tkyTmp = tky;
- auto saveTK = [ polIP, verIP, tkxTmp, tkyTmp ]( void *p, void *o, TastaturEreignis te )
- {
- Data *data = (Data *)p;
- data->zPolygon( *polIP )->zVertex( *verIP )->setTextur( Vertex( (float)(double)* tkxTmp->zText(), (float)(double)* tkyTmp->zText() ) );
- return 1;
- };
- tkx->setNTastaturEreignis( saveTK );
- tky->setNTastaturEreignis( saveTK );
- koordF->addMember( kxT->getThis() );
- koordF->addMember( kyT->getThis() );
- koordF->addMember( kx->getThis() );
- koordF->addMember( ky->getThis() );
- koordF->addMember( tkxT->getThis() );
- koordF->addMember( tkyT->getThis() );
- koordF->addMember( tkx->getThis() );
- koordF->addMember( tky->getThis() );
- polI = 0;
- verI = 0;
- data = 0;
- }
- // Destruktor
- EditorListe::~EditorListe()
- {
- pName->release();
- ram->release();
- scroll->release();
- if( data )
- data->release();
- schrift->release();
- koordF->release();
- kxT->release();
- kyT->release();
- kx->release();
- ky->release();
- tkxT->release();
- tkyT->release();
- tkx->release();
- tky->release();
- tr->release();
- }
- // nicht constant
- void EditorListe::setDataZ( Data * d )
- {
- if( data )
- data->release();
- data = d;
- }
- void EditorListe::doMausEreignis( MausEreignis & me )
- {
- koordF->doMausEreignis( me );
- me.mx -= ram->getX();
- me.my -= ram->getY();
- if( me.mx < 0 || me.my < 0 || me.mx > ram->getBreite() || me.my > ram->getHeight() )
- {
- me.mx += ram->getX();
- me.my += ram->getY();
- return;
- }
- scroll->doMausMessage( ram->getBreite() - 17, 1, 15, ram->getHeight() - 2, me );
- if( data->getSelectedPolygon() >= 0 )
- pName->doMausEreignis( me );
- rend |= scroll->getRend();
- if( me.id == ME_RLinks && !me.verarbeitet )
- {
- int pAnz = data->getPolygonAnzahl();
- int y = -scroll->getScroll();
- for( int i = 0; i < pAnz; i++ )
- {
- if( me.mx > 0 && me.my > y && me.mx < 20 && me.my < y + 20 )
- { // Ein und Ausklappen
- if( !ausgeklappt.hat( i ) )
- ausgeklappt.set( 0, i );
- ausgeklappt.set( !ausgeklappt.get( i ), i );
- rend = 1;
- }
- else if( me.mx > 115 && me.my > y + 1 && me.mx < 132 && me.my < y + 19 )
- { // Löschen
- if( polI == i )
- koordF->removeStyle( Fenster::Style::Sichtbar );
- data->removePolygon( i );
- rend = 1;
- break;
- }
- else if( me.mx > 95 && me.my > y + 5 && me.mx < 105 && me.my < y + 15 )
- {
- data->zPolygon( i )->setTransparent( !data->zPolygon( i )->istTransparent() );
- rend = 1;
- }
- else if( me.mx > 0 && me.my > y &&me.mx < 133 && me.my < y + 20 )
- { // Polygon Auswählen und Abwählen
- if( data->getSelectedPolygon() != i )
- data->selectPolygon( i );
- else
- data->selectPolygon( -1 );
- rend = 1;
- }
- PolygonData * pd = data->zPolygon( i );
- if( pd && ausgeklappt.hat( i ) && ausgeklappt.get( i ) )
- {
- int vAnz = pd->getVertexAnzahl();
- for( int j = 0; j < vAnz; j++ )
- {
- y += 20;
- if( me.mx > 115 && me.my > y + 1 && me.mx < 132 && me.my < y + 19 )
- { // Löschen
- if( polI == i && verI == j )
- koordF->removeStyle( Fenster::Style::Sichtbar );
- pd->removeVertex( j );
- rend = 1;
- }
- else if( me.mx > 95 && me.my > y + 5 && me.mx < 105 && me.my < y + 15 )
- { // Sichtbar und Unsichtbar
- pd->zVertex( j )->setSichtbar( !pd->zVertex( j )->istSichtbar() );
- rend = 1;
- }
- else if( me.mx > 5 && me.my > y + 5 && me.mx < 15 && me.my < y + 15 )
- { // Koordinaten fenster sichtbar machen
- polI = i;
- verI = j;
- tkx->setNTastaturEreignisParameter( data );
- tky->setNTastaturEreignisParameter( data );
- kx->setNTastaturEreignisParameter( data );
- ky->setNTastaturEreignisParameter( data );
- tkx->setText( Text() += pd->zVertex( j )->getTPos().x );
- tky->setText( Text() += pd->zVertex( j )->getTPos().y );
- kx->setText( Text() += pd->zVertex( j )->getPos().x );
- ky->setText( Text() += pd->zVertex( j )->getPos().y );
- koordF->addStyle( Fenster::Style::Sichtbar );
- }
- else if( me.my > y &&me.my < y + 20 && me.mx > 0 && me.mx < 133 )
- { // Auswählen und Abwählen
- pd->zVertex( j )->setAuswahl( !pd->zVertex( j )->istAusgewählt() );
- rend = 1;
- }
- }
- }
- y += 20;
- }
- }
- me.verarbeitet = 1;
- me.mx += ram->getX();
- me.my += ram->getY();
- }
- void EditorListe::doTastaturEreignis( TastaturEreignis & te )
- {
- koordF->doTastaturEreignis( te );
- if( data &&data->getSelectedPolygon() >= 0 )
- pName->doTastaturEreignis( te );
- }
- bool EditorListe::tick( double zeit )
- {
- rend |= koordF->tick( zeit );
- if( data &&data->getSelectedPolygon() >= 0 )
- rend |= pName->tick( zeit );
- bool ret = rend;
- rend = 0;
- return ret;
- }
- void EditorListe::render( Bild & zRObj )
- {
- ram->render( zRObj );
- if( !zRObj.setDrawOptions( ram->getPosition() + Punkt( 1, 1 ), ram->getSize() - Punkt( 2, 2 ) ) )
- return;
- scroll->render( ram->getBreite() - 17, 1, 15, ram->getHeight() - 2, zRObj );
- int pAnz = data->getPolygonAnzahl();
- int y = -scroll->getScroll();
- int maxH = 0;
- tr->setSchriftSize( 12 );
- Text name;
- for( int i = 0; i < pAnz; i++ )
- {
- if( data->getSelectedPolygon() == i )
- {
- pName->setPosition( 20, y );
- pName->setText( data->zPolygon( data->getSelectedPolygon() )->getName() );
- Data *tmpData = data;
- pName->setNTastaturEreignis( [ tmpData ]( void *p, void *o, TastaturEreignis te ) -> bool
- {
- if( tmpData->getSelectedPolygon() >= 0 )
- tmpData->zPolygon( tmpData->getSelectedPolygon() )->setName( ( (TextFeld *)o )->zText()->getText() );
- return 1;
- } );
- zRObj.fillRegion( 0, y, 133, 20, 0xFF002000 );
- pName->render( zRObj );
- }
- else
- {
- if( textLength( data->zPolygon( i )->getName() ) > 0 )
- name = data->zPolygon( i )->getName();
- else
- {
- name = "Polygon ";
- name += i;
- }
- tr->renderText( 20, y + 4, name, zRObj, 0xFFFFFFFF );
- }
- zRObj.drawLinie( Punkt( 115, y + 1 ), Punkt( 132, y + 18 ), 0xFFFF0000 );
- zRObj.drawLinie( Punkt( 132, y + 1 ), Punkt( 115, y + 18 ), 0xFFFF0000 );
- if( data->zPolygon( i )->istTransparent() )
- {
- zRObj.drawLinieH( 95, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinieH( 95, y + 15, 10, 0xFFFFFFFF );
- zRObj.drawLinieV( 95, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinieV( 105, y + 5, 10, 0xFFFFFFFF );
- }
- else
- zRObj.fillRegion( 95, y + 5, 10, 10, 0xFFFFFFFF );
- if( ausgeklappt.hat( i ) && ausgeklappt.get( i ) )
- {
- zRObj.drawDreieck( Punkt( 10, 4 + y ), Punkt( 4, 16 + y ), Punkt( 16, 16 + y ), 0xFFFFFFFF );
- PolygonData * pd = data->zPolygon( i );
- if( pd )
- {
- int vAnz = pd->getVertexAnzahl();
- for( int j = 0; j < vAnz; j++ )
- {
- maxH += 20;
- y += 20;
- if( pd->zVertex( j )->istAusgewählt() )
- zRObj.fillRegion( 0, y, 133, 20, 0xFF101010 );
- name = " Vertex ";
- name += j;
- tr->renderText( 20, y + 4, name, zRObj, 0xFFFFFFFF );
- zRObj.drawLinieH( 5, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinieH( 5, y + 10, 10, 0xFFFFFFFF );
- zRObj.drawLinieH( 5, y + 15, 10, 0xFFFFFFFF );
- zRObj.drawLinieV( 5, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinieV( 10, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinieV( 15, y + 5, 10, 0xFFFFFFFF );
- zRObj.drawLinie( Punkt( 115, y + 1 ), Punkt( 132, y + 18 ), 0xFFFF0000 );
- zRObj.drawLinie( Punkt( 132, y + 1 ), Punkt( 115, y + 18 ), 0xFFFF0000 );
- if( pd->zVertex( j )->istSichtbar() )
- {
- zRObj.drawKreis( 100, y + 10, 5, 0xFFFFFFFF );
- zRObj.drawKreis( 100, y + 10, 1, 0xFFFFFFFF );
- }
- else
- {
- zRObj.drawKreis( 100, y + 10, 5, 0xFF505050 );
- zRObj.drawKreis( 100, y + 10, 1, 0xFF505050 );
- }
- }
- }
- }
- else
- zRObj.drawDreieck( Punkt( 10, 16 + y ), Punkt( 4, 4 + y ), Punkt( 16, 4 + y ), 0xFFFFFFFF );
- maxH += 20;
- y += 20;
- }
- scroll->update( maxH, ram->getHeight() - 2 );
- zRObj.releaseDrawOptions();
- koordF->render( zRObj );
- }
- // Inhalt der Editor2D Klasse aus KEDModel2DEditor.h
- // Konstruktor
- Editor2D::Editor2D( Schrift * zSchrift )
- : Zeichnung()
- {
- pos.x = 10;
- pos.y = 10;
- offs.x = -350;
- offs.y = -250;
- mausPos.x = 0;
- mausPos.y = 0;
- data = 0;
- ram = new LRahmen();
- ram->setFarbe( 0xFFFFFFFF );
- ram->setRamenBreite( 1 );
- ram->setSize( 700, 480 );
- select = new LRahmen();
- select->setFarbe( 0xFF5050FF );
- select->setRamenBreite( 1 );
- schrift = zSchrift->getThis();
- tr = new TextRenderer( schrift->getThis() );
- addV = Vertex( 0, 0 );
- mausIn = 0;
- größe = 1;
- }
- // Destruktor
- Editor2D::~Editor2D()
- {
- ram->release();
- select->release();
- schrift->release();
- tr->release();
- if( data )
- data->release();
- }
- // nicht constant
- void Editor2D::setDataZ( Data * d )
- {
- if( data )
- data->release();
- data = d;
- }
- void Editor2D::doMausEreignis( MausEreignis & me )
- {
- me.mx -= pos.x;
- me.my -= pos.y;
- if( me.mx < 0 || me.my < 0 || me.mx > ram->getBreite() || me.my > ram->getHeight() )
- {
- me.mx += pos.x;
- me.my += pos.y;
- mausIn = 0;
- return;
- }
- mausIn = 1;
- rend = 1;
- addV = Vertex( (float)me.mx, (float)me.my ) / größe + offs;
- if( me.id == ME_UScroll )
- größe += 0.01f;
- if( me.id == ME_DScroll )
- größe -= 0.01f;
- if( me.id == ME_PLinks )
- {
- select->setPosition( me.mx, me.my );
- select->setSize( 0, 0 );
- }
- if( me.id == ME_PRechts || me.id == ME_PMitte )
- {
- mausPos.x = me.mx;
- mausPos.y = me.my;
- }
- if( me.id == ME_Bewegung )
- {
- if( getMausStand( M_Links ) )
- {
- select->setSize( me.mx - select->getX(), me.my - select->getY() );
- }
- if( getMausStand( M_Rechts ) )
- {
- data->nachLinks( ( mausPos.x - me.mx ) / größe );
- data->nachOben( ( mausPos.y - me.my ) / größe );
- mausPos.x = me.mx;
- mausPos.y = me.my;
- }
- if( getMausStand( M_Mitte ) )
- {
- data->tNachLinks( (int)( ( mausPos.x - me.mx ) / größe ) );
- data->tNachOben( (int)( ( mausPos.y - me.my ) / größe ) );
- mausPos.x = me.mx;
- mausPos.y = me.my;
- }
- }
- if( me.id == ME_RLinks )
- {
- if( !getTastenStand( T_Shift ) )
- data->deSelect();
- data->select( ( Vec2<float> )select->getPosition() / größe + offs, ( Vec2<float> )( select->getPosition() + select->getSize() ) / größe + offs );
- select->setSize( 0, 0 );
- select->setPosition( 0, 0 );
- }
- if( me.id == ME_RRechts )
- {
- mausPos.x = 0;
- mausPos.y = 0;
- }
- me.verarbeitet = 1;
- me.mx += pos.x;
- me.my += pos.y;
- }
- void Editor2D::doTastaturEreignis( TastaturEreignis & te )
- {
- if( te.id == TE_Release && te.taste == T_Enter && mausIn )
- {
- PolygonData *pd = data->zPolygon( data->getSelectedPolygon() );
- if( pd )
- {
- pd->addVertex( addV, Punkt( 0, 0 ) );
- rend = 1;
- }
- }
- if( te.id == TE_Release && te.taste == T_Einfg )
- {
- data->addPolygon();
- rend = 1;
- }
- if( te.id == T_Oben )
- offs.y -= 2;
- if( te.id == T_Links )
- offs.x -= 2;
- if( te.id == T_Unten )
- offs.y += 2;
- if( te.id == T_Rechts )
- offs.x += 2;
- if( te.id == T_Oben || te.id == T_Links || te.id == T_Unten || te.id == T_Rechts )
- rend = 1;
- }
- bool Editor2D::tick( double zeit )
- {
- if( mausIn )
- {
- if( getTastenStand( T_Links ) )
- {
- offs.x--;
- rend = 1;
- }
- if( getTastenStand( T_Rechts ) )
- {
- offs.x++;
- rend = 1;
- }
- if( getTastenStand( T_Oben ) )
- {
- offs.y--;
- rend = 1;
- }
- if( getTastenStand( T_Unten ) )
- {
- offs.y++;
- rend = 1;
- }
- if( getTastenStand( 'w' ) )
- {
- data->tNachOben( 1 );
- rend = 1;
- }
- if( getTastenStand( 'a' ) )
- {
- data->tNachLinks( 1 );
- rend = 1;
- }
- if( getTastenStand( 's' ) )
- {
- data->tNachOben( -1 );
- rend = 1;
- }
- if( getTastenStand( 'd' ) )
- {
- data->tNachLinks( -1 );
- rend = 1;
- }
- }
- bool ret = rend;
- rend = 0;
- return ret;
- }
- void Editor2D::render( Bild & zRObj )
- {
- if( !zRObj.setDrawOptions( pos, ram->getSize() ) )
- return;
- ram->render( zRObj );
- if( !zRObj.setDrawOptions( 1, 1, ram->getBreite() - 2, ram->getHeight() - 2 ) )
- {
- zRObj.releaseDrawOptions();
- return;
- }
- if( data->zTextur() )
- {
- Punkt tPos = data->getTPos();
- zRObj.alphaBildSkall( (int)( ( tPos.x - offs.x ) * größe ), (int)( ( tPos.y - offs.y ) * größe ),
- (int)( data->zTextur()->getBreite() * größe ), (int)( data->zTextur()->getHeight() * größe ), *data->zTextur() );
- }
- // Raster mahlen
- int xanz = (int)( ram->getBreite() / ( 50 * größe ) );
- int yanz = (int)( ram->getHeight() / ( 50 * größe ) );
- int xStart = ( 50 - abs( offs.x ) % 50 );
- if( offs.x < 0 )
- xStart = -offs.x % 50;
- if( offs.x == 0 )
- xStart = 0;
- int yStart = ( 50 - abs( offs.y ) % 50 );
- if( offs.y < 0 )
- yStart = -offs.y % 50;
- if( offs.y == 0 )
- yStart = 0;
- for( float x = xStart * größe, y = yStart * größe; !( x > ram->getBreite() && y > ram->getHeight() ); x += 50 * größe, y += 50 * größe )
- {
- zRObj.drawLinieH( 0, (int)y, ram->getBreite(), 0xFF505050 );
- zRObj.drawLinieV( (int)x, 0, ram->getHeight(), 0xFF505050 );
- }
- Text xPos = "";
- xPos = offs.x + (int)( xStart + 50 * ( xanz / 2 ) );
- tr->renderText( (int)( xStart * größe + 50 * größe * ( xanz / 2 ) ), 0, xPos, zRObj, 0xFF505050 );
- xPos = offs.y + (int)( yStart + 50 * ( yanz / 2 ) );
- tr->renderText( 0, (int)( yStart * größe + 50 * größe * ( yanz / 2 ) ), xPos, zRObj, 0xFF505050 );
- // Model mahlen
- int pAnz = data->getPolygonAnzahl();
- for( int i = 0; i < pAnz; i++ )
- {
- PolygonData *p = data->zPolygon( i );
- if( !p->istSichtbar() )
- continue;
- if( data->getSelectedPolygon() == i && mausIn )
- {
- int vAnz = p->getVertexAnzahl();
- VertexData tmp = VertexData( addV, Punkt() );
- VertexData *l = p->zVertex( vAnz - 1 );
- for( int j = -1; j < vAnz && vAnz > 0; j++ )
- {
- VertexData *v = j < 0 ? &tmp : p->zVertex( j );
- if( l &&v )
- {
- if( l->istSichtbar() && v->istSichtbar() )
- zRObj.drawLinie( ( ( l->getPos() - offs ) * größe ), ( ( v->getPos() - offs ) * größe ), 0xFFA0A0A0 );
- else
- zRObj.drawLinie( ( ( l->getPos() - offs ) * größe ), ( ( v->getPos() - offs ) * größe ), 0xFF606060 );
- }
- if( !l->istSichtbar() )
- {
- l = v;
- continue;
- }
- if( j == 0 )
- zRObj.fillRegion( (int)( ( l->getPos().x - offs.x ) *größe ) - 5, (int)( ( l->getPos().y - offs.y ) *größe ) - 5, 10, 10, 0xFF50FF50 );
- else
- {
- if( !l->istAusgewählt() )
- zRObj.fillRegion( (int)( ( l->getPos().x - offs.x ) * größe ) - 5, (int)( ( l->getPos().y - offs.y ) * größe ) - 5, 10, 10, 0xFF5050FF );
- else
- zRObj.fillRegion( (int)( ( l->getPos().x - offs.x ) * größe ) - 5, (int)( ( l->getPos().y - offs.y ) * größe ) - 5, 10, 10, 0xFFFF5050 );
- }
- l = v;
- }
- }
- else
- {
- int vAnz = p->getVertexAnzahl();
- VertexData *l = p->zVertex( vAnz - 1 );
- for( int j = 0; j < vAnz; j++ )
- {
- VertexData *v = p->zVertex( j );
- if( l && v )
- {
- if( l->istSichtbar() && v->istSichtbar() )
- zRObj.drawLinie( ( ( l->getPos() - offs ) * größe ), ( ( v->getPos() - offs ) * größe ), 0xFFA0A0A0 );
- else
- zRObj.drawLinie( ( ( l->getPos() - offs ) * größe ), ( ( v->getPos() - offs ) * größe ), 0xFF606060 );
- }
- if( l )
- {
- if( !l->istSichtbar() )
- {
- l = v;
- continue;
- }
- if( !l->istAusgewählt() )
- zRObj.fillRegion( (int)( ( l->getPos().x - offs.x ) * größe ) - 5, (int)( ( l->getPos().y - offs.y ) * größe ) - 5, 10, 10, 0xFF5050FF );
- else
- zRObj.fillRegion( (int)( ( l->getPos().x - offs.x ) * größe ) - 5, (int)( ( l->getPos().y - offs.y ) * größe ) - 5, 10, 10, 0xFFFF5050 );
- }
- l = v;
- }
- }
- }
- select->render( zRObj );
- zRObj.releaseDrawOptions();
- zRObj.releaseDrawOptions();
- }
- // Inhalt der GUI Klasse aus KEDModel2DEditor.h
- // Konstruktor
- GUI::GUI( Schrift * zSchrift )
- : Zeichnung()
- {
- speichern = initKnopf( 660, 500, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Speichern" );
- abbrechen = initKnopf( 770, 500, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Abbrehen" );
- textur = initKontrollKnopf( 10, 500, 100, 20, zSchrift, KontrollKnopf::Style::Normal, "Textur" );
- texturVerknüpfen = initKnopf( 120, 500, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Textur Speichern" );
- texturLaden = initKnopf( 230, 500, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Textur Laden" );
- data = new Data( 0 );
- editor = new Editor2D( zSchrift );
- editor->setDataZ( data->getThis() );
- liste = new EditorListe( zSchrift );
- liste->setDataZ( data->getThis() );
- importDialog = 0;
- aktion = 0;
- alpha = 0;
- sichtbar = 0;
- }
- // Destruktor
- GUI::~GUI()
- {
- editor->release();
- liste->release();
- speichern->release();
- abbrechen->release();
- data->release();
- textur->release();
- texturVerknüpfen->release();
- texturLaden->release();
- if( importDialog )
- importDialog->release();
- }
- // nicht constant
- void GUI::setSichtbar( bool s )
- {
- sichtbar = s;
- }
- void GUI::setModel( Model2DData * data )
- {
- if( this->data )
- this->data->release();
- this->data = new Data( data );
- editor->setDataZ( this->data->getThis() );
- liste->setDataZ( this->data->getThis() );
- }
- void GUI::doMausEreignis( MausEreignis & me )
- {
- if( !sichtbar )
- return;
- liste->doMausEreignis( me );
- editor->doMausEreignis( me );
- bool vera = me.verarbeitet;
- speichern->doMausEreignis( me );
- if( me.id == ME_RLinks && me.verarbeitet && !vera )
- {
- aktion = 1;
- }
- vera = me.verarbeitet;
- abbrechen->doMausEreignis( me );
- if( me.id == ME_RLinks && me.verarbeitet && !vera )
- {
- aktion = 2;
- }
- vera = me.verarbeitet;
- textur->doMausEreignis( me );
- data->setRTextur( textur->hatStyle( KontrollKnopf::Style::Selected ) );
- vera = me.verarbeitet;
- texturVerknüpfen->doMausEreignis( me );
- if( !vera && me.verarbeitet &&me.id == ME_RLinks )
- data->saveTextur();
- vera = me.verarbeitet;
- texturLaden->doMausEreignis( me );
- if( !vera && me.verarbeitet && me.id == ME_RLinks )
- {
- if( !importDialog )
- {
- importDialog = new DateiDialogTh();
- importDialog->setOpen( 1 );
- importDialog->setDateiTypAuswahl( 4 );
- importDialog->addDateiTyp( "JPEG-Bild", "*.jpg;*.jpeg;*.jpe" );
- importDialog->addDateiTyp( "GIF-Bild", "*.gif" );
- importDialog->addDateiTyp( "PNG-Bild", "*.png" );
- importDialog->addDateiTyp( "Alle Dateien", "*.*" );
- importDialog->start();
- }
- }
- }
- void GUI::doTastaturEreignis( TastaturEreignis & te )
- {
- if( !sichtbar )
- return;
- liste->doTastaturEreignis( te );
- editor->doTastaturEreignis( te );
- }
- bool GUI::tick( double zeit )
- {
- if( importDialog )
- {
- if( !importDialog->isRunning() )
- {
- Text *importPfad = importDialog->getPfad();
- importDialog = importDialog->release();
- if( sichtbar && importPfad )
- {
- importPfad->ersetzen( "\\", "/" );
- Text *err = new Text();
- Bild *b = ladeBild( importPfad->getText(), err );
- if( !b )
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err, new Text( "Ok" ) );
- else
- data->setTextur( b );
- err->release();
- }
- if( importPfad )
- importPfad->release();
- }
- }
- rend |= speichern->tick( zeit );
- rend |= abbrechen->tick( zeit );
- if( sichtbar && alpha != 255 )
- {
- if( alpha + zeit * 200 > 255 )
- alpha = 255;
- else
- alpha += (unsigned char)( zeit * 200 );
- rend = 1;
- }
- else if( !sichtbar && alpha )
- {
- if( alpha - zeit * 200 < 0 )
- alpha = 0;
- else
- alpha -= (unsigned char)( zeit * 200 );
- rend = 1;
- }
- if( sichtbar )
- {
- rend |= editor->tick( zeit );
- rend |= liste->tick( zeit );
- rend |= speichern->tick( zeit );
- rend |= textur->tick( zeit );
- rend |= texturVerknüpfen->tick( zeit );
- rend |= texturLaden->tick( zeit );
- }
- bool ret = rend;
- rend = 0;
- return ret;
- }
- void GUI::render( Bild & zRObj )
- {
- zRObj.setAlpha( alpha );
- editor->render( zRObj );
- liste->render( zRObj );
- speichern->render( zRObj );
- abbrechen->render( zRObj );
- textur->render( zRObj );
- texturVerknüpfen->render( zRObj );
- texturLaden->render( zRObj );
- zRObj.releaseAlpha();
- }
- int GUI::getAktion()
- {
- int ret = aktion;
- aktion = 0;
- return ret;
- }
- // const
- Model2DData *GUI::getM2Data() const
- {
- return data->getM2();
- }
|