Bild.cpp 68 KB

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