#include "Editor.h" #include "ActionThread.h" #include "Interface\Dialogs\Frage.h" #include "Interface\Dialogs\Nachricht.h" #include // Inhalt der Editor Klasse aus Editor.h // Konstruktor Editor::Editor() { schrift = 0; klient = 0; laden = 0; i = 0; alpha = 0; status = START; dialogs = new Array< Dialog* >(); rend = 1; ref = 1; } // Destruktor Editor::~Editor() { if( schrift ) schrift->release(); if( klient ) klient->release(); if( laden ) laden->release(); if( i ) i->release(); } // nicht constant void Editor::addDialog( Dialog *d ) { c.lock(); dialogs->add( d ); c.unlock(); } // nicht constant void Editor::setSchrift( Schrift *schrift ) { if( this->schrift ) this->schrift->release(); this->schrift = schrift; if( !i ) i = new Interface( schrift ); } void Editor::setKlient( KSGClient::EditorServerClient *ekv ) { if( klient ) klient->release(); klient = new EditorKlient( ekv ); } void Editor::setLadeAnimation( Animation2D *la ) { if( laden ) laden->release(); laden = la; } void Editor::setSichtbar() { status = START; EditorKlient *k = klient->getThis(); Schrift *zS = schrift->getThis(); Punkt mS = windowSize; new ActionThread( [ this, k, zS, mS ] (void) -> void { int ret = k->init(); if( ret == 2 ) { std::function< void() > wiederherstellen = [ k ] { // TODO Karte herunterladen und anzeigen }; std::function< void() > verwerfen = [ this, k, zS, mS ] { if( !k->sitzungVerwerfen() ) { Text t = "Fehler beim verwerfen der Sitzung: "; t += k->getLastError(); this->addDialog( new Nachricht( zS, t, mS ) ); } // TODO Karte herunterladen und anzeigen }; this->addDialog( new Frage( zS, "Es wurde eine alte ungespeicherte Sitzung gefunden. möchtest du sie Wiederherstellen?", "Ja", "Nein", wiederherstellen, verwerfen, verwerfen, mS ) ); zS->release(); k->release(); } } ); rend = 1; } void Editor::doMausEreignis( MausEreignis &me ) { c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) i.var->doMausEreignis( me ); bool dialogActive = dialogs->hat( 0 ); c.unlock(); i->doMausEreignis( me ); if( i->hatVerlassen() && status == INITIALIZED && !dialogActive ) { status = EXIT; } } void Editor::doTastaturEreignis( TastaturEreignis &te ) { c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) i.var->doTastaturEreignis( te ); c.unlock(); i->doTastaturEreignis( te ); } bool Editor::tick( double z ) { rend |= i->tick( z ); c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) rend |= i.var->tick( z ); c.unlock(); bool tmp = rend; rend = 0; return tmp; } void Editor::render( Bild &zRObj ) { i->render( zRObj ); c.lock(); for( int i = dialogs->getEintragAnzahl() - 1; i >= 0; i-- ) { dialogs->get( i )->render( zRObj ); if( dialogs->get( i )->hatVerlassen() ) { delete dialogs->get( i ); dialogs->remove( i ); } } c.unlock(); } // constant bool Editor::hatVerlassen( bool jetzt ) const { return status == EXIT; } // Reference Counting EditorV *Editor::getThis() { ref++; return this; } EditorV *Editor::release() { ref--; if( !ref ) delete this; return 0; }