Bild.cpp 86 KB

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