Bild.cpp 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148
  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. if (alpha3D)
  1290. {
  1291. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1292. && count < maxP)
  1293. {
  1294. ++count;
  1295. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1296. alphaPixelP3D(pixel, fc);
  1297. x += xf, y += yf;
  1298. }
  1299. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1300. alphaPixelP3D(pixel, fc);
  1301. }
  1302. else
  1303. {
  1304. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1305. && count < maxP)
  1306. {
  1307. ++count;
  1308. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1309. alphaPixelP(pixel, fc);
  1310. x += xf, y += yf;
  1311. }
  1312. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1313. alphaPixelP(pixel, fc);
  1314. }
  1315. rend = 1;
  1316. }
  1317. }
  1318. void Bild::fillCircle(int xOff,
  1319. int yOff,
  1320. int r,
  1321. int fc) // zeichnet einen Kreis um Punkt( xOff, yOff ) mit radius r
  1322. {
  1323. if (alpha[alphaAnzahl] == 0xFF) return;
  1324. for (int i = r; i > 0; i--)
  1325. drawKreis(xOff, yOff, i, fc);
  1326. }
  1327. void Bild::drawKreis(int xOff,
  1328. int yOff,
  1329. int r,
  1330. int fc) // zeichnet einen Kreis um Punkt( xOff, yOff ) mit radius r
  1331. {
  1332. if (alpha[alphaAnzahl] == 0xFF) return;
  1333. if (alpha[alphaAnzahl])
  1334. {
  1335. drawKreisAlpha(xOff, yOff, r, fc);
  1336. return;
  1337. }
  1338. int dpx = dPosA[doa].x;
  1339. int dpy = dPosA[doa].y;
  1340. int dgx = dSizeA[doa].x;
  1341. int dgy = dSizeA[doa].y;
  1342. xOff += drawOff[doa].x;
  1343. yOff += drawOff[doa].y;
  1344. if (xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy)
  1345. return;
  1346. for (int a = 0; a < r; ++a)
  1347. {
  1348. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1349. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1350. && yOff + b > dpy)
  1351. this->fc[xOff + a + (yOff + b) * size.x] = fc;
  1352. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1353. && yOff + b > dpy)
  1354. this->fc[xOff - a + (yOff + b) * size.x] = fc;
  1355. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1356. && yOff - b > dpy)
  1357. this->fc[xOff + a + (yOff - b) * size.x] = fc;
  1358. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1359. && yOff - b > dpy)
  1360. this->fc[xOff - a + (yOff - b) * size.x] = fc;
  1361. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1362. && yOff + a > dpy)
  1363. this->fc[xOff + b + (yOff + a) * size.x] = fc;
  1364. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1365. && yOff + a > dpy)
  1366. this->fc[xOff - b + (yOff + a) * size.x] = fc;
  1367. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1368. && yOff - a > dpy)
  1369. this->fc[xOff + b + (yOff - a) * size.x] = fc;
  1370. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1371. && yOff - a > dpy)
  1372. this->fc[xOff - b + (yOff - a) * size.x] = fc;
  1373. }
  1374. rend = 1;
  1375. }
  1376. void Bild::drawKreisAlpha(int xOff, int yOff, int r, int fc)
  1377. {
  1378. if (alpha[alphaAnzahl] == 0xFF) return;
  1379. int dpx = dPosA[doa].x;
  1380. int dpy = dPosA[doa].y;
  1381. int dgx = dSizeA[doa].x;
  1382. int dgy = dSizeA[doa].y;
  1383. xOff += drawOff[doa].x;
  1384. yOff += drawOff[doa].y;
  1385. if (xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy)
  1386. return;
  1387. if (alpha[alphaAnzahl] < 0xFF)
  1388. {
  1389. unsigned char* cf = (unsigned char*)&fc;
  1390. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1391. * (cf[3] - alpha[alphaAnzahl]));
  1392. }
  1393. if (alpha3D)
  1394. {
  1395. for (int a = 0; a < r; ++a)
  1396. {
  1397. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1398. int* pixel = 0;
  1399. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1400. && yOff + b > dpy)
  1401. {
  1402. pixel = &this->fc[xOff + a + (yOff + b) * size.x];
  1403. alphaPixelP3D(*pixel, fc);
  1404. }
  1405. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1406. && yOff + b > dpy)
  1407. {
  1408. pixel = &this->fc[xOff - a + (yOff + b) * size.x];
  1409. alphaPixelP3D(*pixel, fc);
  1410. }
  1411. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1412. && yOff - b > dpy)
  1413. {
  1414. pixel = &this->fc[xOff + a + (yOff - b) * size.x];
  1415. alphaPixelP3D(*pixel, fc);
  1416. }
  1417. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1418. && yOff - b > dpy)
  1419. {
  1420. pixel = &this->fc[xOff - a + (yOff - b) * size.x];
  1421. alphaPixelP3D(*pixel, fc);
  1422. }
  1423. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1424. && yOff + a > dpy)
  1425. {
  1426. pixel = &this->fc[xOff + b + (yOff + a) * size.x];
  1427. alphaPixelP3D(*pixel, fc);
  1428. }
  1429. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1430. && yOff + a > dpy)
  1431. {
  1432. pixel = &this->fc[xOff - b + (yOff + a) * size.x];
  1433. alphaPixelP3D(*pixel, fc);
  1434. }
  1435. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1436. && yOff - a > dpy)
  1437. {
  1438. pixel = &this->fc[xOff + b + (yOff - a) * size.x];
  1439. alphaPixelP3D(*pixel, fc);
  1440. }
  1441. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1442. && yOff - a > dpy)
  1443. {
  1444. pixel = &this->fc[xOff - b + (yOff - a) * size.x];
  1445. alphaPixelP3D(*pixel, fc);
  1446. }
  1447. }
  1448. }
  1449. else
  1450. {
  1451. for (int a = 0; a < r; ++a)
  1452. {
  1453. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1454. int* pixel = 0;
  1455. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1456. && yOff + b > dpy)
  1457. {
  1458. pixel = &this->fc[xOff + a + (yOff + b) * size.x];
  1459. alphaPixelP(*pixel, fc);
  1460. }
  1461. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1462. && yOff + b > dpy)
  1463. {
  1464. pixel = &this->fc[xOff - a + (yOff + b) * size.x];
  1465. alphaPixelP(*pixel, fc);
  1466. }
  1467. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1468. && yOff - b > dpy)
  1469. {
  1470. pixel = &this->fc[xOff + a + (yOff - b) * size.x];
  1471. alphaPixelP(*pixel, fc);
  1472. }
  1473. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1474. && yOff - b > dpy)
  1475. {
  1476. pixel = &this->fc[xOff - a + (yOff - b) * size.x];
  1477. alphaPixelP(*pixel, fc);
  1478. }
  1479. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1480. && yOff + a > dpy)
  1481. {
  1482. pixel = &this->fc[xOff + b + (yOff + a) * size.x];
  1483. alphaPixelP(*pixel, fc);
  1484. }
  1485. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1486. && yOff + a > dpy)
  1487. {
  1488. pixel = &this->fc[xOff - b + (yOff + a) * size.x];
  1489. alphaPixelP(*pixel, fc);
  1490. }
  1491. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1492. && yOff - a > dpy)
  1493. {
  1494. pixel = &this->fc[xOff + b + (yOff - a) * size.x];
  1495. alphaPixelP(*pixel, fc);
  1496. }
  1497. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1498. && yOff - a > dpy)
  1499. {
  1500. pixel = &this->fc[xOff - b + (yOff - a) * size.x];
  1501. alphaPixelP(*pixel, fc);
  1502. }
  1503. }
  1504. }
  1505. rend = 1;
  1506. }
  1507. void Bild::drawBild(
  1508. int x, int y, int br, int hi, const Bild& zBild) // zeichet zBild
  1509. {
  1510. if (alpha[alphaAnzahl] == 0xFF) return;
  1511. if (alpha[alphaAnzahl])
  1512. {
  1513. alphaBild(x, y, br, hi, zBild);
  1514. return;
  1515. }
  1516. int dpx = dPosA[doa].x;
  1517. int dpy = dPosA[doa].y;
  1518. int dgx = dSizeA[doa].x;
  1519. int dgy = dSizeA[doa].y;
  1520. x += drawOff[doa].x;
  1521. y += drawOff[doa].y;
  1522. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1523. br = minInt(br, zBild.getBreite());
  1524. hi = minInt(hi, zBild.getHeight());
  1525. int xst = maxInt(dpx - x, 0);
  1526. int yst = maxInt(dpy - y, 0);
  1527. int xst2 = maxInt(x, dpx);
  1528. int yst2 = maxInt(y, dpy);
  1529. dgx = minInt(x + br, dgx);
  1530. dgy = minInt(y + hi, dgy);
  1531. int bb = zBild.getBreite();
  1532. int* ff = zBild.getBuffer();
  1533. int xx, ygr, ygr2;
  1534. for (int yy = yst2; yy < dgy; ++yy)
  1535. {
  1536. ygr = yy * size.x;
  1537. ygr2 = (yy - yst2 + yst) * bb;
  1538. for (xx = xst2; xx < dgx; ++xx)
  1539. fc[xx + ygr] = ff[(xx - xst2 + xst) + ygr2];
  1540. }
  1541. rend = 1;
  1542. }
  1543. void Bild::alphaBildAssoz(int x, int y, int br, int hi, const Bild& zBild)
  1544. {
  1545. if (alpha[alphaAnzahl] == 0xFF) return;
  1546. int dpx = dPosA[doa].x;
  1547. int dpy = dPosA[doa].y;
  1548. int dgx = dSizeA[doa].x;
  1549. int dgy = dSizeA[doa].y;
  1550. x += drawOff[doa].x;
  1551. y += drawOff[doa].y;
  1552. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1553. br = minInt(br, zBild.getBreite());
  1554. hi = minInt(hi, zBild.getHeight());
  1555. int xst = maxInt(dpx - x, 0);
  1556. int yst = maxInt(dpy - y, 0);
  1557. int xst2 = maxInt(x, dpx);
  1558. int yst2 = maxInt(y, dpy);
  1559. dgx = minInt(x + br, dgx);
  1560. dgy = minInt(y + hi, dgy);
  1561. int bb = zBild.getBreite();
  1562. int* ff = zBild.getBuffer();
  1563. if (!alpha[alphaAnzahl])
  1564. {
  1565. int xx, ygr, ygr2;
  1566. for (int yy = yst2; yy < dgy; ++yy)
  1567. {
  1568. ygr = yy * size.x;
  1569. ygr2 = (yy - yst2 + yst) * bb;
  1570. for (xx = xst2; xx < dgx; ++xx)
  1571. alphaPixelAssozP(fc[xx + ygr], ff[(xx - xst2 + xst) + ygr2]);
  1572. }
  1573. }
  1574. else
  1575. {
  1576. int xx, ygr, ygr2;
  1577. for (int yy = yst2; yy < dgy; ++yy)
  1578. {
  1579. ygr = yy * size.x;
  1580. ygr2 = (yy - yst2 + yst) * bb;
  1581. for (xx = xst2; xx < dgx; ++xx)
  1582. {
  1583. int fc = ff[(xx - xst2 + xst) + ygr2];
  1584. unsigned char* cf = (unsigned char*)&fc;
  1585. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1586. * (cf[3] - alpha[alphaAnzahl]));
  1587. alphaPixelAssozP(this->fc[xx + ygr], fc);
  1588. }
  1589. }
  1590. }
  1591. rend = 1;
  1592. }
  1593. void Bild::alphaBild(int x, int y, int br, int hi, const Bild& zBild)
  1594. {
  1595. if (alpha[alphaAnzahl] == 0xFF) return;
  1596. int dpx = dPosA[doa].x;
  1597. int dpy = dPosA[doa].y;
  1598. int dgx = dSizeA[doa].x;
  1599. int dgy = dSizeA[doa].y;
  1600. x += drawOff[doa].x;
  1601. y += drawOff[doa].y;
  1602. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1603. br = minInt(br, zBild.getBreite());
  1604. hi = minInt(hi, zBild.getHeight());
  1605. int xst = maxInt(dpx - x, 0);
  1606. int yst = maxInt(dpy - y, 0);
  1607. int xst2 = maxInt(x, dpx);
  1608. int yst2 = maxInt(y, dpy);
  1609. dgx = minInt(x + br, dgx);
  1610. dgy = minInt(y + hi, dgy);
  1611. int bb = zBild.getBreite();
  1612. int* ff = zBild.getBuffer();
  1613. if (!alpha[alphaAnzahl])
  1614. {
  1615. int xx, ygr, ygr2;
  1616. if (alpha3D)
  1617. {
  1618. for (int yy = yst2; yy < dgy; ++yy)
  1619. {
  1620. ygr = yy * size.x;
  1621. ygr2 = (yy - yst2 + yst) * bb;
  1622. int fci = xst2 + ygr;
  1623. int ffi = xst + ygr2;
  1624. for (xx = xst2; xx < dgx; ++xx, ++fci, ++ffi)
  1625. alphaPixelP3D(fc[fci], ff[ffi]);
  1626. }
  1627. }
  1628. else
  1629. {
  1630. for (int yy = yst2; yy < dgy; ++yy)
  1631. {
  1632. ygr = yy * size.x;
  1633. ygr2 = (yy - yst2 + yst) * bb;
  1634. int fci = xst2 + ygr;
  1635. int ffi = xst + ygr2;
  1636. for (xx = xst2; xx < dgx; ++xx, ++fci, ++ffi)
  1637. alphaPixelP(fc[fci], ff[ffi]);
  1638. }
  1639. }
  1640. }
  1641. else
  1642. {
  1643. int xx, ygr, ygr2;
  1644. if (alpha3D)
  1645. {
  1646. for (int yy = yst2; yy < dgy; ++yy)
  1647. {
  1648. ygr = yy * size.x;
  1649. ygr2 = (yy - yst2 + yst) * bb;
  1650. for (xx = xst2; xx < dgx; ++xx)
  1651. {
  1652. int fc = ff[(xx - xst2 + xst) + ygr2];
  1653. unsigned char* cf = (unsigned char*)&fc;
  1654. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1655. * (cf[3] - alpha[alphaAnzahl]));
  1656. alphaPixelP3D(this->fc[xx + ygr], fc);
  1657. }
  1658. }
  1659. }
  1660. else
  1661. {
  1662. for (int yy = yst2; yy < dgy; ++yy)
  1663. {
  1664. ygr = yy * size.x;
  1665. ygr2 = (yy - yst2 + yst) * bb;
  1666. for (xx = xst2; xx < dgx; ++xx)
  1667. {
  1668. int fc = ff[(xx - xst2 + xst) + ygr2];
  1669. unsigned char* cf = (unsigned char*)&fc;
  1670. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1671. * (cf[3] - alpha[alphaAnzahl]));
  1672. alphaPixelP(this->fc[xx + ygr], fc);
  1673. }
  1674. }
  1675. }
  1676. }
  1677. rend = 1;
  1678. }
  1679. void Bild::drawBild90(int x,
  1680. int y,
  1681. int br,
  1682. int hi,
  1683. const Bild& zBild) // Zeichnet ein um 90 Grad nach rchts gedrehtes Bild
  1684. {
  1685. if (alpha[alphaAnzahl] == 0xFF) return;
  1686. if (alpha[alphaAnzahl])
  1687. {
  1688. alphaBild90(x, y, br, hi, zBild);
  1689. return;
  1690. }
  1691. int dpx = dPosA[doa].x;
  1692. int dpy = dPosA[doa].y;
  1693. int dgx = dSizeA[doa].x;
  1694. int dgy = dSizeA[doa].y;
  1695. x += drawOff[doa].x;
  1696. y += drawOff[doa].y;
  1697. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1698. br = minInt(br, zBild.getHeight());
  1699. hi = minInt(hi, zBild.getBreite());
  1700. int xst = maxInt(dpx - x, 0);
  1701. int yst = maxInt(dpy - y, 0);
  1702. int xst2 = maxInt(x, dpx);
  1703. int yst2 = maxInt(y, dpy);
  1704. dgx = minInt(x + br, dgx);
  1705. dgy = minInt(y + hi, dgy);
  1706. int bb = zBild.getBreite();
  1707. int* ff = zBild.getBuffer();
  1708. int yy, xbb;
  1709. for (int xx = xst2; xx < dgx; ++xx)
  1710. {
  1711. xbb = (zBild.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1712. for (yy = yst2; yy < dgy; ++yy)
  1713. fc[xx + yy * size.x] = ff[(yy - yst2 + yst) + xbb];
  1714. }
  1715. rend = 1;
  1716. }
  1717. void Bild::alphaBild90(int x, int y, int br, int hi, const Bild& zBild)
  1718. {
  1719. if (alpha[alphaAnzahl] == 0xFF) return;
  1720. int dpx = dPosA[doa].x;
  1721. int dpy = dPosA[doa].y;
  1722. int dgx = dSizeA[doa].x;
  1723. int dgy = dSizeA[doa].y;
  1724. x += drawOff[doa].x;
  1725. y += drawOff[doa].y;
  1726. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1727. br = minInt(br, zBild.getHeight());
  1728. hi = minInt(hi, zBild.getBreite());
  1729. int xst = maxInt(dpx - x, 0);
  1730. int yst = maxInt(dpy - y, 0);
  1731. int xst2 = maxInt(x, dpx);
  1732. int yst2 = maxInt(y, dpy);
  1733. dgx = minInt(x + br, dgx);
  1734. dgy = minInt(y + hi, dgy);
  1735. int bb = zBild.getBreite();
  1736. int* ff = zBild.getBuffer();
  1737. if (!alpha[alphaAnzahl])
  1738. {
  1739. int yy, xbb;
  1740. if (alpha3D)
  1741. {
  1742. for (int xx = xst2; xx < dgx; ++xx)
  1743. {
  1744. xbb = (zBild.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1745. for (yy = yst2; yy < dgy; ++yy)
  1746. alphaPixelP3D(xx, yy, ff[(yy - yst2 + yst) + xbb]);
  1747. }
  1748. }
  1749. else
  1750. {
  1751. for (int xx = xst2; xx < dgx; ++xx)
  1752. {
  1753. xbb = (zBild.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1754. for (yy = yst2; yy < dgy; ++yy)
  1755. alphaPixelP(xx, yy, ff[(yy - yst2 + yst) + xbb]);
  1756. }
  1757. }
  1758. }
  1759. else
  1760. {
  1761. int yy, xbb;
  1762. if (alpha3D)
  1763. {
  1764. for (int xx = xst2; xx < dgx; ++xx)
  1765. {
  1766. xbb = (zBild.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1767. for (yy = yst2; yy < dgy; ++yy)
  1768. {
  1769. int fc = ff[(yy - yst2 + yst) + xbb];
  1770. unsigned char* cf = (unsigned char*)&fc;
  1771. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1772. * (cf[3] - alpha[alphaAnzahl]));
  1773. alphaPixelP3D(xx, yy, fc);
  1774. }
  1775. }
  1776. }
  1777. else
  1778. {
  1779. for (int xx = xst2; xx < dgx; ++xx)
  1780. {
  1781. xbb = (zBild.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1782. for (yy = yst2; yy < dgy; ++yy)
  1783. {
  1784. int fc = ff[(yy - yst2 + yst) + xbb];
  1785. unsigned char* cf = (unsigned char*)&fc;
  1786. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1787. * (cf[3] - alpha[alphaAnzahl]));
  1788. alphaPixelP(xx, yy, fc);
  1789. }
  1790. }
  1791. }
  1792. }
  1793. rend = 1;
  1794. }
  1795. void Bild::drawBild180(int x,
  1796. int y,
  1797. int br,
  1798. int hi,
  1799. const Bild& zBild) // Zeichnet ein um 180 Grad nach rchts gedrehtes Bild
  1800. {
  1801. if (alpha[alphaAnzahl] == 0xFF) return;
  1802. if (alpha[alphaAnzahl])
  1803. {
  1804. alphaBild180(x, y, br, hi, zBild);
  1805. return;
  1806. }
  1807. int dpx = dPosA[doa].x;
  1808. int dpy = dPosA[doa].y;
  1809. int dgx = dSizeA[doa].x;
  1810. int dgy = dSizeA[doa].y;
  1811. x += drawOff[doa].x;
  1812. y += drawOff[doa].y;
  1813. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1814. br = minInt(br, zBild.getBreite());
  1815. hi = minInt(hi, zBild.getHeight());
  1816. int xst = maxInt(dpx - x, 0);
  1817. int yst = maxInt(dpy - y, 0);
  1818. int xst2 = maxInt(x, dpx);
  1819. int yst2 = maxInt(y, dpy);
  1820. dgx = minInt(x + br, dgx);
  1821. dgy = minInt(y + hi, dgy);
  1822. int bb = zBild.getBreite();
  1823. int* ff = zBild.getBuffer();
  1824. int xx, ygr, ybb;
  1825. for (int yy = yst2; yy < dgy; ++yy)
  1826. {
  1827. ygr = yy * size.x;
  1828. ybb = (zBild.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1829. for (xx = xst2; xx < dgx; ++xx)
  1830. fc[xx + ygr] = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1831. }
  1832. rend = 1;
  1833. }
  1834. void Bild::alphaBild180(int x, int y, int br, int hi, const Bild& zBild)
  1835. {
  1836. if (alpha[alphaAnzahl] == 0xFF) return;
  1837. int dpx = dPosA[doa].x;
  1838. int dpy = dPosA[doa].y;
  1839. int dgx = dSizeA[doa].x;
  1840. int dgy = dSizeA[doa].y;
  1841. x += drawOff[doa].x;
  1842. y += drawOff[doa].y;
  1843. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1844. br = minInt(br, zBild.getHeight());
  1845. hi = minInt(hi, zBild.getBreite());
  1846. int xst = maxInt(dpx - x, 0);
  1847. int yst = maxInt(dpy - y, 0);
  1848. int xst2 = maxInt(x, dpx);
  1849. int yst2 = maxInt(y, dpy);
  1850. dgx = minInt(x + br, dgx);
  1851. dgy = minInt(y + hi, dgy);
  1852. int bb = zBild.getBreite();
  1853. int* ff = zBild.getBuffer();
  1854. if (!alpha[alphaAnzahl])
  1855. {
  1856. int xx, ygr, ybb;
  1857. if (alpha3D)
  1858. {
  1859. for (int yy = yst2; yy < dgy; ++yy)
  1860. {
  1861. ygr = yy * size.x;
  1862. ybb = (zBild.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1863. for (xx = xst2; xx < dgx; ++xx)
  1864. alphaPixelP3D(
  1865. fc[xx + ygr], ff[(bb - (xx - xst2 + xst + 1)) + ybb]);
  1866. }
  1867. }
  1868. else
  1869. {
  1870. for (int yy = yst2; yy < dgy; ++yy)
  1871. {
  1872. ygr = yy * size.x;
  1873. ybb = (zBild.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1874. for (xx = xst2; xx < dgx; ++xx)
  1875. alphaPixelP(
  1876. fc[xx + ygr], ff[(bb - (xx - xst2 + xst + 1)) + ybb]);
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. int xx, ygr, ybb;
  1883. if (alpha3D)
  1884. {
  1885. for (int yy = yst2; yy < dgy; ++yy)
  1886. {
  1887. ygr = yy * size.x;
  1888. ybb = (zBild.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1889. for (xx = xst2; xx < dgx; ++xx)
  1890. {
  1891. int fc = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1892. unsigned char* cf = (unsigned char*)&fc;
  1893. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1894. * (cf[3] - alpha[alphaAnzahl]));
  1895. alphaPixelP3D(this->fc[xx + ygr], fc);
  1896. }
  1897. }
  1898. }
  1899. else
  1900. {
  1901. for (int yy = yst2; yy < dgy; ++yy)
  1902. {
  1903. ygr = yy * size.x;
  1904. ybb = (zBild.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1905. for (xx = xst2; xx < dgx; ++xx)
  1906. {
  1907. int fc = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1908. unsigned char* cf = (unsigned char*)&fc;
  1909. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1910. * (cf[3] - alpha[alphaAnzahl]));
  1911. alphaPixelP(this->fc[xx + ygr], fc);
  1912. }
  1913. }
  1914. }
  1915. }
  1916. rend = 1;
  1917. }
  1918. void Bild::drawBild270(int x,
  1919. int y,
  1920. int br,
  1921. int hi,
  1922. const Bild& zBild) // Zeichnet ein um 270 Grad nach rchts gedrehtes Bild
  1923. {
  1924. if (alpha[alphaAnzahl] == 0xFF) return;
  1925. if (alpha[alphaAnzahl])
  1926. {
  1927. alphaBild270(x, y, br, hi, zBild);
  1928. return;
  1929. }
  1930. int dpx = dPosA[doa].x;
  1931. int dpy = dPosA[doa].y;
  1932. int dgx = dSizeA[doa].x;
  1933. int dgy = dSizeA[doa].y;
  1934. x += drawOff[doa].x;
  1935. y += drawOff[doa].y;
  1936. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1937. br = minInt(br, zBild.getHeight());
  1938. hi = minInt(hi, zBild.getBreite());
  1939. int xst = maxInt(dpx - x, 0);
  1940. int yst = maxInt(dpy - y, 0);
  1941. int xst2 = maxInt(x, dpx);
  1942. int yst2 = maxInt(y, dpy);
  1943. dgx = minInt(x + br, dgx);
  1944. dgy = minInt(y + hi, dgy);
  1945. int bb = zBild.getBreite();
  1946. int* ff = zBild.getBuffer();
  1947. int yy, xbb;
  1948. for (int xx = xst2; xx < dgx; ++xx)
  1949. {
  1950. xbb = (xx - xst2 + xst) * bb;
  1951. for (yy = yst2; yy < dgy; ++yy)
  1952. fc[xx + yy * size.x] = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  1953. }
  1954. rend = 1;
  1955. }
  1956. void Bild::alphaBild270(int x, int y, int br, int hi, const Bild& zBild)
  1957. {
  1958. if (alpha[alphaAnzahl] == 0xFF) return;
  1959. int dpx = dPosA[doa].x;
  1960. int dpy = dPosA[doa].y;
  1961. int dgx = dSizeA[doa].x;
  1962. int dgy = dSizeA[doa].y;
  1963. x += drawOff[doa].x;
  1964. y += drawOff[doa].y;
  1965. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1966. br = minInt(br, zBild.getHeight());
  1967. hi = minInt(hi, zBild.getBreite());
  1968. int xst = maxInt(dpx - x, 0);
  1969. int yst = maxInt(dpy - y, 0);
  1970. int xst2 = maxInt(x, dpx);
  1971. int yst2 = maxInt(y, dpy);
  1972. dgx = minInt(x + br, dgx);
  1973. dgy = minInt(y + hi, dgy);
  1974. int bb = zBild.getBreite();
  1975. int* ff = zBild.getBuffer();
  1976. if (!alpha[alphaAnzahl])
  1977. {
  1978. int yy, xbb;
  1979. if (alpha3D)
  1980. {
  1981. for (int xx = xst2; xx < dgx; ++xx)
  1982. {
  1983. xbb = (xx - xst2 + xst) * bb;
  1984. for (yy = yst2; yy < dgy; ++yy)
  1985. alphaPixelP3D(
  1986. xx, yy, ff[(bb - (yy - yst2 + yst + 1)) + xbb]);
  1987. }
  1988. }
  1989. else
  1990. {
  1991. for (int xx = xst2; xx < dgx; ++xx)
  1992. {
  1993. xbb = (xx - xst2 + xst) * bb;
  1994. for (yy = yst2; yy < dgy; ++yy)
  1995. alphaPixelP(xx, yy, ff[(bb - (yy - yst2 + yst + 1)) + xbb]);
  1996. }
  1997. }
  1998. }
  1999. else
  2000. {
  2001. int yy, xbb;
  2002. if (alpha3D)
  2003. {
  2004. for (int xx = xst2; xx < dgx; ++xx)
  2005. {
  2006. xbb = (xx - xst2 + xst) * bb;
  2007. for (yy = yst2; yy < dgy; ++yy)
  2008. {
  2009. int fc = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  2010. unsigned char* cf = (unsigned char*)&fc;
  2011. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2012. * (cf[3] - alpha[alphaAnzahl]));
  2013. alphaPixelP3D(xx, yy, fc);
  2014. }
  2015. }
  2016. }
  2017. else
  2018. {
  2019. for (int xx = xst2; xx < dgx; ++xx)
  2020. {
  2021. xbb = (xx - xst2 + xst) * bb;
  2022. for (yy = yst2; yy < dgy; ++yy)
  2023. {
  2024. int fc = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  2025. unsigned char* cf = (unsigned char*)&fc;
  2026. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2027. * (cf[3] - alpha[alphaAnzahl]));
  2028. alphaPixelP(xx, yy, fc);
  2029. }
  2030. }
  2031. }
  2032. }
  2033. rend = 1;
  2034. }
  2035. void Bild::drawBildSkall(
  2036. int x, int y, int br, int hi, const Bild& zBild) // zeichet zBild Skalliert
  2037. {
  2038. if (alpha[alphaAnzahl] == 0xFF) return;
  2039. if (alpha[alphaAnzahl])
  2040. {
  2041. alphaBildSkall(x, y, br, hi, zBild);
  2042. return;
  2043. }
  2044. int dpx = dPosA[doa].x;
  2045. int dpy = dPosA[doa].y;
  2046. int dgx = dSizeA[doa].x;
  2047. int dgy = dSizeA[doa].y;
  2048. x += drawOff[doa].x;
  2049. y += drawOff[doa].y;
  2050. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  2051. double xo = zBild.getBreite() / (double)br;
  2052. double yo = zBild.getHeight() / (double)hi;
  2053. int xst = maxInt(dpx - x, 0);
  2054. int yst = maxInt(dpy - y, 0);
  2055. int xst2 = maxInt(x, dpx);
  2056. int yst2 = maxInt(y, dpy);
  2057. dgx = minInt(x + br, dgx);
  2058. dgy = minInt(y + hi, dgy);
  2059. int bb = zBild.getBreite();
  2060. int* ff = zBild.getBuffer();
  2061. int xx, ygr, ygr2;
  2062. double xb = 0, yb = yst * yo;
  2063. for (int yy = yst2; yy < dgy; ++yy, yb += yo)
  2064. {
  2065. ygr = yy * size.x;
  2066. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2067. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2068. fc[xx + ygr] = ff[(int)xb + ygr2];
  2069. }
  2070. rend = 1;
  2071. }
  2072. void Bild::alphaBildSkall(int x, int y, int br, int hi, const Bild& zBild)
  2073. {
  2074. if (alpha[alphaAnzahl] == 0xFF) return;
  2075. int dpx = dPosA[doa].x;
  2076. int dpy = dPosA[doa].y;
  2077. int dgx = dSizeA[doa].x;
  2078. int dgy = dSizeA[doa].y;
  2079. x += drawOff[doa].x;
  2080. y += drawOff[doa].y;
  2081. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  2082. double xo = zBild.getBreite() / (double)br;
  2083. double yo = zBild.getHeight() / (double)hi;
  2084. int xst = maxInt(dpx - x, 0);
  2085. int yst = maxInt(dpy - y, 0);
  2086. int xst2 = maxInt(x, dpx);
  2087. int yst2 = maxInt(y, dpy);
  2088. dgx = minInt(x + br, dgx);
  2089. dgy = minInt(y + hi, dgy);
  2090. int bb = zBild.getBreite();
  2091. int* ff = zBild.getBuffer();
  2092. int xx, ygr, ygr2;
  2093. double xb = 0;
  2094. if (alpha3D)
  2095. {
  2096. for (int yy = yst2; yy < dgy; ++yy)
  2097. {
  2098. ygr = yy * size.x;
  2099. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2100. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2101. {
  2102. int f = ff[(int)xb + ygr2];
  2103. unsigned char* cf = (unsigned char*)&f;
  2104. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2105. * (cf[3] - alpha[alphaAnzahl]));
  2106. alphaPixelP3D(fc[xx + ygr], f);
  2107. }
  2108. }
  2109. }
  2110. else
  2111. {
  2112. for (int yy = yst2; yy < dgy; ++yy)
  2113. {
  2114. ygr = yy * size.x;
  2115. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2116. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2117. {
  2118. int f = ff[(int)xb + ygr2];
  2119. unsigned char* cf = (unsigned char*)&f;
  2120. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2121. * (cf[3] - alpha[alphaAnzahl]));
  2122. alphaPixelP(fc[xx + ygr], f);
  2123. }
  2124. }
  2125. }
  2126. rend = 1;
  2127. }
  2128. void Bild::drawDreieck(
  2129. Punkt a, Punkt b, Punkt c, int farbe) // füllt eine Dreieck aus
  2130. {
  2131. if (alpha[alphaAnzahl] == 0xFF) return;
  2132. if (alpha[alphaAnzahl])
  2133. {
  2134. drawDreieckAlpha(a, b, c, farbe);
  2135. return;
  2136. }
  2137. int dpx = dPosA[doa].x;
  2138. int dpy = dPosA[doa].y;
  2139. int dgx = dSizeA[doa].x;
  2140. int dgy = dSizeA[doa].y;
  2141. a += drawOff[doa];
  2142. b += drawOff[doa];
  2143. c += drawOff[doa];
  2144. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2145. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2146. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2147. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2148. return;
  2149. if (b.y < a.y) a.Swap(b);
  2150. if (c.y < b.y) b.Swap(c);
  2151. if (b.y < a.y) a.Swap(b);
  2152. if (a.y == b.y)
  2153. {
  2154. if (b.x < a.x) a.Swap(b);
  2155. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2156. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2157. float b2 = (float)a.x - m2 * (float)a.y;
  2158. float b3 = (float)b.x - m3 * (float)b.y;
  2159. drawFlatDreieck(b.y, c.y, m2, b2, m3, b3, farbe);
  2160. }
  2161. else if (b.y == c.y)
  2162. {
  2163. if (c.x < b.x) b.Swap(c);
  2164. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2165. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2166. float b1 = (float)a.x - m1 * (float)a.y;
  2167. float b2 = (float)a.x - m2 * (float)a.y;
  2168. drawFlatDreieck(a.y, b.y, m1, b1, m2, b2, farbe);
  2169. }
  2170. else
  2171. {
  2172. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2173. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2174. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2175. float b1 = (float)a.x - m1 * (float)a.y;
  2176. float b2 = (float)a.x - m2 * (float)a.y;
  2177. float b3 = (float)b.x - m3 * (float)b.y;
  2178. const float qx = m2 * (float)b.y + b2;
  2179. if (qx < (float)b.x)
  2180. {
  2181. drawFlatDreieck(a.y, b.y, m2, b2, m1, b1, farbe);
  2182. drawFlatDreieck(b.y, c.y, m2, b2, m3, b3, farbe);
  2183. }
  2184. else
  2185. {
  2186. drawFlatDreieck(a.y, b.y, m1, b1, m2, b2, farbe);
  2187. drawFlatDreieck(b.y, c.y, m3, b3, m2, b2, farbe);
  2188. }
  2189. }
  2190. rend = 1;
  2191. }
  2192. void Bild::drawDreieckTextur(Punkt a,
  2193. Punkt b,
  2194. Punkt c,
  2195. Punkt ta,
  2196. Punkt tb,
  2197. Punkt tc,
  2198. const Bild& textur) // füllt eine Dreieck aus
  2199. {
  2200. if (alpha[alphaAnzahl] == 0xFF) return;
  2201. if (alpha[alphaAnzahl])
  2202. {
  2203. drawDreieckTexturAlpha(a, b, c, ta, tb, tc, textur);
  2204. return;
  2205. }
  2206. int dpx = dPosA[doa].x;
  2207. int dpy = dPosA[doa].y;
  2208. int dgx = dSizeA[doa].x;
  2209. int dgy = dSizeA[doa].y;
  2210. a += drawOff[doa];
  2211. b += drawOff[doa];
  2212. c += drawOff[doa];
  2213. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2214. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2215. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2216. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2217. return;
  2218. if (b.y < a.y)
  2219. {
  2220. a.Swap(b);
  2221. ta.Swap(tb);
  2222. }
  2223. if (c.y < b.y)
  2224. {
  2225. b.Swap(c);
  2226. tb.Swap(tc);
  2227. }
  2228. if (b.y < a.y)
  2229. {
  2230. a.Swap(b);
  2231. ta.Swap(tb);
  2232. }
  2233. const double m1 = (double)(a.x - b.x) / (a.y - b.y);
  2234. const double m2 = (double)(a.x - c.x) / (a.y - c.y);
  2235. const double m3 = (double)(b.x - c.x) / (b.y - c.y);
  2236. double b1 = a.x - m1 * a.y;
  2237. double b2 = a.x - m2 * a.y;
  2238. double b3 = b.x - m3 * b.y;
  2239. const double qx = m2 * b.y + b2;
  2240. if (qx < b.x)
  2241. {
  2242. double tx1o, ty1o, tx2o, ty2o;
  2243. if (c.y - a.y)
  2244. {
  2245. tx1o = (double)(tc.x - ta.x) / (c.y - a.y);
  2246. ty1o = (double)(tc.y - ta.y) / (c.y - a.y);
  2247. }
  2248. else
  2249. {
  2250. tx1o = 0;
  2251. ty1o = 0;
  2252. }
  2253. if (b.y - a.y)
  2254. {
  2255. tx2o = (double)(tb.x - ta.x) / (b.y - a.y);
  2256. ty2o = (double)(tb.y - ta.y) / (b.y - a.y);
  2257. }
  2258. else
  2259. {
  2260. tx2o = 0;
  2261. ty2o = 0;
  2262. }
  2263. Vec2<double> q(ta.x + tx1o * (b.y - a.y), ta.y + ty1o * (b.y - a.y));
  2264. double txf, tyf;
  2265. if (b.x - qx)
  2266. {
  2267. txf = (tb.x - q.x) / (b.x - qx);
  2268. tyf = (tb.y - q.y) / (b.x - qx);
  2269. }
  2270. else
  2271. {
  2272. txf = 0;
  2273. tyf = 0;
  2274. }
  2275. drawFlatDreieckTextur(a.y,
  2276. b.y,
  2277. m2,
  2278. b2,
  2279. m1,
  2280. b1,
  2281. ta.x,
  2282. ta.y,
  2283. ta.x,
  2284. ta.y,
  2285. tx1o,
  2286. ty1o,
  2287. tx2o,
  2288. ty2o,
  2289. txf,
  2290. tyf,
  2291. textur);
  2292. if (c.y - b.y)
  2293. {
  2294. tx2o = (double)(tc.x - tb.x) / (c.y - b.y);
  2295. ty2o = (double)(tc.y - tb.y) / (c.y - b.y);
  2296. }
  2297. else
  2298. {
  2299. tx2o = 0;
  2300. ty2o = 0;
  2301. }
  2302. drawFlatDreieckTextur(b.y,
  2303. c.y,
  2304. m2,
  2305. b2,
  2306. m3,
  2307. b3,
  2308. q.x,
  2309. q.y,
  2310. tb.x,
  2311. tb.y,
  2312. tx1o,
  2313. ty1o,
  2314. tx2o,
  2315. ty2o,
  2316. txf,
  2317. tyf,
  2318. textur);
  2319. }
  2320. else
  2321. {
  2322. double tx1o, ty1o, tx2o, ty2o;
  2323. if (b.y - a.y)
  2324. {
  2325. tx1o = (double)(tb.x - ta.x) / (b.y - a.y);
  2326. ty1o = (double)(tb.y - ta.y) / (b.y - a.y);
  2327. }
  2328. else
  2329. {
  2330. tx1o = 0;
  2331. ty1o = 0;
  2332. }
  2333. if (c.y - a.y)
  2334. {
  2335. tx2o = (double)(tc.x - ta.x) / (c.y - a.y);
  2336. ty2o = (double)(tc.y - ta.y) / (c.y - a.y);
  2337. }
  2338. else
  2339. {
  2340. tx2o = 0;
  2341. ty2o = 0;
  2342. }
  2343. Vec2<double> q(ta.x + tx2o * (b.y - a.y), ta.y + ty2o * (b.y - a.y));
  2344. double txf, tyf;
  2345. if (qx - b.x)
  2346. {
  2347. txf = (q.x - tb.x) / (qx - b.x);
  2348. tyf = (q.y - tb.y) / (qx - b.x);
  2349. }
  2350. else
  2351. {
  2352. txf = 0;
  2353. tyf = 0;
  2354. }
  2355. drawFlatDreieckTextur(a.y,
  2356. b.y,
  2357. m1,
  2358. b1,
  2359. m2,
  2360. b2,
  2361. ta.x,
  2362. ta.y,
  2363. ta.x,
  2364. ta.y,
  2365. tx1o,
  2366. ty1o,
  2367. tx2o,
  2368. ty2o,
  2369. txf,
  2370. tyf,
  2371. textur);
  2372. if (c.y - b.y)
  2373. {
  2374. tx1o = (double)(tc.x - tb.x) / (c.y - b.y);
  2375. ty1o = (double)(tc.y - tb.y) / (c.y - b.y);
  2376. }
  2377. else
  2378. {
  2379. tx1o = 0;
  2380. ty1o = 0;
  2381. }
  2382. drawFlatDreieckTextur(b.y,
  2383. c.y,
  2384. m3,
  2385. b3,
  2386. m2,
  2387. b2,
  2388. tb.x,
  2389. tb.y,
  2390. q.x,
  2391. q.y,
  2392. tx1o,
  2393. ty1o,
  2394. tx2o,
  2395. ty2o,
  2396. txf,
  2397. tyf,
  2398. textur);
  2399. }
  2400. rend = 1;
  2401. }
  2402. void Bild::drawDreieckAlpha(
  2403. Punkt a, Punkt b, Punkt c, int farbe) // füllt eine Dreieck aus
  2404. {
  2405. if (alpha[alphaAnzahl] == 0xFF) return;
  2406. int dpx = dPosA[doa].x;
  2407. int dpy = dPosA[doa].y;
  2408. int dgx = dSizeA[doa].x;
  2409. int dgy = dSizeA[doa].y;
  2410. a += drawOff[doa];
  2411. b += drawOff[doa];
  2412. c += drawOff[doa];
  2413. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2414. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2415. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2416. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2417. return;
  2418. if (alpha[alphaAnzahl])
  2419. {
  2420. unsigned char* cf = (unsigned char*)&farbe;
  2421. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2422. * (cf[3] - alpha[alphaAnzahl]));
  2423. }
  2424. if (b.y < a.y) a.Swap(b);
  2425. if (c.y < b.y) b.Swap(c);
  2426. if (b.y < a.y) a.Swap(b);
  2427. if (a.y == b.y)
  2428. {
  2429. if (b.x < a.x) a.Swap(b);
  2430. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2431. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2432. float b2 = (float)a.x - m2 * (float)a.y;
  2433. float b3 = (float)b.x - m3 * (float)b.y;
  2434. drawFlatDreieckAlpha(b.y, c.y, m2, b2, m3, b3, farbe);
  2435. }
  2436. else if (b.y == c.y)
  2437. {
  2438. if (c.x < b.x) b.Swap(c);
  2439. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2440. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2441. float b1 = (float)a.x - m1 * (float)a.y;
  2442. float b2 = (float)a.x - m2 * (float)a.y;
  2443. drawFlatDreieckAlpha(a.y, b.y, m1, b1, m2, b2, farbe);
  2444. }
  2445. else
  2446. {
  2447. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2448. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2449. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2450. float b1 = (float)a.x - m1 * (float)a.y;
  2451. float b2 = (float)a.x - m2 * (float)a.y;
  2452. float b3 = (float)b.x - m3 * (float)b.y;
  2453. const float qx = m2 * (float)b.y + b2;
  2454. if (qx < (float)b.x)
  2455. {
  2456. drawFlatDreieckAlpha(a.y, b.y, m2, b2, m1, b1, farbe);
  2457. drawFlatDreieckAlpha(b.y, c.y, m2, b2, m3, b3, farbe);
  2458. }
  2459. else
  2460. {
  2461. drawFlatDreieckAlpha(a.y, b.y, m1, b1, m2, b2, farbe);
  2462. drawFlatDreieckAlpha(b.y, c.y, m3, b3, m2, b2, farbe);
  2463. }
  2464. }
  2465. rend = 1;
  2466. }
  2467. void Bild::drawDreieckTexturAlpha(Punkt a,
  2468. Punkt b,
  2469. Punkt c,
  2470. Punkt ta,
  2471. Punkt tb,
  2472. Punkt tc,
  2473. const Bild& textur) // füllt eine Dreieck aus
  2474. {
  2475. if (alpha[alphaAnzahl] == 0xFF) return;
  2476. int dpx = dPosA[doa].x;
  2477. int dpy = dPosA[doa].y;
  2478. int dgx = dSizeA[doa].x;
  2479. int dgy = dSizeA[doa].y;
  2480. a += drawOff[doa];
  2481. b += drawOff[doa];
  2482. c += drawOff[doa];
  2483. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2484. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2485. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2486. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2487. return;
  2488. if (b.y < a.y)
  2489. {
  2490. a.Swap(b);
  2491. ta.Swap(tb);
  2492. }
  2493. if (c.y < b.y)
  2494. {
  2495. b.Swap(c);
  2496. tb.Swap(tc);
  2497. }
  2498. if (b.y < a.y)
  2499. {
  2500. a.Swap(b);
  2501. ta.Swap(tb);
  2502. }
  2503. const double m1 = (double)(a.x - b.x) / (a.y - b.y);
  2504. const double m2 = (double)(a.x - c.x) / (a.y - c.y);
  2505. const double m3 = (double)(b.x - c.x) / (b.y - c.y);
  2506. double b1 = a.x - m1 * a.y;
  2507. double b2 = a.x - m2 * a.y;
  2508. double b3 = b.x - m3 * b.y;
  2509. const double qx = m2 * b.y + b2;
  2510. if (qx < b.x)
  2511. {
  2512. double tx1o, ty1o, tx2o, ty2o;
  2513. if (c.y - a.y)
  2514. {
  2515. tx1o = (double)(tc.x - ta.x) / (c.y - a.y);
  2516. ty1o = (double)(tc.y - ta.y) / (c.y - a.y);
  2517. }
  2518. else
  2519. {
  2520. tx1o = 0;
  2521. ty1o = 0;
  2522. }
  2523. if (b.y - a.y)
  2524. {
  2525. tx2o = (double)(tb.x - ta.x) / (b.y - a.y);
  2526. ty2o = (double)(tb.y - ta.y) / (b.y - a.y);
  2527. }
  2528. else
  2529. {
  2530. tx2o = 0;
  2531. ty2o = 0;
  2532. }
  2533. Vec2<double> q(ta.x + tx1o * (b.y - a.y), ta.y + ty1o * (b.y - a.y));
  2534. double txf, tyf;
  2535. if (b.x - qx)
  2536. {
  2537. txf = (tb.x - q.x) / (b.x - qx);
  2538. tyf = (tb.y - q.y) / (b.x - qx);
  2539. }
  2540. else
  2541. {
  2542. txf = 0;
  2543. tyf = 0;
  2544. }
  2545. drawFlatDreieckTexturAlpha(a.y,
  2546. b.y,
  2547. m2,
  2548. b2,
  2549. m1,
  2550. b1,
  2551. ta.x,
  2552. ta.y,
  2553. ta.x,
  2554. ta.y,
  2555. tx1o,
  2556. ty1o,
  2557. tx2o,
  2558. ty2o,
  2559. txf,
  2560. tyf,
  2561. textur);
  2562. if (c.y - b.y)
  2563. {
  2564. tx2o = (double)(tc.x - tb.x) / (c.y - b.y);
  2565. ty2o = (double)(tc.y - tb.y) / (c.y - b.y);
  2566. }
  2567. else
  2568. {
  2569. tx2o = 0;
  2570. ty2o = 0;
  2571. }
  2572. drawFlatDreieckTexturAlpha(b.y,
  2573. c.y,
  2574. m2,
  2575. b2,
  2576. m3,
  2577. b3,
  2578. q.x,
  2579. q.y,
  2580. tb.x,
  2581. tb.y,
  2582. tx1o,
  2583. ty1o,
  2584. tx2o,
  2585. ty2o,
  2586. txf,
  2587. tyf,
  2588. textur);
  2589. }
  2590. else
  2591. {
  2592. double tx1o, ty1o, tx2o, ty2o;
  2593. if (b.y - a.y)
  2594. {
  2595. tx1o = (double)(tb.x - ta.x) / (b.y - a.y);
  2596. ty1o = (double)(tb.y - ta.y) / (b.y - a.y);
  2597. }
  2598. else
  2599. {
  2600. tx1o = 0;
  2601. ty1o = 0;
  2602. }
  2603. if (c.y - a.y)
  2604. {
  2605. tx2o = (double)(tc.x - ta.x) / (c.y - a.y);
  2606. ty2o = (double)(tc.y - ta.y) / (c.y - a.y);
  2607. }
  2608. else
  2609. {
  2610. tx2o = 0;
  2611. ty2o = 0;
  2612. }
  2613. Vec2<double> q(ta.x + tx2o * (b.y - a.y), ta.y + ty2o * (b.y - a.y));
  2614. double txf, tyf;
  2615. if (qx - b.x)
  2616. {
  2617. txf = (q.x - tb.x) / (qx - b.x);
  2618. tyf = (q.y - tb.y) / (qx - b.x);
  2619. }
  2620. else
  2621. {
  2622. txf = 0;
  2623. tyf = 0;
  2624. }
  2625. drawFlatDreieckTexturAlpha(a.y,
  2626. b.y,
  2627. m1,
  2628. b1,
  2629. m2,
  2630. b2,
  2631. ta.x,
  2632. ta.y,
  2633. ta.x,
  2634. ta.y,
  2635. tx1o,
  2636. ty1o,
  2637. tx2o,
  2638. ty2o,
  2639. txf,
  2640. tyf,
  2641. textur);
  2642. if (c.y - b.y)
  2643. {
  2644. tx1o = (double)(tc.x - tb.x) / (c.y - b.y);
  2645. ty1o = (double)(tc.y - tb.y) / (c.y - b.y);
  2646. }
  2647. else
  2648. {
  2649. tx1o = 0;
  2650. ty1o = 0;
  2651. }
  2652. drawFlatDreieckTexturAlpha(b.y,
  2653. c.y,
  2654. m3,
  2655. b3,
  2656. m2,
  2657. b2,
  2658. tb.x,
  2659. tb.y,
  2660. q.x,
  2661. q.y,
  2662. tx1o,
  2663. ty1o,
  2664. tx2o,
  2665. ty2o,
  2666. txf,
  2667. tyf,
  2668. textur);
  2669. }
  2670. rend = 1;
  2671. }
  2672. void Bild::replaceColorWithAlpha(int color)
  2673. {
  2674. int r = (color & 0xFF0000) >> 16;
  2675. int g = (color & 0xFF00) >> 8;
  2676. int b = color & 0xFF;
  2677. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2678. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2679. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2680. for (int y = dy + yy; y < hh; y++)
  2681. {
  2682. int ygr = y * size.x;
  2683. for (int x = dx + xx; x < bb; x++)
  2684. {
  2685. unsigned char* cf = (unsigned char*)&(fc[x + ygr]);
  2686. int abstand = (int)sqrt(
  2687. (float)((r - cf[2]) * (r - cf[2]) + (g - cf[1]) * (g - cf[1])
  2688. + (b - cf[0]) * (b - cf[0])));
  2689. if (abstand > 255) abstand = 255;
  2690. cf[3] = (unsigned char)(abstand);
  2691. }
  2692. }
  2693. }
  2694. bool Bild::setDrawOptions(
  2695. const Punkt& pos, const Punkt& gr) // setzt die Drawoptionen
  2696. {
  2697. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2698. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2699. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2700. if (dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x
  2701. || dy + pos.y >= size.y)
  2702. return 0;
  2703. if (pos.x + gr.x + dx < xx || pos.y + gr.y + dy < yy || dx + pos.x >= bb
  2704. || dy + pos.y >= hh)
  2705. return 0;
  2706. ++doa;
  2707. assert(doa < 2000);
  2708. dPosA[doa].x = maxInt(pos.x + dx, xx);
  2709. dPosA[doa].y = maxInt(pos.y + dy, yy);
  2710. dSizeA[doa].x = minInt(pos.x + gr.x + dx, bb);
  2711. dSizeA[doa].y = minInt(pos.y + gr.y + dy, hh);
  2712. drawOff[doa].x = dx + pos.x;
  2713. drawOff[doa].y = dy + pos.y;
  2714. return 1;
  2715. }
  2716. bool Bild::setDrawOptions(int x, int y, int br, int hi)
  2717. {
  2718. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2719. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2720. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2721. if (dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x
  2722. || dy + y >= size.y)
  2723. return 0;
  2724. if (x + br + dx < xx || y + hi + dy < yy || dx + x >= bb || dy + y >= hh)
  2725. return 0;
  2726. ++doa;
  2727. assert(doa < 2000);
  2728. dPosA[doa].x = maxInt(x + dx, xx);
  2729. dPosA[doa].y = maxInt(y + dy, yy);
  2730. dSizeA[doa].x = minInt(x + br + dx, bb);
  2731. dSizeA[doa].y = minInt(y + hi + dy, hh);
  2732. drawOff[doa].x = dx + x;
  2733. drawOff[doa].y = dy + y;
  2734. return 1;
  2735. }
  2736. bool Bild::setDrawOptionsErzwingen(
  2737. const Punkt& pos, const Punkt& gr) // setzt die Drawoptionen
  2738. {
  2739. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2740. if (dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x
  2741. || dy + pos.y >= size.y)
  2742. return 0;
  2743. ++doa;
  2744. assert(doa < 2000);
  2745. dPosA[doa].x = maxInt(pos.x + dx, 0);
  2746. dPosA[doa].y = maxInt(pos.y + dy, 0);
  2747. dSizeA[doa].x = minInt(pos.x + gr.x + dx, size.x);
  2748. dSizeA[doa].y = minInt(pos.y + gr.y + dy, size.y);
  2749. drawOff[doa].x = dx + pos.x;
  2750. drawOff[doa].y = dy + pos.y;
  2751. return 1;
  2752. }
  2753. bool Bild::setDrawOptionsErzwingen(
  2754. int x, int y, int br, int hi) // setzt die Drawoptionen
  2755. {
  2756. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2757. if (dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x
  2758. || dy + y >= size.y)
  2759. return 0;
  2760. ++doa;
  2761. assert(doa < 2000);
  2762. dPosA[doa].x = maxInt(x + dx, 0);
  2763. dPosA[doa].y = maxInt(y + dy, 0);
  2764. dSizeA[doa].x = minInt(x + br + dx, size.x);
  2765. dSizeA[doa].y = minInt(y + hi + dy, size.y);
  2766. drawOff[doa].x = dx + x;
  2767. drawOff[doa].y = dy + y;
  2768. return 1;
  2769. }
  2770. void Bild::setDrawOptionsReset()
  2771. {
  2772. ++doa;
  2773. dPosA[doa].x = 0;
  2774. dPosA[doa].y = 0;
  2775. dSizeA[doa].x = size.x;
  2776. dSizeA[doa].y = size.y;
  2777. drawOff[doa].x = 0;
  2778. drawOff[doa].y = 0;
  2779. }
  2780. void Bild::addScrollOffset(int xOff, int yOff) // setzt ScrollOffset
  2781. {
  2782. drawOff[doa].x -= xOff;
  2783. drawOff[doa].y -= yOff;
  2784. }
  2785. void Bild::releaseDrawOptions() // setzt die Drawoptionen zurück
  2786. {
  2787. --doa;
  2788. }
  2789. bool Bild::getRend()
  2790. {
  2791. bool ret = rend;
  2792. rend = 0;
  2793. return ret;
  2794. }
  2795. // constant
  2796. int* Bild::getBuffer() const // gibt buffer zurück
  2797. {
  2798. return fc;
  2799. }
  2800. int Bild::getPixel(int x, int y) const
  2801. {
  2802. if (x < 0 || y < 0 || x >= size.x || y >= size.y) return 0;
  2803. return fc[x + y * size.x];
  2804. }
  2805. const Punkt& Bild::getSize() const // gibt die Größe zurück
  2806. {
  2807. return size;
  2808. }
  2809. int Bild::getBreite() const // gibt die Breite zurück
  2810. {
  2811. return size.x;
  2812. }
  2813. int Bild::getHeight() const // gibt die Höhe zurück
  2814. {
  2815. return size.y;
  2816. }
  2817. unsigned char Bild::getAlpha() const // gibt den Alpha wert zurück
  2818. {
  2819. return (unsigned char)(255 - alpha[alphaAnzahl]);
  2820. }
  2821. const Punkt& Bild::getDrawPos() const
  2822. {
  2823. return dPosA[doa];
  2824. }
  2825. const Punkt& Bild::getDrawGr() const
  2826. {
  2827. return dSizeA[doa];
  2828. }
  2829. const Punkt& Bild::getDrawOff() const
  2830. {
  2831. return drawOff[doa];
  2832. }
  2833. bool Bild::hasAlpha3D() const
  2834. {
  2835. return alpha3D;
  2836. }
  2837. int Bild::getAverageColor() const
  2838. {
  2839. double a = 0;
  2840. double r = 0;
  2841. double g = 0;
  2842. double b = 0;
  2843. for (int i = 0; i < size.x * size.y; i++)
  2844. {
  2845. float currentA = (float)(fc[i] >> 24) / 255.f;
  2846. a = a + currentA;
  2847. r = r + (double)((float)((fc[i] >> 16) & 0xFF) * currentA);
  2848. g = g + (double)((float)((fc[i] >> 8) & 0xFF) * currentA);
  2849. b = b + (double)((float)(fc[i] & 0xFF) * currentA);
  2850. }
  2851. a = a / (size.x * size.y);
  2852. r = (r / (size.x * size.y)) / a;
  2853. g = (g / (size.x * size.y)) / a;
  2854. b = (b / (size.x * size.y)) / a;
  2855. a = a * 255;
  2856. return ((((int)a) & 0xFF) << 24) | ((((int)r) & 0xFF) << 16)
  2857. | ((((int)g) & 0xFF) << 8) | (((int)b) & 0xFF);
  2858. }
  2859. // Inhalt der BildZ Klasse aus Bild.h
  2860. // Konstruktor
  2861. BildZ::BildZ()
  2862. : ZeichnungHintergrund(),
  2863. bild(0)
  2864. {
  2865. style = Style::MELockZeichnung;
  2866. mak = _ret1ME;
  2867. }
  2868. // Destruktor
  2869. BildZ::~BildZ()
  2870. {
  2871. if (bild) bild->release();
  2872. }
  2873. void BildZ::doMausEreignis(MausEreignis& me, bool userRet) // ruft Mak auf
  2874. {
  2875. if (userRet)
  2876. {
  2877. int rbr = 0;
  2878. if (hatStyle(Style::Rahmen) && rahmen) rbr = rahmen->getRBreite();
  2879. bool vs = hatStyle(Style::VScroll) && vertikalScrollBar;
  2880. bool hs = hatStyle(Style::HScroll) && horizontalScrollBar;
  2881. if (vs)
  2882. {
  2883. if (hs)
  2884. horizontalScrollBar->doMausMessage(
  2885. rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, me);
  2886. vertikalScrollBar->doMausMessage(
  2887. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
  2888. }
  2889. else if (hs)
  2890. horizontalScrollBar->doMausMessage(
  2891. rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, me);
  2892. }
  2893. me.verarbeitet = userRet;
  2894. }
  2895. // nicht constant
  2896. void BildZ::setBildZ(Bild* b) // setzt das Bild
  2897. {
  2898. if (bild) bild->release();
  2899. bild = b;
  2900. if (!vertikalScrollBar) vertikalScrollBar = new VScrollBar();
  2901. if (!horizontalScrollBar) horizontalScrollBar = new HScrollBar();
  2902. if (b)
  2903. {
  2904. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2905. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2906. }
  2907. rend = 1;
  2908. }
  2909. void BildZ::setBild(Bild* b)
  2910. {
  2911. if (!bild) bild = new Bild();
  2912. bild->neuBild(b->getBreite(), b->getHeight(), 0);
  2913. bild->drawBild(0, 0, b->getBreite(), b->getHeight(), *b);
  2914. if (!vertikalScrollBar) vertikalScrollBar = new VScrollBar();
  2915. if (!horizontalScrollBar) horizontalScrollBar = new HScrollBar();
  2916. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2917. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2918. b->release();
  2919. rend = 1;
  2920. }
  2921. bool BildZ::tick(double tickVal) // tick
  2922. {
  2923. return ZeichnungHintergrund::tick(tickVal);
  2924. }
  2925. void BildZ::render(Bild& zRObj) // zeichnet nach zRObj
  2926. {
  2927. if (hatStyle(Style::Sichtbar))
  2928. {
  2929. ZeichnungHintergrund::render(zRObj);
  2930. lockZeichnung();
  2931. if (!zRObj.setDrawOptions(innenPosition, innenSize))
  2932. {
  2933. unlockZeichnung();
  2934. return;
  2935. }
  2936. if (bild)
  2937. {
  2938. int x = 0;
  2939. int y = 0;
  2940. int br = innenSize.x;
  2941. int hi = innenSize.y;
  2942. if (!(vertikalScrollBar && hatStyle(Style::VScroll))
  2943. && !(horizontalScrollBar && hatStyle(Style::HScroll)))
  2944. {
  2945. if (hatStyle(Style::Alpha))
  2946. {
  2947. if (hatStyle(Style::Skalliert))
  2948. zRObj.alphaBildSkall(x, y, br, hi, *bild);
  2949. else
  2950. zRObj.alphaBild(x, y, br, hi, *bild);
  2951. }
  2952. else
  2953. {
  2954. if (hatStyle(Style::Skalliert))
  2955. zRObj.drawBildSkall(x, y, br, hi, *bild);
  2956. else
  2957. zRObj.drawBild(x, y, br, hi, *bild);
  2958. }
  2959. }
  2960. else
  2961. {
  2962. if (!zRObj.setDrawOptions(x, y, br, hi))
  2963. {
  2964. zRObj.releaseDrawOptions();
  2965. unlockZeichnung();
  2966. return;
  2967. }
  2968. if (hatStyle(Style::Alpha))
  2969. zRObj.alphaBild(-horizontalScrollBar->getScroll(),
  2970. -vertikalScrollBar->getScroll(),
  2971. bild->getBreite(),
  2972. bild->getHeight(),
  2973. *bild);
  2974. else
  2975. zRObj.drawBild(-horizontalScrollBar->getScroll(),
  2976. -vertikalScrollBar->getScroll(),
  2977. bild->getBreite(),
  2978. bild->getHeight(),
  2979. *bild);
  2980. zRObj.releaseDrawOptions();
  2981. }
  2982. }
  2983. zRObj.releaseDrawOptions();
  2984. unlockZeichnung();
  2985. }
  2986. }
  2987. // constant
  2988. Bild* BildZ::getBild() const // gibt das Bild zurück
  2989. {
  2990. if (bild) return dynamic_cast<Bild*>(bild->getThis());
  2991. return 0;
  2992. }
  2993. Bild* BildZ::zBild() const
  2994. {
  2995. return bild;
  2996. }
  2997. Zeichnung* BildZ::dublizieren() const // erstellt eine Kopie des Zeichnungs
  2998. {
  2999. BildZ* obj = new BildZ();
  3000. obj->setPosition(pos);
  3001. obj->setSize(gr);
  3002. obj->setMausEreignisParameter(makParam);
  3003. obj->setTastaturEreignisParameter(takParam);
  3004. obj->setMausEreignis(mak);
  3005. obj->setTastaturEreignis(tak);
  3006. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  3007. obj->setStyle(style);
  3008. obj->setHintergrundFarbe(hintergrundFarbe);
  3009. if (hintergrundFeld)
  3010. obj->setAlphaFeldZ((AlphaFeld*)hintergrundFeld->dublizieren());
  3011. if (rahmen) obj->setRahmenZ((Rahmen*)rahmen->dublizieren());
  3012. if (hintergrundBild)
  3013. obj->setHintergrundBild(
  3014. dynamic_cast<Bild*>(hintergrundBild->getThis()));
  3015. if (bild) obj->setBild(dynamic_cast<Bild*>(bild->getThis()));
  3016. obj->setStyle(style);
  3017. return obj;
  3018. }
  3019. #ifdef WIN32
  3020. Bild* Framework::ladeBild(const char* pfad, Text* zError)
  3021. {
  3022. Text p = pfad;
  3023. Text* txt = p.getTeilText(p.positionVon('.', p.anzahlVon('.') - 1));
  3024. if (!(txt->istGleich(".bmp") || txt->istGleich(".jpg")
  3025. || txt->istGleich(".gif") || txt->istGleich(".png")))
  3026. {
  3027. zError->setText("Die Angegebene Datei ist keine gueltige Bilddatei!");
  3028. txt->release();
  3029. return 0;
  3030. }
  3031. txt->release();
  3032. wchar_t* name = new wchar_t[p.getLength() + 1];
  3033. for (int i = 0; i < p.getLength(); i++)
  3034. name[i] = (wchar_t)p.getText()[i];
  3035. name[p.getLength()] = '\0';
  3036. Gdiplus::Bitmap bitmap(name);
  3037. Gdiplus::Color pix;
  3038. delete[] name;
  3039. Bild* ret = new Bild();
  3040. ret->neuBild(bitmap.GetWidth(), bitmap.GetHeight(), 0);
  3041. int* buff = ret->getBuffer();
  3042. for (unsigned int i = 0; i < bitmap.GetWidth() * bitmap.GetHeight(); i++)
  3043. {
  3044. bitmap.GetPixel(i % bitmap.GetWidth(), i / bitmap.GetWidth(), &pix);
  3045. buff[i] = pix.GetValue();
  3046. }
  3047. return ret;
  3048. }
  3049. #endif