NachrichtenListe.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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->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. Alphabet *tmp = zSchrift->getAlphabet( 12 );
  210. TextRenderer rd( zSchrift->getThis() );
  211. rd.setSchriftSize( 12 );
  212. int zeilenHöhe = rd.getZeilenHeight() + rd.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. nachricht = nachricht->release();
  248. text = initTextFeld( 1, 22, 228, y, zSchrift, TextFeld::Style::Text, result->getText() );
  249. result = result->release();
  250. fortschritt = initFBalken( 5, y + 20, 215, 20, zSchrift, FBalken::Style::normal );
  251. herunterladen = initKnopf( 10, 45 + y, 120, 20, zSchrift, Knopf::Style::Sichtbar, "herunterladen" );
  252. abbrechen = initKnopf( 140, 45 + y, 80, 20, zSchrift, Knopf::Style::Sichtbar, "abbrechen" );
  253. this->posAk = posAk;
  254. this->negAk = negAk;
  255. maxHöhe = 75 + y;
  256. update = new Update( zSchrift, fortschritt->getThis(), dgID, [this]( bool ok )
  257. {
  258. this->animation = 3;
  259. if( ok )
  260. this->posAk();
  261. else
  262. this->negAk();
  263. } );
  264. if( !updateH->add( update->getThis() ) )
  265. entfernen();
  266. }
  267. SpielUpdateNachricht::~SpielUpdateNachricht()
  268. {
  269. text->release();
  270. herunterladen->release();
  271. abbrechen->release();
  272. fortschritt->release();
  273. updateH->remove( update->getDateiGruppe() );
  274. update->release();
  275. }
  276. // nicht constant
  277. void SpielUpdateNachricht::entfernen()
  278. {
  279. __super::entfernen();
  280. negAk();
  281. }
  282. void SpielUpdateNachricht::doMausEreignis( MausEreignis &me )
  283. {
  284. __super::doMausEreignis( me );
  285. if( animation != 3 )
  286. {
  287. bool tmp = 0;
  288. if( me.my > höhe || !ausgewählt )
  289. {
  290. tmp = me.verarbeitet;
  291. me.verarbeitet = 1;
  292. }
  293. char aktion = me.verarbeitet ? 3 : 0;
  294. herunterladen->doMausEreignis( me );
  295. if( !aktion )
  296. aktion = me.verarbeitet ? 1 : 0;
  297. abbrechen->doMausEreignis( me );
  298. if( !aktion )
  299. aktion = me.verarbeitet ? 2 : 0;
  300. if( me.my > höhe || !ausgewählt )
  301. {
  302. me.verarbeitet = tmp;
  303. return;
  304. }
  305. if( me.id != ME_RLinks )
  306. return;
  307. switch( aktion )
  308. {
  309. case 1:
  310. // positiv
  311. update->herunterladen();
  312. herunterladen->removeStyle( Knopf::Style::Erlaubt | Knopf::Style::Sichtbar );
  313. break;
  314. case 2:
  315. // negativ
  316. update->abbrechen();
  317. abbrechen->removeStyle( Knopf::Style::Erlaubt | Knopf::Style::Sichtbar );
  318. break;
  319. }
  320. }
  321. }
  322. bool SpielUpdateNachricht::tick( double tickVal )
  323. {
  324. rend |= herunterladen->tick( tickVal );
  325. rend |= fortschritt->tick( tickVal );
  326. rend |= abbrechen->tick( tickVal );
  327. rend |= text->tick( tickVal );
  328. return __super::tick( tickVal );
  329. }
  330. void SpielUpdateNachricht::render( int y, Bild &zRObj )
  331. {
  332. __super::render( y, zRObj );
  333. int rbr = rahmen->getRBreite();
  334. if( !zRObj.setDrawOptions( rbr, y + rbr, rahmen->getBreite() - rbr * 2, rahmen->getHeight() - rbr * 2 ) )
  335. return;
  336. text->render( zRObj );
  337. fortschritt->render( zRObj );
  338. herunterladen->render( zRObj );
  339. abbrechen->render( zRObj );
  340. zRObj.releaseDrawOptions();
  341. }
  342. // Inhalt der Nachricht Klasse aus NachrichtListe.h
  343. // Konstruktor
  344. Nachricht::Nachricht( Schrift *zSchrift, Text *titel, Text *nachricht, Text *positiv, Text *negativ, std::function<void()> posAk, std::function<void()> negAk )
  345. : NLNachricht( zSchrift, titel )
  346. {
  347. Text *result = new Text( nachricht->getText() );
  348. int län = nachricht->getLength();
  349. char *txt = nachricht->getText();
  350. int x = 0;
  351. int y = 0;
  352. Alphabet *tmp = zSchrift->getAlphabet( 12 );
  353. TextRenderer rd( zSchrift->getThis() );
  354. rd.setSchriftSize( 12 );
  355. int zeilenHöhe = rd.getZeilenHeight() + rd.getZeilenAbstand();
  356. int lastPos = -1;
  357. for( int i = 0; i < län; i++ )
  358. {
  359. char c = txt[ i ];
  360. if( c == ' ' )
  361. {
  362. lastPos = i;
  363. x += 6;
  364. continue;
  365. }
  366. if( c == '\n' )
  367. {
  368. x = 0;
  369. y += zeilenHöhe;
  370. lastPos = -1;
  371. continue;
  372. }
  373. Buchstabe *b = tmp->getBuchstabe( (unsigned)c );
  374. if( b )
  375. {
  376. x += b->getBreite();
  377. if( x > 228 && lastPos > -1 )
  378. {
  379. result->ersetzen( lastPos, lastPos + 1, "\n" );
  380. x = 0;
  381. y += zeilenHöhe;
  382. i = lastPos;
  383. lastPos = -1;
  384. }
  385. b = b->release();
  386. }
  387. }
  388. y += zeilenHöhe;
  389. tmp = tmp->release();
  390. nachricht = nachricht->release();
  391. text = initTextFeld( 1, 22, 228, y, zSchrift, TextFeld::Style::Text, result->getText() );
  392. result = result->release();
  393. if( positiv )
  394. {
  395. this->positiv = initKnopf( 10, 20 + y, 100, 20, zSchrift, Knopf::Style::Sichtbar, positiv->getText() );
  396. positiv = positiv->release();
  397. }
  398. else
  399. this->positiv = 0;
  400. if( negativ )
  401. {
  402. this->negativ = initKnopf( 120, 20 + y, 100, 20, zSchrift, Knopf::Style::Sichtbar, negativ->getText() );
  403. negativ = negativ->release();
  404. }
  405. else
  406. this->negativ = 0;
  407. this->posAk = posAk;
  408. this->negAk = negAk;
  409. maxHöhe = 50 + y;
  410. }
  411. // Destruktor
  412. Nachricht::~Nachricht()
  413. {
  414. text = text->release();
  415. if( positiv )
  416. positiv = positiv->release();
  417. if( negativ )
  418. negativ = negativ->release();
  419. }
  420. void Nachricht::entfernen()
  421. {
  422. __super::entfernen();
  423. negAk();
  424. }
  425. void Nachricht::doMausEreignis( MausEreignis &me )
  426. {
  427. __super::doMausEreignis( me );
  428. if( animation != 3 )
  429. {
  430. bool tmp = 0;
  431. if( me.my > höhe || !ausgewählt )
  432. {
  433. tmp = me.verarbeitet;
  434. me.verarbeitet = 1;
  435. }
  436. char aktion = me.verarbeitet ? 3 : 0;
  437. if( positiv )
  438. positiv->doMausEreignis( me );
  439. if( !aktion )
  440. aktion = me.verarbeitet ? 1 : 0;
  441. if( negativ )
  442. negativ->doMausEreignis( me );
  443. if( !aktion )
  444. aktion = me.verarbeitet ? 2 : 0;
  445. if( me.my > höhe || !ausgewählt )
  446. {
  447. me.verarbeitet = tmp;
  448. return;
  449. }
  450. if( me.id != ME_RLinks )
  451. return;
  452. switch( aktion )
  453. {
  454. case 1:
  455. // positiv
  456. __super::entfernen();
  457. posAk();
  458. break;
  459. case 2:
  460. // negativ
  461. __super::entfernen();
  462. negAk();
  463. break;
  464. }
  465. }
  466. }
  467. bool Nachricht::tick( double tickVal )
  468. {
  469. rend |= positiv ? positiv->tick( tickVal ) : 0;
  470. rend |= negativ ? negativ->tick( tickVal ) : 0;
  471. rend |= text->tick( tickVal );
  472. return __super::tick( tickVal );
  473. }
  474. void Nachricht::render( int yPos, Bild &zRObj )
  475. {
  476. __super::render( yPos, zRObj );
  477. int rbr = rahmen->getRBreite();
  478. if( !zRObj.setDrawOptions( rbr, yPos + rbr, rahmen->getBreite() - rbr * 2, rahmen->getHeight() - rbr * 2 ) )
  479. return;
  480. text->render( zRObj );
  481. if( positiv )
  482. positiv->render( zRObj );
  483. if( negativ )
  484. negativ->render( zRObj );
  485. zRObj.releaseDrawOptions();
  486. }
  487. // Inhalt der NachrichtenListeObj Klasse aus NachrichtListe.h
  488. // Konstruktor
  489. NachrichtenListeObj::NachrichtenListeObj( Schrift *zSchrift )
  490. : Zeichnung()
  491. {
  492. members = new RCArray< NLNachricht >();
  493. schrift = zSchrift->getThis();
  494. vsb = new VScrollBar();
  495. vsb->setKlickScroll( 10 );
  496. bildschirmGröße = BildschirmGröße();
  497. vsb->update( 0, bildschirmGröße.y - 122 );
  498. anzahl = 0;
  499. gr = Punkt( 250, bildschirmGröße.y - 122 );
  500. ref = 1;
  501. }
  502. // Destruktor
  503. NachrichtenListeObj::~NachrichtenListeObj()
  504. {
  505. schrift = schrift->release();
  506. vsb = (VScrollBar*)vsb->release();
  507. members = members->release();
  508. }
  509. // nicht constant
  510. void NachrichtenListeObj::addNachricht( NLNachricht *nachricht )
  511. {
  512. members->add( nachricht, anzahl );
  513. anzahl++;
  514. rend = 1;
  515. }
  516. void NachrichtenListeObj::removeNachricht( NLNachricht *zNachricht )
  517. {
  518. for( int i = 0; i < anzahl; i++ )
  519. {
  520. if( members->z( i ) == zNachricht )
  521. {
  522. members->remove( i );
  523. anzahl--;
  524. rend = 1;
  525. break;
  526. }
  527. }
  528. }
  529. void NachrichtenListeObj::removeAll()
  530. {
  531. lockZeichnung();
  532. members->leeren();
  533. anzahl = 0;
  534. rend = 1;
  535. unlockZeichnung();
  536. }
  537. bool NachrichtenListeObj::tick( double tickVal )
  538. {
  539. lockZeichnung();
  540. rend |= vsb->getRend();
  541. rend |= nachLogin->zNachrichtenListe()->tick( tickVal );
  542. for( int i = 0; i < anzahl; i++ )
  543. {
  544. NLNachricht *tmp = members->z( i );
  545. if( tmp )
  546. rend |= tmp->tick( tickVal );
  547. }
  548. unlockZeichnung();
  549. bool ret = rend;
  550. rend = 0;
  551. return ret;
  552. }
  553. void NachrichtenListeObj::doMausEreignis( MausEreignis &me )
  554. {
  555. lockZeichnung();
  556. int my = me.my;
  557. me.my -= 20;
  558. if( me.mx <= 229 && me.mx > 0 && me.my >= 0 )
  559. {
  560. me.my += vsb->getScroll();
  561. for( int i = 0; i < anzahl; i++ )
  562. {
  563. NLNachricht *tmp = members->z( i );
  564. if( tmp )
  565. {
  566. if( me.my > 0 && me.my < tmp->getHeight() )
  567. tmp->setAusgewählt( 1 );
  568. else
  569. tmp->setAusgewählt( 0 );
  570. tmp->doMausEreignis( me );
  571. me.my -= tmp->getHeight();
  572. }
  573. }
  574. me.my -= vsb->getScroll();
  575. }
  576. else
  577. {
  578. me.my += vsb->getScroll();
  579. for( int i = 0; i < anzahl; i++ )
  580. {
  581. NLNachricht *tmp = members->z( i );
  582. if( tmp )
  583. {
  584. tmp->setAusgewählt( 0 );
  585. tmp->doMausEreignis( me );
  586. me.my -= tmp->getHeight();
  587. }
  588. }
  589. me.my -= vsb->getScroll();
  590. }
  591. me.my = my;
  592. vsb->doMausMessage( 229, 20, 20, bildschirmGröße.y - 122, me );
  593. unlockZeichnung();
  594. }
  595. void NachrichtenListeObj::render( Bild &zrObj )
  596. {
  597. lockZeichnung();
  598. int x = pos.x;
  599. int y = pos.y;
  600. int br = gr.x;
  601. int hö = gr.y;
  602. if( !zrObj.setDrawOptions( x, y, br, hö ) )
  603. {
  604. unlockZeichnung();
  605. return;
  606. }
  607. int höhe = 0;
  608. for( int i = 0; i < anzahl; i++ )
  609. {
  610. NLNachricht *tmp = members->z( i );
  611. tmp->render( höhe - ( vsb ? vsb->getScroll() : 0 ), zrObj );
  612. höhe += tmp->getHeight();
  613. }
  614. if( vsb )
  615. {
  616. vsb->update( höhe, bildschirmGröße.y - 122 );
  617. vsb->render( 229, 0, 20, bildschirmGröße.y - 122, zrObj );
  618. }
  619. zrObj.releaseDrawOptions();
  620. unlockZeichnung();
  621. }
  622. // contant
  623. // Reference Counting
  624. NachrichtenListeObj *NachrichtenListeObj::getThis()
  625. {
  626. ref++;
  627. return this;
  628. }
  629. NachrichtenListeObj *NachrichtenListeObj::release()
  630. {
  631. ref--;
  632. if( !ref )
  633. delete this;
  634. return 0;
  635. }
  636. // Inhalt der NachrichtenListe Klasse aus NachrichtListe.h
  637. // Konstruktor
  638. NachrichtenListe::NachrichtenListe( Schrift *zSchrift, Fenster *zNachLoginFenster )
  639. {
  640. schrift = zSchrift->getThis();
  641. minimierenBild = bilder->get( "chat.ltdb/minimieren.png" );
  642. if( !minimierenBild )
  643. {
  644. LTDBDatei *datei = new LTDBDatei();
  645. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  646. datei->leseDaten( 0 );
  647. minimierenBild = datei->laden( 0, new Text( "minimieren.png" ) );
  648. datei->release();
  649. bilder->add( "chat.ltdb/minimieren.png", minimierenBild->getThis() );
  650. }
  651. maximierenBild = bilder->get( "chat.ltdb/maximieren.png" );
  652. if( !maximierenBild )
  653. {
  654. LTDBDatei *datei = new LTDBDatei();
  655. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  656. datei->leseDaten( 0 );
  657. maximierenBild = datei->laden( 0, new Text( "maximieren.png" ) );
  658. datei->release();
  659. bilder->add( "chat.ltdb/maximieren.png", maximierenBild->getThis() );
  660. }
  661. bildschirmGröße = BildschirmGröße();
  662. fenster = initFenster( bildschirmGröße.x - 21, 100, 250, 22, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::BodyHintergrund, "" );
  663. fenster->setKBgFarbe( 0xFF000000 );
  664. überschrift = initTextFeld( 1, 1, 248, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center | TextFeld::Style::Sichtbar, "Nachrichten" );
  665. überschrift->setSchriftSize( 15 );
  666. fenster->addMember( überschrift );
  667. minMax = initKnopf( 1, 1, 20, 20, 0, 0, "" );
  668. minMax->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::HAlpha | Knopf::Style::KlickBuffer );
  669. minMax->setMausEreignisParameter( this );
  670. minMax->setMausEreignis( NachrichtenListeMinMaxME );
  671. minMax->setHintergrundBildZ( minimierenBild->getThis() );
  672. initToolTip( minMax, "Nachrichten Leiste minimieren.", zSchrift->getThis(), hauptScreen );
  673. fenster->addMember( minMax );
  674. nachrichtenListe = new NachrichtenListeObj( zSchrift );
  675. nachrichtenListe->setPosition( 1, 21 );
  676. nachrichtenListe->setSize( 248, bildschirmGröße.y - 122 );
  677. fenster->addMember( nachrichtenListe );
  678. zNachLoginFenster->addMember( fenster );
  679. tickVal = 0;
  680. animation = 1;
  681. rend = 0;
  682. msgSound = 0;
  683. errSound = 0;
  684. HMODULE dll = dllDateien->ladeDLL( "GSL.dll", "data/bin/GSL.dll" );
  685. if( dll )
  686. {
  687. GetGSLDatei getGSLDatei = (GetGSLDatei)GetProcAddress( dll, "getGSLDatei" );
  688. if( getGSLDatei )
  689. {
  690. GSL::GSLDateiV *sDat = getGSLDatei();
  691. sDat->setDatei( "data/sounds/popup.gsl" );
  692. sDat->leseDaten();
  693. msgSound = sDat->getSound( "info.wav" );
  694. errSound = sDat->getSound( "error.wav" );
  695. sDat->release();
  696. if( msgSound )
  697. msgSound->setVolume( 0xFFFF, 0xFFFF );
  698. if( errSound )
  699. errSound->setVolume( 0xFFFF, 0xFFFF );
  700. }
  701. if( !msgSound && !errSound )
  702. dllDateien->releaseDLL( "GSL.dll" );
  703. }
  704. ref = 1;
  705. }
  706. // Destruktor
  707. NachrichtenListe::~NachrichtenListe()
  708. {
  709. if( msgSound || errSound )
  710. {
  711. if( msgSound )
  712. {
  713. msgSound->stopSound();
  714. msgSound->release();
  715. }
  716. if( errSound )
  717. {
  718. errSound->stopSound();
  719. errSound->release();
  720. }
  721. dllDateien->releaseDLL( "GSL.dll" );
  722. }
  723. überschrift = überschrift->release();
  724. fenster = fenster->release();
  725. minMax = minMax->release();
  726. nachrichtenListe = nachrichtenListe->release();
  727. minimierenBild = minimierenBild->release();
  728. maximierenBild = maximierenBild->release();
  729. schrift->release();
  730. }
  731. // nicht constant
  732. void NachrichtenListe::addNachricht( Text *titel, Text *nachricht, Text *positiv, Text *negativ, std::function<void()> posAk, std::function<void()> negAk )
  733. {
  734. if( titel && titel->hat( "Fehler" ) && errSound )
  735. errSound->playSound();
  736. else if( msgSound )
  737. msgSound->playSound();
  738. nachrichtenListe->addNachricht( new Nachricht( schrift, titel, nachricht, positiv, negativ, posAk, negAk ) );
  739. }
  740. void NachrichtenListe::addNachricht( NLNachricht *nachricht )
  741. {
  742. if( nachricht->zTitel() && nachricht->zTitel()->hat( "Fehler" ) && errSound )
  743. errSound->playSound();
  744. else if( msgSound )
  745. msgSound->playSound();
  746. nachrichtenListe->addNachricht( nachricht );
  747. }
  748. void NachrichtenListe::removeNachricht( NLNachricht *zNachricht )
  749. {
  750. nachrichtenListe->removeNachricht( zNachricht );
  751. }
  752. void NachrichtenListe::removeAll()
  753. {
  754. nachrichtenListe->removeAll();
  755. }
  756. bool NachrichtenListe::druckMinMax( MausEreignis &me )
  757. {
  758. if( me.id == ME_RLinks )
  759. {
  760. if( minMax->zHintergrundBild() == minimierenBild )
  761. {
  762. animation = 2;
  763. minMax->setHintergrundBildZ( maximierenBild->getThis() );
  764. minMax->zToolTip()->setText( "Nachrichten Leiste maximieren." );
  765. }
  766. else
  767. {
  768. animation = 1;
  769. minMax->setHintergrundBildZ( minimierenBild->getThis() );
  770. minMax->zToolTip()->setText( "Nachrichten Leiste minimieren." );
  771. }
  772. }
  773. return 1;
  774. }
  775. bool NachrichtenListe::tick( double tickVal )
  776. {
  777. if( !animation )
  778. {
  779. bool ret = rend;
  780. rend = 0;
  781. return ret;
  782. }
  783. this->tickVal += tickVal * 400;
  784. int val = ( int )this->tickVal;
  785. if( val < 1 )
  786. {
  787. bool ret = rend;
  788. rend = 0;
  789. return ret;
  790. }
  791. if( val > 14 )
  792. val = 14;
  793. this->tickVal -= val;
  794. switch( animation )
  795. {
  796. case 1: // maximieren
  797. if( fenster->getX() > bildschirmGröße.x - 250 )
  798. {
  799. fenster->setPosition( fenster->getX() - val, fenster->getY() );
  800. minMax->setPosition( minMax->getX() + val, minMax->getY() );
  801. if( fenster->getX() < bildschirmGröße.x - 250 )
  802. {
  803. fenster->setPosition( bildschirmGröße.x - 250, fenster->getY() );
  804. minMax->setPosition( 229, minMax->getY() );
  805. }
  806. rend = 1;
  807. }
  808. else if( fenster->getHeight() < bildschirmGröße.y - 100 )
  809. {
  810. fenster->setSize( fenster->getBreite(), fenster->getHeight() + val );
  811. if( fenster->getHeight() >= bildschirmGröße.y - 100 )
  812. {
  813. fenster->setSize( fenster->getBreite(), bildschirmGröße.y - 100 );
  814. animation = 0;
  815. }
  816. rend = 1;
  817. }
  818. break;
  819. case 2: // minimieren
  820. if( fenster->getHeight() > 22 )
  821. {
  822. fenster->setSize( fenster->getBreite(), fenster->getHeight() - val );
  823. if( fenster->getHeight() < 22 )
  824. fenster->setSize( fenster->getBreite(), 22 );
  825. rend = 1;
  826. }
  827. else if( fenster->getX() < bildschirmGröße.x - 21 )
  828. {
  829. minMax->setPosition( minMax->getX() - val, minMax->getY() );
  830. fenster->setPosition( fenster->getX() + val, fenster->getY() );
  831. if( fenster->getX() >= bildschirmGröße.x - 21 )
  832. {
  833. minMax->setPosition( 1, minMax->getY() );
  834. fenster->setPosition( bildschirmGröße.x - 21, fenster->getY() );
  835. animation = 0;
  836. }
  837. rend = 1;
  838. }
  839. break;
  840. }
  841. bool ret = rend;
  842. rend = 0;
  843. return ret;
  844. }
  845. // contant
  846. Schrift *NachrichtenListe::zSchrift() const
  847. {
  848. return schrift;
  849. }
  850. // Reference Counting
  851. NachrichtenListe *NachrichtenListe::getThis()
  852. {
  853. ref++;
  854. return this;
  855. }
  856. NachrichtenListe *NachrichtenListe::release()
  857. {
  858. ref--;
  859. if( !ref )
  860. delete this;
  861. return 0;
  862. }
  863. // Nachrichten
  864. bool NachrichtenListeMinMaxME( void *p, void *obj, MausEreignis me )
  865. {
  866. return ( (NachrichtenListe*)p )->druckMinMax( me );
  867. }