NachrichtenListe.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. #include "NachrichtenListe.h"
  2. #include <Punkt.h>
  3. #include <MausEreignis.h>
  4. #include <Bild.h>
  5. #include "../../Global/Initialisierung.h"
  6. #include <Scroll.h>
  7. #include "../../Global/Variablen.h"
  8. #include <Rahmen.h>
  9. #include <DateiSystem.h>
  10. #include <KSGTDatei.h>
  11. #include <ToolTip.h>
  12. #include <GSLDateiV.h>
  13. typedef GSL::GSLDateiV *( *GetGSLDatei )( );
  14. NLNachricht::NLNachricht( Schrift *zSchrift, Text *titel )
  15. {
  16. rahmen = new LRahmen();
  17. rahmen->setRamenBreite( 1 );
  18. rahmen->setFarbe( 0xFFFFFFFF );
  19. this->titel = initTextFeld( 1, 1, 208, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, titel->getText() );
  20. titel = titel->release();
  21. close = initKnopf( 208, 1, 20, 20, 0, 0, "" );
  22. close->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::HAlpha | Knopf::Style::KlickBuffer );
  23. Bild *closeBild = bilder->get( "chat.ltdb/entfernen.png" );
  24. if( !closeBild )
  25. {
  26. LTDBDatei *datei = new LTDBDatei();
  27. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  28. datei->leseDaten( 0 );
  29. closeBild = datei->laden( 0, new Text( "entfernen.png" ) );
  30. datei->release();
  31. bilder->add( "chat.ltdb/entfernen.png", closeBild->getThis() );
  32. }
  33. close->setHintergrundBildZ( closeBild );
  34. initToolTip( close, "Nachricht ignorieren.", zSchrift->getThis(), hauptScreen );
  35. maxHöhe = 20;
  36. ref = 1;
  37. animation = 1;
  38. ausgewählt = 0;
  39. tickVal = 0;
  40. rend = 0;
  41. höhe = 0;
  42. }
  43. NLNachricht::~NLNachricht()
  44. {
  45. titel = titel->release();
  46. close = close->release();
  47. rahmen = rahmen->release();
  48. }
  49. void NLNachricht::entfernen()
  50. {
  51. animation = 3;
  52. }
  53. void NLNachricht::setAusgewählt( bool ausgewählt )
  54. {
  55. if( animation != 3 )
  56. {
  57. this->ausgewählt = ausgewählt;
  58. if( ausgewählt )
  59. animation = 2;
  60. else
  61. animation = 1;
  62. }
  63. }
  64. void NLNachricht::doMausEreignis( MausEreignis &me )
  65. {
  66. if( animation != 3 )
  67. {
  68. bool tmp = 0;
  69. if( me.my > höhe || !ausgewählt )
  70. {
  71. tmp = me.verarbeitet;
  72. me.verarbeitet = 1;
  73. }
  74. char aktion = me.verarbeitet ? 2 : 0;
  75. close->doMausEreignis( me );
  76. if( !aktion )
  77. aktion = me.verarbeitet ? 1 : 0;
  78. if( me.my > höhe || !ausgewählt )
  79. {
  80. me.verarbeitet = tmp;
  81. return;
  82. }
  83. if( me.id != ME_RLinks )
  84. return;
  85. if( aktion == 1 )
  86. entfernen();
  87. }
  88. }
  89. bool NLNachricht::tick( double tickVal )
  90. {
  91. rend |= close->tick( tickVal );
  92. if( !animation )
  93. {
  94. bool ret = rend;
  95. rend = 0;
  96. return ret;
  97. }
  98. this->tickVal += tickVal * 100;
  99. int val = (int)this->tickVal;
  100. if( val < 1 )
  101. {
  102. bool ret = rend;
  103. rend = 0;
  104. return ret;
  105. }
  106. if( val > 4 )
  107. val = 4;
  108. this->tickVal -= val;
  109. switch( animation )
  110. {
  111. case 1:
  112. if( höhe != 20 )
  113. {
  114. if( höhe > 20 )
  115. {
  116. höhe -= val;
  117. if( höhe < 20 )
  118. höhe = 20;
  119. }
  120. else
  121. {
  122. höhe += val;
  123. if( höhe > 20 )
  124. höhe = 20;
  125. }
  126. rend = 1;
  127. }
  128. else
  129. animation = 0;
  130. break;
  131. case 2:
  132. if( höhe != maxHöhe )
  133. {
  134. höhe += val;
  135. if( höhe > maxHöhe )
  136. höhe = maxHöhe;
  137. rend = 1;
  138. }
  139. else
  140. animation = 0;
  141. break;
  142. case 3:
  143. höhe -= val;
  144. if( höhe <= 0 )
  145. {
  146. nachLogin->zNachrichtenListe()->removeNachricht( this ); // delete this
  147. return 1;
  148. }
  149. rend = 1;
  150. break;
  151. }
  152. bool ret = rend;
  153. rend = 0;
  154. return ret;
  155. }
  156. void NLNachricht::render( int y, Bild &zRObj )
  157. {
  158. int br = 228;
  159. int hö = höhe;
  160. if( !zRObj.setDrawOptions( 0, y, br, hö ) )
  161. return;
  162. rahmen->setSize( br, hö );
  163. rahmen->render( zRObj );
  164. int rbr = rahmen->getRBreite();
  165. if( !zRObj.setDrawOptions( rbr, rbr, br - rbr * 2, hö - rbr * 2 ) )
  166. {
  167. zRObj.releaseDrawOptions();
  168. return;
  169. }
  170. titel->render( zRObj );
  171. close->render( zRObj );
  172. zRObj.releaseDrawOptions();
  173. zRObj.releaseDrawOptions();
  174. }
  175. // contant
  176. bool NLNachricht::istAusgewählt() const
  177. {
  178. return ausgewählt;
  179. }
  180. int NLNachricht::getHeight() const
  181. {
  182. return höhe;
  183. }
  184. Text *NLNachricht::zTitel() const
  185. {
  186. return titel->zText();
  187. }
  188. // Reference Counting
  189. NLNachricht *NLNachricht::getThis()
  190. {
  191. ref++;
  192. return this;
  193. }
  194. NLNachricht *NLNachricht::release()
  195. {
  196. ref--;
  197. if( !ref )
  198. delete this;
  199. return 0;
  200. }
  201. SpielUpdateNachricht::SpielUpdateNachricht( Schrift *zSchrift, Text *titel, Text *nachricht, int dgID, std::function<void()> posAk, std::function<void()> negAk )
  202. : NLNachricht( zSchrift, titel )
  203. {
  204. Text *result = new Text( nachricht->getText() );
  205. int län = nachricht->getLength();
  206. char *txt = nachricht->getText();
  207. int x = 0;
  208. int y = 0;
  209. zSchrift->lock();
  210. zSchrift->setSchriftSize( 12 );
  211. Alphabet *tmp = zSchrift->getAlphabet( 12 );
  212. int zeilenHöhe = tmp->getZeilenHeight() + tmp->getZeilenAbstand();
  213. int lastPos = -1;
  214. for( int i = 0; i < län; i++ )
  215. {
  216. char c = txt[ i ];
  217. if( c == ' ' )
  218. {
  219. lastPos = i;
  220. x += 6;
  221. continue;
  222. }
  223. if( c == '\n' )
  224. {
  225. x = 0;
  226. y += zeilenHöhe;
  227. lastPos = -1;
  228. continue;
  229. }
  230. Buchstabe *b = tmp->getBuchstabe( (unsigned)c );
  231. if( b )
  232. {
  233. x += b->getBreite();
  234. if( x > 228 && lastPos > -1 )
  235. {
  236. result->ersetzen( lastPos, lastPos + 1, "\n" );
  237. x = 0;
  238. y += zeilenHöhe;
  239. i = lastPos;
  240. lastPos = -1;
  241. }
  242. b = b->release();
  243. }
  244. }
  245. y += zeilenHöhe;
  246. tmp = tmp->release();
  247. zSchrift->unlock();
  248. nachricht = nachricht->release();
  249. text = initTextFeld( 1, 22, 228, y, zSchrift, TextFeld::Style::Text, result->getText() );
  250. result = result->release();
  251. fortschritt = initFBalken( 5, y + 20, 215, 20, zSchrift, FBalken::Style::normal );
  252. herunterladen = initKnopf( 10, 45 + y, 120, 20, zSchrift, Knopf::Style::Sichtbar, "herunterladen" );
  253. abbrechen = initKnopf( 140, 45 + y, 80, 20, zSchrift, Knopf::Style::Sichtbar, "abbrechen" );
  254. this->posAk = posAk;
  255. this->negAk = negAk;
  256. maxHöhe = 75 + y;
  257. update = new Update( zSchrift, fortschritt->getThis(), dgID, [this]( bool ok )
  258. {
  259. this->animation = 3;
  260. if( ok )
  261. this->posAk();
  262. else
  263. this->negAk();
  264. } );
  265. if( !updateH->add( update->getThis() ) )
  266. entfernen();
  267. }
  268. SpielUpdateNachricht::~SpielUpdateNachricht()
  269. {
  270. text->release();
  271. herunterladen->release();
  272. abbrechen->release();
  273. fortschritt->release();
  274. updateH->remove( update->getDateiGruppe() );
  275. update->release();
  276. }
  277. // nicht constant
  278. void SpielUpdateNachricht::entfernen()
  279. {
  280. __super::entfernen();
  281. negAk();
  282. }
  283. void SpielUpdateNachricht::doMausEreignis( MausEreignis &me )
  284. {
  285. __super::doMausEreignis( me );
  286. if( animation != 3 )
  287. {
  288. bool tmp = 0;
  289. if( me.my > höhe || !ausgewählt )
  290. {
  291. tmp = me.verarbeitet;
  292. me.verarbeitet = 1;
  293. }
  294. char aktion = me.verarbeitet ? 3 : 0;
  295. herunterladen->doMausEreignis( me );
  296. if( !aktion )
  297. aktion = me.verarbeitet ? 1 : 0;
  298. abbrechen->doMausEreignis( me );
  299. if( !aktion )
  300. aktion = me.verarbeitet ? 2 : 0;
  301. if( me.my > höhe || !ausgewählt )
  302. {
  303. me.verarbeitet = tmp;
  304. return;
  305. }
  306. if( me.id != ME_RLinks )
  307. return;
  308. switch( aktion )
  309. {
  310. case 1:
  311. // positiv
  312. update->herunterladen();
  313. herunterladen->removeStyle( Knopf::Style::Erlaubt | Knopf::Style::Sichtbar );
  314. break;
  315. case 2:
  316. // negativ
  317. update->abbrechen();
  318. abbrechen->removeStyle( Knopf::Style::Erlaubt | Knopf::Style::Sichtbar );
  319. break;
  320. }
  321. }
  322. }
  323. bool SpielUpdateNachricht::tick( double tickVal )
  324. {
  325. rend |= herunterladen->tick( tickVal );
  326. rend |= fortschritt->tick( tickVal );
  327. rend |= abbrechen->tick( tickVal );
  328. rend |= text->tick( tickVal );
  329. return __super::tick( tickVal );
  330. }
  331. void SpielUpdateNachricht::render( int y, Bild &zRObj )
  332. {
  333. __super::render( y, zRObj );
  334. int rbr = rahmen->getRBreite();
  335. if( !zRObj.setDrawOptions( rbr, y + rbr, rahmen->getBreite() - rbr * 2, rahmen->getHeight() - rbr * 2 ) )
  336. return;
  337. text->render( zRObj );
  338. fortschritt->render( zRObj );
  339. herunterladen->render( zRObj );
  340. abbrechen->render( zRObj );
  341. zRObj.releaseDrawOptions();
  342. }
  343. // Inhalt der Nachricht Klasse aus NachrichtListe.h
  344. // Konstruktor
  345. Nachricht::Nachricht( Schrift *zSchrift, Text *titel, Text *nachricht, Text *positiv, Text *negativ, std::function<void()> posAk, std::function<void()> negAk )
  346. : NLNachricht( zSchrift, titel )
  347. {
  348. Text *result = new Text( nachricht->getText() );
  349. int län = nachricht->getLength();
  350. char *txt = nachricht->getText();
  351. int x = 0;
  352. int y = 0;
  353. zSchrift->lock();
  354. zSchrift->setSchriftSize( 12 );
  355. Alphabet *tmp = zSchrift->getAlphabet( 12 );
  356. int zeilenHöhe = tmp->getZeilenHeight() + tmp->getZeilenAbstand();
  357. int lastPos = -1;
  358. for( int i = 0; i < län; i++ )
  359. {
  360. char c = txt[ i ];
  361. if( c == ' ' )
  362. {
  363. lastPos = i;
  364. x += 6;
  365. continue;
  366. }
  367. if( c == '\n' )
  368. {
  369. x = 0;
  370. y += zeilenHöhe;
  371. lastPos = -1;
  372. continue;
  373. }
  374. Buchstabe *b = tmp->getBuchstabe( (unsigned)c );
  375. if( b )
  376. {
  377. x += b->getBreite();
  378. if( x > 228 && lastPos > -1 )
  379. {
  380. result->ersetzen( lastPos, lastPos + 1, "\n" );
  381. x = 0;
  382. y += zeilenHöhe;
  383. i = lastPos;
  384. lastPos = -1;
  385. }
  386. b = b->release();
  387. }
  388. }
  389. y += zeilenHöhe;
  390. tmp = tmp->release();
  391. zSchrift->unlock();
  392. nachricht = nachricht->release();
  393. text = initTextFeld( 1, 22, 228, y, zSchrift, TextFeld::Style::Text, result->getText() );
  394. result = result->release();
  395. if( positiv )
  396. {
  397. this->positiv = initKnopf( 10, 20 + y, 100, 20, zSchrift, Knopf::Style::Sichtbar, positiv->getText() );
  398. positiv = positiv->release();
  399. }
  400. else
  401. this->positiv = 0;
  402. if( negativ )
  403. {
  404. this->negativ = initKnopf( 120, 20 + y, 100, 20, zSchrift, Knopf::Style::Sichtbar, negativ->getText() );
  405. negativ = negativ->release();
  406. }
  407. else
  408. this->negativ = 0;
  409. this->posAk = posAk;
  410. this->negAk = negAk;
  411. maxHöhe = 50 + y;
  412. }
  413. // Destruktor
  414. Nachricht::~Nachricht()
  415. {
  416. text = text->release();
  417. if( positiv )
  418. positiv = positiv->release();
  419. if( negativ )
  420. negativ = negativ->release();
  421. }
  422. void Nachricht::entfernen()
  423. {
  424. __super::entfernen();
  425. negAk();
  426. }
  427. void Nachricht::doMausEreignis( MausEreignis &me )
  428. {
  429. __super::doMausEreignis( me );
  430. if( animation != 3 )
  431. {
  432. bool tmp = 0;
  433. if( me.my > höhe || !ausgewählt )
  434. {
  435. tmp = me.verarbeitet;
  436. me.verarbeitet = 1;
  437. }
  438. char aktion = me.verarbeitet ? 3 : 0;
  439. if( positiv )
  440. positiv->doMausEreignis( me );
  441. if( !aktion )
  442. aktion = me.verarbeitet ? 1 : 0;
  443. if( negativ )
  444. negativ->doMausEreignis( me );
  445. if( !aktion )
  446. aktion = me.verarbeitet ? 2 : 0;
  447. if( me.my > höhe || !ausgewählt )
  448. {
  449. me.verarbeitet = tmp;
  450. return;
  451. }
  452. if( me.id != ME_RLinks )
  453. return;
  454. if( aktion )
  455. entfernen();
  456. switch( aktion )
  457. {
  458. case 1:
  459. // positiv
  460. posAk();
  461. break;
  462. case 2:
  463. // negativ
  464. negAk();
  465. break;
  466. }
  467. }
  468. }
  469. bool Nachricht::tick( double tickVal )
  470. {
  471. rend |= positiv ? positiv->tick( tickVal ) : 0;
  472. rend |= negativ ? negativ->tick( tickVal ) : 0;
  473. rend |= text->tick( tickVal );
  474. return __super::tick( tickVal );
  475. }
  476. void Nachricht::render( int yPos, Bild &zRObj )
  477. {
  478. __super::render( yPos, zRObj );
  479. int rbr = rahmen->getRBreite();
  480. if( !zRObj.setDrawOptions( rbr, yPos + rbr, rahmen->getBreite() - rbr * 2, rahmen->getHeight() - rbr * 2 ) )
  481. return;
  482. text->render( zRObj );
  483. if( positiv )
  484. positiv->render( zRObj );
  485. if( negativ )
  486. negativ->render( zRObj );
  487. zRObj.releaseDrawOptions();
  488. }
  489. // Inhalt der NachrichtenListeObj Klasse aus NachrichtListe.h
  490. // Konstruktor
  491. NachrichtenListeObj::NachrichtenListeObj( Schrift *zSchrift )
  492. : Zeichnung()
  493. {
  494. members = new RCArray< NLNachricht >();
  495. schrift = zSchrift->getThis();
  496. vsb = new VScrollBar();
  497. vsb->setKlickScroll( 10 );
  498. bildschirmGröße = BildschirmGröße();
  499. vsb->update( 0, bildschirmGröße.y - 122 );
  500. anzahl = 0;
  501. gr = Punkt( 250, bildschirmGröße.y - 122 );
  502. ref = 1;
  503. }
  504. // Destruktor
  505. NachrichtenListeObj::~NachrichtenListeObj()
  506. {
  507. schrift = schrift->release();
  508. vsb = (VScrollBar*)vsb->release();
  509. members = members->release();
  510. }
  511. // nicht constant
  512. void NachrichtenListeObj::addNachricht( NLNachricht *nachricht )
  513. {
  514. members->add( nachricht, anzahl );
  515. anzahl++;
  516. rend = 1;
  517. }
  518. void NachrichtenListeObj::removeNachricht( NLNachricht *zNachricht )
  519. {
  520. for( int i = 0; i < anzahl; i++ )
  521. {
  522. if( members->z( i ) == zNachricht )
  523. {
  524. members->remove( i );
  525. anzahl--;
  526. rend = 1;
  527. break;
  528. }
  529. }
  530. }
  531. void NachrichtenListeObj::removeAll()
  532. {
  533. lockZeichnung();
  534. members->leeren();
  535. anzahl = 0;
  536. rend = 1;
  537. unlockZeichnung();
  538. }
  539. bool NachrichtenListeObj::tick( double tickVal )
  540. {
  541. lockZeichnung();
  542. rend |= vsb->getRend();
  543. rend |= nachLogin->zNachrichtenListe()->tick( tickVal );
  544. for( int i = 0; i < anzahl; i++ )
  545. {
  546. NLNachricht *tmp = members->z( i );
  547. if( tmp )
  548. rend |= tmp->tick( tickVal );
  549. }
  550. unlockZeichnung();
  551. bool ret = rend;
  552. rend = 0;
  553. return ret;
  554. }
  555. void NachrichtenListeObj::doMausEreignis( MausEreignis &me )
  556. {
  557. lockZeichnung();
  558. int my = me.my;
  559. me.my -= 20;
  560. if( me.mx <= 229 && me.mx > 0 && me.my >= 0 )
  561. {
  562. me.my += vsb->getScroll();
  563. for( int i = 0; i < anzahl; i++ )
  564. {
  565. NLNachricht *tmp = members->z( i );
  566. if( tmp )
  567. {
  568. if( me.my > 0 && me.my < tmp->getHeight() )
  569. tmp->setAusgewählt( 1 );
  570. else
  571. tmp->setAusgewählt( 0 );
  572. tmp->doMausEreignis( me );
  573. me.my -= tmp->getHeight();
  574. }
  575. }
  576. me.my -= vsb->getScroll();
  577. }
  578. else
  579. {
  580. me.my += vsb->getScroll();
  581. for( int i = 0; i < anzahl; i++ )
  582. {
  583. NLNachricht *tmp = members->z( i );
  584. if( tmp )
  585. {
  586. tmp->setAusgewählt( 0 );
  587. tmp->doMausEreignis( me );
  588. me.my -= tmp->getHeight();
  589. }
  590. }
  591. me.my -= vsb->getScroll();
  592. }
  593. me.my = my;
  594. vsb->doMausMessage( 229, 20, 20, bildschirmGröße.y - 122, me );
  595. unlockZeichnung();
  596. }
  597. void NachrichtenListeObj::render( Bild &zrObj )
  598. {
  599. lockZeichnung();
  600. int x = pos.x;
  601. int y = pos.y;
  602. int br = gr.x;
  603. int hö = gr.y;
  604. if( !zrObj.setDrawOptions( x, y, br, hö ) )
  605. {
  606. unlockZeichnung();
  607. return;
  608. }
  609. int höhe = 0;
  610. for( int i = 0; i < anzahl; i++ )
  611. {
  612. NLNachricht *tmp = members->z( i );
  613. tmp->render( höhe - ( vsb ? vsb->getScroll() : 0 ), zrObj );
  614. höhe += tmp->getHeight();
  615. }
  616. if( vsb )
  617. {
  618. vsb->update( höhe, bildschirmGröße.y - 122 );
  619. vsb->render( 229, 0, 20, bildschirmGröße.y - 122, zrObj );
  620. }
  621. zrObj.releaseDrawOptions();
  622. unlockZeichnung();
  623. }
  624. // contant
  625. // Reference Counting
  626. NachrichtenListeObj *NachrichtenListeObj::getThis()
  627. {
  628. ref++;
  629. return this;
  630. }
  631. NachrichtenListeObj *NachrichtenListeObj::release()
  632. {
  633. ref--;
  634. if( !ref )
  635. delete this;
  636. return 0;
  637. }
  638. // Inhalt der NachrichtenListe Klasse aus NachrichtListe.h
  639. // Konstruktor
  640. NachrichtenListe::NachrichtenListe( Schrift *zSchrift, Fenster *zNachLoginFenster )
  641. {
  642. schrift = zSchrift->getThis();
  643. minimierenBild = bilder->get( "chat.ltdb/minimieren.png" );
  644. if( !minimierenBild )
  645. {
  646. LTDBDatei *datei = new LTDBDatei();
  647. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  648. datei->leseDaten( 0 );
  649. minimierenBild = datei->laden( 0, new Text( "minimieren.png" ) );
  650. datei->release();
  651. bilder->add( "chat.ltdb/minimieren.png", minimierenBild->getThis() );
  652. }
  653. maximierenBild = bilder->get( "chat.ltdb/maximieren.png" );
  654. if( !maximierenBild )
  655. {
  656. LTDBDatei *datei = new LTDBDatei();
  657. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  658. datei->leseDaten( 0 );
  659. maximierenBild = datei->laden( 0, new Text( "maximieren.png" ) );
  660. datei->release();
  661. bilder->add( "chat.ltdb/maximieren.png", maximierenBild->getThis() );
  662. }
  663. bildschirmGröße = BildschirmGröße();
  664. fenster = initFenster( bildschirmGröße.x - 21, 100, 250, 22, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::BodyHintergrund, "" );
  665. fenster->setKBgFarbe( 0xFF000000 );
  666. überschrift = initTextFeld( 1, 1, 248, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center | TextFeld::Style::Sichtbar, "Nachrichten" );
  667. überschrift->setSchriftSize( 15 );
  668. fenster->addMember( überschrift );
  669. minMax = initKnopf( 1, 1, 20, 20, 0, 0, "" );
  670. minMax->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::HAlpha | Knopf::Style::KlickBuffer );
  671. minMax->setMausEreignisParameter( this );
  672. minMax->setMausEreignis( NachrichtenListeMinMaxME );
  673. minMax->setHintergrundBildZ( minimierenBild->getThis() );
  674. initToolTip( minMax, "Nachrichten Leiste minimieren.", zSchrift->getThis(), hauptScreen );
  675. fenster->addMember( minMax );
  676. nachrichtenListe = new NachrichtenListeObj( zSchrift );
  677. nachrichtenListe->setPosition( 1, 21 );
  678. nachrichtenListe->setSize( 248, bildschirmGröße.y - 122 );
  679. fenster->addMember( nachrichtenListe );
  680. zNachLoginFenster->addMember( fenster );
  681. tickVal = 0;
  682. animation = 1;
  683. rend = 0;
  684. msgSound = 0;
  685. errSound = 0;
  686. HMODULE dll = dllDateien->ladeDLL( "GSL.dll", "data/bin/GSL.dll" );
  687. if( dll )
  688. {
  689. GetGSLDatei getGSLDatei = (GetGSLDatei)GetProcAddress( dll, "getGSLDatei" );
  690. if( getGSLDatei )
  691. {
  692. GSL::GSLDateiV *sDat = getGSLDatei();
  693. sDat->setDatei( "data/sounds/popup.gsl" );
  694. sDat->leseDaten();
  695. msgSound = sDat->getSound( "info.wav" );
  696. errSound = sDat->getSound( "error.wav" );
  697. sDat->release();
  698. if( msgSound )
  699. msgSound->setVolume( 0xFFFF, 0xFFFF );
  700. if( errSound )
  701. errSound->setVolume( 0xFFFF, 0xFFFF );
  702. }
  703. if( !msgSound && !errSound )
  704. dllDateien->releaseDLL( "GSL.dll" );
  705. }
  706. ref = 1;
  707. }
  708. // Destruktor
  709. NachrichtenListe::~NachrichtenListe()
  710. {
  711. if( msgSound || errSound )
  712. {
  713. if( msgSound )
  714. {
  715. msgSound->stopSound();
  716. msgSound->release();
  717. }
  718. if( errSound )
  719. {
  720. errSound->stopSound();
  721. errSound->release();
  722. }
  723. dllDateien->releaseDLL( "GSL.dll" );
  724. }
  725. überschrift = überschrift->release();
  726. fenster = fenster->release();
  727. minMax = minMax->release();
  728. nachrichtenListe = nachrichtenListe->release();
  729. minimierenBild = minimierenBild->release();
  730. maximierenBild = maximierenBild->release();
  731. schrift->release();
  732. }
  733. // nicht constant
  734. void NachrichtenListe::addNachricht( Text *titel, Text *nachricht, Text *positiv, Text *negativ, std::function<void()> posAk, std::function<void()> negAk )
  735. {
  736. if( titel && titel->hat( "Fehler" ) && errSound )
  737. errSound->playSound();
  738. else if( msgSound )
  739. msgSound->playSound();
  740. nachrichtenListe->addNachricht( new Nachricht( schrift, titel, nachricht, positiv, negativ, posAk, negAk ) );
  741. }
  742. void NachrichtenListe::addNachricht( NLNachricht *nachricht )
  743. {
  744. if( nachricht->zTitel() && nachricht->zTitel()->hat( "Fehler" ) && errSound )
  745. errSound->playSound();
  746. else if( msgSound )
  747. msgSound->playSound();
  748. nachrichtenListe->addNachricht( nachricht );
  749. }
  750. void NachrichtenListe::removeNachricht( NLNachricht *zNachricht )
  751. {
  752. nachrichtenListe->removeNachricht( zNachricht );
  753. }
  754. void NachrichtenListe::removeAll()
  755. {
  756. nachrichtenListe->removeAll();
  757. }
  758. bool NachrichtenListe::druckMinMax( MausEreignis &me )
  759. {
  760. if( me.id == ME_RLinks )
  761. {
  762. if( minMax->zHintergrundBild() == minimierenBild )
  763. {
  764. animation = 2;
  765. minMax->setHintergrundBildZ( maximierenBild->getThis() );
  766. minMax->zToolTip()->setText( "Nachrichten Leiste maximieren." );
  767. }
  768. else
  769. {
  770. animation = 1;
  771. minMax->setHintergrundBildZ( minimierenBild->getThis() );
  772. minMax->zToolTip()->setText( "Nachrichten Leiste minimieren." );
  773. }
  774. }
  775. return 1;
  776. }
  777. bool NachrichtenListe::tick( double tickVal )
  778. {
  779. if( !animation )
  780. {
  781. bool ret = rend;
  782. rend = 0;
  783. return ret;
  784. }
  785. this->tickVal += tickVal * 400;
  786. int val = ( int )this->tickVal;
  787. if( val < 1 )
  788. {
  789. bool ret = rend;
  790. rend = 0;
  791. return ret;
  792. }
  793. if( val > 14 )
  794. val = 14;
  795. this->tickVal -= val;
  796. switch( animation )
  797. {
  798. case 1: // maximieren
  799. if( fenster->getX() > bildschirmGröße.x - 250 )
  800. {
  801. fenster->setPosition( fenster->getX() - val, fenster->getY() );
  802. minMax->setPosition( minMax->getX() + val, minMax->getY() );
  803. if( fenster->getX() < bildschirmGröße.x - 250 )
  804. {
  805. fenster->setPosition( bildschirmGröße.x - 250, fenster->getY() );
  806. minMax->setPosition( 229, minMax->getY() );
  807. }
  808. rend = 1;
  809. }
  810. else if( fenster->getHeight() < bildschirmGröße.y - 100 )
  811. {
  812. fenster->setSize( fenster->getBreite(), fenster->getHeight() + val );
  813. if( fenster->getHeight() >= bildschirmGröße.y - 100 )
  814. {
  815. fenster->setSize( fenster->getBreite(), bildschirmGröße.y - 100 );
  816. animation = 0;
  817. }
  818. rend = 1;
  819. }
  820. break;
  821. case 2: // minimieren
  822. if( fenster->getHeight() > 22 )
  823. {
  824. fenster->setSize( fenster->getBreite(), fenster->getHeight() - val );
  825. if( fenster->getHeight() < 22 )
  826. fenster->setSize( fenster->getBreite(), 22 );
  827. rend = 1;
  828. }
  829. else if( fenster->getX() < bildschirmGröße.x - 21 )
  830. {
  831. minMax->setPosition( minMax->getX() - val, minMax->getY() );
  832. fenster->setPosition( fenster->getX() + val, fenster->getY() );
  833. if( fenster->getX() >= bildschirmGröße.x - 21 )
  834. {
  835. minMax->setPosition( 1, minMax->getY() );
  836. fenster->setPosition( bildschirmGröße.x - 21, fenster->getY() );
  837. animation = 0;
  838. }
  839. rend = 1;
  840. }
  841. break;
  842. }
  843. bool ret = rend;
  844. rend = 0;
  845. return ret;
  846. }
  847. // contant
  848. Schrift *NachrichtenListe::zSchrift() const
  849. {
  850. return schrift;
  851. }
  852. // Reference Counting
  853. NachrichtenListe *NachrichtenListe::getThis()
  854. {
  855. ref++;
  856. return this;
  857. }
  858. NachrichtenListe *NachrichtenListe::release()
  859. {
  860. ref--;
  861. if( !ref )
  862. delete this;
  863. return 0;
  864. }
  865. // Nachrichten
  866. bool NachrichtenListeMinMaxME( void *p, void *obj, MausEreignis me )
  867. {
  868. return ( (NachrichtenListe*)p )->druckMinMax( me );
  869. }