mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
refactor
This commit is contained in:
@@ -78,76 +78,63 @@ MemoryDCP getTempDC(DC& dc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Combine the temporary DCs used in the drawing with the main dc
|
// Combine the temporary DCs used in the drawing with the main dc
|
||||||
//void combineBuffers(DC& dc, DC* borders, DC* interior) {
|
|
||||||
// wxSize s = dc.GetSize();
|
|
||||||
// if (borders) dc.Blit(0, 0, s.GetWidth(), s.GetHeight(), borders, 0, 0, wxOR);
|
|
||||||
// if (interior) dc.Blit(0, 0, s.GetWidth(), s.GetHeight(), interior, 0, 0, wxAND_INVERT);/
|
|
||||||
//}
|
|
||||||
static void bitwiseBlitOr(Image& dst, const Image& src) {
|
|
||||||
int w = dst.GetWidth();
|
|
||||||
int h = dst.GetHeight();
|
|
||||||
if (src.GetWidth() != w || src.GetHeight() != h) return;
|
|
||||||
|
|
||||||
Byte* dd = dst.GetData();
|
|
||||||
const Byte* sd = src.GetData();
|
|
||||||
|
|
||||||
size_t count = (size_t)w * (size_t)h * 3;
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
|
||||||
dd[i] = dd[i] | sd[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bitwiseBlitAndInvert(Image& dst, const Image& src) {
|
|
||||||
int w = dst.GetWidth();
|
|
||||||
int h = dst.GetHeight();
|
|
||||||
if (src.GetWidth() != w || src.GetHeight() != h) return;
|
|
||||||
|
|
||||||
Byte* dd = dst.GetData();
|
|
||||||
const Byte* sd = src.GetData();
|
|
||||||
|
|
||||||
size_t count = (size_t)w * (size_t)h * 3;
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
|
||||||
dd[i] = dd[i] & (Byte)~sd[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void combineBuffers(DC& dc, DC* borders, DC* interior) {
|
void combineBuffers(DC& dc, DC* borders, DC* interior) {
|
||||||
wxSize s = dc.GetSize();
|
if (!borders && !interior) return;
|
||||||
|
|
||||||
// Copy base DC into an image
|
wxSize size = dc.GetSize();
|
||||||
Bitmap outBmp(s.GetWidth(), s.GetHeight(), 24);
|
int width = size.GetWidth();
|
||||||
wxMemoryDC outDC;
|
int height = size.GetHeight();
|
||||||
outDC.SelectObject(outBmp);
|
|
||||||
outDC.Blit(0, 0, s.GetWidth(), s.GetHeight(), &dc, 0, 0, wxCOPY);
|
|
||||||
outDC.SelectObject(wxNullBitmap);
|
|
||||||
|
|
||||||
Image out = outBmp.ConvertToImage();
|
#ifdef __WXMSW__
|
||||||
|
if (borders) dc.Blit(0, 0, width, height, borders, 0, 0, wxOR);
|
||||||
|
if (interior) dc.Blit(0, 0, width, height, interior, 0, 0, wxAND_INVERT);
|
||||||
|
#else
|
||||||
|
// wxOR and wxAND_INVERT are currently only implemented on Windows, so we have to do them manually
|
||||||
|
size_t count = (size_t)width * (size_t)height * 3;
|
||||||
|
|
||||||
if (borders) {
|
// Copy base DC into an image
|
||||||
Bitmap borderBmp(s.GetWidth(), s.GetHeight(), 24);
|
Bitmap outBmp(width, height, 24);
|
||||||
wxMemoryDC borderCopy;
|
wxMemoryDC outDC;
|
||||||
borderCopy.SelectObject(borderBmp);
|
outDC.SelectObject(outBmp);
|
||||||
borderCopy.Blit(0, 0, s.GetWidth(), s.GetHeight(), borders, 0, 0, wxCOPY);
|
outDC.Blit(0, 0, width, height, &dc, 0, 0, wxCOPY);
|
||||||
borderCopy.SelectObject(wxNullBitmap);
|
outDC.SelectObject(wxNullBitmap);
|
||||||
|
Image outImg = outBmp.ConvertToImage();
|
||||||
|
Byte* outData = outImg.GetData();
|
||||||
|
|
||||||
Image borderImg = borderBmp.ConvertToImage();
|
// wxOR border
|
||||||
bitwiseBlitOr(out, borderImg);
|
if (borders) {
|
||||||
|
Bitmap borderBmp(width, height, 24);
|
||||||
|
wxMemoryDC borderDC;
|
||||||
|
borderDC.SelectObject(borderBmp);
|
||||||
|
borderDC.Blit(0, 0, width, height, borders, 0, 0, wxCOPY);
|
||||||
|
borderDC.SelectObject(wxNullBitmap);
|
||||||
|
Image borderImg = borderBmp.ConvertToImage();
|
||||||
|
Byte* borderData = borderImg.GetData();
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
outData[i] = outData[i] | borderData[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (interior) {
|
// wxAND_INVERT interior
|
||||||
Bitmap interiorBmp(s.GetWidth(), s.GetHeight(), 24);
|
if (interior) {
|
||||||
wxMemoryDC interiorCopy;
|
Bitmap interiorBmp(width, height, 24);
|
||||||
interiorCopy.SelectObject(interiorBmp);
|
wxMemoryDC interiorDC;
|
||||||
interiorCopy.Blit(0, 0, s.GetWidth(), s.GetHeight(), interior, 0, 0, wxCOPY);
|
interiorDC.SelectObject(interiorBmp);
|
||||||
interiorCopy.SelectObject(wxNullBitmap);
|
interiorDC.Blit(0, 0, width, height, interior, 0, 0, wxCOPY);
|
||||||
|
interiorDC.SelectObject(wxNullBitmap);
|
||||||
Image interiorImg = interiorBmp.ConvertToImage();
|
Image interiorImg = interiorBmp.ConvertToImage();
|
||||||
bitwiseBlitAndInvert(out, interiorImg);
|
Byte* interiorData = interiorImg.GetData();
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
outData[i] = outData[i] & (Byte)~interiorData[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap finalBmp(outImg);
|
||||||
|
dc.DrawBitmap(finalBmp, 0, 0, false);
|
||||||
|
#endif
|
||||||
|
|
||||||
Bitmap finalBmp(out);
|
|
||||||
dc.DrawBitmap(finalBmp, 0, 0, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolViewer::draw(DC& dc) {
|
void SymbolViewer::draw(DC& dc) {
|
||||||
bool paintedSomething = false;
|
bool paintedSomething = false;
|
||||||
bool buffersFilled = false;
|
bool buffersFilled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user