mirror of https://github.com/bsnes-emu/bsnes.git
Update to v103r13 release.
byuu says: Changelog: - gb/interface: fix Game Boy Color extension to be "gbc" and not "gb" [hex\_usr] - ms/interface: move Master System hardware controls below controller ports - sfc/ppu: improve latching behavior of BGnHOFS registers (not hardware verified) [AWJ] - tomoko/input: rework port/device mapping to support non-sequential ports and devices¹ - todo: should add move() to inputDevice.mappings.append and inputPort.devices.append - note: there's a weird GCC 4.9 bug with brace initialization of InputEmulator; have to assign each field separately - tomoko: all windows sans the main presentation window can be dismissed with the escape key - icarus: the single file selection dialog ("Load ROM Image...") can be dismissed with the escape key - tomoko: do not pause emulation when FocusLoss/Pause is set during exclusive fullscreen mode - hiro/(windows,gtk,qt): implemented Window::setDismissable() function (missing from cocoa port, sorry) - nall/string: fixed printing of largest possible negative numbers (eg `INT_MIN`) [Sintendo] - only took eight months! :D ¹: When I tried to move the Master System hardware port below the controller ports, I ran into a world of pain. The input settings list expects every item in the `InputEmulator<InputPort<InputDevice<InputMapping>>>>` arrays to be populated with valid results. But these would be sparsely populated based on the port and device IDs from inside higan. And that is done so that the Interface::inputPoll can have O(1) lookup of ports and devices. This worked because all the port and device IDs were sequential (they left no gaps in the maps upon creating the lists.) Unfortunately by changing the expectation of port ID to how it appears in the list, inputs would not poll correctly. By leaving them alone and just moving Hardware to the third position, the Game Gear would be missing port IDs of 0 and 1 (the controller ports of the Master System). Even by trying to make separate MasterSystemHardware and GameGearHardware ports, things still fractured when the devices were no longer contigious. I got pretty sick of this and just decided to give up on O(1) port/device lookup, and moved to O(n) lookup. It only knocked the framerate down by maybe one frame per second, enough to be in the margin of error. Inputs aren't polled *that* often for loops that usually terminate after 1-2 cycles to be too detrimental to performance. So the new input system now allows non-sequential port and device IDs. Remember that I killed input IDs a while back. There's never any reason for those to need IDs ... it was easier to just order the inputs in the order you want to see them in the user interface. So the input lookup is still O(1). Only now, everything's safer and I return a maybe<InputMapping&>, and won't crash out the program trying to use a mapping that isn't found for some reason. Errata: the escape key isn't working on the browser/message dialogs on Windows, because of course nothing can ever just be easy and work for me. If anyone else wouldn't mind looking into that, I'd greatly appreciate it. Having the `WM_KEYDOWN` test inside the main `Application_sharedProc`, it seems to not respond to the escape key on modal dialogs. If I put the `WM_KEYDOWN` test in the main window proc, then it doesn't seem to get called for `VK_ESCAPE` at all, and doesn't get called period for modal windows. So I'm at a loss and it's past 4AM here >_>
This commit is contained in:
parent
434e303ffb
commit
ed5ec58595
|
@ -12,7 +12,7 @@ using namespace nall;
|
|||
|
||||
namespace Emulator {
|
||||
static const string Name = "higan";
|
||||
static const string Version = "103.12";
|
||||
static const string Version = "103.13";
|
||||
static const string Author = "byuu";
|
||||
static const string License = "GPLv3";
|
||||
static const string Website = "http://byuu.org/";
|
||||
|
|
|
@ -3,7 +3,7 @@ GameBoyColorInterface::GameBoyColorInterface() {
|
|||
information.name = "Game Boy Color";
|
||||
information.overscan = false;
|
||||
|
||||
media.append({ID::GameBoyColor, "Game Boy Color", "gb"});
|
||||
media.append({ID::GameBoyColor, "Game Boy Color", "gbc"});
|
||||
}
|
||||
|
||||
auto GameBoyColorInterface::videoColors() -> uint32 {
|
||||
|
|
|
@ -5,15 +5,9 @@ MasterSystemInterface::MasterSystemInterface() {
|
|||
|
||||
media.append({ID::MasterSystem, "Master System", "ms"});
|
||||
|
||||
Port hardware{ID::Port::Hardware, "Hardware"};
|
||||
Port controllerPort1{ID::Port::Controller1, "Controller Port 1"};
|
||||
Port controllerPort2{ID::Port::Controller2, "Controller Port 2"};
|
||||
|
||||
{ Device device{ID::Device::MasterSystemControls, "Controls"};
|
||||
device.inputs.append({0, "Reset"});
|
||||
device.inputs.append({0, "Pause"});
|
||||
hardware.devices.append(device);
|
||||
}
|
||||
Port hardware{ID::Port::Hardware, "Hardware"};
|
||||
|
||||
{ Device device{ID::Device::None, "None"};
|
||||
controllerPort1.devices.append(device);
|
||||
|
@ -31,9 +25,15 @@ MasterSystemInterface::MasterSystemInterface() {
|
|||
controllerPort2.devices.append(device);
|
||||
}
|
||||
|
||||
ports.append(move(hardware));
|
||||
{ Device device{ID::Device::MasterSystemControls, "Controls"};
|
||||
device.inputs.append({0, "Reset"});
|
||||
device.inputs.append({0, "Pause"});
|
||||
hardware.devices.append(device);
|
||||
}
|
||||
|
||||
ports.append(move(controllerPort1));
|
||||
ports.append(move(controllerPort2));
|
||||
ports.append(move(hardware));
|
||||
}
|
||||
|
||||
auto MasterSystemInterface::videoResolution() -> VideoResolution {
|
||||
|
|
|
@ -293,8 +293,9 @@ auto PPU::writeIO(uint24 addr, uint8 data) -> void {
|
|||
io.hoffsetMode7 = data << 8 | latch.mode7;
|
||||
latch.mode7 = data;
|
||||
|
||||
bg1.io.hoffset = data << 8 | (latch.bgofs & ~7) | (bg1.io.hoffset >> 8 & 7);
|
||||
latch.bgofs = data;
|
||||
bg1.io.hoffset = data << 8 | (latch.bgofsPPU1 & ~7) | (latch.bgofsPPU2 & 7);
|
||||
latch.bgofsPPU1 = data;
|
||||
latch.bgofsPPU2 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -303,50 +304,53 @@ auto PPU::writeIO(uint24 addr, uint8 data) -> void {
|
|||
io.voffsetMode7 = data << 8 | latch.mode7;
|
||||
latch.mode7 = data;
|
||||
|
||||
bg1.io.voffset = data << 8 | latch.bgofs;
|
||||
latch.bgofs = data;
|
||||
bg1.io.voffset = data << 8 | latch.bgofsPPU1;
|
||||
latch.bgofsPPU1 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG2HOFS
|
||||
case 0x210f: {
|
||||
bg2.io.hoffset = data << 8 | (latch.bgofs & ~7) | (bg2.io.hoffset >> 8 & 7);
|
||||
latch.bgofs = data;
|
||||
bg2.io.hoffset = data << 8 | (latch.bgofsPPU1 & ~7) | (latch.bgofsPPU2 & 7);
|
||||
latch.bgofsPPU1 = data;
|
||||
latch.bgofsPPU2 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG2VOFS
|
||||
case 0x2110: {
|
||||
bg2.io.voffset = data << 8 | latch.bgofs;
|
||||
latch.bgofs = data;
|
||||
bg2.io.voffset = data << 8 | latch.bgofsPPU1;
|
||||
latch.bgofsPPU1 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG3HOFS
|
||||
case 0x2111: {
|
||||
bg3.io.hoffset = data << 8 | (latch.bgofs & ~7) | (bg3.io.hoffset >> 8 & 7);
|
||||
latch.bgofs = data;
|
||||
bg3.io.hoffset = data << 8 | (latch.bgofsPPU1 & ~7) | (latch.bgofsPPU2 & 7);
|
||||
latch.bgofsPPU1 = data;
|
||||
latch.bgofsPPU2 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG3VOFS
|
||||
case 0x2112: {
|
||||
bg3.io.voffset = data << 8 | latch.bgofs;
|
||||
latch.bgofs = data;
|
||||
bg3.io.voffset = data << 8 | latch.bgofsPPU1;
|
||||
latch.bgofsPPU1 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG4HOFS
|
||||
case 0x2113: {
|
||||
bg4.io.hoffset = data << 8 | (latch.bgofs & ~7) | (bg4.io.hoffset >> 8 & 7);
|
||||
latch.bgofs = data;
|
||||
bg4.io.hoffset = data << 8 | (latch.bgofsPPU1 & ~7) | (latch.bgofsPPU2 & 7);
|
||||
latch.bgofsPPU1 = data;
|
||||
latch.bgofsPPU2 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//BG4VOFS
|
||||
case 0x2114: {
|
||||
bg4.io.voffset = data << 8 | latch.bgofs;
|
||||
latch.bgofs = data;
|
||||
bg4.io.voffset = data << 8 | latch.bgofsPPU1;
|
||||
latch.bgofsPPU1 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,8 @@ auto PPU::power() -> void {
|
|||
latch.vram = random(0x0000);
|
||||
latch.oam = random(0x00);
|
||||
latch.cgram = random(0x00);
|
||||
latch.bgofs = random(0x00);
|
||||
latch.bgofsPPU1 = random(0x00);
|
||||
latch.bgofsPPU2 = random(0x00);
|
||||
latch.mode7 = random(0x00);
|
||||
latch.counters = false;
|
||||
latch.hcounter = 0;
|
||||
|
|
|
@ -55,7 +55,8 @@ private:
|
|||
uint16 vram;
|
||||
uint8 oam;
|
||||
uint8 cgram;
|
||||
uint8 bgofs;
|
||||
uint8 bgofsPPU1;
|
||||
uint3 bgofsPPU2;
|
||||
uint8 mode7;
|
||||
uint1 counters;
|
||||
uint1 hcounter;
|
||||
|
|
|
@ -29,7 +29,8 @@ auto PPU::serialize(serializer& s) -> void {
|
|||
s.integer(latch.vram);
|
||||
s.integer(latch.oam);
|
||||
s.integer(latch.cgram);
|
||||
s.integer(latch.bgofs);
|
||||
s.integer(latch.bgofsPPU1);
|
||||
s.integer(latch.bgofsPPU2);
|
||||
s.integer(latch.mode7);
|
||||
s.integer(latch.counters);
|
||||
s.integer(latch.hcounter);
|
||||
|
|
|
@ -96,12 +96,12 @@ auto InputManager::appendHotkeys() -> void {
|
|||
}
|
||||
|
||||
auto InputManager::pollHotkeys() -> void {
|
||||
if(program->allowInput(true)) {
|
||||
for(auto& hotkey : hotkeys) {
|
||||
int16 state = hotkey->poll();
|
||||
if(hotkey->state == 0 && state == 1 && hotkey->press) hotkey->press();
|
||||
if(hotkey->state == 1 && state == 0 && hotkey->release) hotkey->release();
|
||||
hotkey->state = state;
|
||||
}
|
||||
if(!program->focused()) return;
|
||||
|
||||
for(auto& hotkey : hotkeys) {
|
||||
int16 state = hotkey->poll();
|
||||
if(hotkey->state == 0 && state == 1 && hotkey->press) hotkey->press();
|
||||
if(hotkey->state == 1 && state == 0 && hotkey->release) hotkey->release();
|
||||
hotkey->state = state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,27 +192,29 @@ InputManager::InputManager() {
|
|||
frequency = max(1u, settings["Input/Frequency"].natural());
|
||||
|
||||
for(auto& emulator : program->emulators) {
|
||||
auto& inputEmulator = emulators(emulators.size());
|
||||
InputEmulator inputEmulator;
|
||||
inputEmulator.interface = emulator;
|
||||
inputEmulator.name = emulator->information.name;
|
||||
|
||||
for(auto& port : emulator->ports) {
|
||||
auto& inputPort = inputEmulator.ports(port.id);
|
||||
inputPort.name = port.name;
|
||||
InputPort inputPort{port.id, port.name};
|
||||
for(auto& device : port.devices) {
|
||||
auto& inputDevice = inputPort.devices(device.id);
|
||||
inputDevice.name = device.name;
|
||||
InputDevice inputDevice{device.id, device.name};
|
||||
for(auto& input : device.inputs) {
|
||||
auto& inputMapping = inputDevice.mappings(inputDevice.mappings.size());
|
||||
InputMapping inputMapping;
|
||||
inputMapping.name = input.name;
|
||||
inputMapping.type = input.type;
|
||||
|
||||
inputMapping.path = string{inputEmulator.name, "/", inputPort.name, "/", inputDevice.name, "/", inputMapping.name}.replace(" ", "");
|
||||
inputMapping.assignment = settings(inputMapping.path).text();
|
||||
inputMapping.bind();
|
||||
|
||||
inputDevice.mappings.append(inputMapping);
|
||||
}
|
||||
inputPort.devices.append(inputDevice);
|
||||
}
|
||||
inputEmulator.ports.append(move(inputPort));
|
||||
}
|
||||
emulators.append(move(inputEmulator));
|
||||
}
|
||||
|
||||
appendHotkeys();
|
||||
|
@ -278,6 +280,19 @@ auto InputManager::quit() -> void {
|
|||
hotkeys.reset();
|
||||
}
|
||||
|
||||
auto InputManager::mapping(uint port, uint device, uint input) -> maybe<InputMapping&> {
|
||||
if(!emulator) return nothing;
|
||||
for(auto& inputPort : emulator->ports) {
|
||||
if(inputPort.id != port) continue;
|
||||
for(auto& inputDevice : inputPort.devices) {
|
||||
if(inputDevice.id != device) continue;
|
||||
if(input >= inputDevice.mappings.size()) return nothing;
|
||||
return inputDevice.mappings[input];
|
||||
}
|
||||
}
|
||||
return nothing;
|
||||
}
|
||||
|
||||
auto InputManager::findMouse() -> shared_pointer<HID::Device> {
|
||||
for(auto& device : devices) {
|
||||
if(device->isMouse()) return device;
|
||||
|
|
|
@ -39,11 +39,13 @@ struct InputHotkey : InputMapping {
|
|||
};
|
||||
|
||||
struct InputDevice {
|
||||
uint id;
|
||||
string name;
|
||||
vector<InputMapping> mappings;
|
||||
};
|
||||
|
||||
struct InputPort {
|
||||
uint id;
|
||||
string name;
|
||||
vector<InputDevice> devices;
|
||||
};
|
||||
|
@ -62,6 +64,7 @@ struct InputManager {
|
|||
auto onChange(shared_pointer<HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void;
|
||||
auto quit() -> void;
|
||||
|
||||
auto mapping(uint port, uint device, uint input) -> maybe<InputMapping&>;
|
||||
auto findMouse() -> shared_pointer<HID::Device>;
|
||||
|
||||
//hotkeys.cpp
|
||||
|
|
|
@ -23,4 +23,5 @@ AboutWindow::AboutWindow() {
|
|||
setResizable(false);
|
||||
setSize(layout.minimumSize());
|
||||
setCentered();
|
||||
setDismissable();
|
||||
}
|
||||
|
|
|
@ -96,18 +96,20 @@ auto Program::audioSample(const double* samples, uint channels) -> void {
|
|||
}
|
||||
|
||||
auto Program::inputPoll(uint port, uint device, uint input) -> int16 {
|
||||
if(allowInput()) {
|
||||
if(focused() || settings["Input/FocusLoss/AllowInput"].boolean()) {
|
||||
inputManager->poll();
|
||||
auto& mapping = inputManager->emulator->ports[port].devices[device].mappings[input];
|
||||
return mapping.poll();
|
||||
if(auto mapping = inputManager->mapping(port, device, input)) {
|
||||
return mapping->poll();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto Program::inputRumble(uint port, uint device, uint input, bool enable) -> void {
|
||||
if(allowInput() || !enable) {
|
||||
auto& mapping = inputManager->emulator->ports[port].devices[device].mappings[input];
|
||||
return mapping.rumble(enable);
|
||||
if(focused() || settings["Input/FocusLoss/AllowInput"].boolean() || !enable) {
|
||||
if(auto mapping = inputManager->mapping(port, device, input)) {
|
||||
return mapping->rumble(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ auto Program::main() -> void {
|
|||
inputManager->poll();
|
||||
inputManager->pollHotkeys();
|
||||
|
||||
if(!emulator || !emulator->loaded() || pause || (!presentation->focused() && settings["Input/FocusLoss/Pause"].boolean())) {
|
||||
if(!emulator || !emulator->loaded() || pause || (!focused() && settings["Input/FocusLoss/Pause"].boolean())) {
|
||||
audio->clear();
|
||||
usleep(20 * 1000);
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ struct Program : Emulator::Platform {
|
|||
auto updateVideoShader() -> void;
|
||||
auto updateAudioDriver() -> void;
|
||||
auto updateAudioEffects() -> void;
|
||||
auto allowInput(bool hotkey = false) -> bool;
|
||||
auto focused() -> bool;
|
||||
|
||||
bool hasQuit = false;
|
||||
bool pause = false;
|
||||
|
|
|
@ -93,7 +93,7 @@ auto Program::updateAudioEffects() -> void {
|
|||
Emulator::audio.setReverb(reverbEnable);
|
||||
}
|
||||
|
||||
auto Program::allowInput(bool hotkey) -> bool {
|
||||
auto Program::focused() -> bool {
|
||||
//exclusive mode creates its own top-level window: presentation window will not have focus
|
||||
if(video->cap(Video::Exclusive)) {
|
||||
auto value = video->get(Video::Exclusive);
|
||||
|
@ -102,7 +102,5 @@ auto Program::allowInput(bool hotkey) -> bool {
|
|||
|
||||
if(presentation && presentation->focused()) return true;
|
||||
|
||||
if(!hotkey && settings["Input/FocusLoss/AllowInput"].boolean()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ SettingsManager::SettingsManager() {
|
|||
setTitle("Configuration Settings");
|
||||
setSize({600, 405});
|
||||
setAlignment({0.0, 1.0});
|
||||
setDismissable();
|
||||
|
||||
onSize([&] {
|
||||
input.mappingList.resizeColumns();
|
||||
|
|
|
@ -12,6 +12,7 @@ CheatDatabase::CheatDatabase() {
|
|||
|
||||
setSize({800, 400});
|
||||
setAlignment({0.5, 1.0});
|
||||
setDismissable();
|
||||
}
|
||||
|
||||
auto CheatDatabase::findCodes() -> void {
|
||||
|
|
|
@ -14,6 +14,7 @@ ToolsManager::ToolsManager() {
|
|||
setTitle("Tools");
|
||||
setSize({600, 405});
|
||||
setAlignment({1.0, 1.0});
|
||||
setDismissable();
|
||||
|
||||
onSize([&] {
|
||||
cheatEditor.cheatList.resizeColumns();
|
||||
|
|
|
@ -243,6 +243,10 @@ auto pWindow::setBackgroundColor(Color color) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
auto pWindow::setDismissable(bool dismissable) -> void {
|
||||
//todo: not implemented
|
||||
}
|
||||
|
||||
auto pWindow::setDroppable(bool droppable) -> void {
|
||||
@autoreleasepool {
|
||||
if(droppable) {
|
||||
|
@ -404,15 +408,6 @@ auto pWindow::_geometry() -> Geometry {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
auto pWindow::remove(Widget& widget) -> void {
|
||||
@autoreleasepool {
|
||||
[widget.p.cocoaView removeFromSuperview];
|
||||
[[cocoaWindow contentView] setNeedsDisplay:YES];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,6 +39,7 @@ struct pWindow : pObject {
|
|||
auto remove(sMenuBar menuBar) -> void;
|
||||
auto remove(sStatusBar statusBar) -> void;
|
||||
auto setBackgroundColor(Color color) -> void;
|
||||
auto setDismissable(bool dismissable) -> void;
|
||||
auto setDroppable(bool droppable) -> void;
|
||||
auto setFocused() -> void override;
|
||||
auto setFullScreen(bool fullScreen) -> void;
|
||||
|
|
|
@ -672,6 +672,7 @@ struct mWindow : mObject {
|
|||
auto append(sMenuBar menuBar) -> type&;
|
||||
auto append(sStatusBar statusBar) -> type&;
|
||||
auto backgroundColor() const -> Color;
|
||||
auto dismissable() const -> bool;
|
||||
auto doClose() const -> void;
|
||||
auto doDrop(string_vector) const -> void;
|
||||
auto doKeyPress(signed) const -> void;
|
||||
|
@ -699,6 +700,7 @@ struct mWindow : mObject {
|
|||
auto setAlignment(Alignment alignment) -> type&;
|
||||
auto setBackgroundColor(Color color = {}) -> type&;
|
||||
auto setCentered(sWindow parent = {}) -> type&;
|
||||
auto setDismissable(bool dismissable = true) -> type&;
|
||||
auto setDroppable(bool droppable = true) -> type&;
|
||||
auto setFrameGeometry(Geometry geometry) -> type&;
|
||||
auto setFramePosition(Position position) -> type&;
|
||||
|
@ -716,6 +718,7 @@ struct mWindow : mObject {
|
|||
//private:
|
||||
struct State {
|
||||
Color backgroundColor;
|
||||
bool dismissable = false;
|
||||
bool droppable = false;
|
||||
bool fullScreen = false;
|
||||
Geometry geometry = {128, 128, 256, 256};
|
||||
|
|
|
@ -936,6 +936,7 @@ struct Window : sWindow {
|
|||
auto append(sMenuBar menuBar) { return self().append(menuBar), *this; }
|
||||
auto append(sStatusBar statusBar) { return self().append(statusBar), *this; }
|
||||
auto backgroundColor() const { return self().backgroundColor(); }
|
||||
auto dismissable() const { return self().dismissable(); }
|
||||
auto doClose() const { return self().doClose(); }
|
||||
auto doDrop(string_vector names) const { return self().doDrop(names); }
|
||||
auto doKeyPress(signed key) const { return self().doKeyPress(key); }
|
||||
|
@ -963,6 +964,7 @@ struct Window : sWindow {
|
|||
auto setAlignment(Alignment alignment) { return self().setAlignment(alignment), *this; }
|
||||
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
|
||||
auto setCentered(sWindow parent = {}) { return self().setCentered(parent), *this; }
|
||||
auto setDismissable(bool dismissable = true) { return self().setDismissable(dismissable), *this; }
|
||||
auto setDroppable(bool droppable = true) { return self().setDroppable(droppable), *this; }
|
||||
auto setFrameGeometry(Geometry geometry) { return self().setFrameGeometry(geometry), *this; }
|
||||
auto setFramePosition(Position position) { return self().setFramePosition(position), *this; }
|
||||
|
|
|
@ -43,6 +43,10 @@ auto mWindow::backgroundColor() const -> Color {
|
|||
return state.backgroundColor;
|
||||
}
|
||||
|
||||
auto mWindow::dismissable() const -> bool {
|
||||
return state.dismissable;
|
||||
}
|
||||
|
||||
auto mWindow::doClose() const -> void {
|
||||
if(state.onClose) return state.onClose();
|
||||
}
|
||||
|
@ -188,6 +192,12 @@ auto mWindow::setCentered(sWindow parent) -> type& {
|
|||
return setFrameGeometry({x, y, geometry.width(), geometry.height()});
|
||||
}
|
||||
|
||||
auto mWindow::setDismissable(bool dismissable) -> type& {
|
||||
state.dismissable = dismissable;
|
||||
signal(setDismissable, dismissable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto mWindow::setDroppable(bool droppable) -> type& {
|
||||
state.droppable = droppable;
|
||||
signal(setDroppable, droppable);
|
||||
|
|
|
@ -153,6 +153,7 @@ auto BrowserDialogWindow::run() -> BrowserDialog::Response {
|
|||
window.setTitle(state.title);
|
||||
window.setSize({640, 480});
|
||||
window.setCentered(state.parent);
|
||||
window.setDismissable();
|
||||
window.setVisible();
|
||||
view.setFocused();
|
||||
window.setModal();
|
||||
|
|
|
@ -71,6 +71,7 @@ auto MessageDialog::_run() -> string {
|
|||
window.setResizable(false);
|
||||
window.setSize({width, layout.minimumSize().height()});
|
||||
window.setCentered(state.parent);
|
||||
window.setDismissable();
|
||||
window.setVisible();
|
||||
window.setModal();
|
||||
window.setVisible(false);
|
||||
|
|
|
@ -89,6 +89,14 @@ static auto Window_keyPress(GtkWidget* widget, GdkEventKey* event, pWindow* p) -
|
|||
if(auto key = pKeyboard::_translate(event->keyval)) {
|
||||
p->self().doKeyPress(key);
|
||||
}
|
||||
if(p->state().dismissable && event->keyval == GDK_Escape) {
|
||||
if(p->state().onClose) {
|
||||
p->self().doClose();
|
||||
} else {
|
||||
p->self().setVisible(false);
|
||||
}
|
||||
if(p->state().modal && !p->pObject::state().visible) p->self().setModal(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -234,6 +242,9 @@ auto pWindow::setBackgroundColor(Color color) -> void {
|
|||
gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
|
||||
}
|
||||
|
||||
auto pWindow::setDismissable(bool dismissable) -> void {
|
||||
}
|
||||
|
||||
auto pWindow::setDroppable(bool droppable) -> void {
|
||||
gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, nullptr, 0, GDK_ACTION_COPY);
|
||||
if(droppable) gtk_drag_dest_add_uri_targets(widget);
|
||||
|
|
|
@ -14,6 +14,7 @@ struct pWindow : pObject {
|
|||
auto remove(sMenuBar menuBar) -> void;
|
||||
auto remove(sStatusBar statusBar) -> void;
|
||||
auto setBackgroundColor(Color color) -> void;
|
||||
auto setDismissable(bool dismissable) -> void;
|
||||
auto setDroppable(bool droppable) -> void;
|
||||
auto setEnabled(bool enabled) -> void override;
|
||||
auto setFocused() -> void override;
|
||||
|
|
|
@ -100,6 +100,9 @@ auto pWindow::setBackgroundColor(Color color) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
auto pWindow::setDismissable(bool dismissable) -> void {
|
||||
}
|
||||
|
||||
auto pWindow::setDroppable(bool droppable) -> void {
|
||||
qtWindow->setAcceptDrops(droppable);
|
||||
}
|
||||
|
@ -144,10 +147,6 @@ auto pWindow::setGeometry(Geometry geometry) -> void {
|
|||
qtContainer->setMinimumSize(1, 1);
|
||||
}
|
||||
|
||||
// for(auto& layout : window.state.layout) {
|
||||
// geometry.x = geometry.y = 0;
|
||||
// layout.setGeometry(geometry);
|
||||
// }
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
@ -194,20 +193,6 @@ auto pWindow::setVisible(bool visible) -> void {
|
|||
unlock();
|
||||
}
|
||||
|
||||
/*
|
||||
if(!widget.font() && window.state.widgetFont) {
|
||||
widget.setFont(window.state.widgetFont);
|
||||
}
|
||||
if(!widget.font()) widget.p.setFont(Font::sans(8));
|
||||
if(GetParentWidget(&widget)) {
|
||||
widget.p.qtWidget->setParent(GetParentWidget(&widget)->p.container(widget));
|
||||
} else {
|
||||
widget.p.qtWidget->setParent(qtContainer);
|
||||
}
|
||||
widget.setVisible(widget.visible());
|
||||
}
|
||||
*/
|
||||
|
||||
auto pWindow::_append(mWidget& widget) -> void {
|
||||
if(auto self = widget.self()) {
|
||||
self->qtWidget->setParent(qtContainer);
|
||||
|
@ -274,13 +259,19 @@ auto QtWindow::dropEvent(QDropEvent* event) -> void {
|
|||
}
|
||||
|
||||
auto QtWindow::keyPressEvent(QKeyEvent* event) -> void {
|
||||
// Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
|
||||
// if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym);
|
||||
//Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
|
||||
//if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym);
|
||||
|
||||
if(p.state().dismissable && event->key() == Qt::Key_Escape) {
|
||||
if(p.state().onClose) p.self().doClose();
|
||||
else p.self().setVisible(false);
|
||||
if(p.state().modal && !p.self().visible()) p.self().setModal(false);
|
||||
}
|
||||
}
|
||||
|
||||
auto QtWindow::keyReleaseEvent(QKeyEvent* event) -> void {
|
||||
// Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
|
||||
// if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym);
|
||||
//Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
|
||||
//if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym);
|
||||
}
|
||||
|
||||
auto QtWindow::resizeEvent(QResizeEvent*) -> void {
|
||||
|
|
|
@ -14,6 +14,7 @@ struct pWindow : pObject {
|
|||
auto remove(sMenuBar menuBar) -> void;
|
||||
auto remove(sStatusBar statusBar) -> void;
|
||||
auto setBackgroundColor(Color color) -> void;
|
||||
auto setDismissable(bool dismissable) -> void;
|
||||
auto setDroppable(bool droppable) -> void;
|
||||
auto setEnabled(bool enabled) -> void override;
|
||||
auto setFocused() -> void override;
|
||||
|
|
|
@ -146,8 +146,15 @@ static auto Application_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
|
|||
if(auto self = window->self()) {
|
||||
if(!self->_modalityDisabled()) {
|
||||
if(auto code = pKeyboard::_translate(wparam, lparam)) {
|
||||
if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) window->doKeyPress(code);
|
||||
if(msg == WM_KEYUP || msg == WM_SYSKEYUP) window->doKeyRelease(code);
|
||||
if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
|
||||
window->doKeyPress(code);
|
||||
}
|
||||
if(msg == WM_KEYUP || msg == WM_SYSKEYUP) {
|
||||
window->doKeyRelease(code);
|
||||
}
|
||||
}
|
||||
if(window->state.dismissable && msg == WM_KEYDOWN && wparam == VK_ESCAPE) {
|
||||
self->onClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,9 @@ auto pWindow::setBackgroundColor(Color color) -> void {
|
|||
if(color) hbrush = CreateSolidBrush(hbrushColor);
|
||||
}
|
||||
|
||||
auto pWindow::setDismissable(bool dismissable) -> void {
|
||||
}
|
||||
|
||||
auto pWindow::setDroppable(bool droppable) -> void {
|
||||
DragAcceptFiles(hwnd, droppable);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ struct pWindow : pObject {
|
|||
auto remove(sMenuBar menuBar) -> void;
|
||||
auto remove(sStatusBar statusBar) -> void;
|
||||
auto setBackgroundColor(Color color) -> void;
|
||||
auto setDismissable(bool dismissable) -> void;
|
||||
auto setDroppable(bool droppable) -> void;
|
||||
auto setEnabled(bool enabled) -> void;
|
||||
auto setFocused() -> void;
|
||||
|
|
|
@ -94,14 +94,14 @@ auto slice(string_view self, int offset, int length) -> string {
|
|||
|
||||
template<typename T> auto fromInteger(char* result, T value) -> char* {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = -value;
|
||||
if(!negative) value = -value; //negate positive integers to support eg INT_MIN
|
||||
|
||||
char buffer[1 + sizeof(T) * 3];
|
||||
uint size = 0;
|
||||
|
||||
do {
|
||||
uint n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
int n = value % 10; //-0 to -9
|
||||
buffer[size++] = '0' - n; //'0' to '9'
|
||||
value /= 10;
|
||||
} while(value);
|
||||
if(negative) buffer[size++] = '-';
|
||||
|
|
Loading…
Reference in New Issue