Bild.cpp 87 KB

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