Bild.cpp 89 KB

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