Bild.cpp 89 KB

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