Bild.cpp 88 KB

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