Bild.cpp 89 KB

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