2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2011-04-27 08:57:31 +00:00
|
|
|
static LRESULT CALLBACK Canvas_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
2013-05-02 11:25:45 +00:00
|
|
|
Object* object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
2012-01-26 06:50:09 +00:00
|
|
|
if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
if(!dynamic_cast<Canvas*>(object)) return DefWindowProc(hwnd, msg, wparam, lparam);
|
2013-05-02 11:25:45 +00:00
|
|
|
Canvas& canvas = (Canvas&)*object;
|
2012-01-26 06:50:09 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
if(msg == WM_DROPFILES) {
|
|
|
|
lstring paths = DropPaths(wparam);
|
|
|
|
if(paths.empty() == false) {
|
|
|
|
if(canvas.onDrop) canvas.onDrop(paths);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-04 11:57:54 +00:00
|
|
|
if(msg == WM_GETDLGCODE) {
|
|
|
|
return DLGC_STATIC | DLGC_WANTCHARS;
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
if(msg == WM_ERASEBKGND) {
|
|
|
|
//background is erased during WM_PAINT to prevent flickering
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-27 08:57:31 +00:00
|
|
|
if(msg == WM_PAINT) {
|
2012-01-26 06:50:09 +00:00
|
|
|
canvas.p.paint();
|
2011-11-04 11:57:54 +00:00
|
|
|
return TRUE;
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 06:50:09 +00:00
|
|
|
if(msg == WM_MOUSEMOVE) {
|
2013-05-02 11:25:45 +00:00
|
|
|
TRACKMOUSEEVENT tracker = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd};
|
2012-01-26 06:50:09 +00:00
|
|
|
TrackMouseEvent(&tracker);
|
2013-05-02 11:25:45 +00:00
|
|
|
if(canvas.onMouseMove) canvas.onMouseMove({(int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam)});
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_MOUSELEAVE) {
|
|
|
|
if(canvas.onMouseLeave) canvas.onMouseLeave();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
|
|
|
|
if(canvas.onMousePress) switch(msg) {
|
|
|
|
case WM_LBUTTONDOWN: canvas.onMousePress(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONDOWN: canvas.onMousePress(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONDOWN: canvas.onMousePress(Mouse::Button::Right); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
|
|
|
|
if(canvas.onMouseRelease) switch(msg) {
|
|
|
|
case WM_LBUTTONUP: canvas.onMouseRelease(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONUP: canvas.onMouseRelease(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONUP: canvas.onMouseRelease(Mouse::Button::Right); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 11:57:54 +00:00
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pCanvas::setDroppable(bool droppable) {
|
|
|
|
DragAcceptFiles(hwnd, droppable);
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCanvas::setGeometry(Geometry geometry) {
|
|
|
|
if(canvas.state.width == 0 || canvas.state.height == 0) rasterize();
|
|
|
|
unsigned width = canvas.state.width;
|
|
|
|
unsigned height = canvas.state.height;
|
|
|
|
if(width == 0) width = widget.state.geometry.width;
|
|
|
|
if(height == 0) height = widget.state.geometry.height;
|
|
|
|
|
|
|
|
if(width < geometry.width) {
|
|
|
|
geometry.x += (geometry.width - width) / 2;
|
|
|
|
geometry.width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(height < geometry.height) {
|
|
|
|
geometry.y += (geometry.height - height) / 2;
|
|
|
|
geometry.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
pWidget::setGeometry(geometry);
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCanvas::setMode(Canvas::Mode mode) {
|
|
|
|
rasterize(), redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCanvas::setSize(Size size) {
|
|
|
|
rasterize(), redraw();
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pCanvas::constructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD, 0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0);
|
2011-09-05 03:48:23 +00:00
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas);
|
2013-07-29 09:42:45 +00:00
|
|
|
setDroppable(canvas.state.droppable);
|
2013-11-28 10:29:01 +00:00
|
|
|
rasterize();
|
2011-09-05 03:48:23 +00:00
|
|
|
synchronize();
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 03:48:23 +00:00
|
|
|
void pCanvas::destructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
release();
|
2011-09-05 03:48:23 +00:00
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCanvas::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
2011-12-12 10:59:53 +00:00
|
|
|
|
|
|
|
void pCanvas::paint() {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(surface == nullptr) return;
|
2011-12-12 10:59:53 +00:00
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
BeginPaint(hwnd, &ps);
|
|
|
|
|
|
|
|
uint32_t* data = surface;
|
|
|
|
unsigned width = surfaceWidth;
|
|
|
|
unsigned height = surfaceHeight;
|
|
|
|
|
|
|
|
HDC hdc = CreateCompatibleDC(ps.hdc);
|
2011-12-12 10:59:53 +00:00
|
|
|
BITMAPINFO bmi;
|
|
|
|
memset(&bmi, 0, sizeof(BITMAPINFO));
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
|
|
bmi.bmiHeader.biBitCount = 32;
|
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
bmi.bmiHeader.biWidth = width;
|
|
|
|
bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap
|
2013-11-28 10:29:01 +00:00
|
|
|
bmi.bmiHeader.biSizeImage = width * height * sizeof(uint32_t);
|
|
|
|
void* bits = nullptr;
|
|
|
|
HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
|
|
|
|
if(bits) memcpy(bits, data, width * height * sizeof(uint32_t));
|
|
|
|
SelectObject(hdc, bitmap);
|
|
|
|
|
|
|
|
BLENDFUNCTION bf;
|
|
|
|
bf.BlendOp = AC_SRC_OVER;
|
|
|
|
bf.BlendFlags = 0;
|
|
|
|
bf.SourceConstantAlpha = 255;
|
|
|
|
bf.AlphaFormat = AC_SRC_ALPHA;
|
|
|
|
|
|
|
|
RECT rc;
|
|
|
|
GetClientRect(hwnd, &rc);
|
|
|
|
DrawThemeParentBackground(hwnd, ps.hdc, &rc);
|
|
|
|
AlphaBlend(ps.hdc, 0, 0, width, height, hdc, 0, 0, width, height, bf);
|
|
|
|
|
|
|
|
DeleteObject(bitmap);
|
|
|
|
DeleteDC(hdc);
|
2011-12-12 10:59:53 +00:00
|
|
|
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCanvas::rasterize() {
|
|
|
|
unsigned width = canvas.state.width;
|
|
|
|
unsigned height = canvas.state.height;
|
|
|
|
if(width == 0) width = widget.state.geometry.width;
|
|
|
|
if(height == 0) height = widget.state.geometry.height;
|
|
|
|
|
|
|
|
if(width != surfaceWidth || height != surfaceHeight) release();
|
|
|
|
if(!surface) surface = new uint32_t[width * height];
|
|
|
|
|
|
|
|
if(canvas.state.mode == Canvas::Mode::Color) {
|
|
|
|
nall::image image;
|
|
|
|
image.allocate(width, height);
|
|
|
|
image.fill(canvas.state.color.argb());
|
|
|
|
memcpy(surface, image.data, image.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canvas.state.mode == Canvas::Mode::Gradient) {
|
|
|
|
nall::image image;
|
|
|
|
image.allocate(width, height);
|
Update to v094 release.
byuu says:
This release adds support for game libraries, and substantially improves
Game Boy and Game Boy Color emulation with cycle-based renderers. Many
other changes are also present.
It's very important to note that this release now defaults to optimal
drivers rather than safe drivers. This is particularly important if you
do not have strong OpenGL 3.2 drivers. If performance is bad, go to
Settings -> Configuration -> Advanced, change the video driver, and
restart higan. In the rare case that you have trouble opening higan, you
can edit settings.bml directly and change the setting there. The Windows
safe driver is Direct3D, and the Linux safe driver is XShm.
Also note that although display emulation shaders are now supported,
they have not been included in this release as they are not ready yet.
The support has been built-in anyway, so that they can be tested by
everyone. Once refined, future releases of higan will come with built-in
shaders for each emulated system that simulates the unique display
characteristics of each.
Changelog (since v093):
- sfc: added SA-1 MDR support (fixes SD Gundam G-Next bug)
- sfc: remove random/ and config/, merge to system/ with better
randomization
- gb: improved color emulation palette contrast
- gbc: do not sort sprites by X-priority
- gbc: allow transparency on BG priority pixels
- gbc: VRAM DMA timing and register fixes
- gbc: block invalid VRAM DMA transfer source and target addresses
- gba: added LCD color emulation (without it, colors are grossly
over-saturated)
- gba: removed internal frame blending (use shaders to simulate motion
blur if desired)
- gba: added Game Boy Player support (adds joypad rumble support to
supported games)
- gba: SOUND_CTL_H is readable
- gb/gbc: PPU renderer is now cycle-based (major accuracy improvement)
- gb/gbc: OAM DMA runs in parallel with the CPU
- gb/gbc: only HRAM can be accessed during OAM DMA
- gb/gbc: fixed serialization of games with SRAM
- gb/gbc: disallow up+down or left+right at the same time
- gb/gbc: added weak hipass filter to remove DC bias
- gb/gbc: STAT OAM+Hblank IRQs only trigger during active display
- gb/gbc: fixed underflow in window clamping
- gb/gbc/gba: audio mixes internally at 2MHz now instead of 4MHz (does
not affect accuracy)
- gb/gbc/gba: audio volume reduced for consistency with other systems
- fc/sfc/gb/gbc/gba: cheat codes are now stored in universal, decrypted
format
- ethos: replaced file loader with a proper game library
- ethos: added display emulation shader support
- ethos: added color emulation option to video settings
- ethos: program icon upgraded from 48x48 to 512x512
- ethos: settings and tools windows now use tab frames (less wasted
screen space)
- ethos: default to optimal (video, audio, input) drivers instead of
safest drivers
- ethos: input mapping system completely rewritten to support
hotplugging and unique device mappings
- ruby: added fixes for OpenGL 3.2 on AMD graphics cards
- ruby: quark shaders now support user settings inside of manifest
- ruby: quark shaders can use integral textures (allows display
emulation shaders to work with raw colors)
- ruby: add joypad rumble support
- ruby: XInput (Xbox 360) controllers now support hotplugging
- ruby: added Linux udev joypad driver with hotplug support
- phoenix: fixed a rare null pointer dereference issue on Windows
- port: target -std=c++11 instead of -std=gnu++11 (do not rely on GNU
C++ extensions)
- port: added out-of-the-box compilation support for BSD/Clang 3.3+
- port: applied a few Debian upstream patches
- cheats: updated to mightymo's 2014-01-02 release; decrypted all Game
Genie codes
2014-01-20 08:55:17 +00:00
|
|
|
image.gradient(
|
2013-11-28 10:29:01 +00:00
|
|
|
canvas.state.gradient[0].argb(), canvas.state.gradient[1].argb(), canvas.state.gradient[2].argb(), canvas.state.gradient[3].argb()
|
|
|
|
);
|
|
|
|
memcpy(surface, image.data, image.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canvas.state.mode == Canvas::Mode::Image) {
|
|
|
|
nall::image image = canvas.state.image;
|
|
|
|
image.scale(width, height);
|
|
|
|
image.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0);
|
|
|
|
memcpy(surface, image.data, image.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canvas.state.mode == Canvas::Mode::Data) {
|
|
|
|
if(width == canvas.state.width && height == canvas.state.height) {
|
|
|
|
memcpy(surface, canvas.state.data, width * height * sizeof(uint32_t));
|
|
|
|
} else {
|
|
|
|
memset(surface, 0x00, width * height * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
surfaceWidth = width;
|
|
|
|
surfaceHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCanvas::redraw() {
|
|
|
|
InvalidateRect(hwnd, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCanvas::release() {
|
|
|
|
if(surface) {
|
|
|
|
delete[] surface;
|
|
|
|
surface = nullptr;
|
|
|
|
surfaceWidth = 0;
|
|
|
|
surfaceHeight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|