Bild.cpp 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466
  1. //---Include---
  2. #ifdef WIN32
  3. #include <Windows.h>
  4. #include <GdiPlus.h>
  5. #pragma comment( lib, "gdiplus.lib" )
  6. #endif
  7. #include "Bild.h"
  8. #include "DateiSystem.h"
  9. #include "Scroll.h"
  10. #include "Rahmen.h"
  11. #include "MausEreignis.h"
  12. #include "Globals.h"
  13. #include "ToolTip.h"
  14. #include "Text.h"
  15. #include "AlphaFeld.h"
  16. #ifndef WIN32
  17. #include <math.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #ifndef max
  21. #define max( a, b ) ( ( (a) > (b) ) ? (a) : (b) )
  22. #endif
  23. #ifndef min
  24. #define min( a, b ) ( ( (a) < (b) ) ? (a) : (b) )
  25. #endif
  26. #endif
  27. using namespace Framework;
  28. // Inhalt der Bild Klasse aus Bild.h
  29. // Konstruktor
  30. Bild::Bild( bool options )
  31. : fc( 0 ),
  32. delFc( 1 ),
  33. size( 0, 0 ),
  34. ref( 1 ),
  35. drawOff( options ? new Punkt[ 2000 ] : new Punkt[ 1 ] ),
  36. dPosA( options ? new Punkt[ 2000 ] : new Punkt[ 1 ] ),
  37. dSizeA( options ? new Punkt[ 2000 ] : new Punkt[ 1 ] ),
  38. doa( 0 ),
  39. alpha( options ? new unsigned char[ 1000 ] : new unsigned char[ 1 ] ),
  40. alphaAnzahl( 0 ),
  41. rend( 0 ),
  42. alpha3D( 0 )
  43. {
  44. alpha[ 0 ] = 0;
  45. }
  46. // Destruktor
  47. Bild::~Bild()
  48. {
  49. if( delFc )
  50. {
  51. delete[] fc;
  52. fc = 0;
  53. }
  54. delete[] dPosA;
  55. delete[] dSizeA;
  56. delete[] alpha;
  57. delete[] drawOff;
  58. }
  59. // privat
  60. inline void Bild::alphaPixelP( int x, int y, int f )
  61. {
  62. alphaPixelP( fc[ x + y * size.x ], f );
  63. }
  64. inline void Bild::alphaPixelP( int &fc, int colorb )
  65. {
  66. int alpha = ( ( colorb >> 24 ) & 0xFF );
  67. int na = ( 0x100 - alpha );
  68. fc = ( ( ( ( ( na * ( fc & 0xFF00FF ) ) >> 8 ) + ( ( alpha * ( colorb & 0xFF00FF ) ) >> 8 ) ) & 0xFF00FF ) |
  69. ( ( ( ( na * ( fc & 0x00FF00 ) ) >> 8 ) + ( ( alpha * ( colorb & 0x00FF00 ) ) >> 8 ) ) & 0x00FF00 ) |
  70. ( ( fc & 0xFF000000 ) ) ) * ( fc != 0 || !alpha3D ) | ( fc == 0 && alpha3D ) * colorb;
  71. //unsigned char *fc1 = (unsigned char*)&fc[ i ];
  72. //unsigned char *fc2 = (unsigned char*)&colorb;
  73. //unsigned char na = ~fc2[ 3 ];
  74. //fc1[ 3 ] = fc2[ 3 ];
  75. //fc1[ 2 ] = (unsigned char)( ( fc2[ 2 ] * fc2[ 3 ] + fc1[ 2 ] * na ) / 255 );
  76. //fc1[ 1 ] = (unsigned char)( ( fc2[ 1 ] * fc2[ 3 ] + fc1[ 1 ] * na ) / 255 );
  77. //fc1[ 0 ] = (unsigned char)( ( fc2[ 0 ] * fc2[ 3 ] + fc1[ 0 ] * na ) / 255 );
  78. }
  79. char Bild::getOutCode( Punkt p ) const
  80. {
  81. char ret = 0;
  82. if( p.x < dPosA[ doa ].x )
  83. ret = 1;
  84. if( p.x >= dSizeA[ doa ].x )
  85. ret = 2;
  86. if( p.y < dPosA[ doa ].y )
  87. ret |= 4;
  88. if( p.y >= dSizeA[ doa ].y )
  89. ret |= 8;
  90. return ret;
  91. }
  92. void Bild::drawFlatDreieck( int y1, int y2, float m1, float b1, float m2, float b2, int farbe )
  93. {
  94. const int yStart = max( y1, dPosA[ doa ].y );
  95. const int yEnd = min( y2, dSizeA[ doa ].y );
  96. for( int y = yStart; y < yEnd; y++ )
  97. {
  98. const int xStart = max( (int)( m1 * (float)y + b1 + 0.5f ), dPosA[ doa ].x );
  99. const int xEnd = min( (int)( m2 * (float)y + b2 + 0.5f ), dSizeA[ doa ].x );
  100. for( int x = xStart; x < xEnd; x++ )
  101. fc[ x + y * size.x ] = farbe;
  102. }
  103. }
  104. void Bild::drawFlatDreieckTextur( int y1, int y2, double m1, double b1, double m2, double b2, double tx1, double ty1, double tx2, double ty2,
  105. double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
  106. {
  107. const double yStart = max( y1, dPosA[ doa ].y );
  108. const double yEnd = min( y2, dSizeA[ doa ].y );
  109. double tx_1 = tx1 + tx_1o * ( yStart - y1 ), ty_1 = ty1 + ty_1o * ( yStart - y1 ), tx_2 = tx2 + tx_2o * ( yStart - y1 ), ty_2 = ty2 + ty_2o * ( yStart - y1 );
  110. for( double y = yStart; y < yEnd; y++, tx_1 += tx_1o, ty_1 += ty_1o, tx_2 += tx_2o, ty_2 += ty_2o )
  111. {
  112. const double xStart = m1 * y + b1;
  113. const double xEnd = m2 * y + b2;
  114. drawLinieHTextur( Vec2< double >( xStart, y ), xEnd - xStart, Vec2< double >( tx_1, ty_1 ), Vec2< double >( tx_2, ty_2 ), txf, tyf, textur );
  115. }
  116. }
  117. void Bild::drawFlatDreieckAlpha( int y1, int y2, float m1, float b1, float m2, float b2, int farbe )
  118. {
  119. const int yStart = max( (int)( y1 + 0.5 ), dPosA[ doa ].y );
  120. const int yEnd = min( (int)( y2 + 0.5 ), dSizeA[ doa ].y );
  121. for( int y = yStart; y < yEnd; y++ )
  122. {
  123. const int xStart = max( (int)( m1 * ( (float)y + 0.5f ) + b1 + 0.5f ), dPosA[ doa ].x );
  124. const int xEnd = min( (int)( m2 * ( (float)y + 0.5 ) + b2 + 0.5f ), dSizeA[ doa ].x );
  125. for( int x = xStart; x < xEnd; x++ )
  126. alphaPixelP( fc[ x + y * size.x ], farbe );
  127. }
  128. }
  129. void Bild::drawFlatDreieckTexturAlpha( int y1, int y2, double m1, double b1, double m2, double b2, double tx1, double ty1, double tx2, double ty2,
  130. double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
  131. {
  132. const double yStart = max( y1, dPosA[ doa ].y );
  133. const double yEnd = min( y2, dSizeA[ doa ].y );
  134. double tx_1 = tx1 + tx_1o * ( yStart - y1 ), ty_1 = ty1 + ty_1o * ( yStart - y1 ), tx_2 = tx2 + tx_2o * ( yStart - y1 ), ty_2 = ty2 + ty_2o * ( yStart - y1 );
  135. for( double y = yStart; y < yEnd; y++, tx_1 += tx_1o, ty_1 += ty_1o, tx_2 += tx_2o, ty_2 += ty_2o )
  136. {
  137. const double xStart = m1 * y + b1;
  138. const double xEnd = m2 * y + b2;
  139. drawLinieHTexturAlpha( Vec2< double >( xStart, y ), xEnd - xStart, Vec2< double >( tx_1, ty_1 ), Vec2< double >( tx_2, ty_2 ), txf, tyf, textur );
  140. }
  141. }
  142. void Bild::drawLinieHTextur( Vec2< double > p, double len, Vec2< double > ta, Vec2< double > tb, double txo, double tyo, Bild &textur ) // zeichnet eine horizontale Linie
  143. {
  144. if( alpha[ alphaAnzahl ] == 0xFF )
  145. return;
  146. if( alpha[ alphaAnzahl ] )
  147. {
  148. drawLinieHTexturAlpha( p, len, ta, tb, txo, tyo, textur );
  149. return;
  150. }
  151. if( len < 0 )
  152. {
  153. p.x += len;
  154. len = -len;
  155. ta.Swap( tb );
  156. }
  157. int dpx = dPosA[ doa ].x;
  158. int dpy = dPosA[ doa ].y;
  159. int dgx = dSizeA[ doa ].x;
  160. int dgy = dSizeA[ doa ].y;
  161. if( p.y < dpy || p.y >= dgy )
  162. return;
  163. double off = 0;
  164. if( p.x < dpx )
  165. {
  166. off = dpx - p.x;
  167. len -= dpx - p.x;
  168. if( len <= 0 )
  169. return;
  170. p.x = dpx;
  171. }
  172. if( p.x + len >= dgx )
  173. {
  174. len -= p.x - dgx + len;
  175. if( len <= 0 )
  176. return;
  177. }
  178. int br = size.x;
  179. int *fc = this->fc + (int)( p.x + (int)p.y * br );
  180. double x = ta.x + txo * off, y = ta.y + tyo * off;
  181. int *buffer = textur.getBuffer();
  182. int txtBr = textur.getBreite();
  183. for( int i = 0; i < len; ++i, ++fc )
  184. {
  185. *fc = buffer[ (int)( (int)( x + 0.5 ) + (int)( y + 0.5 ) * txtBr ) ];
  186. x += txo, y += tyo;
  187. }
  188. rend = 1;
  189. }
  190. void Bild::drawLinieHTexturAlpha( Vec2< double > p, double len, Vec2< double > ta, Vec2< double > tb, double txo, double tyo, Bild &textur ) // zeichnet eine horizontale Linie
  191. {
  192. if( alpha[ alphaAnzahl ] == 0xFF )
  193. return;
  194. if( len < 0 )
  195. {
  196. p.x += len;
  197. len = -len;
  198. ta.Swap( tb );
  199. }
  200. int dpx = dPosA[ doa ].x;
  201. int dpy = dPosA[ doa ].y;
  202. int dgx = dSizeA[ doa ].x;
  203. int dgy = dSizeA[ doa ].y;
  204. if( p.y < dpy || p.y >= dgy )
  205. return;
  206. double off = 0;
  207. if( p.x < dpx )
  208. {
  209. off = dpx - p.x;
  210. len -= dpx - p.x;
  211. if( len <= 0 )
  212. return;
  213. p.x = dpx;
  214. }
  215. if( p.x + len >= dgx )
  216. {
  217. len -= p.x - dgx + len;
  218. if( len <= 0 )
  219. return;
  220. }
  221. int br = size.x;
  222. int *fc = this->fc + (int)( p.x + (int)p.y * br );
  223. double x = ta.x + txo * off, y = ta.y + tyo * off;
  224. int *buffer = textur.getBuffer();
  225. int txtBr = textur.getBreite();
  226. int f;
  227. for( int i = 0; i < len; ++i, ++fc )
  228. {
  229. f = buffer[ (int)( (int)( x + 0.5 ) + (int)( y + 0.5 ) * txtBr ) ];
  230. if( alpha[ alphaAnzahl ] )
  231. {
  232. unsigned char *cf = (unsigned char*)&f;
  233. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  234. }
  235. alphaPixelP( *fc, f );
  236. x += txo, y += tyo;
  237. }
  238. rend = 1;
  239. }
  240. // nicht constant
  241. // Prüft ob ein Rechteck vollständig oder teilweise in der Zeichen Fläche liegt.
  242. // return 0, falls das Rechteck nicht in der Zeichenfläche liegt, 1 sonst
  243. bool Bild::isAreaDrawable( int x, int y, int b, int h )
  244. {
  245. int dpx = dPosA[ doa ].x;
  246. int dpy = dPosA[ doa ].y;
  247. int dgx = dSizeA[ doa ].x;
  248. int dgy = dSizeA[ doa ].y;
  249. x += drawOff[ doa ].x;
  250. y += drawOff[ doa ].y;
  251. if( x + b < dpx || y + h < dpy || x > dgx || y > dgy )
  252. return 0;
  253. return 1;
  254. }
  255. // Wird dieser Flag gesetzt, so wird beim Alpha Blending wenn die vorheriege Farbe 0 ist nur die neue mit ihrem Alpha Wert kopiert.
  256. // Das ist sinnvoll für die Verwendung im 3DBildschirm, wo das Gezeichnette Bild später mittels Alpha Blending angezeigt wird
  257. void Bild::setAlpha3D( bool erlaubt )
  258. {
  259. alpha3D = erlaubt;
  260. }
  261. void Bild::setAlpha( unsigned char alpha ) // setzt die Transparenz der nachfolgenden Zeichnunge
  262. {
  263. int last = this->alpha[ alphaAnzahl ];
  264. ++alphaAnzahl;
  265. assert( alphaAnzahl < 1000 );
  266. this->alpha[ alphaAnzahl ] = (unsigned char)( ( 255 - alpha ) > last ? ( 255 - alpha ) : last );
  267. }
  268. void Bild::releaseAlpha() // Löscht alpha
  269. {
  270. --alphaAnzahl;
  271. }
  272. void Bild::setPixelBuffer( int *buffer, bool deleteBuffer, int breite, int height ) // setzt den Zeiger auf die Pixel des Bildes
  273. {
  274. if( delFc )
  275. delete[]fc;
  276. fc = buffer;
  277. delFc = deleteBuffer;
  278. size.x = breite;
  279. size.y = height;
  280. rend = 1;
  281. }
  282. void Bild::neuBild( int breite, int height, int fillColor )
  283. {
  284. if( fc && delFc )
  285. delete[] fc;
  286. size.x = breite;
  287. size.y = height;
  288. fc = new int[ size.x * size.y ];
  289. setFarbe( fillColor );
  290. drawOff[ 0 ].x = 0;
  291. drawOff[ 0 ].y = 0;
  292. dPosA[ 0 ].x = 0;
  293. dPosA[ 0 ].y = 0;
  294. dSizeA[ 0 ] = size;
  295. alphaAnzahl = 0;
  296. alpha[ 0 ] = 0;
  297. doa = 0;
  298. rend = 1;
  299. }
  300. void Bild::setFarbe( int f )
  301. {
  302. if( ( f & 0xFF ) == ( ( f >> 8 ) & 0xFF ) && ( f & 0xFF ) == ( ( f >> 16 ) & 0xFF ) && ( f & 0xFF ) == ( ( f >> 24 ) & 0xFF ) )
  303. memset( fc, f, size.x * size.y * 4 );
  304. else
  305. {
  306. for( int *i = fc, *end = i + size.x * size.y; i < end; i++ )
  307. *i = f;
  308. }
  309. rend = 1;
  310. }
  311. void Bild::fillRegion( int x, int y, int b, int h, int ff )
  312. {
  313. if( alpha[ alphaAnzahl ] == 0xFF )
  314. return;
  315. if( alpha[ alphaAnzahl ] )
  316. {
  317. alphaRegion( x, y, b, h, ff );
  318. return;
  319. }
  320. int dpx = dPosA[ doa ].x;
  321. int dpy = dPosA[ doa ].y;
  322. int dgx = dSizeA[ doa ].x;
  323. int dgy = dSizeA[ doa ].y;
  324. x += drawOff[ doa ].x;
  325. y += drawOff[ doa ].y;
  326. if( x + b < dpx || y + h < dpy || x > dgx || y > dgy )
  327. return;
  328. if( x < dpx )
  329. {
  330. b -= dpx - x;
  331. x = dpx;
  332. }
  333. if( y < dpy )
  334. {
  335. h -= dpy - y;
  336. y = dpy;
  337. }
  338. b = ( x + b ) >= dgx ? ( dgx - x ) : b;
  339. h = ( y + h ) >= dgy ? ( dgy - y ) : h;
  340. int *pixel = fc + y * size.x + x;
  341. int *rowEnd = pixel + b;
  342. for( int i = 0; i < h; pixel += size.x - b, ++i, rowEnd += size.x )
  343. {
  344. for( ; pixel < rowEnd; ++pixel )
  345. *pixel = ff;
  346. }
  347. rend = 1;
  348. }
  349. void Bild::alphaRegion( int x, int y, int b, int h, int ff )
  350. {
  351. if( alpha[ alphaAnzahl ] == 0xFF )
  352. return;
  353. int dpx = dPosA[ doa ].x;
  354. int dpy = dPosA[ doa ].y;
  355. int dgx = dSizeA[ doa ].x;
  356. int dgy = dSizeA[ doa ].y;
  357. x += drawOff[ doa ].x;
  358. y += drawOff[ doa ].y;
  359. if( x + b < dpx || y + h < dpy || x > dgx || y > dgy )
  360. return;
  361. if( x < dpx )
  362. {
  363. b -= dpx - x;
  364. x = dpx;
  365. }
  366. if( y < dpy )
  367. {
  368. h -= dpy - y;
  369. y = dpy;
  370. }
  371. b = ( x + b ) >= dgx ? ( dgx - x ) : b;
  372. h = ( y + h ) >= dgy ? ( dgy - y ) : h;
  373. if( alpha[ alphaAnzahl ] )
  374. {
  375. unsigned char *cf = (unsigned char*)&ff;
  376. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  377. }
  378. int *pixel = fc + y * size.x + x;
  379. int *rowEnd = pixel + b;
  380. int alpha = ( ( ff >> 24 ) & 0xFF );
  381. int na = ( 0x100 - alpha );
  382. int i1 = ( alpha * ( ff & 0xFF00FF ) ) >> 8;
  383. int i2 = ( alpha * ( ff & 0x00FF00 ) ) >> 8;
  384. for( int i = 0; i < h; pixel += size.x - b, ++i, rowEnd += size.x )
  385. {
  386. for( ; pixel < rowEnd; ++pixel )
  387. {
  388. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  389. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  390. ( ( *pixel & 0xFF000000 ) ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * ff;
  391. }
  392. }
  393. rend = 1;
  394. }
  395. void Bild::alphaPixel( int i, int f )
  396. {
  397. if( !alpha[ alphaAnzahl ] )
  398. alphaPixelP( fc[ i ], f );
  399. if( alpha[ alphaAnzahl ] < 0xFF )
  400. {
  401. unsigned char *cf = (unsigned char*)&f;
  402. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  403. alphaPixelP( fc[ i ], f );
  404. rend = 1;
  405. }
  406. }
  407. void Bild::alphaPixel( int x, int y, int f )
  408. {
  409. if( !alpha[ alphaAnzahl ] )
  410. alphaPixelP( fc[ x + y * size.x ], f );
  411. if( alpha[ alphaAnzahl ] < 0xFF )
  412. {
  413. unsigned char *cf = (unsigned char*)&f;
  414. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  415. alphaPixelP( fc[ x + y * size.x ], f );
  416. rend = 1;
  417. }
  418. }
  419. void Bild::alphaPixelDP( int x, int y, int f )
  420. {
  421. if( alpha[ alphaAnzahl ] == 0xFF )
  422. return;
  423. int dpx = dPosA[ doa ].x;
  424. int dpy = dPosA[ doa ].y;
  425. int dgx = dSizeA[ doa ].x;
  426. int dgy = dSizeA[ doa ].y;
  427. if( x < dpx || y < dpy || x > dgx || y > dgy )
  428. return;
  429. if( alpha[ alphaAnzahl ] )
  430. {
  431. unsigned char *cf = (unsigned char*)&f;
  432. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  433. }
  434. alphaPixelP( fc[ x + y * size.x ], f );
  435. rend = 1;
  436. }
  437. void Bild::alphaPixelDP( int i, int f )
  438. {
  439. int x = i % size.x;
  440. int y = i / size.x;
  441. alphaPixelDP( x, y, f );
  442. rend = 1;
  443. }
  444. void Bild::setPixelDP( int x, int y, int f )
  445. {
  446. if( alpha[ alphaAnzahl ] == 0xFF )
  447. return;
  448. if( alpha[ alphaAnzahl ] )
  449. {
  450. alphaPixelDP( x, y, f );
  451. return;
  452. }
  453. int dpx = dPosA[ doa ].x;
  454. int dpy = dPosA[ doa ].y;
  455. int dgx = dSizeA[ doa ].x;
  456. int dgy = dSizeA[ doa ].y;
  457. if( x < dpx || y < dpy || x > dgx || y > dgy )
  458. return;
  459. fc[ x + y * size.x ] = f;
  460. rend = 1;
  461. }
  462. void Bild::setPixelDP( int i, int f )
  463. {
  464. int x = i % size.x;
  465. int y = i / size.x;
  466. setPixelDP( x, y, f );
  467. rend = 1;
  468. }
  469. void Bild::drawLinieH( int x, int y, int len, int f ) // zeichnet eine horizontale Linie
  470. {
  471. if( alpha[ alphaAnzahl ] == 0xFF )
  472. return;
  473. if( alpha[ alphaAnzahl ] )
  474. {
  475. drawLinieHAlpha( x, y, len, f );
  476. return;
  477. }
  478. int dpx = dPosA[ doa ].x;
  479. int dpy = dPosA[ doa ].y;
  480. int dgx = dSizeA[ doa ].x;
  481. int dgy = dSizeA[ doa ].y;
  482. x += drawOff[ doa ].x;
  483. y += drawOff[ doa ].y;
  484. if( y < dpy || y >= dgy )
  485. return;
  486. if( x < dpx )
  487. {
  488. len -= dpx - x;
  489. if( len <= 0 )
  490. return;
  491. x = dpx;
  492. }
  493. if( x + len >= dgx )
  494. {
  495. len -= x - dgx + len;
  496. if( len <= 0 )
  497. return;
  498. }
  499. int br = size.x;
  500. int *fc = this->fc + x + y * br;
  501. int pval = len < 0 ? -1 : 1;
  502. len = len > 0 ? len : -len;
  503. for( int i = 0; i < len; ++i, fc += pval )
  504. *fc = f;
  505. rend = 1;
  506. }
  507. void Bild::drawLinieV( int x, int y, int len, int f ) // zeichnet eine vertikale Linie
  508. {
  509. if( alpha[ alphaAnzahl ] == 0xFF )
  510. return;
  511. if( alpha[ alphaAnzahl ] )
  512. {
  513. drawLinieVAlpha( x, y, len, f );
  514. return;
  515. }
  516. int dpx = dPosA[ doa ].x;
  517. int dpy = dPosA[ doa ].y;
  518. int dgx = dSizeA[ doa ].x;
  519. int dgy = dSizeA[ doa ].y;
  520. x += drawOff[ doa ].x;
  521. y += drawOff[ doa ].y;
  522. if( x < dpx || x >= dgx )
  523. return;
  524. if( y < dpy )
  525. {
  526. len -= dpy - y;
  527. if( len <= 0 )
  528. return;
  529. y = dpy;
  530. }
  531. if( y + len >= dgy )
  532. {
  533. len -= y - dgy + len;
  534. if( len < 0 )
  535. return;
  536. }
  537. int br = size.x;
  538. int *fc = this->fc + x + y * br;
  539. int pval = len < 0 ? -br : br;
  540. len = len > 0 ? len : -len;
  541. for( int i = 0; i < len; ++i, fc += pval )
  542. *fc = f;
  543. rend = 1;
  544. }
  545. void Bild::drawLinieHAlpha( int x, int y, int len, int f ) // zeichnet eine horizontale Linie
  546. {
  547. if( alpha[ alphaAnzahl ] == 0xFF )
  548. return;
  549. int dpx = dPosA[ doa ].x;
  550. int dpy = dPosA[ doa ].y;
  551. int dgx = dSizeA[ doa ].x;
  552. int dgy = dSizeA[ doa ].y;
  553. x += drawOff[ doa ].x;
  554. y += drawOff[ doa ].y;
  555. if( y < dpy || y >= dgy )
  556. return;
  557. if( x < dpx )
  558. {
  559. len -= dpx - x;
  560. if( len <= 0 )
  561. return;
  562. x = dpx;
  563. }
  564. if( x + len >= dgx )
  565. {
  566. len -= x - dgx + len;
  567. if( len <= 0 )
  568. return;
  569. }
  570. int br = size.x;
  571. int pval = len < 0 ? -1 : 1;
  572. len = len > 0 ? len : -len;
  573. int end = 0;
  574. if( alpha[ alphaAnzahl ] )
  575. {
  576. unsigned char *cf = (unsigned char*)&f;
  577. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  578. }
  579. int alpha = ( ( f >> 24 ) & 0xFF );
  580. int na = ( 0x100 - alpha );
  581. int i1 = ( alpha * ( f & 0xFF00FF ) ) >> 8;
  582. int i2 = ( alpha * ( f & 0x00FF00 ) ) >> 8;
  583. for( int i = x + y * br; end < len; ++end, i += pval )
  584. {
  585. fc[ i ] = ( ( ( ( ( na * ( fc[ i ] & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  586. ( ( ( ( na * ( fc[ i ] & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  587. ( ( fc[ i ] & 0xFF000000 ) ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
  588. }
  589. rend = 1;
  590. }
  591. void Bild::drawLinieVAlpha( int x, int y, int len, int f ) // zeichnet eine vertikale Linie
  592. {
  593. if( alpha[ alphaAnzahl ] == 0xFF )
  594. return;
  595. int dpx = dPosA[ doa ].x;
  596. int dpy = dPosA[ doa ].y;
  597. int dgx = dSizeA[ doa ].x;
  598. int dgy = dSizeA[ doa ].y;
  599. x += drawOff[ doa ].x;
  600. y += drawOff[ doa ].y;
  601. if( x < dpx || x >= dgx )
  602. return;
  603. if( y < dpy )
  604. {
  605. len -= dpy - y;
  606. if( len <= 0 )
  607. return;
  608. y = dpy;
  609. }
  610. if( y + len >= dgy )
  611. {
  612. len -= y - dgy + len;
  613. if( len < 0 )
  614. return;
  615. }
  616. int br = size.x;
  617. int pval = len < 0 ? -br : br;
  618. len = len > 0 ? len : -len;
  619. int end = 0;
  620. if( alpha[ alphaAnzahl ] )
  621. {
  622. unsigned char *cf = (unsigned char*)&f;
  623. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  624. }
  625. int alpha = ( ( f >> 24 ) & 0xFF );
  626. int na = ( 0x100 - alpha );
  627. int i1 = ( alpha * ( f & 0xFF00FF ) ) >> 8;
  628. int i2 = ( alpha * ( f & 0x00FF00 ) ) >> 8;
  629. for( int i = x + y * br; end < len; ++end, i += pval )
  630. {
  631. fc[ i ] = ( ( ( ( ( na * ( fc[ i ] & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  632. ( ( ( ( na * ( fc[ i ] & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  633. ( fc[ i ] & 0xFF000000 ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
  634. }
  635. rend = 1;
  636. }
  637. void Bild::drawLinieBordered( Punkt a, Punkt b, int bc, int fc )
  638. {
  639. if( alpha[ alphaAnzahl ] == 0xFF )
  640. return;
  641. if( alpha[ alphaAnzahl ] )
  642. {
  643. drawLinieBorderedAlpha( a, b, bc, fc );
  644. return;
  645. }
  646. a += drawOff[ doa ];
  647. b += drawOff[ doa ];
  648. char outCode1 = getOutCode( a );
  649. char outCode2 = getOutCode( b );
  650. bool ok = 0;
  651. while( 1 )
  652. {
  653. int xMax = dSizeA[ doa ].x - 1;
  654. int yMax = dSizeA[ doa ].y - 1;
  655. if( !( outCode1 | outCode2 ) )
  656. {
  657. ok = 1;
  658. break;
  659. }
  660. else if( outCode1 & outCode2 )
  661. break;
  662. else
  663. {
  664. int x = 0, y = 0;
  665. char outCodeOut = outCode1 ? outCode1 : outCode2;
  666. if( outCodeOut & 8 )
  667. {
  668. x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
  669. y = yMax;
  670. }
  671. else if( outCodeOut & 4 )
  672. {
  673. x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
  674. y = dPosA[ doa ].y;
  675. }
  676. else if( outCodeOut & 2 )
  677. {
  678. y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
  679. x = xMax;
  680. }
  681. else if( outCodeOut & 1 )
  682. {
  683. y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
  684. x = dPosA[ doa ].x;
  685. }
  686. if( outCodeOut == outCode1 )
  687. {
  688. a.x = x;
  689. a.y = y;
  690. outCode1 = getOutCode( a );
  691. }
  692. else
  693. {
  694. b.x = x;
  695. b.y = y;
  696. outCode2 = getOutCode( b );
  697. }
  698. }
  699. }
  700. if( ok )
  701. {
  702. int xlen = b.x - a.x, axlen = abs( xlen );
  703. int ylen = b.y - a.y, aylen = abs( ylen );
  704. double xf = (double)xlen / ( aylen ? aylen : 1 );
  705. double yf = (double)ylen / ( axlen ? axlen : 1 );
  706. if( axlen > aylen )
  707. xf = xf < 0 ? -1 : 1;
  708. else
  709. yf = yf < 0 ? -1 : 1;
  710. double x = (double)a.x, y = (double)a.y;
  711. int maxP = (int)( sqrt( (float)(xlen * xlen + ylen * ylen) ) + 0.5 );
  712. int count = 0;
  713. int maxPixel = size.x * size.y;
  714. while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
  715. {
  716. ++count;
  717. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ) ] = fc;
  718. if( (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel &&
  719. this->fc[ (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) ] != fc )
  720. this->fc[ (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) ] = bc;
  721. if( (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel &&
  722. this->fc[ (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) ] != fc )
  723. this->fc[ (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) ] = bc;
  724. if( (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) < maxPixel &&
  725. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) ] != fc )
  726. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) ] = bc;
  727. if( (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) < maxPixel &&
  728. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) ] != fc )
  729. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) ] = bc;
  730. x += xf, y += yf;
  731. }
  732. rend = 1;
  733. }
  734. }
  735. void Bild::drawLinieBorderedAlpha( Punkt a, Punkt b, int bc, int fc )
  736. {
  737. if( alpha[ alphaAnzahl ] == 0xFF )
  738. return;
  739. a += drawOff[ doa ];
  740. b += drawOff[ doa ];
  741. char outCode1 = getOutCode( a );
  742. char outCode2 = getOutCode( b );
  743. bool ok = 0;
  744. while( 1 )
  745. {
  746. int xMax = dSizeA[ doa ].x - 1;
  747. int yMax = dSizeA[ doa ].y - 1;
  748. if( !( outCode1 | outCode2 ) )
  749. {
  750. ok = 1;
  751. break;
  752. }
  753. else if( outCode1 & outCode2 )
  754. break;
  755. else
  756. {
  757. int x = 0, y = 0;
  758. char outCodeOut = outCode1 ? outCode1 : outCode2;
  759. if( outCodeOut & 8 )
  760. {
  761. x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
  762. y = yMax;
  763. }
  764. else if( outCodeOut & 4 )
  765. {
  766. x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
  767. y = dPosA[ doa ].y;
  768. }
  769. else if( outCodeOut & 2 )
  770. {
  771. y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
  772. x = xMax;
  773. }
  774. else if( outCodeOut & 1 )
  775. {
  776. y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
  777. x = dPosA[ doa ].x;
  778. }
  779. if( outCodeOut == outCode1 )
  780. {
  781. a.x = x;
  782. a.y = y;
  783. outCode1 = getOutCode( a );
  784. }
  785. else
  786. {
  787. b.x = x;
  788. b.y = y;
  789. outCode2 = getOutCode( b );
  790. }
  791. }
  792. }
  793. if( ok )
  794. {
  795. int xlen = b.x - a.x, axlen = abs( xlen );
  796. int ylen = b.y - a.y, aylen = abs( ylen );
  797. double xf = (double)xlen / ( aylen ? aylen : 1 );
  798. double yf = (double)ylen / ( axlen ? axlen : 1 );
  799. if( axlen > aylen )
  800. xf = xf < 0 ? -1 : 1;
  801. else
  802. yf = yf < 0 ? -1 : 1;
  803. double x = (double)a.x, y = (double)a.y;
  804. if( alpha[ alphaAnzahl ] )
  805. {
  806. unsigned char *cf = (unsigned char*)&fc;
  807. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  808. }
  809. int maxP = (int)( sqrt( (float)(xlen * xlen + ylen * ylen) ) + 0.5 );
  810. int alpha = ( ( fc >> 24 ) & 0xFF );
  811. int alpha2 = ( ( bc >> 24 ) & 0xFF );
  812. int na = ( 0x100 - alpha );
  813. int na2 = ( 0x100 - alpha2 );
  814. int i1 = ( alpha * ( fc & 0xFF00FF ) ) >> 8;
  815. int i2 = ( alpha * ( fc & 0x00FF00 ) ) >> 8;
  816. int j1 = ( alpha2 * ( bc & 0xFF00FF ) ) >> 8;
  817. int j2 = ( alpha2 * ( bc & 0x00FF00 ) ) >> 8;
  818. int count = 0;
  819. int maxPixel = size.x * size.y;
  820. while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
  821. {
  822. ++count;
  823. if( (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel )
  824. {
  825. int &pixel = this->fc[ (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ];
  826. pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
  827. ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
  828. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
  829. }
  830. if( (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel )
  831. {
  832. int &pixel = this->fc[ (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ];
  833. pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
  834. ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
  835. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
  836. }
  837. if( (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) < maxPixel )
  838. {
  839. int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ];
  840. pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
  841. ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
  842. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
  843. }
  844. if( (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) < maxPixel )
  845. {
  846. int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ];
  847. pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
  848. ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
  849. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
  850. }
  851. x += xf, y += yf;
  852. }
  853. count = 0;
  854. while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
  855. {
  856. ++count;
  857. int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ];
  858. pixel = ( ( ( ( ( na * ( pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  859. ( ( ( ( na * ( pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  860. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
  861. x += xf, y += yf;
  862. }
  863. rend = 1;
  864. }
  865. }
  866. void Bild::drawLinie( Punkt a, Punkt b, int fc ) // zeichnet eine Linie von Punkt( x1, y1 ) nach Punke( x2, y2 )
  867. {
  868. if( alpha[ alphaAnzahl ] == 0xFF )
  869. return;
  870. if( alpha[ alphaAnzahl ] )
  871. {
  872. drawLinieAlpha( a, b, fc );
  873. return;
  874. }
  875. a += drawOff[ doa ];
  876. b += drawOff[ doa ];
  877. char outCode1 = getOutCode( a );
  878. char outCode2 = getOutCode( b );
  879. bool ok = 0;
  880. while( 1 )
  881. {
  882. int xMax = dSizeA[ doa ].x - 1;
  883. int yMax = dSizeA[ doa ].y - 1;
  884. if( !( outCode1 | outCode2 ) )
  885. {
  886. ok = 1;
  887. break;
  888. }
  889. else if( outCode1 & outCode2 )
  890. break;
  891. else
  892. {
  893. int x = 0, y = 0;
  894. char outCodeOut = outCode1 ? outCode1 : outCode2;
  895. if( outCodeOut & 8 )
  896. {
  897. x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
  898. y = yMax;
  899. }
  900. else if( outCodeOut & 4 )
  901. {
  902. x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
  903. y = dPosA[ doa ].y;
  904. }
  905. else if( outCodeOut & 2 )
  906. {
  907. y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
  908. x = xMax;
  909. }
  910. else if( outCodeOut & 1 )
  911. {
  912. y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
  913. x = dPosA[ doa ].x;
  914. }
  915. if( outCodeOut == outCode1 )
  916. {
  917. a.x = x;
  918. a.y = y;
  919. outCode1 = getOutCode( a );
  920. }
  921. else
  922. {
  923. b.x = x;
  924. b.y = y;
  925. outCode2 = getOutCode( b );
  926. }
  927. }
  928. }
  929. if( ok )
  930. {
  931. int xlen = b.x - a.x, axlen = abs( xlen );
  932. int ylen = b.y - a.y, aylen = abs( ylen );
  933. double xf = (double)xlen / ( aylen ? aylen : 1 );
  934. double yf = (double)ylen / ( axlen ? axlen : 1 );
  935. if( axlen > aylen )
  936. xf = xf < 0 ? -1 : 1;
  937. else
  938. yf = yf < 0 ? -1 : 1;
  939. double x = (double)a.x, y = (double)a.y;
  940. int maxP = (int)( sqrt( (float)(xlen * xlen + ylen * ylen) ) + 0.5 );
  941. int count = 0;
  942. while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
  943. {
  944. ++count;
  945. this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ) ] = fc;
  946. x += xf, y += yf;
  947. }
  948. rend = 1;
  949. }
  950. }
  951. void Bild::drawLinieAlpha( Punkt a, Punkt b, int fc )
  952. {
  953. if( alpha[ alphaAnzahl ] == 0xFF )
  954. return;
  955. a += drawOff[ doa ];
  956. b += drawOff[ doa ];
  957. char outCode1 = getOutCode( a );
  958. char outCode2 = getOutCode( b );
  959. bool ok = 0;
  960. while( 1 )
  961. {
  962. int xMax = dSizeA[ doa ].x - 1;
  963. int yMax = dSizeA[ doa ].y - 1;
  964. if( !( outCode1 | outCode2 ) )
  965. {
  966. ok = 1;
  967. break;
  968. }
  969. else if( outCode1 & outCode2 )
  970. break;
  971. else
  972. {
  973. int x = 0, y = 0;
  974. char outCodeOut = outCode1 ? outCode1 : outCode2;
  975. if( outCodeOut & 8 )
  976. {
  977. x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
  978. y = yMax;
  979. }
  980. else if( outCodeOut & 4 )
  981. {
  982. x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
  983. y = dPosA[ doa ].y;
  984. }
  985. else if( outCodeOut & 2 )
  986. {
  987. y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
  988. x = xMax;
  989. }
  990. else if( outCodeOut & 1 )
  991. {
  992. y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
  993. x = dPosA[ doa ].x;
  994. }
  995. if( outCodeOut == outCode1 )
  996. {
  997. a.x = x;
  998. a.y = y;
  999. outCode1 = getOutCode( a );
  1000. }
  1001. else
  1002. {
  1003. b.x = x;
  1004. b.y = y;
  1005. outCode2 = getOutCode( b );
  1006. }
  1007. }
  1008. }
  1009. if( ok )
  1010. {
  1011. int xlen = b.x - a.x, axlen = abs( xlen );
  1012. int ylen = b.y - a.y, aylen = abs( ylen );
  1013. double xf = (double)xlen / ( aylen ? aylen : 1 );
  1014. double yf = (double)ylen / ( axlen ? axlen : 1 );
  1015. if( axlen > aylen )
  1016. xf = xf < 0 ? -1 : 1;
  1017. else
  1018. yf = yf < 0 ? -1 : 1;
  1019. double x = (double)a.x, y = (double)a.y;
  1020. if( alpha[ alphaAnzahl ] )
  1021. {
  1022. unsigned char *cf = (unsigned char*)&fc;
  1023. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1024. }
  1025. int maxP = (int)( sqrt( (float)(xlen * xlen + ylen * ylen) ) + 0.5 );
  1026. int count = 0;
  1027. int alpha = ( ( fc >> 24 ) & 0xFF );
  1028. int na = ( 0x100 - alpha );
  1029. int i1 = ( alpha * ( fc & 0xFF00FF ) ) >> 8;
  1030. int i2 = ( alpha * ( fc & 0x00FF00 ) ) >> 8;
  1031. while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
  1032. {
  1033. ++count;
  1034. int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ];
  1035. pixel = ( ( ( ( ( na * ( pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1036. ( ( ( ( na * ( pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1037. ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
  1038. x += xf, y += yf;
  1039. }
  1040. rend = 1;
  1041. }
  1042. }
  1043. void Bild::fillCircle( int xOff, int yOff, int r, int fc ) // zeichnet einen Kreis um Punkt( xOff, yOff ) mit radius r
  1044. {
  1045. if( alpha[ alphaAnzahl ] == 0xFF )
  1046. return;
  1047. for( int i = r; i > 0; i-- )
  1048. drawKreis( xOff, yOff, i, fc );
  1049. }
  1050. void Bild::drawKreis( int xOff, int yOff, int r, int fc ) // zeichnet einen Kreis um Punkt( xOff, yOff ) mit radius r
  1051. {
  1052. if( alpha[ alphaAnzahl ] == 0xFF )
  1053. return;
  1054. if( alpha[ alphaAnzahl ] )
  1055. {
  1056. drawKreisAlpha( xOff, yOff, r, fc );
  1057. return;
  1058. }
  1059. int dpx = dPosA[ doa ].x;
  1060. int dpy = dPosA[ doa ].y;
  1061. int dgx = dSizeA[ doa ].x;
  1062. int dgy = dSizeA[ doa ].y;
  1063. xOff += drawOff[ doa ].x;
  1064. yOff += drawOff[ doa ].y;
  1065. if( xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy )
  1066. return;
  1067. for( int a = 0; a < r; ++a )
  1068. {
  1069. int b = (int)( sqrt( (float)(long)( r * r - a * a ) ) + 0.5 );
  1070. if( xOff + a < dgx && xOff + a > dpx && yOff + b < dgy && yOff + b > dpy )
  1071. this->fc[ xOff + a + ( yOff + b ) * size.x ] = fc;
  1072. if( xOff - a < dgx && xOff - a > dpx && yOff + b < dgy && yOff + b > dpy )
  1073. this->fc[ xOff - a + ( yOff + b ) * size.x ] = fc;
  1074. if( xOff + a < dgx && xOff + a > dpx && yOff - b < dgy && yOff - b > dpy )
  1075. this->fc[ xOff + a + ( yOff - b ) * size.x ] = fc;
  1076. if( xOff - a < dgx && xOff - a > dpx && yOff - b < dgy && yOff - b > dpy )
  1077. this->fc[ xOff - a + ( yOff - b ) * size.x ] = fc;
  1078. if( xOff + b < dgx && xOff + b > dpx && yOff + a < dgy && yOff + a > dpy )
  1079. this->fc[ xOff + b + ( yOff + a ) * size.x ] = fc;
  1080. if( xOff - b < dgx && xOff - b > dpx && yOff + a < dgy && yOff + a > dpy )
  1081. this->fc[ xOff - b + ( yOff + a ) * size.x ] = fc;
  1082. if( xOff + b < dgx && xOff + b > dpx && yOff - a < dgy && yOff - a > dpy )
  1083. this->fc[ xOff + b + ( yOff - a ) * size.x ] = fc;
  1084. if( xOff - b < dgx && xOff - b > dpx && yOff - a < dgy && yOff - a > dpy )
  1085. this->fc[ xOff - b + ( yOff - a ) * size.x ] = fc;
  1086. }
  1087. rend = 1;
  1088. }
  1089. void Bild::drawKreisAlpha( int xOff, int yOff, int r, int fc )
  1090. {
  1091. if( alpha[ alphaAnzahl ] == 0xFF )
  1092. return;
  1093. int dpx = dPosA[ doa ].x;
  1094. int dpy = dPosA[ doa ].y;
  1095. int dgx = dSizeA[ doa ].x;
  1096. int dgy = dSizeA[ doa ].y;
  1097. xOff += drawOff[ doa ].x;
  1098. yOff += drawOff[ doa ].y;
  1099. if( xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy )
  1100. return;
  1101. if( alpha[ alphaAnzahl ] < 0xFF )
  1102. {
  1103. unsigned char *cf = (unsigned char*)&fc;
  1104. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1105. }
  1106. int alpha = ( ( fc >> 24 ) & 0xFF );
  1107. int na = ( 0x100 - alpha );
  1108. int i1 = ( alpha * ( fc & 0xFF00FF ) ) >> 8;
  1109. int i2 = ( alpha * ( fc & 0x00FF00 ) ) >> 8;
  1110. for( int a = 0; a < r; ++a )
  1111. {
  1112. int b = (int)( sqrt( (float)(long)( r * r - a * a ) ) + 0.5 );
  1113. int *pixel = 0;
  1114. if( xOff + a < dgx && xOff + a > dpx && yOff + b < dgy && yOff + b > dpy )
  1115. {
  1116. pixel = &this->fc[ xOff + a + ( yOff + b ) * size.x ];
  1117. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1118. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1119. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1120. }
  1121. if( xOff - a < dgx && xOff - a > dpx && yOff + b < dgy && yOff + b > dpy )
  1122. {
  1123. pixel = &this->fc[ xOff - a + ( yOff + b ) * size.x ];
  1124. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1125. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1126. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1127. }
  1128. if( xOff + a < dgx && xOff + a > dpx && yOff - b < dgy && yOff - b > dpy )
  1129. {
  1130. pixel = &this->fc[ xOff + a + ( yOff - b ) * size.x ];
  1131. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1132. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1133. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1134. }
  1135. if( xOff - a < dgx && xOff - a > dpx && yOff - b < dgy && yOff - b > dpy )
  1136. {
  1137. pixel = &this->fc[ xOff - a + ( yOff - b ) * size.x ];
  1138. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1139. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1140. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1141. }
  1142. if( xOff + b < dgx && xOff + b > dpx && yOff + a < dgy && yOff + a > dpy )
  1143. {
  1144. pixel = &this->fc[ xOff + b + ( yOff + a ) * size.x ];
  1145. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1146. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1147. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1148. }
  1149. if( xOff - b < dgx && xOff - b > dpx && yOff + a < dgy && yOff + a > dpy )
  1150. {
  1151. pixel = &this->fc[ xOff - b + ( yOff + a ) * size.x ];
  1152. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1153. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1154. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1155. }
  1156. if( xOff + b < dgx && xOff + b > dpx && yOff - a < dgy && yOff - a > dpy )
  1157. {
  1158. pixel = &this->fc[ xOff + b + ( yOff - a ) * size.x ];
  1159. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1160. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1161. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1162. }
  1163. if( xOff - b < dgx && xOff - b > dpx && yOff - a < dgy && yOff - a > dpy )
  1164. {
  1165. pixel = &this->fc[ xOff - b + ( yOff - a ) * size.x ];
  1166. *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
  1167. ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
  1168. ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
  1169. }
  1170. }
  1171. rend = 1;
  1172. }
  1173. void Bild::drawBild( int x, int y, int br, int hi, Bild &zBild ) // zeichet zBild
  1174. {
  1175. if( alpha[ alphaAnzahl ] == 0xFF )
  1176. return;
  1177. if( alpha[ alphaAnzahl ] )
  1178. {
  1179. alphaBild( x, y, br, hi, zBild );
  1180. return;
  1181. }
  1182. int dpx = dPosA[ doa ].x;
  1183. int dpy = dPosA[ doa ].y;
  1184. int dgx = dSizeA[ doa ].x;
  1185. int dgy = dSizeA[ doa ].y;
  1186. x += drawOff[ doa ].x;
  1187. y += drawOff[ doa ].y;
  1188. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1189. return;
  1190. br = minInt( br, zBild.getBreite() );
  1191. hi = minInt( hi, zBild.getHeight() );
  1192. int xst = maxInt( dpx - x, 0 );
  1193. int yst = maxInt( dpy - y, 0 );
  1194. int xst2 = maxInt( x, dpx );
  1195. int yst2 = maxInt( y, dpy );
  1196. dgx = minInt( x + br, dgx );
  1197. dgy = minInt( y + hi, dgy );
  1198. int bb = zBild.getBreite();
  1199. int *ff = zBild.getBuffer();
  1200. int xx, ygr, ygr2;
  1201. for( int yy = yst2; yy < dgy; ++yy )
  1202. {
  1203. ygr = yy * size.x;
  1204. ygr2 = ( yy - yst2 + yst ) * bb;
  1205. for( xx = xst2; xx < dgx; ++xx )
  1206. fc[ xx + ygr ] = ff[ ( xx - xst2 + xst ) + ygr2 ];
  1207. }
  1208. rend = 1;
  1209. }
  1210. void Bild::alphaBild( int x, int y, int br, int hi, Bild &zBild )
  1211. {
  1212. if( alpha[ alphaAnzahl ] == 0xFF )
  1213. return;
  1214. int dpx = dPosA[ doa ].x;
  1215. int dpy = dPosA[ doa ].y;
  1216. int dgx = dSizeA[ doa ].x;
  1217. int dgy = dSizeA[ doa ].y;
  1218. x += drawOff[ doa ].x;
  1219. y += drawOff[ doa ].y;
  1220. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1221. return;
  1222. br = minInt( br, zBild.getBreite() );
  1223. hi = minInt( hi, zBild.getHeight() );
  1224. int xst = maxInt( dpx - x, 0 );
  1225. int yst = maxInt( dpy - y, 0 );
  1226. int xst2 = maxInt( x, dpx );
  1227. int yst2 = maxInt( y, dpy );
  1228. dgx = minInt( x + br, dgx );
  1229. dgy = minInt( y + hi, dgy );
  1230. int bb = zBild.getBreite();
  1231. int *ff = zBild.getBuffer();
  1232. if( !alpha[ alphaAnzahl ] )
  1233. {
  1234. int xx, ygr, ygr2;
  1235. for( int yy = yst2; yy < dgy; ++yy )
  1236. {
  1237. ygr = yy * size.x;
  1238. ygr2 = ( yy - yst2 + yst ) * bb;
  1239. for( xx = xst2; xx < dgx; ++xx )
  1240. alphaPixelP( fc[ xx + ygr ], ff[ ( xx - xst2 + xst ) + ygr2 ] );
  1241. }
  1242. }
  1243. else
  1244. {
  1245. int xx, ygr, ygr2;
  1246. for( int yy = yst2; yy < dgy; ++yy )
  1247. {
  1248. ygr = yy * size.x;
  1249. ygr2 = ( yy - yst2 + yst ) * bb;
  1250. for( xx = xst2; xx < dgx; ++xx )
  1251. {
  1252. int fc = ff[ ( xx - xst2 + xst ) + ygr2 ];
  1253. unsigned char *cf = (unsigned char*)&fc;
  1254. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1255. alphaPixelP( this->fc[ xx + ygr ], fc );
  1256. }
  1257. }
  1258. }
  1259. rend = 1;
  1260. }
  1261. void Bild::drawBild90( int x, int y, int br, int hi, Bild &zBild ) // Zeichnet ein um 90 Grad nach rchts gedrehtes Bild
  1262. {
  1263. if( alpha[ alphaAnzahl ] == 0xFF )
  1264. return;
  1265. if( alpha[ alphaAnzahl ] )
  1266. {
  1267. alphaBild90( x, y, br, hi, zBild );
  1268. return;
  1269. }
  1270. int dpx = dPosA[ doa ].x;
  1271. int dpy = dPosA[ doa ].y;
  1272. int dgx = dSizeA[ doa ].x;
  1273. int dgy = dSizeA[ doa ].y;
  1274. x += drawOff[ doa ].x;
  1275. y += drawOff[ doa ].y;
  1276. if( x + hi < dpx || y + br < dpy || x > dgx || y > dgy )
  1277. return;
  1278. br = minInt( br, zBild.getBreite() );
  1279. hi = minInt( hi, zBild.getHeight() );
  1280. int xst = maxInt( dpx - x, 0 );
  1281. int yst = maxInt( dpy - y, 0 );
  1282. int xst2 = maxInt( x, dpx );
  1283. int yst2 = maxInt( y, dpy );
  1284. dgx = minInt( x + hi, dgx );
  1285. dgy = minInt( y + br, dgy );
  1286. int bb = zBild.getBreite();
  1287. int *ff = zBild.getBuffer();
  1288. int yy, xbb;
  1289. for( int xx = xst2; xx < dgx; ++xx )
  1290. {
  1291. xbb = ( zBild.getHeight() - ( xx - xst2 + xst + 1 ) ) * bb;
  1292. for( yy = yst2; yy < dgy; ++yy )
  1293. fc[ xx + yy * size.x ] = ff[ ( yy - yst2 + yst ) + xbb ];
  1294. }
  1295. rend = 1;
  1296. }
  1297. void Bild::alphaBild90( int x, int y, int br, int hi, Bild &zBild )
  1298. {
  1299. if( alpha[ alphaAnzahl ] == 0xFF )
  1300. return;
  1301. int dpx = dPosA[ doa ].x;
  1302. int dpy = dPosA[ doa ].y;
  1303. int dgx = dSizeA[ doa ].x;
  1304. int dgy = dSizeA[ doa ].y;
  1305. x += drawOff[ doa ].x;
  1306. y += drawOff[ doa ].y;
  1307. if( x + hi < dpx || y + br < dpy || x > dgx || y > dgy )
  1308. return;
  1309. br = minInt( br, zBild.getBreite() );
  1310. hi = minInt( hi, zBild.getHeight() );
  1311. int xst = maxInt( dpx - x, 0 );
  1312. int yst = maxInt( dpy - y, 0 );
  1313. int xst2 = maxInt( x, dpx );
  1314. int yst2 = maxInt( y, dpy );
  1315. dgx = minInt( x + hi, dgx );
  1316. dgy = minInt( y + br, dgy );
  1317. int bb = zBild.getBreite();
  1318. int *ff = zBild.getBuffer();
  1319. if( !alpha[ alphaAnzahl ] )
  1320. {
  1321. int yy, xbb;
  1322. for( int xx = xst2; xx < dgx; ++xx )
  1323. {
  1324. xbb = ( zBild.getHeight() - ( xx - xst2 + xst + 1 ) ) * bb;
  1325. for( yy = yst2; yy < dgy; ++yy )
  1326. alphaPixelP( xx, yy, ff[ ( yy - yst2 + yst ) + xbb ] );
  1327. }
  1328. }
  1329. else
  1330. {
  1331. int yy, xbb;
  1332. for( int xx = xst2; xx < dgx; ++xx )
  1333. {
  1334. xbb = ( zBild.getHeight() - ( xx - xst2 + xst + 1 ) ) * bb;
  1335. for( yy = yst2; yy < dgy; ++yy )
  1336. {
  1337. int fc = ff[ ( yy - yst2 + yst ) + xbb ];
  1338. unsigned char *cf = (unsigned char*)&fc;
  1339. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1340. alphaPixelP( xx, yy, fc );
  1341. }
  1342. }
  1343. }
  1344. rend = 1;
  1345. }
  1346. void Bild::drawBild180( int x, int y, int br, int hi, Bild &zBild ) // Zeichnet ein um 180 Grad nach rchts gedrehtes Bild
  1347. {
  1348. if( alpha[ alphaAnzahl ] == 0xFF )
  1349. return;
  1350. if( alpha[ alphaAnzahl ] )
  1351. {
  1352. alphaBild180( x, y, br, hi, zBild );
  1353. return;
  1354. }
  1355. int dpx = dPosA[ doa ].x;
  1356. int dpy = dPosA[ doa ].y;
  1357. int dgx = dSizeA[ doa ].x;
  1358. int dgy = dSizeA[ doa ].y;
  1359. x += drawOff[ doa ].x;
  1360. y += drawOff[ doa ].y;
  1361. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1362. return;
  1363. br = minInt( br, zBild.getBreite() );
  1364. hi = minInt( hi, zBild.getHeight() );
  1365. int xst = maxInt( dpx - x, 0 );
  1366. int yst = maxInt( dpy - y, 0 );
  1367. int xst2 = maxInt( x, dpx );
  1368. int yst2 = maxInt( y, dpy );
  1369. dgx = minInt( x + br, dgx );
  1370. dgy = minInt( y + hi, dgy );
  1371. int bb = zBild.getBreite();
  1372. int *ff = zBild.getBuffer();
  1373. int xx, ygr, ybb;
  1374. for( int yy = yst2; yy < dgy; ++yy )
  1375. {
  1376. ygr = yy * size.x;
  1377. ybb = ( zBild.getHeight() - ( yy - yst2 + yst + 1 ) ) * bb;
  1378. for( xx = xst2; xx < dgx; ++xx )
  1379. fc[ xx + ygr ] = ff[ ( bb - ( xx - xst2 + xst + 1 ) ) + ybb ];
  1380. }
  1381. rend = 1;
  1382. }
  1383. void Bild::alphaBild180( int x, int y, int br, int hi, Bild &zBild )
  1384. {
  1385. if( alpha[ alphaAnzahl ] == 0xFF )
  1386. return;
  1387. int dpx = dPosA[ doa ].x;
  1388. int dpy = dPosA[ doa ].y;
  1389. int dgx = dSizeA[ doa ].x;
  1390. int dgy = dSizeA[ doa ].y;
  1391. x += drawOff[ doa ].x;
  1392. y += drawOff[ doa ].y;
  1393. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1394. return;
  1395. br = minInt( br, zBild.getBreite() );
  1396. hi = minInt( hi, zBild.getHeight() );
  1397. int xst = maxInt( dpx - x, 0 );
  1398. int yst = maxInt( dpy - y, 0 );
  1399. int xst2 = maxInt( x, dpx );
  1400. int yst2 = maxInt( y, dpy );
  1401. dgx = minInt( x + br, dgx );
  1402. dgy = minInt( y + hi, dgy );
  1403. int bb = zBild.getBreite();
  1404. int *ff = zBild.getBuffer();
  1405. if( !alpha[ alphaAnzahl ] )
  1406. {
  1407. int xx, ygr, ybb;
  1408. for( int yy = yst2; yy < dgy; ++yy )
  1409. {
  1410. ygr = yy * size.x;
  1411. ybb = ( zBild.getHeight() - ( yy - yst2 + yst + 1 ) ) * bb;
  1412. for( xx = xst2; xx < dgx; ++xx )
  1413. alphaPixelP( fc[ xx + ygr ], ff[ ( bb - ( xx - xst2 + xst + 1 ) ) + ybb ] );
  1414. }
  1415. }
  1416. else
  1417. {
  1418. int xx, ygr, ybb;
  1419. for( int yy = yst2; yy < dgy; ++yy )
  1420. {
  1421. ygr = yy * size.x;
  1422. ybb = ( zBild.getHeight() - ( yy - yst2 + yst + 1 ) ) * bb;
  1423. for( xx = xst2; xx < dgx; ++xx )
  1424. {
  1425. int fc = ff[ ( bb - ( xx - xst2 + xst + 1 ) ) + ybb ];
  1426. unsigned char *cf = (unsigned char*)&fc;
  1427. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1428. alphaPixelP( this->fc[ xx + ygr ], fc );
  1429. }
  1430. }
  1431. }
  1432. rend = 1;
  1433. }
  1434. void Bild::drawBild270( int x, int y, int br, int hi, Bild &zBild ) // Zeichnet ein um 270 Grad nach rchts gedrehtes Bild
  1435. {
  1436. if( alpha[ alphaAnzahl ] == 0xFF )
  1437. return;
  1438. if( alpha[ alphaAnzahl ] )
  1439. {
  1440. alphaBild270( x, y, br, hi, zBild );
  1441. return;
  1442. }
  1443. int dpx = dPosA[ doa ].x;
  1444. int dpy = dPosA[ doa ].y;
  1445. int dgx = dSizeA[ doa ].x;
  1446. int dgy = dSizeA[ doa ].y;
  1447. x += drawOff[ doa ].x;
  1448. y += drawOff[ doa ].y;
  1449. if( x + hi < dpx || y + br < dpy || x > dgx || y > dgy )
  1450. return;
  1451. br = minInt( br, zBild.getBreite() );
  1452. hi = minInt( hi, zBild.getHeight() );
  1453. int xst = maxInt( dpx - x, 0 );
  1454. int yst = maxInt( dpy - y, 0 );
  1455. int xst2 = maxInt( x, dpx );
  1456. int yst2 = maxInt( y, dpy );
  1457. dgx = minInt( x + hi, dgx );
  1458. dgy = minInt( y + br, dgy );
  1459. int bb = zBild.getBreite();
  1460. int *ff = zBild.getBuffer();
  1461. int yy, xbb;
  1462. for( int xx = xst2; xx < dgx; ++xx )
  1463. {
  1464. xbb = ( xx - xst2 + xst ) * bb;
  1465. for( yy = yst2; yy < dgy; ++yy )
  1466. fc[ xx + yy * size.x ] = ff[ ( bb - ( yy - yst2 + yst + 1 ) ) + xbb ];
  1467. }
  1468. rend = 1;
  1469. }
  1470. void Bild::alphaBild270( int x, int y, int br, int hi, Bild &zBild )
  1471. {
  1472. if( alpha[ alphaAnzahl ] == 0xFF )
  1473. return;
  1474. int dpx = dPosA[ doa ].x;
  1475. int dpy = dPosA[ doa ].y;
  1476. int dgx = dSizeA[ doa ].x;
  1477. int dgy = dSizeA[ doa ].y;
  1478. x += drawOff[ doa ].x;
  1479. y += drawOff[ doa ].y;
  1480. if( x + hi < dpx || y + br < dpy || x > dgx || y > dgy )
  1481. return;
  1482. br = minInt( br, zBild.getBreite() );
  1483. hi = minInt( hi, zBild.getBreite() );
  1484. int xst = maxInt( dpx - x, 0 );
  1485. int yst = maxInt( dpy - y, 0 );
  1486. int xst2 = maxInt( x, dpx );
  1487. int yst2 = maxInt( y, dpy );
  1488. dgx = minInt( x + hi, dgx );
  1489. dgy = minInt( y + br, dgy );
  1490. int bb = zBild.getBreite();
  1491. int *ff = zBild.getBuffer();
  1492. if( !alpha[ alphaAnzahl ] )
  1493. {
  1494. int yy, xbb;
  1495. for( int xx = xst2; xx < dgx; ++xx )
  1496. {
  1497. xbb = ( xx - xst2 + xst ) * bb;
  1498. for( yy = yst2; yy < dgy; ++yy )
  1499. alphaPixelP( xx, yy, ff[ ( bb - ( yy - yst2 + yst + 1 ) ) + xbb ] );
  1500. }
  1501. }
  1502. else
  1503. {
  1504. int yy, xbb;
  1505. for( int xx = xst2; xx < dgx; ++xx )
  1506. {
  1507. xbb = ( xx - xst2 + xst ) * bb;
  1508. for( yy = yst2; yy < dgy; ++yy )
  1509. {
  1510. int fc = ff[ ( bb - ( yy - yst2 + yst + 1 ) ) + xbb ];
  1511. unsigned char *cf = (unsigned char*)&fc;
  1512. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1513. alphaPixelP( xx, yy, fc );
  1514. }
  1515. }
  1516. }
  1517. rend = 1;
  1518. }
  1519. void Bild::drawBildSkall( int x, int y, int br, int hi, Bild &zBild ) // zeichet zBild Skalliert
  1520. {
  1521. if( alpha[ alphaAnzahl ] == 0xFF )
  1522. return;
  1523. if( alpha[ alphaAnzahl ] )
  1524. {
  1525. alphaBildSkall( x, y, br, hi, zBild );
  1526. return;
  1527. }
  1528. int dpx = dPosA[ doa ].x;
  1529. int dpy = dPosA[ doa ].y;
  1530. int dgx = dSizeA[ doa ].x;
  1531. int dgy = dSizeA[ doa ].y;
  1532. x += drawOff[ doa ].x;
  1533. y += drawOff[ doa ].y;
  1534. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1535. return;
  1536. double xo = zBild.getBreite() / (double)br;
  1537. double yo = zBild.getHeight() / (double)hi;
  1538. int xst = maxInt( dpx - x, 0 );
  1539. int yst = maxInt( dpy - y, 0 );
  1540. int xst2 = maxInt( x, dpx );
  1541. int yst2 = maxInt( y, dpy );
  1542. dgx = minInt( x + br, dgx );
  1543. dgy = minInt( y + hi, dgy );
  1544. int bb = zBild.getBreite();
  1545. int *ff = zBild.getBuffer();
  1546. int xx, ygr, ygr2;
  1547. double xb = 0, yb = yst * yo;
  1548. for( int yy = yst2; yy < dgy; ++yy, yb += yo )
  1549. {
  1550. ygr = yy * size.x;
  1551. ygr2 = (int)( ( yy - yst2 + yst ) * yo ) * bb;
  1552. for( xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo )
  1553. fc[ xx + ygr ] = ff[ (int)xb + ygr2 ];
  1554. }
  1555. rend = 1;
  1556. }
  1557. void Bild::alphaBildSkall( int x, int y, int br, int hi, Bild &zBild )
  1558. {
  1559. if( alpha[ alphaAnzahl ] == 0xFF )
  1560. return;
  1561. int dpx = dPosA[ doa ].x;
  1562. int dpy = dPosA[ doa ].y;
  1563. int dgx = dSizeA[ doa ].x;
  1564. int dgy = dSizeA[ doa ].y;
  1565. x += drawOff[ doa ].x;
  1566. y += drawOff[ doa ].y;
  1567. if( x + br < dpx || y + hi < dpy || x > dgx || y > dgy )
  1568. return;
  1569. double xo = zBild.getBreite() / (double)br;
  1570. double yo = zBild.getHeight() / (double)hi;
  1571. int xst = maxInt( dpx - x, 0 );
  1572. int yst = maxInt( dpy - y, 0 );
  1573. int xst2 = maxInt( x, dpx );
  1574. int yst2 = maxInt( y, dpy );
  1575. dgx = minInt( x + br, dgx );
  1576. dgy = minInt( y + hi, dgy );
  1577. int bb = zBild.getBreite();
  1578. int *ff = zBild.getBuffer();
  1579. int xx, ygr, ygr2;
  1580. double xb = 0;
  1581. for( int yy = yst2; yy < dgy; ++yy )
  1582. {
  1583. ygr = yy * size.x;
  1584. ygr2 = (int)( ( yy - yst2 + yst ) * yo ) * bb;
  1585. for( xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo )
  1586. {
  1587. int f = ff[ (int)xb + ygr2 ];
  1588. unsigned char *cf = (unsigned char*)&f;
  1589. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1590. alphaPixelP( fc[ xx + ygr ], f );
  1591. }
  1592. }
  1593. rend = 1;
  1594. }
  1595. void Bild::drawDreieck( Punkt a, Punkt b, Punkt c, int farbe ) // füllt eine Dreieck aus
  1596. {
  1597. if( alpha[ alphaAnzahl ] == 0xFF )
  1598. return;
  1599. if( alpha[ alphaAnzahl ] )
  1600. {
  1601. drawDreieckAlpha( a, b, c, farbe );
  1602. return;
  1603. }
  1604. int dpx = dPosA[ doa ].x;
  1605. int dpy = dPosA[ doa ].y;
  1606. int dgx = dSizeA[ doa ].x;
  1607. int dgy = dSizeA[ doa ].y;
  1608. a += drawOff[ doa ];
  1609. b += drawOff[ doa ];
  1610. c += drawOff[ doa ];
  1611. if( ( a.x < dpx && b.x < dpx && c.x < dpx ) || ( a.y < dpy && b.y < dpy && c.y < dpy ) ||
  1612. ( a.x > dgx && b.x > dgx && c.x > dgx ) || ( a.y > dgy && b.y > dgy && c.y > dgy ) )
  1613. return;
  1614. if( b.y < a.y )
  1615. a.Swap( b );
  1616. if( c.y < b.y )
  1617. b.Swap( c );
  1618. if( b.y < a.y )
  1619. a.Swap( b );
  1620. if( a.y == b.y )
  1621. {
  1622. if( b.x < a.x )
  1623. a.Swap( b );
  1624. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1625. const float m3 = (float)( b.x - c.x ) / (float)( b.y - c.y );
  1626. float b2 = (float)a.x - m2 * (float)a.y;
  1627. float b3 = (float)b.x - m3 * (float)b.y;
  1628. drawFlatDreieck( b.y, c.y, m2, b2, m3, b3, farbe );
  1629. }
  1630. else if( b.y == c.y )
  1631. {
  1632. if( c.x < b.x )
  1633. b.Swap( c );
  1634. const float m1 = (float)( a.x - b.x ) / (float)( a.y - b.y );
  1635. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1636. float b1 = (float)a.x - m1 * (float)a.y;
  1637. float b2 = (float)a.x - m2 * (float)a.y;
  1638. drawFlatDreieck( a.y, b.y, m1, b1, m2, b2, farbe );
  1639. }
  1640. else
  1641. {
  1642. const float m1 = (float)( a.x - b.x ) / (float)( a.y - b.y );
  1643. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1644. const float m3 = (float)( b.x - c.x ) / (float)( b.y - c.y );
  1645. float b1 = (float)a.x - m1 * (float)a.y;
  1646. float b2 = (float)a.x - m2 * (float)a.y;
  1647. float b3 = (float)b.x - m3 * (float)b.y;
  1648. const float qx = m2 * (float)b.y + b2;
  1649. if( qx < b.x )
  1650. {
  1651. drawFlatDreieck( a.y, b.y, m2, b2, m1, b1, farbe );
  1652. drawFlatDreieck( b.y, c.y, m2, b2, m3, b3, farbe );
  1653. }
  1654. else
  1655. {
  1656. drawFlatDreieck( a.y, b.y, m1, b1, m2, b2, farbe );
  1657. drawFlatDreieck( b.y, c.y, m3, b3, m2, b2, farbe );
  1658. }
  1659. }
  1660. rend = 1;
  1661. }
  1662. void Bild::drawDreieckTextur( Punkt a, Punkt b, Punkt c, Punkt ta, Punkt tb, Punkt tc, Bild &textur ) // füllt eine Dreieck aus
  1663. {
  1664. if( alpha[ alphaAnzahl ] == 0xFF )
  1665. return;
  1666. if( alpha[ alphaAnzahl ] )
  1667. {
  1668. drawDreieckTexturAlpha( a, b, c, ta, tb, tc, textur );
  1669. return;
  1670. }
  1671. int dpx = dPosA[ doa ].x;
  1672. int dpy = dPosA[ doa ].y;
  1673. int dgx = dSizeA[ doa ].x;
  1674. int dgy = dSizeA[ doa ].y;
  1675. a += drawOff[ doa ];
  1676. b += drawOff[ doa ];
  1677. c += drawOff[ doa ];
  1678. if( ( a.x < dpx && b.x < dpx && c.x < dpx ) || ( a.y < dpy && b.y < dpy && c.y < dpy ) ||
  1679. ( a.x > dgx && b.x > dgx && c.x > dgx ) || ( a.y > dgy && b.y > dgy && c.y > dgy ) )
  1680. return;
  1681. if( b.y < a.y )
  1682. {
  1683. a.Swap( b );
  1684. ta.Swap( tb );
  1685. }
  1686. if( c.y < b.y )
  1687. {
  1688. b.Swap( c );
  1689. tb.Swap( tc );
  1690. }
  1691. if( b.y < a.y )
  1692. {
  1693. a.Swap( b );
  1694. ta.Swap( tb );
  1695. }
  1696. const double m1 = (double)( a.x - b.x ) / ( a.y - b.y );
  1697. const double m2 = (double)( a.x - c.x ) / ( a.y - c.y );
  1698. const double m3 = (double)( b.x - c.x ) / ( b.y - c.y );
  1699. double b1 = a.x - m1 * a.y;
  1700. double b2 = a.x - m2 * a.y;
  1701. double b3 = b.x - m3 * b.y;
  1702. const double qx = m2 * b.y + b2;
  1703. if( qx < b.x )
  1704. {
  1705. double tx1o, ty1o, tx2o, ty2o;
  1706. if( c.y - a.y )
  1707. {
  1708. tx1o = (double)( tc.x - ta.x ) / ( c.y - a.y );
  1709. ty1o = (double)( tc.y - ta.y ) / ( c.y - a.y );
  1710. }
  1711. else
  1712. {
  1713. tx1o = 0;
  1714. ty1o = 0;
  1715. }
  1716. if( b.y - a.y )
  1717. {
  1718. tx2o = (double)( tb.x - ta.x ) / ( b.y - a.y );
  1719. ty2o = (double)( tb.y - ta.y ) / ( b.y - a.y );
  1720. }
  1721. else
  1722. {
  1723. tx2o = 0;
  1724. ty2o = 0;
  1725. }
  1726. Vec2< double > q( ta.x + tx1o * ( b.y - a.y ), ta.y + ty1o * ( b.y - a.y ) );
  1727. double txf, tyf;
  1728. if( b.x - qx )
  1729. {
  1730. txf = ( tb.x - q.x ) / ( b.x - qx );
  1731. tyf = ( tb.y - q.y ) / ( b.x - qx );
  1732. }
  1733. else
  1734. {
  1735. txf = 0;
  1736. tyf = 0;
  1737. }
  1738. drawFlatDreieckTextur( a.y, b.y, m2, b2, m1, b1, ta.x, ta.y, ta.x, ta.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1739. if( c.y - b.y )
  1740. {
  1741. tx2o = (double)( tc.x - tb.x ) / ( c.y - b.y );
  1742. ty2o = (double)( tc.y - tb.y ) / ( c.y - b.y );
  1743. }
  1744. else
  1745. {
  1746. tx2o = 0;
  1747. ty2o = 0;
  1748. }
  1749. drawFlatDreieckTextur( b.y, c.y, m2, b2, m3, b3, q.x, q.y, tb.x, tb.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1750. }
  1751. else
  1752. {
  1753. double tx1o, ty1o, tx2o, ty2o;
  1754. if( b.y - a.y )
  1755. {
  1756. tx1o = (double)( tb.x - ta.x ) / ( b.y - a.y );
  1757. ty1o = (double)( tb.y - ta.y ) / ( b.y - a.y );
  1758. }
  1759. else
  1760. {
  1761. tx1o = 0;
  1762. ty1o = 0;
  1763. }
  1764. if( c.y - a.y )
  1765. {
  1766. tx2o = (double)( tc.x - ta.x ) / ( c.y - a.y );
  1767. ty2o = (double)( tc.y - ta.y ) / ( c.y - a.y );
  1768. }
  1769. else
  1770. {
  1771. tx2o = 0;
  1772. ty2o = 0;
  1773. }
  1774. Vec2< double > q( ta.x + tx2o * ( b.y - a.y ), ta.y + ty2o * ( b.y - a.y ) );
  1775. double txf, tyf;
  1776. if( qx - b.x )
  1777. {
  1778. txf = ( q.x - tb.x ) / ( qx - b.x );
  1779. tyf = ( q.y - tb.y ) / ( qx - b.x );
  1780. }
  1781. else
  1782. {
  1783. txf = 0;
  1784. tyf = 0;
  1785. }
  1786. drawFlatDreieckTextur( a.y, b.y, m1, b1, m2, b2, ta.x, ta.y, ta.x, ta.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1787. if( c.y - b.y )
  1788. {
  1789. tx1o = (double)( tc.x - tb.x ) / ( c.y - b.y );
  1790. ty1o = (double)( tc.y - tb.y ) / ( c.y - b.y );
  1791. }
  1792. else
  1793. {
  1794. tx1o = 0;
  1795. ty1o = 0;
  1796. }
  1797. drawFlatDreieckTextur( b.y, c.y, m3, b3, m2, b2, tb.x, tb.y, q.x, q.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1798. }
  1799. rend = 1;
  1800. }
  1801. void Bild::drawDreieckAlpha( Punkt a, Punkt b, Punkt c, int farbe ) // füllt eine Dreieck aus
  1802. {
  1803. if( alpha[ alphaAnzahl ] == 0xFF )
  1804. return;
  1805. int dpx = dPosA[ doa ].x;
  1806. int dpy = dPosA[ doa ].y;
  1807. int dgx = dSizeA[ doa ].x;
  1808. int dgy = dSizeA[ doa ].y;
  1809. a += drawOff[ doa ];
  1810. b += drawOff[ doa ];
  1811. c += drawOff[ doa ];
  1812. if( ( a.x < dpx && b.x < dpx && c.x < dpx ) || ( a.y < dpy && b.y < dpy && c.y < dpy ) ||
  1813. ( a.x > dgx && b.x > dgx && c.x > dgx ) || ( a.y > dgy && b.y > dgy && c.y > dgy ) )
  1814. return;
  1815. if( alpha[ alphaAnzahl ] )
  1816. {
  1817. unsigned char *cf = (unsigned char*)&farbe;
  1818. cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
  1819. }
  1820. if( b.y < a.y )
  1821. a.Swap( b );
  1822. if( c.y < b.y )
  1823. b.Swap( c );
  1824. if( b.y < a.y )
  1825. a.Swap( b );
  1826. if( a.y == b.y )
  1827. {
  1828. if( b.x < a.x )
  1829. a.Swap( b );
  1830. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1831. const float m3 = (float)( b.x - c.x ) / (float)( b.y - c.y );
  1832. float b2 = (float)a.x - m2 * (float)a.y;
  1833. float b3 = (float)b.x - m3 * (float)b.y;
  1834. drawFlatDreieckAlpha( b.y, c.y, m2, b2, m3, b3, farbe );
  1835. }
  1836. else if( b.y == c.y )
  1837. {
  1838. if( c.x < b.x )
  1839. b.Swap( c );
  1840. const float m1 = (float)( a.x - b.x ) / (float)( a.y - b.y );
  1841. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1842. float b1 = (float)a.x - m1 * (float)a.y;
  1843. float b2 = (float)a.x - m2 * (float)a.y;
  1844. drawFlatDreieckAlpha( a.y, b.y, m1, b1, m2, b2, farbe );
  1845. }
  1846. else
  1847. {
  1848. const float m1 = (float)( a.x - b.x ) / (float)( a.y - b.y );
  1849. const float m2 = (float)( a.x - c.x ) / (float)( a.y - c.y );
  1850. const float m3 = (float)( b.x - c.x ) / (float)( b.y - c.y );
  1851. float b1 = (float)a.x - m1 * (float)a.y;
  1852. float b2 = (float)a.x - m2 * (float)a.y;
  1853. float b3 = (float)b.x - m3 * (float)b.y;
  1854. const float qx = m2 * (float)b.y + b2;
  1855. if( qx < b.x )
  1856. {
  1857. drawFlatDreieckAlpha( a.y, b.y, m2, b2, m1, b1, farbe );
  1858. drawFlatDreieckAlpha( b.y, c.y, m2, b2, m3, b3, farbe );
  1859. }
  1860. else
  1861. {
  1862. drawFlatDreieckAlpha( a.y, b.y, m1, b1, m2, b2, farbe );
  1863. drawFlatDreieckAlpha( b.y, c.y, m3, b3, m2, b2, farbe );
  1864. }
  1865. }
  1866. rend = 1;
  1867. }
  1868. void Bild::drawDreieckTexturAlpha( Punkt a, Punkt b, Punkt c, Punkt ta, Punkt tb, Punkt tc, Bild &textur ) // füllt eine Dreieck aus
  1869. {
  1870. if( alpha[ alphaAnzahl ] == 0xFF )
  1871. return;
  1872. int dpx = dPosA[ doa ].x;
  1873. int dpy = dPosA[ doa ].y;
  1874. int dgx = dSizeA[ doa ].x;
  1875. int dgy = dSizeA[ doa ].y;
  1876. a += drawOff[ doa ];
  1877. b += drawOff[ doa ];
  1878. c += drawOff[ doa ];
  1879. if( ( a.x < dpx && b.x < dpx && c.x < dpx ) || ( a.y < dpy && b.y < dpy && c.y < dpy ) ||
  1880. ( a.x > dgx && b.x > dgx && c.x > dgx ) || ( a.y > dgy && b.y > dgy && c.y > dgy ) )
  1881. return;
  1882. if( b.y < a.y )
  1883. {
  1884. a.Swap( b );
  1885. ta.Swap( tb );
  1886. }
  1887. if( c.y < b.y )
  1888. {
  1889. b.Swap( c );
  1890. tb.Swap( tc );
  1891. }
  1892. if( b.y < a.y )
  1893. {
  1894. a.Swap( b );
  1895. ta.Swap( tb );
  1896. }
  1897. const double m1 = (double)( a.x - b.x ) / ( a.y - b.y );
  1898. const double m2 = (double)( a.x - c.x ) / ( a.y - c.y );
  1899. const double m3 = (double)( b.x - c.x ) / ( b.y - c.y );
  1900. double b1 = a.x - m1 * a.y;
  1901. double b2 = a.x - m2 * a.y;
  1902. double b3 = b.x - m3 * b.y;
  1903. const double qx = m2 * b.y + b2;
  1904. if( qx < b.x )
  1905. {
  1906. double tx1o, ty1o, tx2o, ty2o;
  1907. if( c.y - a.y )
  1908. {
  1909. tx1o = (double)( tc.x - ta.x ) / ( c.y - a.y );
  1910. ty1o = (double)( tc.y - ta.y ) / ( c.y - a.y );
  1911. }
  1912. else
  1913. {
  1914. tx1o = 0;
  1915. ty1o = 0;
  1916. }
  1917. if( b.y - a.y )
  1918. {
  1919. tx2o = (double)( tb.x - ta.x ) / ( b.y - a.y );
  1920. ty2o = (double)( tb.y - ta.y ) / ( b.y - a.y );
  1921. }
  1922. else
  1923. {
  1924. tx2o = 0;
  1925. ty2o = 0;
  1926. }
  1927. Vec2< double > q( ta.x + tx1o * ( b.y - a.y ), ta.y + ty1o * ( b.y - a.y ) );
  1928. double txf, tyf;
  1929. if( b.x - qx )
  1930. {
  1931. txf = ( tb.x - q.x ) / ( b.x - qx );
  1932. tyf = ( tb.y - q.y ) / ( b.x - qx );
  1933. }
  1934. else
  1935. {
  1936. txf = 0;
  1937. tyf = 0;
  1938. }
  1939. drawFlatDreieckTexturAlpha( a.y, b.y, m2, b2, m1, b1, ta.x, ta.y, ta.x, ta.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1940. if( c.y - b.y )
  1941. {
  1942. tx2o = (double)( tc.x - tb.x ) / ( c.y - b.y );
  1943. ty2o = (double)( tc.y - tb.y ) / ( c.y - b.y );
  1944. }
  1945. else
  1946. {
  1947. tx2o = 0;
  1948. ty2o = 0;
  1949. }
  1950. drawFlatDreieckTexturAlpha( b.y, c.y, m2, b2, m3, b3, q.x, q.y, tb.x, tb.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1951. }
  1952. else
  1953. {
  1954. double tx1o, ty1o, tx2o, ty2o;
  1955. if( b.y - a.y )
  1956. {
  1957. tx1o = (double)( tb.x - ta.x ) / ( b.y - a.y );
  1958. ty1o = (double)( tb.y - ta.y ) / ( b.y - a.y );
  1959. }
  1960. else
  1961. {
  1962. tx1o = 0;
  1963. ty1o = 0;
  1964. }
  1965. if( c.y - a.y )
  1966. {
  1967. tx2o = (double)( tc.x - ta.x ) / ( c.y - a.y );
  1968. ty2o = (double)( tc.y - ta.y ) / ( c.y - a.y );
  1969. }
  1970. else
  1971. {
  1972. tx2o = 0;
  1973. ty2o = 0;
  1974. }
  1975. Vec2< double > q( ta.x + tx2o * ( b.y - a.y ), ta.y + ty2o * ( b.y - a.y ) );
  1976. double txf, tyf;
  1977. if( qx - b.x )
  1978. {
  1979. txf = ( q.x - tb.x ) / ( qx - b.x );
  1980. tyf = ( q.y - tb.y ) / ( qx - b.x );
  1981. }
  1982. else
  1983. {
  1984. txf = 0;
  1985. tyf = 0;
  1986. }
  1987. drawFlatDreieckTexturAlpha( a.y, b.y, m1, b1, m2, b2, ta.x, ta.y, ta.x, ta.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1988. if( c.y - b.y )
  1989. {
  1990. tx1o = (double)( tc.x - tb.x ) / ( c.y - b.y );
  1991. ty1o = (double)( tc.y - tb.y ) / ( c.y - b.y );
  1992. }
  1993. else
  1994. {
  1995. tx1o = 0;
  1996. ty1o = 0;
  1997. }
  1998. drawFlatDreieckTexturAlpha( b.y, c.y, m3, b3, m2, b2, tb.x, tb.y, q.x, q.y, tx1o, ty1o, tx2o, ty2o, txf, tyf, textur );
  1999. }
  2000. rend = 1;
  2001. }
  2002. void Bild::replaceColorWithAlpha( int color )
  2003. {
  2004. int r = ( color & 0xFF0000 ) >> 16;
  2005. int g = ( color & 0xFF00 ) >> 8;
  2006. int b = color & 0xFF;
  2007. int dx = drawOff[ doa ].x, dy = drawOff[ doa ].y;
  2008. int xx = dPosA[ doa ].x, yy = dPosA[ doa ].y;
  2009. int bb = dSizeA[ doa ].x, hh = dSizeA[ doa ].y;
  2010. for( int y = dy + yy; y < hh; y++ )
  2011. {
  2012. int ygr = y * size.x;
  2013. for( int x = dx + xx; x < bb; x++ )
  2014. {
  2015. unsigned char *cf = ( unsigned char* )&( fc[ x + ygr ] );
  2016. int abstand = (int)sqrt( (float)(( r - cf[ 2 ] ) * ( r - cf[ 2 ] ) + ( g - cf[ 1 ] ) * ( g - cf[ 1 ] ) + ( b - cf[ 0 ] ) * ( b - cf[ 0 ] )) );
  2017. if( abstand > 255 )
  2018. abstand = 255;
  2019. cf[ 3 ] = (unsigned char)( abstand );
  2020. }
  2021. }
  2022. }
  2023. bool Bild::setDrawOptions( const Punkt &pos, const Punkt &gr ) // setzt die Drawoptionen
  2024. {
  2025. int dx = drawOff[ doa ].x, dy = drawOff[ doa ].y;
  2026. int xx = dPosA[ doa ].x, yy = dPosA[ doa ].y;
  2027. int bb = dSizeA[ doa ].x, hh = dSizeA[ doa ].y;
  2028. if( dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x || dy + pos.y >= size.y )
  2029. return 0;
  2030. if( pos.x + gr.x + dx < xx || pos.y + gr.y + dy < yy || dx + pos.x >= bb || dy + pos.y >= hh )
  2031. return 0;
  2032. ++doa;
  2033. assert( doa < 2000 );
  2034. dPosA[ doa ].x = maxInt( pos.x + dx, xx );
  2035. dPosA[ doa ].y = maxInt( pos.y + dy, yy );
  2036. dSizeA[ doa ].x = minInt( pos.x + gr.x + dx, bb );
  2037. dSizeA[ doa ].y = minInt( pos.y + gr.y + dy, hh );
  2038. drawOff[ doa ].x = dx + pos.x;
  2039. drawOff[ doa ].y = dy + pos.y;
  2040. return 1;
  2041. }
  2042. bool Bild::setDrawOptions( int x, int y, int br, int hi )
  2043. {
  2044. int dx = drawOff[ doa ].x, dy = drawOff[ doa ].y;
  2045. int xx = dPosA[ doa ].x, yy = dPosA[ doa ].y;
  2046. int bb = dSizeA[ doa ].x, hh = dSizeA[ doa ].y;
  2047. if( dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x || dy + y >= size.y )
  2048. return 0;
  2049. if( x + br + dx < xx || y + hi + dy < yy || dx + x >= bb || dy + y >= hh )
  2050. return 0;
  2051. ++doa;
  2052. assert( doa < 2000 );
  2053. dPosA[ doa ].x = maxInt( x + dx, xx );
  2054. dPosA[ doa ].y = maxInt( y + dy, yy );
  2055. dSizeA[ doa ].x = minInt( x + br + dx, bb );
  2056. dSizeA[ doa ].y = minInt( y + hi + dy, hh );
  2057. drawOff[ doa ].x = dx + x;
  2058. drawOff[ doa ].y = dy + y;
  2059. return 1;
  2060. }
  2061. bool Bild::setDrawOptionsErzwingen( const Punkt &pos, const Punkt &gr ) // setzt die Drawoptionen
  2062. {
  2063. int dx = drawOff[ doa ].x, dy = drawOff[ doa ].y;
  2064. if( dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x || dy + pos.y >= size.y )
  2065. return 0;
  2066. ++doa;
  2067. assert( doa < 2000 );
  2068. dPosA[ doa ].x = maxInt( pos.x + dx, 0 );
  2069. dPosA[ doa ].y = maxInt( pos.y + dy, 0 );
  2070. dSizeA[ doa ].x = minInt( pos.x + gr.x + dx, size.x );
  2071. dSizeA[ doa ].y = minInt( pos.y + gr.y + dy, size.y );
  2072. drawOff[ doa ].x = dx + pos.x;
  2073. drawOff[ doa ].y = dy + pos.y;
  2074. return 1;
  2075. }
  2076. bool Bild::setDrawOptionsErzwingen( int x, int y, int br, int hi ) // setzt die Drawoptionen
  2077. {
  2078. int dx = drawOff[ doa ].x, dy = drawOff[ doa ].y;
  2079. if( dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x || dy + y >= size.y )
  2080. return 0;
  2081. ++doa;
  2082. assert( doa < 2000 );
  2083. dPosA[ doa ].x = maxInt( x + dx, 0 );
  2084. dPosA[ doa ].y = maxInt( y + dy, 0 );
  2085. dSizeA[ doa ].x = minInt( x + br + dx, size.x );
  2086. dSizeA[ doa ].y = minInt( y + hi + dy, size.y );
  2087. drawOff[ doa ].x = dx + x;
  2088. drawOff[ doa ].y = dy + y;
  2089. return 1;
  2090. }
  2091. void Bild::addScrollOffset( int xOff, int yOff ) // setzt ScrollOffset
  2092. {
  2093. drawOff[ doa ].x -= xOff;
  2094. drawOff[ doa ].y -= yOff;
  2095. }
  2096. void Bild::releaseDrawOptions() // setzt die Drawoptionen zurück
  2097. {
  2098. --doa;
  2099. }
  2100. bool Bild::getRend()
  2101. {
  2102. bool ret = rend;
  2103. rend = 0;
  2104. return ret;
  2105. }
  2106. // constant
  2107. int *Bild::getBuffer()const // gibt buffer zurück
  2108. {
  2109. return fc;
  2110. }
  2111. int Bild::getPixel( int x, int y ) const
  2112. {
  2113. if( x < 0 || y < 0 || x >= size.x || y >= size.y )
  2114. return 0;
  2115. return fc[ x + y * size.x ];
  2116. }
  2117. const Punkt &Bild::getSize() const // gibt die Größe zurück
  2118. {
  2119. return size;
  2120. }
  2121. int Bild::getBreite() const // gibt die Breite zurück
  2122. {
  2123. return size.x;
  2124. }
  2125. int Bild::getHeight() const // gibt die Höhe zurück
  2126. {
  2127. return size.y;
  2128. }
  2129. unsigned char Bild::getAlpha() const // gibt den Alpha wert zurück
  2130. {
  2131. return (unsigned char)( 255 - alpha[ alphaAnzahl ] );
  2132. }
  2133. const Punkt &Bild::getDrawPos() const
  2134. {
  2135. return dPosA[ doa ];
  2136. }
  2137. const Punkt &Bild::getDrawGr() const
  2138. {
  2139. return dSizeA[ doa ];
  2140. }
  2141. const Punkt &Bild::getDrawOff() const
  2142. {
  2143. return drawOff[ doa ];
  2144. }
  2145. // Reference Counting
  2146. Bild *Bild::getThis()
  2147. {
  2148. ++ref;
  2149. return this;
  2150. }
  2151. Bild *Bild::release()
  2152. {
  2153. --ref;
  2154. if( ref < 1 )
  2155. delete this;
  2156. return 0;
  2157. }
  2158. // Inhalt der BildZ Klasse aus Bild.h
  2159. // Konstruktor
  2160. BildZ::BildZ()
  2161. : ZeichnungHintergrund(),
  2162. bild( 0 )
  2163. {
  2164. style = 0;
  2165. mak = _ret1ME;
  2166. }
  2167. // Destruktor
  2168. BildZ::~BildZ()
  2169. {
  2170. if( bild )
  2171. bild->release();
  2172. }
  2173. // nicht constant
  2174. void BildZ::setBildZ( Bild *b ) // setzt das Bild
  2175. {
  2176. if( bild )
  2177. bild->release();
  2178. bild = b;
  2179. if( !vertikalScrollBar )
  2180. vertikalScrollBar = new VScrollBar();
  2181. if( !horizontalScrollBar )
  2182. horizontalScrollBar = new HScrollBar();
  2183. if( b )
  2184. {
  2185. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2186. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2187. }
  2188. rend = 1;
  2189. }
  2190. void BildZ::setBild( Bild *b )
  2191. {
  2192. if( !bild )
  2193. bild = new Bild();
  2194. bild->neuBild( b->getBreite(), b->getHeight(), 0 );
  2195. bild->drawBild( 0, 0, b->getBreite(), b->getHeight(), *b );
  2196. if( !vertikalScrollBar )
  2197. vertikalScrollBar = new VScrollBar();
  2198. if( !horizontalScrollBar )
  2199. horizontalScrollBar = new HScrollBar();
  2200. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2201. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2202. b->release();
  2203. rend = 1;
  2204. }
  2205. bool BildZ::tick( double tickVal ) // tick
  2206. {
  2207. return ZeichnungHintergrund::tick( tickVal );
  2208. }
  2209. void BildZ::doMausEreignis( MausEreignis &me ) // ruft Mak auf
  2210. {
  2211. if( me.verarbeitet || !( me.mx >= pos.x && me.mx <= pos.x + gr.x && me.my >= pos.y && me.my <= pos.y + gr.y ) )
  2212. {
  2213. if( mausIn )
  2214. {
  2215. mausIn = 0;
  2216. MausEreignis me2;
  2217. me2.id = ME_Leaves;
  2218. me2.mx = me.mx;
  2219. me2.my = me.my;
  2220. me2.verarbeitet = 0;
  2221. doMausEreignis( me2 );
  2222. return;
  2223. }
  2224. }
  2225. if( !( me.mx >= pos.x && me.mx <= pos.x + gr.x && me.my >= pos.y && me.my <= pos.y + gr.y ) && me.id != ME_Leaves )
  2226. {
  2227. return;
  2228. }
  2229. if( !mausIn && me.id != ME_Leaves )
  2230. {
  2231. mausIn = 1;
  2232. MausEreignis me2;
  2233. me2.id = ME_Betritt;
  2234. me2.mx = me.mx;
  2235. me2.my = me.my;
  2236. me2.verarbeitet = 0;
  2237. doMausEreignis( me2 );
  2238. }
  2239. me.mx -= pos.x;
  2240. me.my -= pos.y;
  2241. if( hatStyle( Style::Sichtbar ) )
  2242. {
  2243. if( mak && ( me.verarbeitet || mak( makParam, this, me ) ) )
  2244. {
  2245. if( me.id != ME_Betritt && me.id != ME_Leaves )
  2246. {
  2247. lockZeichnung();
  2248. int rbr = 0;
  2249. if( hatStyle( Style::Rahmen ) && rahmen )
  2250. rbr = rahmen->getRBreite();
  2251. bool vs = hatStyle( Style::VScroll ) && vertikalScrollBar;
  2252. bool hs = hatStyle( Style::HScroll ) && horizontalScrollBar;
  2253. if( vs )
  2254. {
  2255. if( hs )
  2256. horizontalScrollBar->doMausMessage( rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, me );
  2257. vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me );
  2258. }
  2259. else if( hs )
  2260. horizontalScrollBar->doMausMessage( rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, me );
  2261. unlockZeichnung();
  2262. if( vs || hs )
  2263. me.verarbeitet = 1;
  2264. }
  2265. }
  2266. }
  2267. me.mx += pos.x;
  2268. me.my += pos.y;
  2269. }
  2270. void BildZ::render( Bild &zRObj ) // zeichnet nach zRObj
  2271. {
  2272. if( hatStyle( Style::Sichtbar ) )
  2273. {
  2274. ZeichnungHintergrund::render( zRObj );
  2275. lockZeichnung();
  2276. if( !zRObj.setDrawOptions( innenPosition, innenSize ) )
  2277. {
  2278. unlockZeichnung();
  2279. return;
  2280. }
  2281. if( bild )
  2282. {
  2283. int x = 0;
  2284. int y = 0;
  2285. int br = innenSize.x;
  2286. int hi = innenSize.y;
  2287. if( !( vertikalScrollBar && hatStyle( Style::VScroll ) ) && !( horizontalScrollBar && hatStyle( Style::HScroll ) ) )
  2288. {
  2289. if( hatStyle( Style::Alpha ) )
  2290. zRObj.alphaBild( x, y, br, hi, *bild );
  2291. else
  2292. zRObj.drawBild( x, y, br, hi, *bild );
  2293. }
  2294. else
  2295. {
  2296. if( !zRObj.setDrawOptions( x, y, br, hi ) )
  2297. {
  2298. zRObj.releaseDrawOptions();
  2299. unlockZeichnung();
  2300. return;
  2301. }
  2302. if( hatStyle( Style::Alpha ) )
  2303. zRObj.alphaBild( -horizontalScrollBar->getScroll(), -vertikalScrollBar->getScroll(), bild->getBreite(), bild->getHeight(), *bild );
  2304. else
  2305. zRObj.drawBild( -horizontalScrollBar->getScroll(), -vertikalScrollBar->getScroll(), bild->getBreite(), bild->getHeight(), *bild );
  2306. zRObj.releaseDrawOptions();
  2307. }
  2308. }
  2309. zRObj.releaseDrawOptions();
  2310. unlockZeichnung();
  2311. }
  2312. }
  2313. // constant
  2314. Bild *BildZ::getBild() const // gibt das Bild zurück
  2315. {
  2316. if( bild )
  2317. return bild->getThis();
  2318. return 0;
  2319. }
  2320. Bild *BildZ::zBild() const
  2321. {
  2322. return bild;
  2323. }
  2324. Zeichnung *BildZ::dublizieren() const // erstellt eine Kopie des Zeichnungs
  2325. {
  2326. BildZ *obj = new BildZ();
  2327. obj->setPosition( pos );
  2328. obj->setSize( gr );
  2329. obj->setMausEreignisParameter( makParam );
  2330. obj->setTastaturEreignisParameter( takParam );
  2331. obj->setMausEreignis( mak );
  2332. obj->setTastaturEreignis( tak );
  2333. if( toolTip )
  2334. obj->setToolTipText( toolTip->zText()->getText(), toolTip->zBildschirm() );
  2335. obj->setStyle( style );
  2336. obj->setHintergrundFarbe( hintergrundFarbe );
  2337. if( hintergrundFeld )
  2338. obj->setAlphaFeldZ( (AlphaFeld*)hintergrundFeld->dublizieren() );
  2339. if( rahmen )
  2340. obj->setRahmenZ( (Rahmen*)rahmen->dublizieren() );
  2341. if( hintergrundBild )
  2342. obj->setHintergrundBild( hintergrundBild->getThis() );
  2343. if( bild )
  2344. obj->setBild( bild->getThis() );
  2345. obj->setStyle( style );
  2346. return obj;
  2347. }
  2348. #ifdef WIN32
  2349. Bild *Framework::ladeBild( char *pfad, Text *zError )
  2350. {
  2351. Text p = pfad;
  2352. Text *txt = p.getTeilText( p.positionVon( '.', p.anzahlVon( '.' ) - 1 ) );
  2353. if( !( txt->istGleich( ".bmp" ) || txt->istGleich( ".jpg" ) || txt->istGleich( ".gif" ) || txt->istGleich( ".png" ) ) )
  2354. {
  2355. zError->setText( "Die Angegebene Datei ist keine gueltige Bilddatei!" );
  2356. txt->release();
  2357. return 0;
  2358. }
  2359. txt->release();
  2360. wchar_t *name = new wchar_t[ p.getLength() + 1 ];
  2361. for( int i = 0; i < p.getLength(); i++ )
  2362. name[ i ] = (wchar_t)p.getText()[ i ];
  2363. name[ p.getLength() ] = '\0';
  2364. Gdiplus::Bitmap bitmap( name );
  2365. Gdiplus::Color pix;
  2366. delete[]name;
  2367. Bild *ret = new Bild();
  2368. ret->neuBild( bitmap.GetWidth(), bitmap.GetHeight(), 0 );
  2369. int *buff = ret->getBuffer();
  2370. for( unsigned int i = 0; i < bitmap.GetWidth() * bitmap.GetHeight(); i++ )
  2371. {
  2372. bitmap.GetPixel( i % bitmap.GetWidth(), i / bitmap.GetWidth(), &pix );
  2373. buff[ i ] = pix.GetValue();
  2374. }
  2375. return ret;
  2376. }
  2377. #endif