Bild.cpp 77 KB

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