2015-06-12 13:14:38 +00:00
|
|
|
#if defined(Hiro_Canvas)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
static auto CALLBACK Canvas_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
|
|
|
|
auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
if(!object) return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
auto canvas = dynamic_cast<mCanvas*>(object);
|
|
|
|
if(!canvas) return DefWindowProc(hwnd, msg, wparam, lparam);
|
2012-01-26 06:50:09 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
if(msg == WM_DROPFILES) {
|
2015-06-12 13:14:38 +00:00
|
|
|
if(auto paths = DropPaths(wparam)) canvas->doDrop(paths);
|
|
|
|
return false;
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
|
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
|
2015-06-12 13:14:38 +00:00
|
|
|
return true;
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 08:57:31 +00:00
|
|
|
if(msg == WM_PAINT) {
|
2015-06-12 13:14:38 +00:00
|
|
|
if(auto self = canvas->self()) self->_paint();
|
|
|
|
return true;
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 06:50:09 +00:00
|
|
|
if(msg == WM_MOUSEMOVE) {
|
2015-06-12 13:14:38 +00:00
|
|
|
TRACKMOUSEEVENT tracker{sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd};
|
2012-01-26 06:50:09 +00:00
|
|
|
TrackMouseEvent(&tracker);
|
2015-06-12 13:14:38 +00:00
|
|
|
canvas->doMouseMove({(int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam)});
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_MOUSELEAVE) {
|
2015-06-12 13:14:38 +00:00
|
|
|
canvas->doMouseLeave();
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
|
2015-06-12 13:14:38 +00:00
|
|
|
switch(msg) {
|
|
|
|
case WM_LBUTTONDOWN: canvas->doMousePress(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONDOWN: canvas->doMousePress(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONDOWN: canvas->doMousePress(Mouse::Button::Right); break;
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
|
2015-06-12 13:14:38 +00:00
|
|
|
switch(msg) {
|
|
|
|
case WM_LBUTTONUP: canvas->doMouseRelease(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONUP: canvas->doMouseRelease(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONUP: canvas->doMouseRelease(Mouse::Button::Right); break;
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 11:57:54 +00:00
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::construct() -> void {
|
|
|
|
hwnd = CreateWindow(L"hiroCanvas", L"", WS_CHILD, 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
|
|
|
|
pWidget::_setState();
|
|
|
|
setDroppable(state().droppable);
|
|
|
|
update();
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::destruct() -> void {
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::minimumSize() const -> Size {
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
if(auto& image = state().image) return image.size();
|
|
|
|
return {0, 0};
|
2015-06-12 13:14:38 +00:00
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::setColor(Color color) -> void {
|
|
|
|
update();
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::setDroppable(bool droppable) -> void {
|
|
|
|
DragAcceptFiles(hwnd, droppable);
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::setGeometry(Geometry geometry) -> void {
|
|
|
|
pWidget::setGeometry(geometry);
|
|
|
|
update();
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
auto pCanvas::setGradient(Gradient gradient) -> void {
|
2015-06-12 13:14:38 +00:00
|
|
|
update();
|
2011-09-05 03:48:23 +00:00
|
|
|
}
|
|
|
|
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
auto pCanvas::setImage(const Image& image) -> void {
|
2015-06-12 13:14:38 +00:00
|
|
|
update();
|
2011-04-27 08:57:31 +00:00
|
|
|
}
|
2011-12-12 10:59:53 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::update() -> void {
|
|
|
|
_rasterize();
|
|
|
|
_redraw();
|
|
|
|
}
|
2011-12-12 10:59:53 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::_paint() -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
BeginPaint(hwnd, &ps);
|
|
|
|
|
|
|
|
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
|
2015-06-12 13:14:38 +00:00
|
|
|
bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32_t);
|
2013-11-28 10:29:01 +00:00
|
|
|
void* bits = nullptr;
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0);
|
|
|
|
if(bits) {
|
|
|
|
auto source = (const uint8_t*)pixels.data();
|
|
|
|
auto target = (uint8_t*)bits;
|
|
|
|
for(auto n : range(width * height)) {
|
|
|
|
target[0] = (source[0] * source[3]) / 255;
|
|
|
|
target[1] = (source[1] * source[3]) / 255;
|
|
|
|
target[2] = (source[2] * source[3]) / 255;
|
|
|
|
target[3] = (source[3]);
|
|
|
|
source += 4, target += 4;
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
SelectObject(hdc, bitmap);
|
|
|
|
|
|
|
|
RECT rc;
|
|
|
|
GetClientRect(hwnd, &rc);
|
|
|
|
DrawThemeParentBackground(hwnd, ps.hdc, &rc);
|
2015-06-12 13:14:38 +00:00
|
|
|
|
|
|
|
BLENDFUNCTION bf{AC_SRC_OVER, 0, (BYTE)255, AC_SRC_ALPHA};
|
2013-11-28 10:29:01 +00:00
|
|
|
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
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::_rasterize() -> void {
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
if(auto& image = state().image) {
|
|
|
|
width = image.width();
|
|
|
|
height = image.height();
|
|
|
|
} else {
|
2015-06-12 13:14:38 +00:00
|
|
|
width = self().geometry().width();
|
|
|
|
height = self().geometry().height();
|
|
|
|
}
|
|
|
|
if(width <= 0 || height <= 0) return;
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
pixels.reallocate(width * height);
|
2013-11-28 10:29:01 +00:00
|
|
|
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
if(auto& image = state().image) {
|
|
|
|
memory::copy(pixels.data(), image.data(), width * height * sizeof(uint32_t));
|
|
|
|
} else if(auto& gradient = state().gradient) {
|
|
|
|
auto& colors = gradient.state.colors;
|
|
|
|
nall::image fill;
|
2015-06-12 13:14:38 +00:00
|
|
|
fill.allocate(width, height);
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value());
|
2015-06-18 10:48:53 +00:00
|
|
|
memory::copy(pixels.data(), fill.data(), fill.size());
|
Update to v094r43 release.
byuu says:
Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)
Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.
Also enhanced the command-line game loading. You can now use any of
these methods:
higan /path/to/game-folder.sfc
higan /path/to/game-folder.sfc/
higan /path/to/game-folder.sfc/program.rom
The idea is to support launchers that insist on loading files only.
Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.
Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.
Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
|
|
|
} else {
|
|
|
|
uint32_t color = state().color.value();
|
|
|
|
for(auto& pixel : pixels) pixel = color;
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pCanvas::_redraw() -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
InvalidateRect(hwnd, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
#endif
|