Bild.cpp 58 KB

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