bsnes/hiro/windows/widget/label.cpp

82 lines
2.5 KiB
C++
Raw Normal View History

#if defined(Hiro_Label)
namespace hiro {
auto pLabel::construct() -> void {
hwnd = CreateWindow(L"hiroLabel", L"",
WS_CHILD,
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
pWidget::_setState();
setAlignment(state().alignment);
setText(state().text);
}
auto pLabel::destruct() -> void {
DestroyWindow(hwnd);
}
auto pLabel::minimumSize() const -> Size {
Update to v100 release. byuu says: higan has finally reached v100! I feel it's important to stress right away that this is not "version 1.00", nor is it a major milestone release. Rather than arbitrary version numbers, all of my software simply bumps version numbers by one for each official release. As such, higan v100 is simply higan's 100th release. That said, the primary focus of this release has been code clean-ups. These are always somewhat dangerous in that regressions are possible. We've tested through sixteen WIP revisions, one of which was open to the public, to try and minimize any regressions. But all the same, please report any regressions if you discover any. Changelog (since v099): FC: render during pixels 1-256 instead of 0-255 [hex_usr] FC: rewrote controller emulation code SFC: 8% speedup over the previous release thanks to PPU optimizations SFC: fixed nasty DB address wrapping regression from v099 SFC: USART developer controller removed; superseded by 21fx SFC: Super Multitap option removed from controller port 1; ports renamed 2-5 SFC: hidden option to experiment with 128KB VRAM (strictly for novelty) higan: audio volume no longer divided by number of audio streams higan: updated controller polling code to fix possible future mapping issues higan: replaced nall/stream with nall/vfs for file-loading subsystem tomoko: can now load multi-slotted games via command-line tomoko: synchronize video removed from UI; still available in the settings file tomoko, icarus: can navigate to root drive selection on Windows all: major code cleanups and refactoring (~1MB diff against v099) Note 1: the audio volume change means that SGB and MSU1 games won't lose half the volume on the SNES sounds anymore. However, if one goes overboard and drives the sound all the way to max volume with the MSU1, clamping may occur. The obvious solution is not to drive volume that high (it will vastly overpower the SNES audio, which usually never exceeds 25% volume.) Another option is to lower the volume in the audio settings panel to 50%. In general, neither is likely to ever be necessary. Note 2: the synchronize video option was hidden from the UI because it is no longer useful. With the advent of compositors, the loss of the complicated timing settings panel, support for the WonderSwan and its 75hz display, the need to emulate variable refresh rate behaviors in the Game Boy, the unfortunate latency spike and audio distortion caused by long Vsync pauses, and the arrival of adaptive sync technology ... it no longer makes sense to present this option. However, as stated, you can edit settings.bml to enable this option anyway if you insist and understand the aforementioned risks. Changelog (since v099r16 open beta): - fixed MSU1 audio sign extension - fixed compilation with SGB support disabled - icarus can now navigate to root directory - fixed compilation issues with OS X port - (hopefully) fixed label height issue with hiro that affected icarus import dialog - (mostly) fixed BS Memory, Sufami Turbo slot loading Errata: - forgot to remove the " - Slot A", " - Slot B" suffixes for Sufami Turbo slot loading - this means you have to navigate up one folder and then into Sufami Turbo/ to load games for this system - moving WonderSwan orientation controls to the device slot is causing some nastiness - can now select orientation from the main menu, but it doesn't rotate the display
2016-07-08 12:04:32 +00:00
auto size = pFont::size(self().font(true), state().text ? state().text : " ");
return {size.width(), size.height()};
}
auto pLabel::setAlignment(Alignment alignment) -> void {
InvalidateRect(hwnd, 0, false);
}
auto pLabel::setText(const string& text) -> void {
SetWindowText(hwnd, utf16_t(text));
InvalidateRect(hwnd, 0, false);
}
static auto CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
auto label = (mLabel*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if(!label) return DefWindowProc(hwnd, msg, wparam, lparam);
auto window = label->parentWindow(true);
if(!window) return DefWindowProc(hwnd, msg, wparam, lparam);
switch(msg) {
case WM_GETDLGCODE: return DLGC_STATIC | DLGC_WANTCHARS;
case WM_ERASEBKGND: return true;
case WM_PAINT: {
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
RECT rc;
GetClientRect(hwnd, &rc);
//todo: use DrawThemeParentBackground if Label is inside TabFrame
if(auto brush = window->self()->hbrush) {
FillRect(ps.hdc, &rc, brush);
} else {
DrawThemeParentBackground(hwnd, ps.hdc, &rc);
}
SetBkMode(ps.hdc, TRANSPARENT);
SelectObject(ps.hdc, label->self()->hfont);
uint length = GetWindowTextLength(hwnd);
wchar_t text[length + 1];
GetWindowText(hwnd, text, length + 1);
text[length] = 0;
DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS);
uint height = rc.bottom;
GetClientRect(hwnd, &rc);
rc.top = (rc.bottom - height) / 2;
rc.bottom = rc.top + height;
uint horizontalAlignment = DT_CENTER;
if(label->alignment().horizontal() < 0.333) horizontalAlignment = DT_LEFT;
if(label->alignment().horizontal() > 0.666) horizontalAlignment = DT_RIGHT;
uint verticalAlignment = DT_VCENTER;
if(label->alignment().vertical() < 0.333) verticalAlignment = DT_TOP;
if(label->alignment().vertical() > 0.666) verticalAlignment = DT_BOTTOM;
DrawText(ps.hdc, text, -1, &rc, DT_END_ELLIPSIS | horizontalAlignment | verticalAlignment);
EndPaint(hwnd, &ps);
return false;
}
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
#endif