Bild.cpp 70 KB

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