Update to v082r02 release.

byuu says:

Has Jonas Quinn's many Game Boy APU fixes, and two more from blargg's
notes that I added.

It also has the new dynamic phoenix. So yeah, it'll crash on bsnes/Qt
exit. If anyone can fix it *properly* and wants the money, I'll pay them
$20 for the trouble =)
This commit is contained in:
Tim Allen 2011-09-05 13:48:23 +10:00
parent d8f9204e18
commit a86c5ee59d
121 changed files with 3060 additions and 1188 deletions

View File

@ -80,10 +80,10 @@ uint8 APU::mmio_read(uint16 addr) {
if(addr == 0xff26) { if(addr == 0xff26) {
uint8 data = master.enable << 7; uint8 data = master.enable << 7;
if(square1.counter && square1.length) data |= 0x01; if(square1.enable) data |= 0x01;
if(square2.counter && square2.length) data |= 0x02; if(square2.enable) data |= 0x02;
if( wave.counter && wave.length) data |= 0x04; if( wave.enable) data |= 0x04;
if( noise.counter && noise.length) data |= 0x08; if( noise.enable) data |= 0x08;
return data | table[addr - 0xff10]; return data | table[addr - 0xff10];
} }

View File

@ -16,12 +16,6 @@ void APU::Master::run() {
sample >>= 2; sample >>= 2;
center = sclamp<16>(sample); center = sclamp<16>(sample);
if(left_enable == false && right_enable == false) {
left = center;
right = center;
return;
}
sample = 0; sample = 0;
channels = 0; channels = 0;
if(channel1_left_enable) { sample += apu.square1.output; channels++; } if(channel1_left_enable) { sample += apu.square1.output; channels++; }
@ -41,7 +35,6 @@ void APU::Master::run() {
case 6: left -= (left >> 3); break; // 87.5% case 6: left -= (left >> 3); break; // 87.5%
//case 7: break; //100.0% //case 7: break; //100.0%
} }
if(left_enable == false) left = 0;
sample = 0; sample = 0;
channels = 0; channels = 0;
@ -62,18 +55,17 @@ void APU::Master::run() {
case 6: right -= (right >> 3); break; // 87.5% case 6: right -= (right >> 3); break; // 87.5%
//case 7: break; //100.0% //case 7: break; //100.0%
} }
if(right_enable == false) right = 0;
} }
void APU::Master::write(unsigned r, uint8 data) { void APU::Master::write(unsigned r, uint8 data) {
if(r == 0) { if(r == 0) { //$ff24 NR50
left_enable = data & 0x80; left_in_enable = data & 0x80;
left_volume = (data >> 4) & 7; left_volume = (data >> 4) & 7;
right_enable = data & 0x08; right_in_enable = data & 0x08;
right_volume = (data >> 0) & 7; right_volume = (data >> 0) & 7;
} }
if(r == 1) { if(r == 1) { //$ff25 NR51
channel4_left_enable = data & 0x80; channel4_left_enable = data & 0x80;
channel3_left_enable = data & 0x40; channel3_left_enable = data & 0x40;
channel2_left_enable = data & 0x20; channel2_left_enable = data & 0x20;
@ -84,15 +76,15 @@ void APU::Master::write(unsigned r, uint8 data) {
channel1_right_enable = data & 0x01; channel1_right_enable = data & 0x01;
} }
if(r == 2) { if(r == 2) { //$ff26 NR52
enable = data & 0x80; enable = data & 0x80;
} }
} }
void APU::Master::power() { void APU::Master::power() {
left_enable = 0; left_in_enable = 0;
left_volume = 0; left_volume = 0;
right_enable = 0; right_in_enable = 0;
right_volume = 0; right_volume = 0;
channel4_left_enable = 0; channel4_left_enable = 0;
channel3_left_enable = 0; channel3_left_enable = 0;
@ -110,9 +102,9 @@ void APU::Master::power() {
} }
void APU::Master::serialize(serializer &s) { void APU::Master::serialize(serializer &s) {
s.integer(left_enable); s.integer(left_in_enable);
s.integer(left_volume); s.integer(left_volume);
s.integer(right_enable); s.integer(right_in_enable);
s.integer(right_volume); s.integer(right_volume);
s.integer(channel4_left_enable); s.integer(channel4_left_enable);
s.integer(channel3_left_enable); s.integer(channel3_left_enable);

View File

@ -1,7 +1,7 @@
struct Master { struct Master {
bool left_enable; bool left_in_enable;
unsigned left_volume; unsigned left_volume;
bool right_enable; bool right_in_enable;
unsigned right_volume; unsigned right_volume;
bool channel4_left_enable; bool channel4_left_enable;
bool channel3_left_enable; bool channel3_left_enable;

View File

@ -1,5 +1,9 @@
#ifdef APU_CPP #ifdef APU_CPP
bool APU::Noise::dac_enable() {
return (envelope_volume || envelope_direction);
}
void APU::Noise::run() { void APU::Noise::run() {
if(period && --period == 0) { if(period && --period == 0) {
period = divisor << frequency; period = divisor << frequency;
@ -10,36 +14,39 @@ void APU::Noise::run() {
} }
uint4 sample = (lfsr & 1) ? 0 : volume; uint4 sample = (lfsr & 1) ? 0 : volume;
if(counter && length == 0) sample = 0; if(enable == false) sample = 0;
output = (sample * 4369) - 32768; output = (sample * 4369) - 32768;
} }
void APU::Noise::clock_length() { void APU::Noise::clock_length() {
if(counter && length) length--; if(counter && length) {
if(--length == 0) enable = false;
}
} }
void APU::Noise::clock_envelope() { void APU::Noise::clock_envelope() {
if(envelope_period && --envelope_period == 0) { if(envelope_period && --envelope_period == 0) {
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
if(envelope_period == 0) envelope_period = 8;
if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 0 && volume > 0) volume--;
if(envelope_direction == 1 && volume < 15) volume++; if(envelope_direction == 1 && volume < 15) volume++;
} }
} }
void APU::Noise::write(unsigned r, uint8 data) { void APU::Noise::write(unsigned r, uint8 data) {
if(r == 1) { if(r == 1) { //$ff20 NR41
initial_length = 64 - (data & 0x3f); length = 64 - (data & 0x3f);
length = initial_length;
} }
if(r == 2) { if(r == 2) { //$ff21 NR42
envelope_volume = data >> 4; envelope_volume = data >> 4;
envelope_direction = data & 0x08; envelope_direction = data & 0x08;
envelope_frequency = data & 0x07; envelope_frequency = data & 0x07;
if(dac_enable() == false) enable = false;
} }
if(r == 3) { if(r == 3) { //$ff22 NR43
frequency = data >> 4; frequency = data >> 4;
narrow_lfsr = data & 0x08; narrow_lfsr = data & 0x08;
divisor = (data & 0x07) << 4; divisor = (data & 0x07) << 4;
@ -47,20 +54,23 @@ void APU::Noise::write(unsigned r, uint8 data) {
period = divisor << frequency; period = divisor << frequency;
} }
if(r == 4) { if(r == 4) { //$ff34 NR44
bool initialize = data & 0x80; bool initialize = data & 0x80;
counter = data & 0x40; counter = data & 0x40;
if(initialize) { if(initialize) {
enable = dac_enable();
lfsr = ~0U; lfsr = ~0U;
length = initial_length;
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
volume = envelope_volume; volume = envelope_volume;
if(length == 0) length = 64;
} }
} }
} }
void APU::Noise::power() { void APU::Noise::power() {
enable = 0;
envelope_volume = 0; envelope_volume = 0;
envelope_direction = 0; envelope_direction = 0;
envelope_frequency = 0; envelope_frequency = 0;
@ -70,7 +80,6 @@ void APU::Noise::power() {
counter = 0; counter = 0;
output = 0; output = 0;
initial_length = 0;
length = 0; length = 0;
envelope_period = 0; envelope_period = 0;
volume = 0; volume = 0;
@ -79,6 +88,8 @@ void APU::Noise::power() {
} }
void APU::Noise::serialize(serializer &s) { void APU::Noise::serialize(serializer &s) {
s.integer(enable);
s.integer(envelope_volume); s.integer(envelope_volume);
s.integer(envelope_direction); s.integer(envelope_direction);
s.integer(envelope_frequency); s.integer(envelope_frequency);
@ -88,7 +99,6 @@ void APU::Noise::serialize(serializer &s) {
s.integer(counter); s.integer(counter);
s.integer(output); s.integer(output);
s.integer(initial_length);
s.integer(length); s.integer(length);
s.integer(envelope_period); s.integer(envelope_period);
s.integer(volume); s.integer(volume);

View File

@ -1,4 +1,6 @@
struct Noise { struct Noise {
bool enable;
unsigned envelope_volume; unsigned envelope_volume;
bool envelope_direction; bool envelope_direction;
unsigned envelope_frequency; unsigned envelope_frequency;
@ -8,13 +10,14 @@ struct Noise {
bool counter; bool counter;
int16 output; int16 output;
unsigned initial_length;
unsigned length; unsigned length;
unsigned envelope_period; unsigned envelope_period;
unsigned volume; unsigned volume;
unsigned period; unsigned period;
uint15 lfsr; uint15 lfsr;
bool dac_enable();
void run(); void run();
void clock_length(); void clock_length();
void clock_envelope(); void clock_envelope();

View File

@ -1,5 +1,9 @@
#ifdef APU_CPP #ifdef APU_CPP
bool APU::Square1::dac_enable() {
return (envelope_volume || envelope_direction);
}
void APU::Square1::run() { void APU::Square1::run() {
if(period && --period == 0) { if(period && --period == 0) {
period = 4 * (2048 - frequency); period = 4 * (2048 - frequency);
@ -13,86 +17,92 @@ void APU::Square1::run() {
} }
uint4 sample = (duty_output ? volume : 0); uint4 sample = (duty_output ? volume : 0);
if(counter && length == 0) sample = 0; if(enable == false) sample = 0;
output = (sample * 4369) - 32768; output = (sample * 4369) - 32768;
} }
void APU::Square1::sweep() { void APU::Square1::sweep(bool update) {
if(enable == false) return; if(sweep_enable == false) return;
signed offset = frequency_shadow >> sweep_shift; sweep_negate = sweep_direction;
if(sweep_direction) offset = -offset; unsigned delta = frequency_shadow >> sweep_shift;
frequency_shadow += offset; signed freq = frequency_shadow + (sweep_negate ? -delta : delta);
if(frequency_shadow < 0) { if(freq > 2047) {
frequency_shadow = 0;
} else if(frequency_shadow > 2047) {
frequency_shadow = 2048;
enable = false; enable = false;
} } else if(sweep_shift && update) {
frequency_shadow = freq;
if(frequency_shadow <= 2047 && sweep_shift) { frequency = freq & 2047;
frequency = frequency_shadow;
period = 4 * (2048 - frequency); period = 4 * (2048 - frequency);
} }
} }
void APU::Square1::clock_length() { void APU::Square1::clock_length() {
if(counter && length) length--; if(counter && length) {
if(--length == 0) enable = false;
}
} }
void APU::Square1::clock_sweep() { void APU::Square1::clock_sweep() {
if(sweep_frequency && sweep_period && --sweep_period == 0) { if(enable && --sweep_period == 0) {
sweep_period = sweep_frequency; sweep_period = sweep_frequency;
sweep(); if(sweep_period == 0) sweep_period = 8;
if(sweep_frequency) {
sweep(1);
sweep(0);
}
} }
} }
void APU::Square1::clock_envelope() { void APU::Square1::clock_envelope() {
if(envelope_period && --envelope_period == 0) { if(envelope_period && --envelope_period == 0) {
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
if(envelope_period == 0) envelope_period = 8;
if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 0 && volume > 0) volume--;
if(envelope_direction == 1 && volume < 15) volume++; if(envelope_direction == 1 && volume < 15) volume++;
} }
} }
void APU::Square1::write(unsigned r, uint8 data) { void APU::Square1::write(unsigned r, uint8 data) {
if(r == 0) { if(r == 0) { //$ff10 NR10
if(sweep_negate && sweep_direction && !(data & 0x08)) enable = false;
sweep_frequency = (data >> 4) & 7; sweep_frequency = (data >> 4) & 7;
sweep_direction = data & 0x08; sweep_direction = data & 0x08;
sweep_shift = data & 0x07; sweep_shift = data & 0x07;
} }
if(r == 1) { if(r == 1) { //$ff11 NR11
duty = data >> 6; duty = data >> 6;
initial_length = 64 - (data & 0x3f); length = 64 - (data & 0x3f);
length = initial_length;
} }
if(r == 2) { if(r == 2) { //$ff12 NR12
envelope_volume = data >> 4; envelope_volume = data >> 4;
envelope_direction = data & 0x08; envelope_direction = data & 0x08;
envelope_frequency = data & 0x07; envelope_frequency = data & 0x07;
if(dac_enable() == false) enable = false;
} }
if(r == 3) { if(r == 3) { //$ff13 NR13
frequency = (frequency & 0x0700) | data; frequency = (frequency & 0x0700) | data;
} }
if(r == 4) { if(r == 4) { //$ff14 NR14
bool initialize = data & 0x80; bool initialize = data & 0x80;
counter = data & 0x40; counter = data & 0x40;
frequency = ((data & 7) << 8) | (frequency & 0x00ff); frequency = ((data & 7) << 8) | (frequency & 0x00ff);
if(initialize) { if(initialize) {
length = initial_length; enable = dac_enable();
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
volume = envelope_volume; volume = envelope_volume;
frequency_shadow = frequency; frequency_shadow = frequency;
sweep_period = sweep_frequency; sweep_period = sweep_frequency;
enable = sweep_period || sweep_shift; sweep_enable = sweep_period || sweep_shift;
if(sweep_shift) sweep(); sweep_negate = false;
if(sweep_shift) sweep(0);
if(length == 0) length = 64;
} }
} }
@ -100,11 +110,13 @@ void APU::Square1::write(unsigned r, uint8 data) {
} }
void APU::Square1::power() { void APU::Square1::power() {
enable = 0;
sweep_frequency = 0; sweep_frequency = 0;
sweep_direction = 0; sweep_direction = 0;
sweep_shift = 0; sweep_shift = 0;
sweep_negate = 0;
duty = 0; duty = 0;
initial_length = 0;
length = 0; length = 0;
envelope_volume = 0; envelope_volume = 0;
envelope_direction = 0; envelope_direction = 0;
@ -119,16 +131,18 @@ void APU::Square1::power() {
envelope_period = 0; envelope_period = 0;
sweep_period = 0; sweep_period = 0;
frequency_shadow = 0; frequency_shadow = 0;
enable = 0; sweep_enable = 0;
volume = 0; volume = 0;
} }
void APU::Square1::serialize(serializer &s) { void APU::Square1::serialize(serializer &s) {
s.integer(enable);
s.integer(sweep_frequency); s.integer(sweep_frequency);
s.integer(sweep_direction); s.integer(sweep_direction);
s.integer(sweep_shift); s.integer(sweep_shift);
s.integer(sweep_negate);
s.integer(duty); s.integer(duty);
s.integer(initial_length);
s.integer(length); s.integer(length);
s.integer(envelope_volume); s.integer(envelope_volume);
s.integer(envelope_direction); s.integer(envelope_direction);
@ -143,7 +157,7 @@ void APU::Square1::serialize(serializer &s) {
s.integer(envelope_period); s.integer(envelope_period);
s.integer(sweep_period); s.integer(sweep_period);
s.integer(frequency_shadow); s.integer(frequency_shadow);
s.integer(enable); s.integer(sweep_enable);
s.integer(volume); s.integer(volume);
} }

View File

@ -1,9 +1,11 @@
struct Square1 { struct Square1 {
bool enable;
unsigned sweep_frequency; unsigned sweep_frequency;
unsigned sweep_direction; unsigned sweep_direction;
unsigned sweep_shift; unsigned sweep_shift;
bool sweep_negate;
unsigned duty; unsigned duty;
unsigned initial_length;
unsigned length; unsigned length;
unsigned envelope_volume; unsigned envelope_volume;
unsigned envelope_direction; unsigned envelope_direction;
@ -18,11 +20,13 @@ struct Square1 {
unsigned envelope_period; unsigned envelope_period;
unsigned sweep_period; unsigned sweep_period;
signed frequency_shadow; signed frequency_shadow;
bool enable; bool sweep_enable;
unsigned volume; unsigned volume;
bool dac_enable();
void run(); void run();
void sweep(); void sweep(bool update);
void clock_length(); void clock_length();
void clock_sweep(); void clock_sweep();
void clock_envelope(); void clock_envelope();

View File

@ -1,5 +1,9 @@
#ifdef APU_CPP #ifdef APU_CPP
bool APU::Square2::dac_enable() {
return (envelope_volume || envelope_direction);
}
void APU::Square2::run() { void APU::Square2::run() {
if(period && --period == 0) { if(period && --period == 0) {
period = 4 * (2048 - frequency); period = 4 * (2048 - frequency);
@ -13,49 +17,53 @@ void APU::Square2::run() {
} }
uint4 sample = (duty_output ? volume : 0); uint4 sample = (duty_output ? volume : 0);
if(counter && length == 0) sample = 0; if(enable == false) sample = 0;
output = (sample * 4369) - 32768; output = (sample * 4369) - 32768;
} }
void APU::Square2::clock_length() { void APU::Square2::clock_length() {
if(counter && length) length--; if(counter && length) {
if(--length == 0) enable = false;
}
} }
void APU::Square2::clock_envelope() { void APU::Square2::clock_envelope() {
if(envelope_period && --envelope_period == 0) { if(envelope_period && --envelope_period == 0) {
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
if(envelope_period == 0) envelope_period = 8;
if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 0 && volume > 0) volume--;
if(envelope_direction == 1 && volume < 15) volume++; if(envelope_direction == 1 && volume < 15) volume++;
} }
} }
void APU::Square2::write(unsigned r, uint8 data) { void APU::Square2::write(unsigned r, uint8 data) {
if(r == 1) { if(r == 1) { //$ff16 NR21
duty = data >> 6; duty = data >> 6;
initial_length = 64 - (data & 0x3f); length = 64 - (data & 0x3f);
length = initial_length;
} }
if(r == 2) { if(r == 2) { //$ff17 NR22
envelope_volume = data >> 4; envelope_volume = data >> 4;
envelope_direction = data & 0x08; envelope_direction = data & 0x08;
envelope_frequency = data & 0x07; envelope_frequency = data & 0x07;
if(dac_enable() == false) enable = false;
} }
if(r == 3) { if(r == 3) { //$ff18 NR23
frequency = (frequency & 0x0700) | data; frequency = (frequency & 0x0700) | data;
} }
if(r == 4) { if(r == 4) { //$ff19 NR24
bool initialize = data & 0x80; bool initialize = data & 0x80;
counter = data & 0x40; counter = data & 0x40;
frequency = ((data & 7) << 8) | (frequency & 0x00ff); frequency = ((data & 7) << 8) | (frequency & 0x00ff);
if(initialize) { if(initialize) {
length = initial_length; enable = dac_enable();
envelope_period = envelope_frequency; envelope_period = envelope_frequency;
volume = envelope_volume; volume = envelope_volume;
if(length == 0) length = 64;
} }
} }
@ -63,8 +71,9 @@ void APU::Square2::write(unsigned r, uint8 data) {
} }
void APU::Square2::power() { void APU::Square2::power() {
enable = 0;
duty = 0; duty = 0;
initial_length = 0;
length = 0; length = 0;
envelope_volume = 0; envelope_volume = 0;
envelope_direction = 0; envelope_direction = 0;
@ -81,8 +90,9 @@ void APU::Square2::power() {
} }
void APU::Square2::serialize(serializer &s) { void APU::Square2::serialize(serializer &s) {
s.integer(enable);
s.integer(duty); s.integer(duty);
s.integer(initial_length);
s.integer(length); s.integer(length);
s.integer(envelope_volume); s.integer(envelope_volume);
s.integer(envelope_direction); s.integer(envelope_direction);

View File

@ -1,6 +1,7 @@
struct Square2 { struct Square2 {
bool enable;
unsigned duty; unsigned duty;
unsigned initial_length;
unsigned length; unsigned length;
unsigned envelope_volume; unsigned envelope_volume;
unsigned envelope_direction; unsigned envelope_direction;
@ -15,6 +16,8 @@ struct Square2 {
unsigned envelope_period; unsigned envelope_period;
unsigned volume; unsigned volume;
bool dac_enable();
void run(); void run();
void clock_length(); void clock_length();
void clock_envelope(); void clock_envelope();

View File

@ -8,7 +8,6 @@ void APU::Wave::run() {
} }
uint4 sample = pattern_sample; uint4 sample = pattern_sample;
if(counter && length == 0) sample = 0;
if(enable == false) sample = 0; if(enable == false) sample = 0;
output = (sample * 4369) - 32768; output = (sample * 4369) - 32768;
@ -16,22 +15,22 @@ void APU::Wave::run() {
} }
void APU::Wave::clock_length() { void APU::Wave::clock_length() {
if(counter && length) length--; if(counter && length) {
if(--length == 0) enable = false;
}
} }
void APU::Wave::write(unsigned r, uint8 data) { void APU::Wave::write(unsigned r, uint8 data) {
if(r == 0) { if(r == 0) { //$ff1a NR30
dac_enable = data & 0x80; dac_enable = data & 0x80;
if(dac_enable == false) enable = false; if(dac_enable == false) enable = false;
} }
if(r == 1) { if(r == 1) { //$ff1b NR31
initial_length = 256 - data; length = 256 - data;
length = initial_length;
} }
if(r == 2) { if(r == 2) { //$ff1c NR32
switch((data >> 5) & 3) { switch((data >> 5) & 3) {
case 0: volume = 16; break; // 0% case 0: volume = 16; break; // 0%
case 1: volume = 0; break; //100% case 1: volume = 0; break; //100%
@ -40,19 +39,19 @@ void APU::Wave::write(unsigned r, uint8 data) {
} }
} }
if(r == 3) { if(r == 3) { //$ff1d NR33
frequency = (frequency & 0x0700) | data; frequency = (frequency & 0x0700) | data;
} }
if(r == 4) { if(r == 4) { //$ff1e NR34
bool initialize = data & 0x80; bool initialize = data & 0x80;
counter = data & 0x40; counter = data & 0x40;
frequency = ((data & 7) << 8) | (frequency & 0x00ff); frequency = ((data & 7) << 8) | (frequency & 0x00ff);
if(initialize && dac_enable) { if(initialize) {
enable = true; enable = dac_enable;
pattern_offset = 0; pattern_offset = 0;
length = initial_length; if(length == 0) length = 256;
} }
} }
@ -66,6 +65,8 @@ void APU::Wave::write_pattern(unsigned p, uint8 data) {
} }
void APU::Wave::power() { void APU::Wave::power() {
enable = 0;
dac_enable = 0; dac_enable = 0;
volume = 0; volume = 0;
frequency = 0; frequency = 0;
@ -75,8 +76,6 @@ void APU::Wave::power() {
foreach(n, pattern) n = r() & 15; foreach(n, pattern) n = r() & 15;
output = 0; output = 0;
enable = 0;
initial_length = 0;
length = 0; length = 0;
period = 0; period = 0;
pattern_offset = 0; pattern_offset = 0;
@ -84,6 +83,8 @@ void APU::Wave::power() {
} }
void APU::Wave::serialize(serializer &s) { void APU::Wave::serialize(serializer &s) {
s.integer(enable);
s.integer(dac_enable); s.integer(dac_enable);
s.integer(volume); s.integer(volume);
s.integer(frequency); s.integer(frequency);
@ -91,8 +92,6 @@ void APU::Wave::serialize(serializer &s) {
s.array(pattern); s.array(pattern);
s.integer(output); s.integer(output);
s.integer(enable);
s.integer(initial_length);
s.integer(length); s.integer(length);
s.integer(period); s.integer(period);
s.integer(pattern_offset); s.integer(pattern_offset);

View File

@ -1,4 +1,6 @@
struct Wave { struct Wave {
bool enable;
bool dac_enable; bool dac_enable;
unsigned volume; unsigned volume;
unsigned frequency; unsigned frequency;
@ -6,8 +8,6 @@ struct Wave {
uint8 pattern[32]; uint8 pattern[32];
int16 output; int16 output;
bool enable;
unsigned initial_length;
unsigned length; unsigned length;
unsigned period; unsigned period;
unsigned pattern_offset; unsigned pattern_offset;

View File

@ -5,7 +5,7 @@
namespace GameBoy { namespace GameBoy {
namespace Info { namespace Info {
static const char Name[] = "bgameboy"; static const char Name[] = "bgameboy";
static const char Version[] = "000.21"; static const char Version[] = "000.22";
static unsigned SerializerVersion = 2; static unsigned SerializerVersion = 2;
} }
} }

View File

@ -46,9 +46,9 @@ protected:
IEND = 0x49454e44, IEND = 0x49454e44,
}; };
static const unsigned interlace[7][4];
unsigned bitpos; unsigned bitpos;
inline unsigned interlace(unsigned pass, unsigned index);
inline unsigned inflateSize(); inline unsigned inflateSize();
inline bool deinterlace(const uint8_t *&inputData, unsigned pass); inline bool deinterlace(const uint8_t *&inputData, unsigned pass);
inline bool filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height); inline bool filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height);
@ -172,16 +172,19 @@ bool png::decode(const uint8_t *sourceData, unsigned sourceSize) {
return true; return true;
} }
const unsigned png::interlace[7][4] = { unsigned png::interlace(unsigned pass, unsigned index) {
//x-distance, y-distance, x-origin, y-origin static const unsigned data[7][4] = {
{ 8, 8, 0, 0 }, //x-distance, y-distance, x-origin, y-origin
{ 8, 8, 4, 0 }, { 8, 8, 0, 0 },
{ 4, 8, 0, 4 }, { 8, 8, 4, 0 },
{ 4, 4, 2, 0 }, { 4, 8, 0, 4 },
{ 2, 4, 0, 2 }, { 4, 4, 2, 0 },
{ 2, 2, 1, 0 }, { 2, 4, 0, 2 },
{ 1, 2, 0, 1 }, { 2, 2, 1, 0 },
}; { 1, 2, 0, 1 },
};
return data[pass][index];
}
unsigned png::inflateSize() { unsigned png::inflateSize() {
if(info.interlaceMethod == 0) { if(info.interlaceMethod == 0) {
@ -190,8 +193,8 @@ unsigned png::inflateSize() {
unsigned size = 0; unsigned size = 0;
for(unsigned pass = 0; pass < 7; pass++) { for(unsigned pass = 0; pass < 7; pass++) {
unsigned xd = interlace[pass][0], yd = interlace[pass][1]; unsigned xd = interlace(pass, 0), yd = interlace(pass, 1);
unsigned xo = interlace[pass][2], yo = interlace[pass][3]; unsigned xo = interlace(pass, 2), yo = interlace(pass, 3);
unsigned width = (info.width + (xd - xo - 1)) / xd; unsigned width = (info.width + (xd - xo - 1)) / xd;
unsigned height = (info.height + (yd - yo - 1)) / yd; unsigned height = (info.height + (yd - yo - 1)) / yd;
if(width == 0 || height == 0) continue; if(width == 0 || height == 0) continue;
@ -201,8 +204,8 @@ unsigned png::inflateSize() {
} }
bool png::deinterlace(const uint8_t *&inputData, unsigned pass) { bool png::deinterlace(const uint8_t *&inputData, unsigned pass) {
unsigned xd = interlace[pass][0], yd = interlace[pass][1]; unsigned xd = interlace(pass, 0), yd = interlace(pass, 1);
unsigned xo = interlace[pass][2], yo = interlace[pass][3]; unsigned xo = interlace(pass, 2), yo = interlace(pass, 3);
unsigned width = (info.width + (xd - xo - 1)) / xd; unsigned width = (info.width + (xd - xo - 1)) / xd;
unsigned height = (info.height + (yd - yo - 1)) / yd; unsigned height = (info.height + (yd - yo - 1)) / yd;
if(width == 0 || height == 0) return true; if(width == 0 || height == 0) return true;

View File

@ -36,10 +36,26 @@ namespace nall {
buffersize = newsize; buffersize = newsize;
} }
void append(const T data) { bool append(const T data) {
for(unsigned index = 0; index < buffersize; index++) {
if(pool[index] == &data) return false;
}
unsigned index = buffersize++; unsigned index = buffersize++;
if(index >= poolsize) resize(index + 1); if(index >= poolsize) resize(index + 1);
pool[index] = &data; pool[index] = &data;
return true;
}
bool remove(const T data) {
for(unsigned index = 0; index < buffersize; index++) {
if(pool[index] == &data) {
for(unsigned i = index; i < buffersize - 1; i++) pool[i] = pool[i + 1];
resize(buffersize - 1);
return true;
}
}
return false;
} }
template<typename... Args> reference_array(Args&... args) : pool(0), poolsize(0), buffersize(0) { template<typename... Args> reference_array(Args&... args) : pool(0), poolsize(0), buffersize(0) {

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,13 @@
struct Font; struct Font;
struct Window; struct Window;
struct Menu; struct Menu;
struct Sizable;
struct Layout; struct Layout;
struct Widget; struct Widget;
struct pOS;
struct pFont; struct pFont;
struct pObject;
struct pOS;
struct pTimer; struct pTimer;
struct pWindow; struct pWindow;
struct pAction; struct pAction;
@ -14,6 +16,7 @@ struct pSeparator;
struct pItem; struct pItem;
struct pCheckItem; struct pCheckItem;
struct pRadioItem; struct pRadioItem;
struct pSizable;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pButton; struct pButton;
@ -45,6 +48,12 @@ struct Geometry {
inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {}
}; };
struct Font {
nall::string description;
Geometry geometry(const nall::string &text);
Font(const nall::string &description = "");
};
struct Color { struct Color {
uint8_t red, green, blue, alpha; uint8_t red, green, blue, alpha;
inline Color() : red(0), green(0), blue(0), alpha(255) {} inline Color() : red(0), green(0), blue(0), alpha(255) {}
@ -52,10 +61,11 @@ struct Color {
}; };
struct Object { struct Object {
Object(); Object(pObject &p);
Object& operator=(const Object&) = delete; Object& operator=(const Object&) = delete;
Object(const Object&) = delete; Object(const Object&) = delete;
virtual void unused() {} //allows dynamic_cast<> on Object virtual ~Object();
pObject &p;
}; };
struct OS : Object { struct OS : Object {
@ -77,27 +87,14 @@ private:
static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter); static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter);
}; };
struct Font : Object { struct Timer : private nall::base_from_member<pTimer&>, Object {
Geometry geometry(const nall::string &text);
void setBold(bool bold = true);
void setFamily(const nall::string &family);
void setItalic(bool italic = true);
void setSize(unsigned size);
void setUnderline(bool underline = true);
Font();
struct State;
State &state;
pFont &p;
};
struct Timer : Object {
nall::function<void ()> onTimeout; nall::function<void ()> onTimeout;
void setEnabled(bool enabled = true); void setEnabled(bool enabled = true);
void setInterval(unsigned milliseconds); void setInterval(unsigned milliseconds);
Timer(); Timer();
~Timer();
struct State; struct State;
State &state; State &state;
pTimer &p; pTimer &p;
@ -123,7 +120,7 @@ struct MessageWindow : Object {
static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok); static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
}; };
struct Window : Object { struct Window : private nall::base_from_member<pWindow&>, Object {
static Window None; static Window None;
nall::function<void ()> onClose; nall::function<void ()> onClose;
nall::function<void ()> onMove; nall::function<void ()> onMove;
@ -137,22 +134,28 @@ struct Window : Object {
Geometry frameMargin(); Geometry frameMargin();
bool focused(); bool focused();
Geometry geometry(); Geometry geometry();
void ignore();
void remove(Layout &layout);
void remove(Menu &menu);
void remove(Widget &widget);
void setBackgroundColor(const Color &color); void setBackgroundColor(const Color &color);
void setFrameGeometry(const Geometry &geometry); void setFrameGeometry(const Geometry &geometry);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen = true); void setFullScreen(bool fullScreen = true);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setMenuFont(Font &font); void setMenuFont(const nall::string &font);
void setMenuVisible(bool visible = true); void setMenuVisible(bool visible = true);
void setResizable(bool resizable = true); void setResizable(bool resizable = true);
void setStatusFont(Font &font); void setStatusFont(const nall::string &font);
void setStatusText(const nall::string &text); void setStatusText(const nall::string &text);
void setStatusVisible(bool visible = true); void setStatusVisible(bool visible = true);
void setTitle(const nall::string &text); void setTitle(const nall::string &text);
void setVisible(bool visible = true); void setVisible(bool visible = true);
void setWidgetFont(Font &font); void setWidgetFont(const nall::string &font);
void synchronize();
Window(); Window();
~Window();
struct State; struct State;
State &state; State &state;
pWindow &p; pWindow &p;
@ -163,6 +166,7 @@ struct Action : Object {
void setVisible(bool visible = true); void setVisible(bool visible = true);
Action(pAction &p); Action(pAction &p);
~Action();
struct State; struct State;
State &state; State &state;
pAction &p; pAction &p;
@ -170,9 +174,11 @@ struct Action : Object {
struct Menu : private nall::base_from_member<pMenu&>, Action { struct Menu : private nall::base_from_member<pMenu&>, Action {
void append(Action &action); void append(Action &action);
void remove(Action &action);
void setText(const nall::string &text); void setText(const nall::string &text);
Menu(); Menu();
~Menu();
struct State; struct State;
State &state; State &state;
pMenu &p; pMenu &p;
@ -180,6 +186,7 @@ struct Menu : private nall::base_from_member<pMenu&>, Action {
struct Separator : private nall::base_from_member<pSeparator&>, Action { struct Separator : private nall::base_from_member<pSeparator&>, Action {
Separator(); Separator();
~Separator();
pSeparator &p; pSeparator &p;
}; };
@ -189,6 +196,7 @@ struct Item : private nall::base_from_member<pItem&>, Action {
void setText(const nall::string &text); void setText(const nall::string &text);
Item(); Item();
~Item();
struct State; struct State;
State &state; State &state;
pItem &p; pItem &p;
@ -202,6 +210,7 @@ struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
void setText(const nall::string &text); void setText(const nall::string &text);
CheckItem(); CheckItem();
~CheckItem();
struct State; struct State;
State &state; State &state;
pCheckItem &p; pCheckItem &p;
@ -218,41 +227,58 @@ struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
void setText(const nall::string &text); void setText(const nall::string &text);
RadioItem(); RadioItem();
~RadioItem();
struct State; struct State;
State &state; State &state;
pRadioItem &p; pRadioItem &p;
}; };
struct Layout;
struct Sizable : Object { struct Sizable : Object {
virtual bool enabled() = 0;
Layout* layout();
virtual Geometry minimumGeometry() = 0; virtual Geometry minimumGeometry() = 0;
virtual void setEnabled(bool enabled = true) = 0;
virtual void setGeometry(const Geometry &geometry) = 0; virtual void setGeometry(const Geometry &geometry) = 0;
virtual void setLayout(Layout &layout) = 0;
virtual void setParent(Window &parent) = 0;
virtual void setVisible(bool visible = true) = 0; virtual void setVisible(bool visible = true) = 0;
virtual bool visible() = 0; virtual bool visible() = 0;
Window* window();
Sizable(pSizable &p);
~Sizable();
struct State;
State &state;
pSizable &p;
}; };
struct Layout : Sizable { struct Layout : private nall::base_from_member<pLayout&>, Sizable {
virtual void append(Sizable &sizable);
virtual void remove(Sizable &sizable);
virtual void reset() {}
virtual void synchronize() = 0;
Layout();
Layout(pLayout &p);
~Layout();
struct State;
State &state;
pLayout &p;
}; };
struct Widget : Sizable { struct Widget : private nall::base_from_member<pWidget&>, Sizable {
bool enabled(); bool enabled();
Font& font(); nall::string font();
Geometry geometry(); Geometry geometry();
Geometry minimumGeometry(); Geometry minimumGeometry();
void setEnabled(bool enabled = true); void setEnabled(bool enabled = true);
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(const nall::string &font);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setLayout(Layout &layout);
void setParent(Window &parent);
void setVisible(bool visible = true); void setVisible(bool visible = true);
bool visible(); bool visible();
Widget(); Widget();
Widget(pWidget &p); Widget(pWidget &p);
~Widget();
struct State; struct State;
State &state; State &state;
pWidget &p; pWidget &p;
@ -264,6 +290,7 @@ struct Button : private nall::base_from_member<pButton&>, Widget {
void setText(const nall::string &text); void setText(const nall::string &text);
Button(); Button();
~Button();
struct State; struct State;
State &state; State &state;
pButton &p; pButton &p;
@ -274,6 +301,7 @@ struct Canvas : private nall::base_from_member<pCanvas&>, Widget {
void update(); void update();
Canvas(); Canvas();
~Canvas();
pCanvas &p; pCanvas &p;
}; };
@ -285,6 +313,7 @@ struct CheckBox : private nall::base_from_member<pCheckBox&>, Widget {
void setText(const nall::string &text); void setText(const nall::string &text);
CheckBox(); CheckBox();
~CheckBox();
struct State; struct State;
State &state; State &state;
pCheckBox &p; pCheckBox &p;
@ -299,6 +328,7 @@ struct ComboBox : private nall::base_from_member<pComboBox&>, Widget {
void setSelection(unsigned row); void setSelection(unsigned row);
ComboBox(); ComboBox();
~ComboBox();
struct State; struct State;
State &state; State &state;
pComboBox &p; pComboBox &p;
@ -315,6 +345,7 @@ struct HexEdit : private nall::base_from_member<pHexEdit&>, Widget {
void update(); void update();
HexEdit(); HexEdit();
~HexEdit();
struct State; struct State;
State &state; State &state;
pHexEdit &p; pHexEdit &p;
@ -328,6 +359,7 @@ struct HorizontalScrollBar : private nall::base_from_member<pHorizontalScrollBar
void setPosition(unsigned position); void setPosition(unsigned position);
HorizontalScrollBar(); HorizontalScrollBar();
~HorizontalScrollBar();
struct State; struct State;
State &state; State &state;
pHorizontalScrollBar &p; pHorizontalScrollBar &p;
@ -341,6 +373,7 @@ struct HorizontalSlider : private nall::base_from_member<pHorizontalSlider&>, Wi
void setPosition(unsigned position); void setPosition(unsigned position);
HorizontalSlider(); HorizontalSlider();
~HorizontalSlider();
struct State; struct State;
State &state; State &state;
pHorizontalSlider &p; pHorizontalSlider &p;
@ -350,6 +383,7 @@ struct Label : private nall::base_from_member<pLabel&>, Widget {
void setText(const nall::string &text); void setText(const nall::string &text);
Label(); Label();
~Label();
struct State; struct State;
State &state; State &state;
pLabel &p; pLabel &p;
@ -364,6 +398,7 @@ struct LineEdit : private nall::base_from_member<pLineEdit&>, Widget {
nall::string text(); nall::string text();
LineEdit(); LineEdit();
~LineEdit();
struct State; struct State;
State &state; State &state;
pLineEdit &p; pLineEdit &p;
@ -389,6 +424,7 @@ struct ListView : private nall::base_from_member<pListView&>, Widget {
void setSelection(unsigned row); void setSelection(unsigned row);
ListView(); ListView();
~ListView();
struct State; struct State;
State &state; State &state;
pListView &p; pListView &p;
@ -403,6 +439,7 @@ struct ProgressBar : private nall::base_from_member<pProgressBar&>, Widget {
void setPosition(unsigned position); void setPosition(unsigned position);
ProgressBar(); ProgressBar();
~ProgressBar();
struct State; struct State;
State &state; State &state;
pProgressBar &p; pProgressBar &p;
@ -419,6 +456,7 @@ struct RadioBox : private nall::base_from_member<pRadioBox&>, Widget {
void setText(const nall::string &text); void setText(const nall::string &text);
RadioBox(); RadioBox();
~RadioBox();
struct State; struct State;
State &state; State &state;
pRadioBox &p; pRadioBox &p;
@ -434,6 +472,7 @@ struct TextEdit : private nall::base_from_member<pTextEdit&>, Widget {
nall::string text(); nall::string text();
TextEdit(); TextEdit();
~TextEdit();
struct State; struct State;
State &state; State &state;
pTextEdit &p; pTextEdit &p;
@ -447,6 +486,7 @@ struct VerticalScrollBar : private nall::base_from_member<pVerticalScrollBar&>,
void setPosition(unsigned position); void setPosition(unsigned position);
VerticalScrollBar(); VerticalScrollBar();
~VerticalScrollBar();
struct State; struct State;
State &state; State &state;
pVerticalScrollBar &p; pVerticalScrollBar &p;
@ -460,6 +500,7 @@ struct VerticalSlider : private nall::base_from_member<pVerticalSlider&>, Widget
void setPosition(unsigned position); void setPosition(unsigned position);
VerticalSlider(); VerticalSlider();
~VerticalSlider();
struct State; struct State;
State &state; State &state;
pVerticalSlider &p; pVerticalSlider &p;
@ -469,6 +510,7 @@ struct Viewport : private nall::base_from_member<pViewport&>, Widget {
uintptr_t handle(); uintptr_t handle();
Viewport(); Viewport();
~Viewport();
pViewport &p; pViewport &p;
}; };

View File

@ -1,12 +1,16 @@
void FixedLayout::setParent(Window &parent) {
foreach(child, children) {
child.sizable->setParent(parent);
child.sizable->setGeometry(child.geometry);
}
}
void FixedLayout::append(Sizable &sizable, const Geometry &geometry) { void FixedLayout::append(Sizable &sizable, const Geometry &geometry) {
children.append({ &sizable, geometry }); children.append({ &sizable, geometry });
synchronize();
}
void FixedLayout::append(Sizable &sizable) {
foreach(child, children) if(child.sizable == &sizable) return;
Layout::append(sizable);
}
bool FixedLayout::enabled() {
if(layout()) return state.enabled && layout()->enabled();
return state.enabled;
} }
Geometry FixedLayout::minimumGeometry() { Geometry FixedLayout::minimumGeometry() {
@ -18,27 +22,56 @@ Geometry FixedLayout::minimumGeometry() {
return { 0, 0, width, height }; return { 0, 0, width, height };
} }
void FixedLayout::remove(Sizable &sizable) {
for(unsigned n = 0; n < children.size(); n++) {
if(children[n].sizable == &sizable) {
children.remove(n);
Layout::remove(sizable);
break;
}
}
}
void FixedLayout::reset() {
foreach(child, children) {
if(window() && dynamic_cast<Widget*>(child.sizable)) window()->remove((Widget&)*child.sizable);
}
}
void FixedLayout::setEnabled(bool enabled) {
state.enabled = enabled;
foreach(child, children) {
child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->enabled() : enabled);
}
}
void FixedLayout::setGeometry(const Geometry &geometry) { void FixedLayout::setGeometry(const Geometry &geometry) {
} }
void FixedLayout::setLayout(Layout &layout) {
this->layout = &layout;
}
void FixedLayout::setVisible(bool visible) { void FixedLayout::setVisible(bool visible) {
visible_ = visible; state.visible = visible;
foreach(child, children) { foreach(child, children) {
child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible); child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible);
} }
} }
void FixedLayout::synchronize() {
foreach(child, children) {
Layout::append(*child.sizable);
child.sizable->setGeometry(child.geometry);
}
}
bool FixedLayout::visible() { bool FixedLayout::visible() {
if(layout) return visible_ && layout->visible(); if(layout()) return state.visible && layout()->visible();
return visible_; return state.visible;
} }
FixedLayout::FixedLayout() { FixedLayout::FixedLayout() {
layout = 0; state.enabled = true;
parent = 0; state.visible = true;
visible_ = true; }
FixedLayout::~FixedLayout() {
while(children.size()) remove(*children[0].sizable);
} }

View File

@ -1,17 +1,24 @@
struct FixedLayout : Layout { struct FixedLayout : Layout {
void append(Sizable &sizable, const Geometry &geometry); void append(Sizable &sizable, const Geometry &geometry);
void append(Sizable &sizable);
bool enabled();
Geometry minimumGeometry(); Geometry minimumGeometry();
void remove(Sizable &sizable);
void reset();
void setEnabled(bool enabled = true);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setLayout(Layout &layout); void setVisible(bool visible = true);
void setParent(Window &parent); void synchronize();
void setVisible(bool visible);
bool visible(); bool visible();
FixedLayout(); FixedLayout();
~FixedLayout();
//private: //private:
Layout *layout; struct State {
Window *parent; bool enabled;
bool visible_; bool visible;
} state;
struct Children { struct Children {
Sizable *sizable; Sizable *sizable;
Geometry geometry; Geometry geometry;

View File

@ -1,6 +1,18 @@
void HorizontalLayout::append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing) { void HorizontalLayout::append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing) {
sizable.setLayout(*this); foreach(child, children) if(child.sizable == &sizable) return;
children.append({ &sizable, width, height, spacing }); children.append({ &sizable, width, height, spacing });
synchronize();
}
void HorizontalLayout::append(Sizable &sizable) {
foreach(child, children) if(child.sizable == &sizable) return;
Layout::append(sizable);
if(window()) window()->synchronize();
}
bool HorizontalLayout::enabled() {
if(layout()) return state.enabled && layout()->enabled();
return state.enabled;
} }
Geometry HorizontalLayout::minimumGeometry() { Geometry HorizontalLayout::minimumGeometry() {
@ -23,47 +35,34 @@ Geometry HorizontalLayout::minimumGeometry() {
height = max(height, child.height); height = max(height, child.height);
} }
return { 0, 0, margin * 2 + width, margin * 2 + height }; return { 0, 0, state.margin * 2 + width, state.margin * 2 + height };
} }
Geometry HorizontalLayout::minimumLayoutGeometry() { void HorizontalLayout::remove(Sizable &sizable) {
unsigned width = 0, height = 0; for(unsigned n = 0; n < children.size(); n++) {
bool maximumWidth = false; if(children[n].sizable == &sizable) {
bool maximumHeight = false; children.remove(n);
Layout::remove(sizable);
foreach(child, children) {
if(child.width == MaximumSize) {
maximumWidth = true;
break; break;
} }
if(child.width == MinimumSize) {
width += child.sizable->minimumGeometry().width;
continue;
}
width += child.width;
} }
}
void HorizontalLayout::reset() {
foreach(child, children) { foreach(child, children) {
if(child.height == MaximumSize) { if(window() && dynamic_cast<Widget*>(child.sizable)) window()->remove((Widget&)*child.sizable);
maximumHeight = true;
break;
}
if(child.height == MinimumSize) {
height = max(height, child.sizable->minimumGeometry().height);
continue;
}
height = max(height, child.height);
} }
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
} }
void HorizontalLayout::setAlignment(double alignment) { void HorizontalLayout::setAlignment(double alignment) {
this->alignment = max(0.0, min(1.0, alignment)); state.alignment = max(0.0, min(1.0, alignment));
}
void HorizontalLayout::setEnabled(bool enabled) {
state.enabled = enabled;
foreach(child, children) {
child.sizable->setEnabled(dynamic_cast<Widget*>(child.sizable) ? child.sizable->enabled() : enabled);
}
} }
void HorizontalLayout::setGeometry(const Geometry &containerGeometry) { void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
@ -74,10 +73,10 @@ void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
} }
Geometry geometry = containerGeometry; Geometry geometry = containerGeometry;
geometry.x += margin; geometry.x += state.margin;
geometry.y += margin; geometry.y += state.margin;
geometry.width -= margin * 2; geometry.width -= state.margin * 2;
geometry.height -= margin * 2; geometry.height -= state.margin * 2;
unsigned minimumWidth = 0, maximumWidthCounter = 0; unsigned minimumWidth = 0, maximumWidthCounter = 0;
foreach(child, children) { foreach(child, children) {
@ -95,7 +94,7 @@ void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
foreach(child, children) maximumHeight = max(maximumHeight, child.height); foreach(child, children) maximumHeight = max(maximumHeight, child.height);
foreach(child, children) { foreach(child, children) {
unsigned pivot = (maximumHeight - child.height) * alignment; unsigned pivot = (maximumHeight - child.height) * state.alignment;
Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height }; Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height };
child.sizable->setGeometry(childGeometry); child.sizable->setGeometry(childGeometry);
@ -104,35 +103,33 @@ void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
} }
} }
void HorizontalLayout::setLayout(Layout &layout) {
this->layout = &layout;
}
void HorizontalLayout::setMargin(unsigned margin) { void HorizontalLayout::setMargin(unsigned margin) {
this->margin = margin; state.margin = margin;
}
void HorizontalLayout::setParent(Window &parent) {
foreach(child, children) {
child.sizable->setParent(parent);
}
} }
void HorizontalLayout::setVisible(bool visible) { void HorizontalLayout::setVisible(bool visible) {
visible_ = visible; state.visible = visible;
foreach(child, children) { foreach(child, children) {
child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible); child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible);
} }
} }
void HorizontalLayout::synchronize() {
foreach(child, children) Layout::append(*child.sizable);
}
bool HorizontalLayout::visible() { bool HorizontalLayout::visible() {
if(layout) return visible_ && layout->visible(); if(layout()) return state.visible && layout()->visible();
return visible_; return state.visible;
} }
HorizontalLayout::HorizontalLayout() { HorizontalLayout::HorizontalLayout() {
alignment = 0.5; state.alignment = 0.5;
layout = 0; state.enabled = true;
margin = 0; state.margin = 0;
visible_ = true; state.visible = true;
}
HorizontalLayout::~HorizontalLayout() {
while(children.size()) remove(*children[0].sizable);
} }

View File

@ -1,23 +1,28 @@
struct VerticalLayout;
struct HorizontalLayout : public Layout { struct HorizontalLayout : public Layout {
void append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing = 0); void append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing = 0);
void append(Sizable &sizable);
bool enabled();
Geometry minimumGeometry(); Geometry minimumGeometry();
Geometry minimumLayoutGeometry(); void remove(Sizable &sizable);
void reset();
void setAlignment(double alignment); void setAlignment(double alignment);
void setEnabled(bool enabled = true);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setLayout(Layout &layout);
void setMargin(unsigned margin); void setMargin(unsigned margin);
void setParent(Window &parent); void setVisible(bool visible = true);
void setVisible(bool visible); void synchronize();
bool visible(); bool visible();
HorizontalLayout(); HorizontalLayout();
~HorizontalLayout();
//private: //private:
double alignment; struct State {
Layout *layout; double alignment;
unsigned margin; bool enabled;
bool visible_; unsigned margin;
bool visible;
} state;
struct Children { struct Children {
Sizable *sizable; Sizable *sizable;
unsigned width, height, spacing; unsigned width, height, spacing;

View File

@ -1,6 +1,18 @@
void VerticalLayout::append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing) { void VerticalLayout::append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing) {
sizable.setLayout(*this); foreach(child, children) if(child.sizable == &sizable) return;
children.append({ &sizable, width, height, spacing }); children.append({ &sizable, width, height, spacing });
synchronize();
}
void VerticalLayout::append(Sizable &sizable) {
foreach(child, children) if(child.sizable == &sizable) return;
Layout::append(sizable);
if(window()) window()->synchronize();
}
bool VerticalLayout::enabled() {
if(layout()) return state.enabled && layout()->enabled();
return state.enabled;
} }
Geometry VerticalLayout::minimumGeometry() { Geometry VerticalLayout::minimumGeometry() {
@ -23,61 +35,52 @@ Geometry VerticalLayout::minimumGeometry() {
height += child.height; height += child.height;
} }
return { 0, 0, margin * 2 + width, margin * 2 + height }; return { 0, 0, state.margin * 2 + width, state.margin * 2 + height };
} }
Geometry VerticalLayout::minimumLayoutGeometry() { void VerticalLayout::remove(Sizable &sizable) {
unsigned width = 0, height = 0; for(unsigned n = 0; n < children.size(); n++) {
bool maximumWidth = false; if(children[n].sizable == &sizable) {
bool maximumHeight = false; if(dynamic_cast<Layout*>(children[n].sizable)) {
Layout *layout = (Layout*)children[n].sizable;
foreach(child, children) { layout->reset();
if(child.width == MaximumSize) { }
maximumWidth = true; children.remove(n);
Layout::remove(sizable);
break; break;
} }
if(child.width == MinimumSize) {
width = max(width, child.sizable->minimumGeometry().width);
continue;
}
width = max(width, child.width);
} }
}
void VerticalLayout::reset() {
foreach(child, children) { foreach(child, children) {
if(child.height == MaximumSize) { if(window() && dynamic_cast<Widget*>(child.sizable)) window()->remove((Widget&)*child.sizable);
maximumHeight = true;
break;
}
if(child.height == MinimumSize) {
height += child.sizable->minimumGeometry().height;
continue;
}
height += child.height;
} }
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
} }
void VerticalLayout::setAlignment(double alignment) { void VerticalLayout::setAlignment(double alignment) {
this->alignment = max(0.0, min(1.0, alignment)); state.alignment = max(0.0, min(1.0, alignment));
}
void VerticalLayout::setEnabled(bool enabled) {
state.enabled = enabled;
foreach(child, children) {
child.sizable->setEnabled(dynamic_cast<Widget*>(child.sizable) ? child.sizable->enabled() : enabled);
}
} }
void VerticalLayout::setGeometry(const Geometry &containerGeometry) { void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
auto children = this->children; auto children = this->children;
foreach(child, children) { foreach(child, children) {
if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width;
if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height;
} }
Geometry geometry = containerGeometry; Geometry geometry = containerGeometry;
geometry.x += margin; geometry.x += state.margin;
geometry.y += margin; geometry.y += state.margin;
geometry.width -= margin * 2; geometry.width -= state.margin * 2;
geometry.height -= margin * 2; geometry.height -= state.margin * 2;
unsigned minimumHeight = 0, maximumHeightCounter = 0; unsigned minimumHeight = 0, maximumHeightCounter = 0;
foreach(child, children) { foreach(child, children) {
@ -95,7 +98,7 @@ void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
foreach(child, children) maximumWidth = max(maximumWidth, child.width); foreach(child, children) maximumWidth = max(maximumWidth, child.width);
foreach(child, children) { foreach(child, children) {
unsigned pivot = (maximumWidth - child.width) * alignment; unsigned pivot = (maximumWidth - child.width) * state.alignment;
Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height }; Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height };
child.sizable->setGeometry(childGeometry); child.sizable->setGeometry(childGeometry);
@ -104,35 +107,33 @@ void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
} }
} }
void VerticalLayout::setLayout(Layout &layout) {
this->layout = &layout;
}
void VerticalLayout::setMargin(unsigned margin) { void VerticalLayout::setMargin(unsigned margin) {
this->margin = margin; state.margin = margin;
}
void VerticalLayout::setParent(Window &parent) {
foreach(child, children) {
child.sizable->setParent(parent);
}
} }
void VerticalLayout::setVisible(bool visible) { void VerticalLayout::setVisible(bool visible) {
visible_ = visible; state.visible = visible;
foreach(child, children) { foreach(child, children) {
child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible); child.sizable->setVisible(dynamic_cast<Widget*>(child.sizable) ? child.sizable->visible() : visible);
} }
} }
void VerticalLayout::synchronize() {
foreach(child, children) Layout::append(*child.sizable);
}
bool VerticalLayout::visible() { bool VerticalLayout::visible() {
if(layout) return visible_ && layout->visible(); if(layout()) return state.visible && layout()->visible();
return visible_; return state.visible;
} }
VerticalLayout::VerticalLayout() { VerticalLayout::VerticalLayout() {
alignment = 0.0; state.alignment = 0.0;
layout = 0; state.enabled = true;
margin = 0; state.margin = 0;
visible_ = true; state.visible = true;
}
VerticalLayout::~VerticalLayout() {
while(children.size()) remove(*children[0].sizable);
} }

View File

@ -1,23 +1,28 @@
struct HorizontalLayout;
struct VerticalLayout : public Layout { struct VerticalLayout : public Layout {
void append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing = 0); void append(Sizable &sizable, unsigned width, unsigned height, unsigned spacing = 0);
void append(Sizable &sizable);
bool enabled();
Geometry minimumGeometry(); Geometry minimumGeometry();
Geometry minimumLayoutGeometry(); void remove(Sizable &sizable);
void reset();
void setAlignment(double alignment); void setAlignment(double alignment);
void setEnabled(bool enabled = true);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setLayout(Layout &layout);
void setMargin(unsigned margin); void setMargin(unsigned margin);
void setParent(Window &parent); void setVisible(bool visible = true);
void setVisible(bool visible); void synchronize();
bool visible(); bool visible();
VerticalLayout(); VerticalLayout();
~VerticalLayout();
//private: //private:
double alignment; struct State {
Layout *layout; double alignment;
unsigned margin; bool enabled;
bool visible_; unsigned margin;
bool visible;
} state;
struct Children { struct Children {
Sizable *sizable; Sizable *sizable;
unsigned width, height, spacing; unsigned width, height, spacing;

View File

@ -1,18 +1,3 @@
struct Font::State {
bool bold;
string family;
bool italic;
unsigned size;
bool underline;
State() {
bold = false;
italic = false;
size = 8;
underline = false;
}
};
struct Timer::State { struct Timer::State {
bool enabled; bool enabled;
unsigned milliseconds; unsigned milliseconds;
@ -28,42 +13,44 @@ struct Window::State {
Color backgroundColor; Color backgroundColor;
bool fullScreen; bool fullScreen;
Geometry geometry; Geometry geometry;
bool ignore;
reference_array<Layout&> layout; reference_array<Layout&> layout;
reference_array<Menu&> menu; reference_array<Menu&> menu;
Font *menuFont; string menuFont;
bool menuVisible; bool menuVisible;
bool resizable; bool resizable;
Font *statusFont; string statusFont;
string statusText; string statusText;
bool statusVisible; bool statusVisible;
string title; string title;
bool visible; bool visible;
reference_array<Widget&> widget; reference_array<Widget&> widget;
Font *widgetFont; string widgetFont;
State() { State() {
backgroundColorOverride = false; backgroundColorOverride = false;
backgroundColor = { 0, 0, 0, 255 }; backgroundColor = { 0, 0, 0, 255 };
fullScreen = false; fullScreen = false;
geometry = { 128, 128, 256, 256 }; geometry = { 128, 128, 256, 256 };
menuFont = 0; ignore = false;
menuVisible = false; menuVisible = false;
resizable = true; resizable = true;
statusVisible = false; statusVisible = false;
visible = false; visible = false;
widgetFont = 0;
} }
}; };
struct Action::State { struct Action::State {
bool enabled; bool enabled;
Window *parent; Menu *menu;
bool visible; bool visible;
Window *window;
State() { State() {
enabled = true; enabled = true;
parent = 0; menu = 0;
visible = true; visible = true;
window = 0;
} }
}; };
@ -95,22 +82,32 @@ struct RadioItem::State {
} }
}; };
struct Sizable::State {
Layout *layout;
Window *window;
State() {
layout = 0;
window = 0;
}
};
struct Layout::State {
State() {
}
};
struct Widget::State { struct Widget::State {
bool abstract; bool abstract;
bool enabled; bool enabled;
Font *font; string font;
Geometry geometry; Geometry geometry;
Layout *layout;
Window *parent;
bool visible; bool visible;
State() { State() {
abstract = false; abstract = false;
enabled = true; enabled = true;
font = 0;
geometry = { 0, 0, 0, 0 }; geometry = { 0, 0, 0, 0 };
layout = 0;
parent = 0;
visible = true; visible = true;
} }
}; };

View File

@ -1,17 +1,9 @@
static void Action_setFont(GtkWidget *widget, gpointer font) {
if(font == 0) return;
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
if(GTK_IS_CONTAINER(widget)) {
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Action_setFont, (PangoFontDescription*)font);
}
}
void pAction::setEnabled(bool enabled) { void pAction::setEnabled(bool enabled) {
gtk_widget_set_sensitive(widget, enabled); gtk_widget_set_sensitive(widget, enabled);
} }
void pAction::setFont(Font &font) { void pAction::setFont(const string &font) {
Action_setFont(widget, font.p.gtkFont); pFont::setFont(widget, font);
} }
void pAction::setVisible(bool visible) { void pAction::setVisible(bool visible) {
@ -20,3 +12,6 @@ void pAction::setVisible(bool visible) {
void pAction::constructor() { void pAction::constructor() {
} }
void pAction::orphan() {
}

View File

@ -17,6 +17,16 @@ void pCheckItem::setText(const string &text) {
} }
void pCheckItem::constructor() { void pCheckItem::constructor() {
widget = gtk_check_menu_item_new_with_label(""); widget = gtk_check_menu_item_new_with_label(checkItem.state.text);
setChecked(checkItem.state.checked);
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem); g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem);
} }
void pCheckItem::destructor() {
gtk_widget_destroy(widget);
}
void pCheckItem::orphan() {
destructor();
constructor();
}

View File

@ -7,6 +7,15 @@ void pItem::setText(const string &text) {
} }
void pItem::constructor() { void pItem::constructor() {
widget = gtk_menu_item_new_with_label(""); widget = gtk_menu_item_new_with_label(item.state.text);
g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_tick), (gpointer)&item); g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_tick), (gpointer)&item);
} }
void pItem::destructor() {
gtk_widget_destroy(widget);
}
void pItem::orphan() {
destructor();
constructor();
}

View File

@ -1,11 +1,16 @@
void pMenu::append(Action &action) { void pMenu::append(Action &action) {
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), action.p.widget); action.state.window = this->action.state.window;
gtk_menu_shell_append(GTK_MENU_SHELL(gtkMenu), action.p.widget);
if(action.state.window && action.state.window->state.menuFont != "") {
action.p.setFont(action.state.window->state.menuFont);
}
gtk_widget_show(action.p.widget); gtk_widget_show(action.p.widget);
} }
void pMenu::setFont(Font &font) { void pMenu::remove(Action &action) {
pAction::setFont(font); action.p.orphan();
foreach(item, menu.state.action) item.p.setFont(font); action.state.window = 0;
} }
void pMenu::setText(const string &text) { void pMenu::setText(const string &text) {
@ -13,7 +18,24 @@ void pMenu::setText(const string &text) {
} }
void pMenu::constructor() { void pMenu::constructor() {
submenu = gtk_menu_new(); gtkMenu = gtk_menu_new();
widget = gtk_menu_item_new_with_label(""); widget = gtk_menu_item_new_with_label(menu.state.text);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), submenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), gtkMenu);
}
void pMenu::destructor() {
gtk_widget_destroy(gtkMenu);
gtk_widget_destroy(widget);
}
void pMenu::orphan() {
foreach(action, menu.state.action) action.p.orphan();
destructor();
constructor();
foreach(action, menu.state.action) append(action);
}
void pMenu::setFont(const string &font) {
pAction::setFont(font);
foreach(item, menu.state.action) item.p.setFont(font);
} }

View File

@ -1,4 +1,5 @@
static void RadioItem_tick(RadioItem *self) { static void RadioItem_tick(RadioItem *self) {
foreach(item, self->state.group) item.state.checked = (&item == self);
if(self->p.locked == false && self->checked() && self->onTick) self->onTick(); if(self->p.locked == false && self->checked() && self->onTick) self->onTick();
} }
@ -28,6 +29,19 @@ void pRadioItem::setText(const string &text) {
} }
void pRadioItem::constructor() { void pRadioItem::constructor() {
widget = gtk_radio_menu_item_new_with_label(0, ""); widget = gtk_radio_menu_item_new_with_label(0, radioItem.state.text);
setGroup(radioItem.state.group);
foreach(item, radioItem.state.group, n) {
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), item.state.checked);
}
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_tick), (gpointer)&radioItem); g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_tick), (gpointer)&radioItem);
} }
void pRadioItem::destructor() {
gtk_widget_destroy(widget);
}
void pRadioItem::orphan() {
destructor();
constructor();
}

View File

@ -1,3 +1,12 @@
void pSeparator::constructor() { void pSeparator::constructor() {
widget = gtk_separator_menu_item_new(); widget = gtk_separator_menu_item_new();
} }
void pSeparator::destructor() {
gtk_widget_destroy(widget);
}
void pSeparator::orphan() {
destructor();
constructor();
}

View File

@ -1,34 +1,55 @@
Geometry pFont::geometry(const string &text) { Geometry pFont::geometry(const string &description, const string &text) {
pango_layout_set_font_description(gtkLayout, gtkFont); PangoFontDescription *font = create(description);
pango_layout_set_text(gtkLayout, text, -1); Geometry geometry = pFont::geometry(font, text);
free(font);
return geometry;
}
PangoFontDescription* pFont::create(const string &description) {
lstring part;
part.split(",", description);
foreach(item, part) item.trim(" ");
string family = part[0];
unsigned size = decimal(part[1]);
bool bold = part[2].position("Bold");
bool italic = part[2].position("Italic");
if(family == "") family = "Sans";
if(size == 0) size = 8;
PangoFontDescription *font = pango_font_description_new();
pango_font_description_set_family(font, family);
pango_font_description_set_size(font, size * PANGO_SCALE);
pango_font_description_set_weight(font, !bold ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD);
pango_font_description_set_style(font, !italic ? PANGO_STYLE_NORMAL : PANGO_STYLE_OBLIQUE);
return font;
}
void pFont::free(PangoFontDescription *font) {
pango_font_description_free(font);
}
Geometry pFont::geometry(PangoFontDescription *font, const string &text) {
PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
PangoLayout *layout = pango_layout_new(context);
pango_layout_set_font_description(layout, font);
pango_layout_set_text(layout, text, -1);
int width = 0, height = 0; int width = 0, height = 0;
pango_layout_get_pixel_size(gtkLayout, &width, &height); pango_layout_get_pixel_size(layout, &width, &height);
g_object_unref((gpointer)layout);
return { 0, 0, width, height }; return { 0, 0, width, height };
} }
void pFont::setBold(bool bold) { void pFont::setFont(GtkWidget *widget, const string &font) {
pango_font_description_set_weight(gtkFont, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); auto gtkFont = pFont::create(font);
pFont::setFont(widget, (gpointer)gtkFont);
pFont::free(gtkFont);
} }
void pFont::setFamily(const string &family) { void pFont::setFont(GtkWidget *widget, gpointer font) {
pango_font_description_set_family(gtkFont, family); if(font == 0) return;
} gtk_widget_modify_font(widget, (PangoFontDescription*)font);
if(GTK_IS_CONTAINER(widget)) {
void pFont::setItalic(bool italic) { gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)pFont::setFont, font);
pango_font_description_set_style(gtkFont, italic ? PANGO_STYLE_OBLIQUE : PANGO_STYLE_NORMAL); }
}
void pFont::setSize(unsigned size) {
pango_font_description_set_size(gtkFont, size * PANGO_SCALE);
}
void pFont::setUnderline(bool underline) {
}
void pFont::constructor() {
gtkFont = pango_font_description_new();
PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
gtkLayout = pango_layout_new(context);
font.setFamily("Sans");
font.setSize(8);
} }

View File

@ -1,4 +1,4 @@
#include "gtk.hpp" #include "platform.hpp"
#include "settings.cpp" #include "settings.cpp"
#include "font.cpp" #include "font.cpp"

View File

@ -11,18 +11,30 @@ struct Settings : public configuration {
Settings(); Settings();
}; };
struct pFont;
struct pWindow; struct pWindow;
struct pMenu; struct pMenu;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pFont {
static Geometry geometry(const string &description, const string &text);
static PangoFontDescription* create(const string &description);
static void free(PangoFontDescription *font);
static Geometry geometry(PangoFontDescription *font, const string &text);
static void setFont(GtkWidget *widget, const string &font);
static void setFont(GtkWidget *widget, gpointer font);
};
struct pObject { struct pObject {
Object &object;
bool locked; bool locked;
pObject() { pObject(Object &object) : object(object), locked(false) {}
locked = false; virtual ~pObject() {}
}
void constructor() {}
void destructor() {}
}; };
struct pOS : public pObject { struct pOS : public pObject {
@ -41,29 +53,13 @@ struct pOS : public pObject {
static void initialize(); static void initialize();
}; };
struct pFont : public pObject {
Font &font;
PangoFontDescription *gtkFont;
PangoLayout *gtkLayout;
Geometry geometry(const string &text);
void setBold(bool bold);
void setFamily(const string &family);
void setItalic(bool italic);
void setSize(unsigned size);
void setUnderline(bool underline);
pFont(Font &font) : font(font) {}
void constructor();
};
struct pTimer : public pObject { struct pTimer : public pObject {
Timer &timer; Timer &timer;
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setInterval(unsigned milliseconds); void setInterval(unsigned milliseconds);
pTimer(Timer &timer) : timer(timer) {} pTimer(Timer &timer) : pObject(timer), timer(timer) {}
void constructor(); void constructor();
}; };
@ -91,21 +87,24 @@ struct pWindow : public pObject {
bool focused(); bool focused();
Geometry frameMargin(); Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void remove(Layout &layout);
void remove(Menu &menu);
void remove(Widget &widget);
void setBackgroundColor(const Color &color); void setBackgroundColor(const Color &color);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setMenuFont(Font &font); void setMenuFont(const string &font);
void setMenuVisible(bool visible); void setMenuVisible(bool visible);
void setResizable(bool resizable); void setResizable(bool resizable);
void setStatusFont(Font &font); void setStatusFont(const string &font);
void setStatusText(const string &text); void setStatusText(const string &text);
void setStatusVisible(bool visible); void setStatusVisible(bool visible);
void setTitle(const string &text); void setTitle(const string &text);
void setVisible(bool visible); void setVisible(bool visible);
void setWidgetFont(Font &font); void setWidgetFont(const string &font);
pWindow(Window &window) : window(window) {} pWindow(Window &window) : pObject(window), window(window) {}
void constructor(); void constructor();
unsigned menuHeight(); unsigned menuHeight();
unsigned statusHeight(); unsigned statusHeight();
@ -118,21 +117,25 @@ struct pAction : public pObject {
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setVisible(bool visible); void setVisible(bool visible);
pAction(Action &action) : action(action) {} pAction(Action &action) : pObject(action), action(action) {}
void constructor(); void constructor();
virtual void setFont(Font &font); virtual void orphan();
virtual void setFont(const string &font);
}; };
struct pMenu : public pAction { struct pMenu : public pAction {
Menu &menu; Menu &menu;
GtkWidget *submenu; GtkWidget *gtkMenu;
void append(Action &action); void append(Action &action);
void remove(Action &action);
void setText(const string &text); void setText(const string &text);
pMenu(Menu &menu) : pAction(menu), menu(menu) {} pMenu(Menu &menu) : pAction(menu), menu(menu) {}
void constructor(); void constructor();
void setFont(Font &font); void destructor();
void orphan();
void setFont(const string &font);
}; };
struct pSeparator : public pAction { struct pSeparator : public pAction {
@ -140,6 +143,8 @@ struct pSeparator : public pAction {
pSeparator(Separator &separator) : pAction(separator), separator(separator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pItem : public pAction { struct pItem : public pAction {
@ -149,6 +154,8 @@ struct pItem : public pAction {
pItem(Item &item) : pAction(item), item(item) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pCheckItem : public pAction { struct pCheckItem : public pAction {
@ -160,6 +167,8 @@ struct pCheckItem : public pAction {
pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pRadioItem : public pAction { struct pRadioItem : public pAction {
@ -172,25 +181,38 @@ struct pRadioItem : public pAction {
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pWidget : public pObject { struct pSizable : public pObject {
Sizable &sizable;
pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {}
};
struct pLayout : public pSizable {
Layout &layout;
pLayout(Layout &layout) : pSizable(layout), layout(layout) {}
};
struct pWidget : public pSizable {
Widget &widget; Widget &widget;
GtkWidget *gtkWidget; GtkWidget *gtkWidget;
pWindow *parentWindow;
bool enabled(); bool enabled();
Font& font();
virtual Geometry minimumGeometry(); virtual Geometry minimumGeometry();
void setEnabled(bool enabled); void setEnabled(bool enabled);
virtual void setFocused(); virtual void setFocused();
virtual void setFont(Font &font); virtual void setFont(const string &font);
virtual void setGeometry(const Geometry &geometry); virtual void setGeometry(const Geometry &geometry);
void setParent(Window &parent);
void setVisible(bool visible); void setVisible(bool visible);
pWidget(Widget &widget) : widget(widget) {} pWidget(Widget &widget) : pSizable(widget), widget(widget) {}
void constructor(); void constructor();
void destructor();
virtual void orphan();
}; };
struct pButton : public pWidget { struct pButton : public pWidget {
@ -201,6 +223,8 @@ struct pButton : public pWidget {
pButton(Button &button) : pWidget(button), button(button) {} pButton(Button &button) : pWidget(button), button(button) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pCanvas : public pWidget { struct pCanvas : public pWidget {
@ -213,6 +237,8 @@ struct pCanvas : public pWidget {
pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pCheckBox : public pWidget { struct pCheckBox : public pWidget {
@ -225,6 +251,8 @@ struct pCheckBox : public pWidget {
pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pComboBox : public pWidget { struct pComboBox : public pWidget {
@ -239,6 +267,8 @@ struct pComboBox : public pWidget {
pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pHexEdit : public pWidget { struct pHexEdit : public pWidget {
@ -257,6 +287,8 @@ struct pHexEdit : public pWidget {
pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
unsigned cursorPosition(); unsigned cursorPosition();
bool keyPress(unsigned scancode); bool keyPress(unsigned scancode);
void scroll(unsigned position); void scroll(unsigned position);
@ -275,6 +307,8 @@ struct pHorizontalScrollBar : public pWidget {
pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pHorizontalSlider : public pWidget { struct pHorizontalSlider : public pWidget {
@ -287,6 +321,8 @@ struct pHorizontalSlider : public pWidget {
pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pLabel : public pWidget { struct pLabel : public pWidget {
@ -297,6 +333,8 @@ struct pLabel : public pWidget {
pLabel(Label &label) : pWidget(label), label(label) {} pLabel(Label &label) : pWidget(label), label(label) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pLineEdit : public pWidget { struct pLineEdit : public pWidget {
@ -309,6 +347,8 @@ struct pLineEdit : public pWidget {
pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pListView : public pWidget { struct pListView : public pWidget {
@ -338,9 +378,10 @@ struct pListView : public pWidget {
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}
void constructor(); void constructor();
void create(); void destructor();
void orphan();
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(const string &font);
}; };
struct pProgressBar : public pWidget { struct pProgressBar : public pWidget {
@ -351,6 +392,8 @@ struct pProgressBar : public pWidget {
pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pRadioBox : public pWidget { struct pRadioBox : public pWidget {
@ -364,6 +407,8 @@ struct pRadioBox : public pWidget {
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pTextEdit : public pWidget { struct pTextEdit : public pWidget {
@ -379,6 +424,8 @@ struct pTextEdit : public pWidget {
pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pVerticalScrollBar : public pWidget { struct pVerticalScrollBar : public pWidget {
@ -391,6 +438,8 @@ struct pVerticalScrollBar : public pWidget {
pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pVerticalSlider : public pWidget { struct pVerticalSlider : public pWidget {
@ -403,6 +452,8 @@ struct pVerticalSlider : public pWidget {
pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pViewport : public pWidget { struct pViewport : public pWidget {
@ -412,4 +463,6 @@ struct pViewport : public pWidget {
pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };

View File

@ -3,8 +3,7 @@ static void Button_tick(Button *self) {
} }
Geometry pButton::minimumGeometry() { Geometry pButton::minimumGeometry() {
Font &font = pWidget::font(); Geometry geometry = pFont::geometry(widget.state.font, button.state.text);
Geometry geometry = font.geometry(button.state.text);
return { 0, 0, geometry.width + 24, geometry.height + 12 }; return { 0, 0, geometry.width + 24, geometry.height + 12 };
} }
@ -15,5 +14,15 @@ void pButton::setText(const string &text) {
void pButton::constructor() { void pButton::constructor() {
gtkWidget = gtk_button_new(); gtkWidget = gtk_button_new();
g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_tick), (gpointer)&button); g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_tick), (gpointer)&button);
//g_object_ref((gpointer)gtkWidget);
setText(button.state.text);
}
void pButton::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pButton::orphan() {
destructor();
constructor();
} }

View File

@ -36,3 +36,13 @@ void pCanvas::constructor() {
gtk_widget_add_events(gtkWidget, GDK_EXPOSURE_MASK); gtk_widget_add_events(gtkWidget, GDK_EXPOSURE_MASK);
g_signal_connect(G_OBJECT(gtkWidget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); g_signal_connect(G_OBJECT(gtkWidget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this);
} }
void pCanvas::destructor() {
gtk_widget_destroy(gtkWidget);
cairo_surface_destroy(surface);
}
void pCanvas::orphan() {
destructor();
constructor();
}

View File

@ -1,4 +1,5 @@
static void CheckBox_tick(CheckBox *self) { static void CheckBox_tick(CheckBox *self) {
self->state.checked = self->checked();
if(self->p.locked == false && self->onTick) self->onTick(); if(self->p.locked == false && self->onTick) self->onTick();
} }
@ -7,8 +8,7 @@ bool pCheckBox::checked() {
} }
Geometry pCheckBox::minimumGeometry() { Geometry pCheckBox::minimumGeometry() {
Font &font = pWidget::font(); Geometry geometry = pFont::geometry(widget.state.font, checkBox.state.text);
Geometry geometry = font.geometry(checkBox.state.text);
return { 0, 0, geometry.width + 28, geometry.height + 4 }; return { 0, 0, geometry.width + 28, geometry.height + 4 };
} }
@ -25,4 +25,16 @@ void pCheckBox::setText(const string &text) {
void pCheckBox::constructor() { void pCheckBox::constructor() {
gtkWidget = gtk_check_button_new_with_label(""); gtkWidget = gtk_check_button_new_with_label("");
g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_tick), (gpointer)&checkBox); g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_tick), (gpointer)&checkBox);
setChecked(checkBox.state.checked);
setText(checkBox.state.text);
}
void pCheckBox::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pCheckBox::orphan() {
destructor();
constructor();
} }

View File

@ -1,5 +1,8 @@
static void ComboBox_change(ComboBox *self) { static void ComboBox_change(ComboBox *self) {
if(self->p.locked == false && self->onChange) self->onChange(); if(self->p.locked == false) {
self->state.selection = self->selection();
if(self->onChange) self->onChange();
}
} }
void pComboBox::append(const string &text) { void pComboBox::append(const string &text) {
@ -8,11 +11,10 @@ void pComboBox::append(const string &text) {
} }
Geometry pComboBox::minimumGeometry() { Geometry pComboBox::minimumGeometry() {
Font &font = pWidget::font();
unsigned maximumWidth = 0; unsigned maximumWidth = 0;
foreach(item, comboBox.state.text) maximumWidth = max(maximumWidth, font.geometry(item).width); foreach(item, comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(widget.state.font, item).width);
Geometry geometry = font.geometry(" "); Geometry geometry = pFont::geometry(widget.state.font, " ");
return { 0, 0, maximumWidth + 44, geometry.height + 12 }; return { 0, 0, maximumWidth + 44, geometry.height + 12 };
} }
@ -37,4 +39,18 @@ void pComboBox::constructor() {
itemCounter = 0; itemCounter = 0;
gtkWidget = gtk_combo_box_new_text(); gtkWidget = gtk_combo_box_new_text();
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox); g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox);
locked = true;
foreach(text, comboBox.state.text) append(text);
locked = false;
setSelection(comboBox.state.selection);
}
void pComboBox::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pComboBox::orphan() {
destructor();
constructor();
} }

View File

@ -96,6 +96,24 @@ void pHexEdit::constructor() {
gtk_widget_show(scrollBar); gtk_widget_show(scrollBar);
gtk_widget_show(subWidget); gtk_widget_show(subWidget);
gtk_widget_show(container); gtk_widget_show(container);
setColumns(hexEdit.state.columns);
setRows(hexEdit.state.rows);
setLength(hexEdit.state.length);
setOffset(hexEdit.state.offset);
update();
}
void pHexEdit::destructor() {
gtk_widget_destroy(scrollBar);
gtk_widget_destroy(subWidget);
gtk_widget_destroy(container);
gtk_widget_destroy(gtkWidget);
}
void pHexEdit::orphan() {
destructor();
constructor();
} }
unsigned pHexEdit::cursorPosition() { unsigned pHexEdit::cursorPosition() {

View File

@ -24,6 +24,17 @@ void pHorizontalScrollBar::setPosition(unsigned position) {
void pHorizontalScrollBar::constructor() { void pHorizontalScrollBar::constructor() {
gtkWidget = gtk_hscrollbar_new(0); gtkWidget = gtk_hscrollbar_new(0);
setLength(101);
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar); g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar);
setLength(horizontalScrollBar.state.length);
setPosition(horizontalScrollBar.state.position);
}
void pHorizontalScrollBar::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pHorizontalScrollBar::orphan() {
destructor();
constructor();
} }

View File

@ -25,6 +25,17 @@ void pHorizontalSlider::setPosition(unsigned position) {
void pHorizontalSlider::constructor() { void pHorizontalSlider::constructor() {
gtkWidget = gtk_hscale_new_with_range(0, 100, 1); gtkWidget = gtk_hscale_new_with_range(0, 100, 1);
gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false);
setLength(101);
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider); g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider);
setLength(horizontalSlider.state.length);
setPosition(horizontalSlider.state.position);
}
void pHorizontalSlider::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pHorizontalSlider::orphan() {
destructor();
constructor();
} }

View File

@ -1,6 +1,5 @@
Geometry pLabel::minimumGeometry() { Geometry pLabel::minimumGeometry() {
Font &font = pWidget::font(); Geometry geometry = pFont::geometry(widget.state.font, label.state.text);
Geometry geometry = font.geometry(label.state.text);
return { 0, 0, geometry.width, geometry.height }; return { 0, 0, geometry.width, geometry.height };
} }
@ -11,4 +10,15 @@ void pLabel::setText(const string &text) {
void pLabel::constructor() { void pLabel::constructor() {
gtkWidget = gtk_label_new(""); gtkWidget = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5); gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5);
setText(label.state.text);
}
void pLabel::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pLabel::orphan() {
destructor();
constructor();
} }

View File

@ -3,12 +3,12 @@ static void LineEdit_activate(LineEdit *self) {
} }
static void LineEdit_change(LineEdit *self) { static void LineEdit_change(LineEdit *self) {
self->state.text = self->text();
if(self->p.locked == false && self->onChange) self->onChange(); if(self->p.locked == false && self->onChange) self->onChange();
} }
Geometry pLineEdit::minimumGeometry() { Geometry pLineEdit::minimumGeometry() {
Font &font = pWidget::font(); Geometry geometry = pFont::geometry(widget.state.font, lineEdit.state.text);
Geometry geometry = font.geometry(lineEdit.state.text);
return { 0, 0, geometry.width + 10, geometry.height + 10 }; return { 0, 0, geometry.width + 10, geometry.height + 10 };
} }
@ -30,4 +30,16 @@ void pLineEdit::constructor() {
gtkWidget = gtk_entry_new(); gtkWidget = gtk_entry_new();
g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit); g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit);
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit); g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit);
setEditable(lineEdit.state.editable);
setText(lineEdit.state.text);
}
void pLineEdit::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pLineEdit::orphan() {
destructor();
constructor();
} }

View File

@ -99,7 +99,8 @@ void pListView::setChecked(unsigned row, bool checked) {
} }
void pListView::setHeaderText(const lstring &text) { void pListView::setHeaderText(const lstring &text) {
create(); destructor();
constructor();
} }
void pListView::setHeaderVisible(bool visible) { void pListView::setHeaderVisible(bool visible) {
@ -140,12 +141,6 @@ void pListView::setSelection(unsigned row) {
void pListView::constructor() { void pListView::constructor() {
gtkWidget = 0; gtkWidget = 0;
subWidget = 0; subWidget = 0;
create();
}
void pListView::create() {
if(subWidget) gtk_widget_destroy(subWidget);
if(gtkWidget) gtk_widget_destroy(gtkWidget);
gtkWidget = gtk_scrolled_window_new(0, 0); gtkWidget = gtk_scrolled_window_new(0, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
@ -189,23 +184,33 @@ void pListView::create() {
g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView); g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView);
g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView); g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView);
gtk_widget_show(subWidget);
setHeaderVisible(listView.state.headerVisible); setHeaderVisible(listView.state.headerVisible);
setCheckable(listView.state.checkable); setCheckable(listView.state.checkable);
foreach(text, listView.state.text) append(text); foreach(text, listView.state.text) append(text);
foreach(checked, listView.state.checked, n) setChecked(n, checked); foreach(checked, listView.state.checked, n) setChecked(n, checked);
if(listView.state.selected) setSelection(listView.state.selection); if(listView.state.selected) setSelection(listView.state.selection);
autoSizeColumns(); autoSizeColumns();
}
gtk_widget_show(subWidget); void pListView::destructor() {
gtk_widget_destroy(subWidget);
gtk_widget_destroy(gtkWidget);
}
void pListView::orphan() {
destructor();
constructor();
} }
void pListView::setFocused() { void pListView::setFocused() {
gtk_widget_grab_focus(subWidget); gtk_widget_grab_focus(subWidget);
} }
void pListView::setFont(Font &font) { void pListView::setFont(const string &font) {
pWidget::setFont(font); pFont::setFont(gtkWidget, font);
for(unsigned n = 0; n < 1 + listView.state.headerText.size(); n++) { for(unsigned n = 0; n < 1 + listView.state.headerText.size(); n++) {
gtk_widget_modify_font(column[n].label, font.p.gtkFont); pFont::setFont(column[n].label, font);
} }
} }

View File

@ -9,4 +9,15 @@ void pProgressBar::setPosition(unsigned position) {
void pProgressBar::constructor() { void pProgressBar::constructor() {
gtkWidget = gtk_progress_bar_new(); gtkWidget = gtk_progress_bar_new();
setPosition(progressBar.state.position);
}
void pProgressBar::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pProgressBar::orphan() {
destructor();
constructor();
} }

View File

@ -7,8 +7,9 @@ bool pRadioBox::checked() {
} }
Geometry pRadioBox::minimumGeometry() { Geometry pRadioBox::minimumGeometry() {
Font &font = pWidget::font(); Geometry geometry = pFont::geometry(widget.state.font, radioBox.state.text);
Geometry geometry = font.geometry(radioBox.state.text); //Font &font = pWidget::font();
//Geometry geometry = font.geometry(radioBox.state.text);
return { 0, 0, geometry.width + 28, geometry.height + 4 }; return { 0, 0, geometry.width + 28, geometry.height + 4 };
} }
@ -35,4 +36,15 @@ void pRadioBox::setText(const string &text) {
void pRadioBox::constructor() { void pRadioBox::constructor() {
gtkWidget = gtk_radio_button_new_with_label(0, ""); gtkWidget = gtk_radio_button_new_with_label(0, "");
g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)&radioBox); g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)&radioBox);
setText(radioBox.state.text);
}
void pRadioBox::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pRadioBox::orphan() {
destructor();
constructor();
} }

View File

@ -1,4 +1,5 @@
static void TextEdit_change(TextEdit *self) { static void TextEdit_change(TextEdit *self) {
self->state.text = self->text();
if(self->p.locked == false && self->onChange) self->onChange(); if(self->p.locked == false && self->onChange) self->onChange();
} }
@ -45,4 +46,18 @@ void pTextEdit::constructor() {
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget));
g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit); g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit);
gtk_widget_show(subWidget); gtk_widget_show(subWidget);
setEditable(textEdit.state.editable);
setText(textEdit.state.text);
setWordWrap(textEdit.state.wordWrap);
}
void pTextEdit::destructor() {
gtk_widget_destroy(subWidget);
gtk_widget_destroy(gtkWidget);
}
void pTextEdit::orphan() {
destructor();
constructor();
} }

View File

@ -24,6 +24,17 @@ void pVerticalScrollBar::setPosition(unsigned position) {
void pVerticalScrollBar::constructor() { void pVerticalScrollBar::constructor() {
gtkWidget = gtk_vscrollbar_new(0); gtkWidget = gtk_vscrollbar_new(0);
setLength(101);
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalScrollBar_change), (gpointer)&verticalScrollBar); g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalScrollBar_change), (gpointer)&verticalScrollBar);
setLength(verticalScrollBar.state.length);
setPosition(verticalScrollBar.state.position);
}
void pVerticalScrollBar::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pVerticalScrollBar::orphan() {
destructor();
constructor();
} }

View File

@ -25,6 +25,17 @@ void pVerticalSlider::setPosition(unsigned position) {
void pVerticalSlider::constructor() { void pVerticalSlider::constructor() {
gtkWidget = gtk_vscale_new_with_range(0, 100, 1); gtkWidget = gtk_vscale_new_with_range(0, 100, 1);
gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false);
setLength(101);
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider); g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider);
setLength(verticalSlider.state.length);
setPosition(verticalSlider.state.position);
}
void pVerticalSlider::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pVerticalSlider::orphan() {
destructor();
constructor();
} }

View File

@ -13,3 +13,12 @@ void pViewport::constructor() {
color.blue = 0; color.blue = 0;
gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color); gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color);
} }
void pViewport::destructor() {
gtk_widget_destroy(gtkWidget);
}
void pViewport::orphan() {
destructor();
constructor();
}

View File

@ -1,16 +1,3 @@
static void Widget_setFont(GtkWidget *widget, gpointer font) {
if(font == 0) return;
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
if(GTK_IS_CONTAINER(widget)) {
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Widget_setFont, font);
}
}
Font& pWidget::font() {
if(widget.state.font) return *widget.state.font;
return pOS::defaultFont;
}
Geometry pWidget::minimumGeometry() { Geometry pWidget::minimumGeometry() {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
@ -20,6 +7,8 @@ bool pWidget::enabled() {
} }
void pWidget::setEnabled(bool enabled) { void pWidget::setEnabled(bool enabled) {
if(widget.state.abstract) enabled = false;
if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false;
gtk_widget_set_sensitive(gtkWidget, enabled); gtk_widget_set_sensitive(gtkWidget, enabled);
} }
@ -27,35 +16,32 @@ void pWidget::setFocused() {
gtk_widget_grab_focus(gtkWidget); gtk_widget_grab_focus(gtkWidget);
} }
void pWidget::setFont(Font &font) { void pWidget::setFont(const string &font) {
Widget_setFont(gtkWidget, font.p.gtkFont); pFont::setFont(gtkWidget, font);
} }
void pWidget::setGeometry(const Geometry &geometry) { void pWidget::setGeometry(const Geometry &geometry) {
if(parentWindow) gtk_fixed_move(GTK_FIXED(parentWindow->formContainer), gtkWidget, geometry.x, geometry.y); if(sizable.state.window) gtk_fixed_move(GTK_FIXED(sizable.state.window->p.formContainer), gtkWidget, geometry.x, geometry.y);
unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width; unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width;
unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height; unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height;
gtk_widget_set_size_request(gtkWidget, width, height); gtk_widget_set_size_request(gtkWidget, width, height);
} }
void pWidget::setParent(Window &parent) {
parentWindow = &parent.p;
if(!widget.state.font && parent.state.widgetFont) {
setFont(*parent.state.widgetFont);
}
gtk_fixed_put(GTK_FIXED(parent.p.formContainer), gtkWidget, 0, 0);
widget.setVisible(widget.visible());
}
void pWidget::setVisible(bool visible) { void pWidget::setVisible(bool visible) {
if(widget.state.abstract) visible = false; if(widget.state.abstract) visible = false;
if(widget.state.layout && widget.state.layout->visible() == false) visible = false; if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false;
gtk_widget_set_visible(gtkWidget, visible); gtk_widget_set_visible(gtkWidget, visible);
} }
void pWidget::constructor() { void pWidget::constructor() {
parentWindow = 0;
if(widget.state.abstract) gtkWidget = gtk_label_new(""); if(widget.state.abstract) gtkWidget = gtk_label_new("");
} }
void pWidget::destructor() {
if(widget.state.abstract) gtk_widget_destroy(gtkWidget);
}
void pWidget::orphan() {
destructor();
constructor();
}

View File

@ -1,9 +1,7 @@
static void Action_setFont(GtkWidget *widget, gpointer font);
static void Widget_setFont(GtkWidget *widget, gpointer font);
static gint Window_close(GtkWidget *widget, GdkEvent *event, Window *window) { static gint Window_close(GtkWidget *widget, GdkEvent *event, Window *window) {
window->state.ignore = false;
if(window->onClose) window->onClose(); if(window->onClose) window->onClose();
window->setVisible(false); if(window->state.ignore == false) window->setVisible(false);
return true; return true;
} }
@ -78,25 +76,24 @@ static gboolean Window_configure(GtkWidget *widget, GdkEvent *event, Window *win
} }
void pWindow::append(Layout &layout) { void pWindow::append(Layout &layout) {
layout.setParent(window);
Geometry geometry = this->geometry(); Geometry geometry = this->geometry();
geometry.x = geometry.y = 0; geometry.x = geometry.y = 0;
layout.setGeometry(geometry); layout.setGeometry(geometry);
} }
void pWindow::append(Menu &subMenu) { void pWindow::append(Menu &menu) {
if(window.state.menuFont) subMenu.p.setFont(*window.state.menuFont); if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), subMenu.p.widget); else menu.p.setFont("Sans, 8");
gtk_widget_show(subMenu.p.widget); gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), menu.p.widget);
gtk_widget_show(menu.p.widget);
} }
void pWindow::append(Widget &widget) { void pWindow::append(Widget &widget) {
widget.p.parentWindow = this;
if(!widget.state.font && window.state.widgetFont) {
widget.setFont(*window.state.widgetFont);
}
gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0); gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0);
widget.setVisible(); if(widget.state.font != "") widget.p.setFont(widget.state.font);
else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont);
else widget.p.setFont("Sans, 8");
widget.setVisible(widget.visible());
} }
Color pWindow::backgroundColor() { Color pWindow::backgroundColor() {
@ -126,6 +123,17 @@ Geometry pWindow::geometry() {
return window.state.geometry; return window.state.geometry;
} }
void pWindow::remove(Layout &layout) {
}
void pWindow::remove(Menu &menu) {
menu.p.orphan();
}
void pWindow::remove(Widget &widget) {
widget.p.orphan();
}
void pWindow::setBackgroundColor(const Color &color) { void pWindow::setBackgroundColor(const Color &color) {
GdkColor gdkColor; GdkColor gdkColor;
gdkColor.pixel = (color.red << 16) | (color.green << 8) | (color.blue << 0); gdkColor.pixel = (color.red << 16) | (color.green << 8) | (color.blue << 0);
@ -170,7 +178,7 @@ void pWindow::setGeometry(const Geometry &geometry) {
} }
} }
void pWindow::setMenuFont(Font &font) { void pWindow::setMenuFont(const string &font) {
foreach(item, window.state.menu) item.p.setFont(font); foreach(item, window.state.menu) item.p.setFont(font);
} }
@ -183,8 +191,8 @@ void pWindow::setResizable(bool resizable) {
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable); gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable);
} }
void pWindow::setStatusFont(Font &font) { void pWindow::setStatusFont(const string &font) {
Widget_setFont(status, (gpointer)font.p.gtkFont); pFont::setFont(status, font);
} }
void pWindow::setStatusText(const string &text) { void pWindow::setStatusText(const string &text) {
@ -204,9 +212,9 @@ void pWindow::setVisible(bool visible) {
gtk_widget_set_visible(widget, visible); gtk_widget_set_visible(widget, visible);
} }
void pWindow::setWidgetFont(Font &font) { void pWindow::setWidgetFont(const string &font) {
foreach(item, window.state.widget) { foreach(item, window.state.widget) {
if(!item.state.font) item.setFont(font); if(item.state.font == "") item.setFont(font);
} }
} }
@ -244,6 +252,8 @@ void pWindow::constructor() {
setTitle(""); setTitle("");
setGeometry(window.state.geometry); setGeometry(window.state.geometry);
setMenuFont("Sans, 8");
setStatusFont("Sans, 8");
g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window); g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window);
g_signal_connect(G_OBJECT(widget), "expose-event", G_CALLBACK(Window_expose), (gpointer)&window); g_signal_connect(G_OBJECT(widget), "expose-event", G_CALLBACK(Window_expose), (gpointer)&window);

View File

@ -12,17 +12,19 @@ void pAction::setEnabled(bool enabled) {
} }
} }
void pAction::setFont(Font &font) { void pAction::setFont(const string &font) {
QFont qtFont = pFont::create(font);
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
((Menu&)action).p.setFont(font); ((Menu&)action).p.setFont(font);
} else if(dynamic_cast<Separator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
((Separator&)action).p.qtAction->setFont(*font.p.qtFont); ((Separator&)action).p.qtAction->setFont(qtFont);
} else if(dynamic_cast<Item*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
((Item&)action).p.qtAction->setFont(*font.p.qtFont); ((Item&)action).p.qtAction->setFont(qtFont);
} else if(dynamic_cast<CheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
((CheckItem&)action).p.qtAction->setFont(*font.p.qtFont); ((CheckItem&)action).p.qtAction->setFont(qtFont);
} else if(dynamic_cast<RadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
((RadioItem&)action).p.qtAction->setFont(*font.p.qtFont); ((RadioItem&)action).p.qtAction->setFont(qtFont);
} }
} }
@ -42,3 +44,6 @@ void pAction::setVisible(bool visible) {
void pAction::constructor() { void pAction::constructor() {
} }
void pAction::destructor() {
}

View File

@ -16,6 +16,11 @@ void pCheckItem::constructor() {
connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
} }
void pCheckItem::destructor() {
if(action.state.menu) action.state.menu->remove(checkItem);
delete qtAction;
}
void pCheckItem::onTick() { void pCheckItem::onTick() {
checkItem.state.checked = checked(); checkItem.state.checked = checked();
if(checkItem.onTick) checkItem.onTick(); if(checkItem.onTick) checkItem.onTick();

View File

@ -7,6 +7,11 @@ void pItem::constructor() {
connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
} }
void pItem::destructor() {
if(action.state.menu) action.state.menu->remove(item);
delete qtAction;
}
void pItem::onTick() { void pItem::onTick() {
if(item.onTick) item.onTick(); if(item.onTick) item.onTick();
} }

View File

@ -12,8 +12,24 @@ void pMenu::append(Action &action) {
} }
} }
void pMenu::setFont(Font &font) { void pMenu::remove(Action &action) {
qtMenu->setFont(*font.p.qtFont); if(dynamic_cast<Menu*>(&action)) {
//QMenu::removeMenu() does not exist
qtMenu->clear();
foreach(action, menu.state.action) append(action);
} else if(dynamic_cast<Separator*>(&action)) {
qtMenu->removeAction(((Separator&)action).p.qtAction);
} else if(dynamic_cast<Item*>(&action)) {
qtMenu->removeAction(((Item&)action).p.qtAction);
} else if(dynamic_cast<CheckItem*>(&action)) {
qtMenu->removeAction(((CheckItem&)action).p.qtAction);
} else if(dynamic_cast<RadioItem*>(&action)) {
qtMenu->removeAction(((CheckItem&)action).p.qtAction);
}
}
void pMenu::setFont(const string &font) {
qtMenu->setFont(pFont::create(font));
foreach(item, menu.state.action) item.p.setFont(font); foreach(item, menu.state.action) item.p.setFont(font);
} }
@ -24,3 +40,8 @@ void pMenu::setText(const string &text) {
void pMenu::constructor() { void pMenu::constructor() {
qtMenu = new QMenu; qtMenu = new QMenu;
} }
void pMenu::destructor() {
if(action.state.menu) action.state.menu->remove(menu);
delete qtMenu;
}

View File

@ -28,6 +28,11 @@ void pRadioItem::constructor() {
connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
} }
void pRadioItem::destructor() {
if(action.state.menu) action.state.menu->remove(radioItem);
delete qtAction;
}
void pRadioItem::onTick() { void pRadioItem::onTick() {
if(radioItem.state.checked == false) { if(radioItem.state.checked == false) {
setChecked(); setChecked();

View File

@ -2,3 +2,8 @@ void pSeparator::constructor() {
qtAction = new QAction(0); qtAction = new QAction(0);
qtAction->setSeparator(true); qtAction->setSeparator(true);
} }
void pSeparator::destructor() {
if(action.state.menu) action.state.menu->remove(separator);
delete qtAction;
}

View File

@ -1,5 +1,27 @@
Geometry pFont::geometry(const string &text) { Geometry pFont::geometry(const string &description, const string &text) {
QFontMetrics metrics(*qtFont); return pFont::geometry(pFont::create(description), text);
}
QFont pFont::create(const string &description) {
lstring part;
part.split(",", description);
foreach(item, part) item.trim(" ");
string name = part[0] != "" ? part[0] : "Sans";
unsigned size = part.size() >= 2 ? decimal(part[1]) : 8u;
bool bold = part[2].position("Bold");
bool italic = part[2].position("Italic");
QFont qtFont;
qtFont.setFamily(part[0]);
qtFont.setPointSize(decimal(part[1]));
if(bold) qtFont.setBold(true);
if(italic) qtFont.setItalic(true);
return qtFont;
}
Geometry pFont::geometry(const QFont &qtFont, const string &text) {
QFontMetrics metrics(qtFont);
lstring lines; lstring lines;
lines.split("\n", text); lines.split("\n", text);
@ -11,23 +33,3 @@ Geometry pFont::geometry(const string &text) {
return { 0, 0, maxWidth, metrics.height() * lines.size() }; return { 0, 0, maxWidth, metrics.height() * lines.size() };
} }
void pFont::setBold(bool bold) { update(); }
void pFont::setFamily(const string &family) { update(); }
void pFont::setItalic(bool italic) { update(); }
void pFont::setSize(unsigned size) { update(); }
void pFont::setUnderline(bool underline) { update(); }
void pFont::constructor() {
qtFont = new QFont;
font.setFamily("Sans");
font.setSize(8);
}
void pFont::update() {
qtFont->setFamily(QString::fromUtf8(font.state.family));
qtFont->setPointSize(font.state.size);
qtFont->setBold(font.state.bold);
qtFont->setItalic(font.state.italic);
qtFont->setUnderline(font.state.underline);
}

View File

@ -1,5 +1,5 @@
#include "qt.moc.hpp" #include "platform.moc.hpp"
#include "qt.moc" #include "platform.moc"
#include "settings.cpp" #include "settings.cpp"
#include "font.cpp" #include "font.cpp"
@ -32,9 +32,6 @@
#include "widget/vertical-slider.cpp" #include "widget/vertical-slider.cpp"
#include "widget/viewport.cpp" #include "widget/viewport.cpp"
QApplication *pOS::application = 0;
Font pOS::defaultFont;
Geometry pOS::availableGeometry() { Geometry pOS::availableGeometry() {
QRect rect = QApplication::desktop()->availableGeometry(); QRect rect = QApplication::desktop()->availableGeometry();
return { rect.x(), rect.y(), rect.width(), rect.height() }; return { rect.x(), rect.y(), rect.width(), rect.height() };
@ -118,6 +115,8 @@ void pOS::processEvents() {
void pOS::quit() { void pOS::quit() {
settings.save(); settings.save();
QApplication::quit(); QApplication::quit();
//note: QApplication cannot be deleted; or libQtGui will crash
qtApplication = 0;
} }
void pOS::initialize() { void pOS::initialize() {
@ -129,5 +128,6 @@ void pOS::initialize() {
argv[1] = 0; argv[1] = 0;
strcpy(argv[0], "phoenix"); strcpy(argv[0], "phoenix");
char **argvp = argv; char **argvp = argv;
application = new QApplication(argc, argvp);
qtApplication = new QApplication(argc, argvp);
} }

View File

@ -1,14 +1,14 @@
/**************************************************************************** /****************************************************************************
** Meta object code from reading C++ file 'qt.moc.hpp' ** Meta object code from reading C++ file 'platform.moc.hpp'
** **
** Created: Mon Aug 22 04:02:58 2011 ** Created: Tue Aug 30 09:38:15 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0) ** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!
*****************************************************************************/ *****************************************************************************/
#if !defined(Q_MOC_OUTPUT_REVISION) #if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qt.moc.hpp' doesn't include <QObject>." #error "The header file 'platform.moc.hpp' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62 #elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.7.0. It" #error "This file was generated using the moc from 4.7.0. It"
#error "cannot be used with the include files from this version of Qt." #error "cannot be used with the include files from this version of Qt."

View File

@ -1,3 +1,5 @@
static QApplication *qtApplication = 0;
struct Settings : public configuration { struct Settings : public configuration {
unsigned frameGeometryX; unsigned frameGeometryX;
unsigned frameGeometryY; unsigned frameGeometryY;
@ -9,24 +11,29 @@ struct Settings : public configuration {
Settings(); Settings();
}; };
struct pFont;
struct pWindow; struct pWindow;
struct pMenu; struct pMenu;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pFont {
static Geometry geometry(const string &description, const string &text);
static QFont create(const string &description);
static Geometry geometry(const QFont &qtFont, const string &text);
};
struct pObject { struct pObject {
Object &object;
bool locked; bool locked;
pObject() { pObject(Object &object) : object(object), locked(false) {}
locked = false; virtual ~pObject() {}
} void constructor() {}
void destructor() {}
}; };
struct pOS : public pObject { struct pOS : public pObject {
static QApplication *application;
static Font defaultFont;
static Geometry availableGeometry(); static Geometry availableGeometry();
static Geometry desktopGeometry(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
@ -40,22 +47,6 @@ struct pOS : public pObject {
static void initialize(); static void initialize();
}; };
struct pFont : public pObject {
Font &font;
QFont *qtFont;
Geometry geometry(const string &text);
void setBold(bool bold);
void setFamily(const string &family);
void setItalic(bool italic);
void setSize(unsigned size);
void setUnderline(bool underline);
pFont(Font &font) : font(font) {}
void constructor();
void update();
};
struct pTimer : public QObject, public pObject { struct pTimer : public QObject, public pObject {
Q_OBJECT Q_OBJECT
@ -66,8 +57,9 @@ public:
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setInterval(unsigned milliseconds); void setInterval(unsigned milliseconds);
pTimer(Timer &timer) : timer(timer) {} pTimer(Timer &timer) : pObject(timer), timer(timer) {}
void constructor(); void constructor();
void destructor();
public slots: public slots:
void onTimeout(); void onTimeout();
@ -105,22 +97,26 @@ public:
Geometry frameMargin(); Geometry frameMargin();
bool focused(); bool focused();
Geometry geometry(); Geometry geometry();
void remove(Layout &layout);
void remove(Menu &menu);
void remove(Widget &widget);
void setBackgroundColor(const Color &color); void setBackgroundColor(const Color &color);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setMenuFont(Font &font); void setMenuFont(const string &font);
void setMenuVisible(bool visible); void setMenuVisible(bool visible);
void setResizable(bool resizable); void setResizable(bool resizable);
void setStatusFont(Font &font); void setStatusFont(const string &font);
void setStatusText(const string &text); void setStatusText(const string &text);
void setStatusVisible(bool visible); void setStatusVisible(bool visible);
void setTitle(const string &text); void setTitle(const string &text);
void setVisible(bool visible); void setVisible(bool visible);
void setWidgetFont(Font &font); void setWidgetFont(const string &font);
pWindow(Window &window) : window(window) {} pWindow(Window &window) : pObject(window), window(window) {}
void constructor(); void constructor();
void destructor();
void updateFrameGeometry(); void updateFrameGeometry();
}; };
@ -128,11 +124,12 @@ struct pAction : public pObject {
Action &action; Action &action;
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setFont(Font &font); void setFont(const string &font);
void setVisible(bool visible); void setVisible(bool visible);
pAction(Action &action) : action(action) {} pAction(Action &action) : pObject(action), action(action) {}
void constructor(); void constructor();
void destructor();
}; };
struct pMenu : public pAction { struct pMenu : public pAction {
@ -140,11 +137,13 @@ struct pMenu : public pAction {
QMenu *qtMenu; QMenu *qtMenu;
void append(Action &action); void append(Action &action);
void setFont(Font &font); void remove(Action &action);
void setFont(const string &font);
void setText(const string &text); void setText(const string &text);
pMenu(Menu &menu) : pAction(menu), menu(menu) {} pMenu(Menu &menu) : pAction(menu), menu(menu) {}
void constructor(); void constructor();
void destructor();
}; };
struct pSeparator : public pAction { struct pSeparator : public pAction {
@ -153,6 +152,7 @@ struct pSeparator : public pAction {
pSeparator(Separator &separator) : pAction(separator), separator(separator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
void destructor();
}; };
struct pItem : public QObject, public pAction { struct pItem : public QObject, public pAction {
@ -166,6 +166,7 @@ public:
pItem(Item &item) : pAction(item), item(item) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
void destructor();
public slots: public slots:
void onTick(); void onTick();
@ -184,6 +185,7 @@ public:
pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
void destructor();
public slots: public slots:
void onTick(); void onTick();
@ -204,26 +206,45 @@ public:
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
void destructor();
public slots: public slots:
void onTick(); void onTick();
}; };
struct pWidget : public pObject { struct pSizable : public pObject {
Sizable &sizable;
pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {}
void constructor() {}
void destructor() {}
};
struct pLayout : public pSizable {
Layout &layout;
pLayout(Layout &layout) : pSizable(layout), layout(layout) {}
void constructor() {}
void destructor() {}
};
struct pWidget : public pSizable {
Widget &widget; Widget &widget;
QWidget *qtWidget; QWidget *qtWidget;
Font& font();
virtual Geometry minimumGeometry(); virtual Geometry minimumGeometry();
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(const string &font);
virtual void setGeometry(const Geometry &geometry); virtual void setGeometry(const Geometry &geometry);
void setParent(Window &parent);
void setVisible(bool visible); void setVisible(bool visible);
pWidget(Widget &widget) : widget(widget) {} pWidget(Widget &widget) : pSizable(widget), widget(widget) {}
void constructor(); void constructor();
void destructor();
virtual void orphan();
}; };
struct pButton : public QObject, public pWidget { struct pButton : public QObject, public pWidget {
@ -238,6 +259,8 @@ public:
pButton(Button &button) : pWidget(button), button(button) {} pButton(Button &button) : pWidget(button), button(button) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onTick(); void onTick();
@ -261,6 +284,8 @@ public:
pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
}; };
@ -279,6 +304,8 @@ public:
pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onTick(); void onTick();
@ -299,6 +326,8 @@ public:
pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -326,6 +355,8 @@ public:
pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
void keyPressEvent(QKeyEvent*); void keyPressEvent(QKeyEvent*);
public slots: public slots:
@ -346,6 +377,8 @@ public:
pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -365,6 +398,8 @@ public:
pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -379,6 +414,8 @@ struct pLabel : public pWidget {
pLabel(Label &label) : pWidget(label), label(label) {} pLabel(Label &label) : pWidget(label), label(label) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pLineEdit : public QObject, public pWidget { struct pLineEdit : public QObject, public pWidget {
@ -395,6 +432,8 @@ public:
pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onActivate(); void onActivate();
@ -424,6 +463,8 @@ public:
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onActivate(); void onActivate();
@ -440,6 +481,8 @@ struct pProgressBar : public pWidget {
pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };
struct pRadioBox : public QObject, public pWidget { struct pRadioBox : public QObject, public pWidget {
@ -458,6 +501,8 @@ public:
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onTick(); void onTick();
@ -478,6 +523,8 @@ public:
pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -497,6 +544,8 @@ public:
pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -516,6 +565,8 @@ public:
pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {}
void constructor(); void constructor();
void destructor();
void orphan();
public slots: public slots:
void onChange(); void onChange();
@ -528,4 +579,6 @@ struct pViewport : public pWidget {
pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {}
void constructor(); void constructor();
void destructor();
void orphan();
}; };

View File

@ -16,6 +16,10 @@ void pTimer::constructor() {
connect(qtTimer, SIGNAL(timeout()), SLOT(onTimeout())); connect(qtTimer, SIGNAL(timeout()), SLOT(onTimeout()));
} }
void pTimer::destructor() {
delete qtTimer;
}
void pTimer::onTimeout() { void pTimer::onTimeout() {
if(timer.onTimeout) timer.onTimeout(); if(timer.onTimeout) timer.onTimeout();
} }

View File

@ -1,6 +1,5 @@
Geometry pButton::minimumGeometry() { Geometry pButton::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(qtWidget->font(), button.state.text);
Geometry geometry = font.geometry(button.state.text);
return { 0, 0, geometry.width + 20, geometry.height + 12 }; return { 0, 0, geometry.width + 20, geometry.height + 12 };
} }
@ -11,6 +10,17 @@ void pButton::setText(const string &text) {
void pButton::constructor() { void pButton::constructor() {
qtWidget = qtButton = new QPushButton; qtWidget = qtButton = new QPushButton;
connect(qtButton, SIGNAL(released()), SLOT(onTick())); connect(qtButton, SIGNAL(released()), SLOT(onTick()));
setText(button.state.text);
}
void pButton::destructor() {
delete qtButton;
qtWidget = qtButton = 0;
}
void pButton::orphan() {
destructor();
constructor();
} }
void pButton::onTick() { void pButton::onTick() {

View File

@ -16,6 +16,20 @@ void pCanvas::update() {
void pCanvas::constructor() { void pCanvas::constructor() {
qtWidget = qtCanvas = new QtCanvas(*this); qtWidget = qtCanvas = new QtCanvas(*this);
qtImage = new QImage(256, 256, QImage::Format_RGB32); qtImage = new QImage(256, 256, QImage::Format_RGB32);
update();
}
void pCanvas::destructor() {
delete qtCanvas;
delete qtImage;
qtWidget = qtCanvas = 0;
qtImage = 0;
}
void pCanvas::orphan() {
destructor();
constructor();
} }
void pCanvas::QtCanvas::paintEvent(QPaintEvent *event) { void pCanvas::QtCanvas::paintEvent(QPaintEvent *event) {

View File

@ -3,8 +3,7 @@ bool pCheckBox::checked() {
} }
Geometry pCheckBox::minimumGeometry() { Geometry pCheckBox::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(qtWidget->font(), checkBox.state.text);
Geometry geometry = font.geometry(checkBox.state.text);
return { 0, 0, geometry.width + 26, geometry.height + 6 }; return { 0, 0, geometry.width + 26, geometry.height + 6 };
} }
@ -21,8 +20,22 @@ void pCheckBox::setText(const string &text) {
void pCheckBox::constructor() { void pCheckBox::constructor() {
qtWidget = qtCheckBox = new QCheckBox; qtWidget = qtCheckBox = new QCheckBox;
connect(qtCheckBox, SIGNAL(stateChanged(int)), SLOT(onTick())); connect(qtCheckBox, SIGNAL(stateChanged(int)), SLOT(onTick()));
setChecked(checkBox.state.checked);
setText(checkBox.state.text);
}
void pCheckBox::destructor() {
delete qtCheckBox;
qtWidget = qtCheckBox = 0;
}
void pCheckBox::orphan() {
destructor();
constructor();
} }
void pCheckBox::onTick() { void pCheckBox::onTick() {
checkBox.state.checked = checked();
if(locked == false && checkBox.onTick) checkBox.onTick(); if(locked == false && checkBox.onTick) checkBox.onTick();
} }

View File

@ -3,10 +3,9 @@ void pComboBox::append(const string &text) {
} }
Geometry pComboBox::minimumGeometry() { Geometry pComboBox::minimumGeometry() {
Font &font = this->font();
unsigned maximumWidth = 0; unsigned maximumWidth = 0;
foreach(text, comboBox.state.text) maximumWidth = max(maximumWidth, font.geometry(text).width); foreach(text, comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(qtWidget->font(), text).width);
Geometry geometry = font.geometry(" "); Geometry geometry = pFont::geometry(qtWidget->font(), " ");
return { 0, 0, maximumWidth + 32, geometry.height + 12 }; return { 0, 0, maximumWidth + 32, geometry.height + 12 };
} }
@ -28,9 +27,25 @@ void pComboBox::setSelection(unsigned row) {
void pComboBox::constructor() { void pComboBox::constructor() {
qtWidget = qtComboBox = new QComboBox; qtWidget = qtComboBox = new QComboBox;
connect(qtComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onChange())); connect(qtComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onChange()));
locked = true;
foreach(text, comboBox.state.text) append(text);
locked = false;
setSelection(comboBox.state.selection);
}
void pComboBox::destructor() {
delete qtComboBox;
qtWidget = qtComboBox = 0;
}
void pComboBox::orphan() {
destructor();
constructor();
} }
void pComboBox::onChange() { void pComboBox::onChange() {
if(locked == true) return;
comboBox.state.selection = selection(); comboBox.state.selection = selection();
if(locked == false && comboBox.onChange) comboBox.onChange(); if(comboBox.onChange) comboBox.onChange();
} }

View File

@ -80,6 +80,26 @@ void pHexEdit::constructor() {
qtLayout->addWidget(qtScroll); qtLayout->addWidget(qtScroll);
connect(qtScroll, SIGNAL(actionTriggered(int)), SLOT(onScroll())); connect(qtScroll, SIGNAL(actionTriggered(int)), SLOT(onScroll()));
setColumns(hexEdit.state.columns);
setRows(hexEdit.state.rows);
setLength(hexEdit.state.length);
setOffset(hexEdit.state.offset);
update();
}
void pHexEdit::destructor() {
delete qtScroll;
delete qtLayout;
delete qtHexEdit;
qtWidget = qtHexEdit = 0;
qtLayout = 0;
qtScroll = 0;
}
void pHexEdit::orphan() {
destructor();
constructor();
} }
void pHexEdit::keyPressEvent(QKeyEvent *event) { void pHexEdit::keyPressEvent(QKeyEvent *event) {

View File

@ -21,6 +21,19 @@ void pHorizontalScrollBar::constructor() {
qtScrollBar->setRange(0, 100); qtScrollBar->setRange(0, 100);
qtScrollBar->setPageStep(101 >> 3); qtScrollBar->setPageStep(101 >> 3);
connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange()));
setLength(horizontalScrollBar.state.length);
setPosition(horizontalScrollBar.state.position);
}
void pHorizontalScrollBar::destructor() {
delete qtScrollBar;
qtWidget = qtScrollBar = 0;
}
void pHorizontalScrollBar::orphan() {
destructor();
constructor();
} }
void pHorizontalScrollBar::onChange() { void pHorizontalScrollBar::onChange() {

View File

@ -21,6 +21,19 @@ void pHorizontalSlider::constructor() {
qtSlider->setRange(0, 100); qtSlider->setRange(0, 100);
qtSlider->setPageStep(101 >> 3); qtSlider->setPageStep(101 >> 3);
connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange()));
setLength(horizontalSlider.state.length);
setPosition(horizontalSlider.state.position);
}
void pHorizontalSlider::destructor() {
delete qtSlider;
qtWidget = qtSlider = 0;
}
void pHorizontalSlider::orphan() {
destructor();
constructor();
} }
void pHorizontalSlider::onChange() { void pHorizontalSlider::onChange() {

View File

@ -1,6 +1,5 @@
Geometry pLabel::minimumGeometry() { Geometry pLabel::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(qtWidget->font(), label.state.text);
Geometry geometry = font.geometry(label.state.text);
return { 0, 0, geometry.width, geometry.height }; return { 0, 0, geometry.width, geometry.height };
} }
@ -10,4 +9,15 @@ void pLabel::setText(const string &text) {
void pLabel::constructor() { void pLabel::constructor() {
qtWidget = qtLabel = new QLabel; qtWidget = qtLabel = new QLabel;
setText(label.state.text);
}
void pLabel::destructor() {
delete qtLabel;
qtWidget = qtLabel = 0;
}
void pLabel::orphan() {
destructor();
constructor();
} }

View File

@ -1,6 +1,5 @@
Geometry pLineEdit::minimumGeometry() { Geometry pLineEdit::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(qtWidget->font(), lineEdit.state.text);
Geometry geometry = font.geometry(lineEdit.state.text);
return { 0, 0, geometry.width + 12, geometry.height + 12 }; return { 0, 0, geometry.width + 12, geometry.height + 12 };
} }
@ -20,6 +19,18 @@ void pLineEdit::constructor() {
qtWidget = qtLineEdit = new QLineEdit; qtWidget = qtLineEdit = new QLineEdit;
connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate())); connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate()));
connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange())); connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange()));
setEditable(lineEdit.state.editable);
setText(lineEdit.state.text);
}
void pLineEdit::destructor() {
delete qtLineEdit;
qtWidget = qtLineEdit = 0;
}
void pLineEdit::orphan() {
destructor();
constructor();
} }
void pLineEdit::onActivate() { void pLineEdit::onActivate() {

View File

@ -95,14 +95,34 @@ void pListView::setSelection(unsigned row) {
void pListView::constructor() { void pListView::constructor() {
qtWidget = qtListView = new QTreeWidget; qtWidget = qtListView = new QTreeWidget;
qtListView->setHeaderLabels(QStringList() << "");
qtListView->setHeaderHidden(true);
qtListView->setAllColumnsShowFocus(true); qtListView->setAllColumnsShowFocus(true);
qtListView->setRootIsDecorated(false); qtListView->setRootIsDecorated(false);
connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate())); connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate()));
connect(qtListView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(onChange(QTreeWidgetItem*))); connect(qtListView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(onChange(QTreeWidgetItem*)));
connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onTick(QTreeWidgetItem*))); connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onTick(QTreeWidgetItem*)));
setCheckable(listView.state.checkable);
setHeaderText(listView.state.headerText.size() ? listView.state.headerText : lstring{ " " });
setHeaderVisible(listView.state.headerVisible);
foreach(row, listView.state.text) append(row);
if(listView.state.checkable) {
for(unsigned n = 0; n < listView.state.checked.size(); n++) {
setChecked(n, listView.state.checked[n]);
}
}
setSelected(listView.state.selected);
if(listView.state.selected) setSelection(listView.state.selection);
}
void pListView::destructor() {
delete qtListView;
qtWidget = qtListView = 0;
}
void pListView::orphan() {
destructor();
constructor();
} }
void pListView::onActivate() { void pListView::onActivate() {

View File

@ -10,4 +10,16 @@ void pProgressBar::constructor() {
qtWidget = qtProgressBar = new QProgressBar; qtWidget = qtProgressBar = new QProgressBar;
qtProgressBar->setRange(0, 100); qtProgressBar->setRange(0, 100);
qtProgressBar->setTextVisible(false); qtProgressBar->setTextVisible(false);
setPosition(progressBar.state.position);
}
void pProgressBar::destructor() {
delete qtProgressBar;
qtWidget = qtProgressBar = 0;
}
void pProgressBar::orphan() {
destructor();
constructor();
} }

View File

@ -3,8 +3,7 @@ bool pRadioBox::checked() {
} }
Geometry pRadioBox::minimumGeometry() { Geometry pRadioBox::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(qtWidget->font(), radioBox.state.text);
Geometry geometry = font.geometry(radioBox.state.text);
return { 0, 0, geometry.width + 26, geometry.height + 6 }; return { 0, 0, geometry.width + 26, geometry.height + 6 };
} }
@ -42,6 +41,20 @@ void pRadioBox::constructor() {
qtGroup->addButton(qtRadioBox); qtGroup->addButton(qtRadioBox);
qtRadioBox->setChecked(true); qtRadioBox->setChecked(true);
connect(qtRadioBox, SIGNAL(toggled(bool)), SLOT(onTick())); connect(qtRadioBox, SIGNAL(toggled(bool)), SLOT(onTick()));
setText(radioBox.state.text);
}
void pRadioBox::destructor() {
delete qtGroup;
delete qtRadioBox;
qtWidget = qtRadioBox = 0;
qtGroup = 0;
}
void pRadioBox::orphan() {
destructor();
constructor();
} }
void pRadioBox::onTick() { void pRadioBox::onTick() {

View File

@ -24,6 +24,20 @@ string pTextEdit::text() {
void pTextEdit::constructor() { void pTextEdit::constructor() {
qtWidget = qtTextEdit = new QTextEdit; qtWidget = qtTextEdit = new QTextEdit;
connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange())); connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange()));
setEditable(textEdit.state.editable);
setText(textEdit.state.text);
setWordWrap(textEdit.state.wordWrap);
}
void pTextEdit::destructor() {
if(sizable.state.layout) sizable.state.layout->remove(textEdit);
delete qtTextEdit;
qtWidget = qtTextEdit = 0;
}
void pTextEdit::orphan() {
destructor();
constructor();
} }
void pTextEdit::onChange() { void pTextEdit::onChange() {

View File

@ -21,6 +21,19 @@ void pVerticalScrollBar::constructor() {
qtScrollBar->setRange(0, 100); qtScrollBar->setRange(0, 100);
qtScrollBar->setPageStep(101 >> 3); qtScrollBar->setPageStep(101 >> 3);
connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange()));
setLength(verticalScrollBar.state.length);
setPosition(verticalScrollBar.state.position);
}
void pVerticalScrollBar::destructor() {
delete qtScrollBar;
qtWidget = qtScrollBar = 0;
}
void pVerticalScrollBar::orphan() {
destructor();
constructor();
} }
void pVerticalScrollBar::onChange() { void pVerticalScrollBar::onChange() {

View File

@ -21,6 +21,19 @@ void pVerticalSlider::constructor() {
qtSlider->setRange(0, 100); qtSlider->setRange(0, 100);
qtSlider->setPageStep(101 >> 3); qtSlider->setPageStep(101 >> 3);
connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange()));
setLength(verticalSlider.state.length);
setPosition(verticalSlider.state.position);
}
void pVerticalSlider::destructor() {
delete qtSlider;
qtWidget = qtSlider = 0;
}
void pVerticalSlider::orphan() {
destructor();
constructor();
} }
void pVerticalSlider::onChange() { void pVerticalSlider::onChange() {

View File

@ -7,3 +7,13 @@ void pViewport::constructor() {
qtWidget->setAttribute(Qt::WA_PaintOnScreen, true); qtWidget->setAttribute(Qt::WA_PaintOnScreen, true);
qtWidget->setStyleSheet("background: #000000"); qtWidget->setStyleSheet("background: #000000");
} }
void pViewport::destructor() {
delete qtWidget;
qtWidget = 0;
}
void pViewport::orphan() {
destructor();
constructor();
}

View File

@ -1,13 +1,10 @@
Font& pWidget::font() {
if(widget.state.font) return *widget.state.font;
return pOS::defaultFont;
}
Geometry pWidget::minimumGeometry() { Geometry pWidget::minimumGeometry() {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
void pWidget::setEnabled(bool enabled) { void pWidget::setEnabled(bool enabled) {
if(widget.state.abstract) enabled = false;
if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false;
qtWidget->setEnabled(enabled); qtWidget->setEnabled(enabled);
} }
@ -15,28 +12,33 @@ void pWidget::setFocused() {
qtWidget->setFocus(Qt::OtherFocusReason); qtWidget->setFocus(Qt::OtherFocusReason);
} }
void pWidget::setFont(Font &font) { void pWidget::setFont(const string &font) {
qtWidget->setFont(*font.p.qtFont); qtWidget->setFont(pFont::create(font));
} }
void pWidget::setGeometry(const Geometry &geometry) { void pWidget::setGeometry(const Geometry &geometry) {
qtWidget->setGeometry(geometry.x, geometry.y, geometry.width, geometry.height); qtWidget->setGeometry(geometry.x, geometry.y, geometry.width, geometry.height);
} }
void pWidget::setParent(Window &parent) {
if(!widget.state.font && parent.state.widgetFont) {
setFont(*parent.state.widgetFont);
}
qtWidget->setParent(parent.p.qtContainer);
widget.setVisible(widget.visible());
}
void pWidget::setVisible(bool visible) { void pWidget::setVisible(bool visible) {
if(widget.state.abstract) visible = false; if(widget.state.abstract) visible = false;
if(widget.state.layout && widget.state.layout->visible() == false) visible = false; if(sizable.state.layout == 0) visible = false;
if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false;
qtWidget->setVisible(visible); qtWidget->setVisible(visible);
} }
void pWidget::constructor() { void pWidget::constructor() {
if(widget.state.abstract) qtWidget = new QWidget; if(widget.state.abstract) qtWidget = new QWidget;
} }
void pWidget::destructor() {
if(widget.state.abstract) {
delete qtWidget;
qtWidget = 0;
}
}
void pWidget::orphan() {
destructor();
constructor();
}

View File

@ -1,21 +1,22 @@
void pWindow::append(Layout &layout) { void pWindow::append(Layout &layout) {
layout.setParent(window);
Geometry geometry = window.state.geometry; Geometry geometry = window.state.geometry;
geometry.x = geometry.y = 0; geometry.x = geometry.y = 0;
layout.setGeometry(geometry); layout.setGeometry(geometry);
} }
void pWindow::append(Menu &menu) { void pWindow::append(Menu &menu) {
if(window.state.menuFont) menu.p.qtMenu->setFont(*window.state.menuFont->p.qtFont); if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont);
else menu.p.setFont("Sans, 8");
qtMenu->addMenu(menu.p.qtMenu); qtMenu->addMenu(menu.p.qtMenu);
} }
void pWindow::append(Widget &widget) { void pWindow::append(Widget &widget) {
if(!widget.state.font && window.state.widgetFont) { if(widget.state.font == "") {
widget.setFont(*window.state.widgetFont); if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont);
else widget.p.setFont("Sans, 8");
} }
widget.p.qtWidget->setParent(qtContainer); widget.p.qtWidget->setParent(qtContainer);
widget.setVisible(widget.state.visible); widget.setVisible(widget.visible());
} }
Color pWindow::backgroundColor() { Color pWindow::backgroundColor() {
@ -49,6 +50,21 @@ Geometry pWindow::geometry() {
return window.state.geometry; return window.state.geometry;
} }
void pWindow::remove(Layout &layout) {
}
void pWindow::remove(Menu &menu) {
//QMenuBar::removeMenu() does not exist
qtMenu->clear();
foreach(menu, window.state.menu) append(menu);
}
void pWindow::remove(Widget &widget) {
//bugfix: orphan() destroys and recreates widgets (to disassociate them from their parent);
//attempting to create widget again after QApplication::quit() crashes libQtGui
if(qtApplication) widget.p.orphan();
}
void pWindow::setBackgroundColor(const Color &color) { void pWindow::setBackgroundColor(const Color &color) {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Window, QColor(color.red, color.green, color.blue)); palette.setColor(QPalette::Window, QColor(color.red, color.green, color.blue));
@ -90,8 +106,8 @@ void pWindow::setGeometry(const Geometry &geometry_) {
locked = false; locked = false;
} }
void pWindow::setMenuFont(Font &font) { void pWindow::setMenuFont(const string &font) {
qtMenu->setFont(*font.p.qtFont); qtMenu->setFont(pFont::create(font));
foreach(item, window.state.menu) item.p.setFont(font); foreach(item, window.state.menu) item.p.setFont(font);
} }
@ -111,8 +127,8 @@ void pWindow::setResizable(bool resizable) {
qtStatus->setSizeGripEnabled(resizable); qtStatus->setSizeGripEnabled(resizable);
} }
void pWindow::setStatusFont(Font &font) { void pWindow::setStatusFont(const string &font) {
qtStatus->setFont(*font.p.qtFont); qtStatus->setFont(pFont::create(font));
} }
void pWindow::setStatusText(const string &text) { void pWindow::setStatusText(const string &text) {
@ -138,7 +154,7 @@ void pWindow::setVisible(bool visible) {
locked = false; locked = false;
} }
void pWindow::setWidgetFont(Font &font) { void pWindow::setWidgetFont(const string &font) {
foreach(item, window.state.widget) { foreach(item, window.state.widget) {
if(!item.state.font) item.setFont(font); if(!item.state.font) item.setFont(font);
} }
@ -168,6 +184,16 @@ void pWindow::constructor() {
qtLayout->addWidget(qtStatus); qtLayout->addWidget(qtStatus);
setGeometry(window.state.geometry); setGeometry(window.state.geometry);
setMenuFont("Sans, 8");
setStatusFont("Sans, 8");
}
void pWindow::destructor() {
delete qtStatus;
delete qtContainer;
delete qtMenu;
delete qtLayout;
delete qtWindow;
} }
void pWindow::updateFrameGeometry() { void pWindow::updateFrameGeometry() {
@ -186,9 +212,10 @@ void pWindow::updateFrameGeometry() {
} }
void pWindow::QtWindow::closeEvent(QCloseEvent *event) { void pWindow::QtWindow::closeEvent(QCloseEvent *event) {
self.window.state.ignore = false;
event->ignore(); event->ignore();
hide();
if(self.window.onClose) self.window.onClose(); if(self.window.onClose) self.window.onClose();
if(self.window.state.ignore == false) hide();
} }
void pWindow::QtWindow::moveEvent(QMoveEvent *event) { void pWindow::QtWindow::moveEvent(QMoveEvent *event) {

View File

@ -10,3 +10,6 @@ void pCheckItem::setText(const string &text) {
void pCheckItem::constructor() { void pCheckItem::constructor() {
} }
void pCheckItem::destructor() {
}

View File

@ -3,3 +3,6 @@ void pItem::setText(const string &text) {
void pItem::constructor() { void pItem::constructor() {
} }
void pItem::destructor() {
}

View File

@ -1,8 +1,14 @@
void pMenu::append(Action &action) { void pMenu::append(Action &action) {
} }
void pMenu::remove(Action &action) {
}
void pMenu::setText(const string &text) { void pMenu::setText(const string &text) {
} }
void pMenu::constructor() { void pMenu::constructor() {
} }
void pMenu::destructor() {
}

View File

@ -13,3 +13,6 @@ void pRadioItem::setText(const string &text) {
void pRadioItem::constructor() { void pRadioItem::constructor() {
} }
void pRadioItem::destructor() {
}

View File

@ -1,2 +1,5 @@
void pSeparator::constructor() { void pSeparator::constructor() {
} }
void pSeparator::destructor() {
}

View File

@ -1,21 +1,3 @@
Geometry pFont::geometry(const string &text) { Geometry pFont::geometry(const string &description, const string &text) {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
void pFont::setBold(bool bold) {
}
void pFont::setFamily(const string &family) {
}
void pFont::setItalic(bool italic) {
}
void pFont::setSize(unsigned size) {
}
void pFont::setUnderline(bool underline) {
}
void pFont::constructor() {
}

View File

@ -1,4 +1,4 @@
#include "reference.hpp" #include "platform.hpp"
#include "font.cpp" #include "font.cpp"
#include "timer.cpp" #include "timer.cpp"

View File

@ -4,12 +4,19 @@ struct pMenu;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pFont {
static Geometry geometry(const string &description, const string &text);
};
struct pObject { struct pObject {
Object &object;
bool locked; bool locked;
pObject() { pObject(Object &object) : object(object), locked(locked) {}
locked = false; virtual ~pObject() {}
}
void constructor() {}
void destructor() {}
}; };
struct pOS : public pObject { struct pOS : public pObject {
@ -26,27 +33,13 @@ struct pOS : public pObject {
static void initialize(); static void initialize();
}; };
struct pFont : public pObject {
Font &font;
Geometry geometry(const string &text);
void setBold(bool bold);
void setFamily(const string &family);
void setItalic(bool italic);
void setSize(unsigned size);
void setUnderline(bool underline);
pFont(Font &font) : font(font) {}
void constructor();
};
struct pTimer : public pObject { struct pTimer : public pObject {
Timer &timer; Timer &timer;
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setInterval(unsigned milliseconds); void setInterval(unsigned milliseconds);
pTimer(Timer &timer) : timer(timer) {} pTimer(Timer &timer) : pObject(timer), timer(timer) {}
void constructor(); void constructor();
}; };
@ -67,21 +60,24 @@ struct pWindow : public pObject {
bool focused(); bool focused();
Geometry frameMargin(); Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void remove(Layout &layout);
void remove(Menu &menu);
void remove(Widget &widget);
void setBackgroundColor(const Color &color); void setBackgroundColor(const Color &color);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setMenuFont(Font &font); void setMenuFont(const string &font);
void setMenuVisible(bool visible); void setMenuVisible(bool visible);
void setResizable(bool resizable); void setResizable(bool resizable);
void setStatusFont(Font &font); void setStatusFont(const string &font);
void setStatusText(const string &text); void setStatusText(const string &text);
void setStatusVisible(bool visible); void setStatusVisible(bool visible);
void setTitle(const string &text); void setTitle(const string &text);
void setVisible(bool visible); void setVisible(bool visible);
void setWidgetFont(Font &font); void setWidgetFont(const string &font);
pWindow(Window &window) : window(window) {} pWindow(Window &window) : pObject(window), window(window) {}
void constructor(); void constructor();
}; };
@ -91,7 +87,7 @@ struct pAction : public pObject {
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setVisible(bool visible); void setVisible(bool visible);
pAction(Action &action) : action(action) {} pAction(Action &action) : pObject(action), action(action) {}
void constructor(); void constructor();
}; };
@ -99,10 +95,12 @@ struct pMenu : public pAction {
Menu &menu; Menu &menu;
void append(Action &action); void append(Action &action);
void remove(Action &action);
void setText(const string &text); void setText(const string &text);
pMenu(Menu &menu) : pAction(menu), menu(menu) {} pMenu(Menu &menu) : pAction(menu), menu(menu) {}
void constructor(); void constructor();
void destructor();
}; };
struct pSeparator : public pAction { struct pSeparator : public pAction {
@ -110,6 +108,7 @@ struct pSeparator : public pAction {
pSeparator(Separator &separator) : pAction(separator), separator(separator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
void destructor();
}; };
struct pItem : public pAction { struct pItem : public pAction {
@ -119,6 +118,7 @@ struct pItem : public pAction {
pItem(Item &item) : pAction(item), item(item) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
void destructor();
}; };
struct pCheckItem : public pAction { struct pCheckItem : public pAction {
@ -130,6 +130,7 @@ struct pCheckItem : public pAction {
pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
void destructor();
}; };
struct pRadioItem : public pAction { struct pRadioItem : public pAction {
@ -142,21 +143,33 @@ struct pRadioItem : public pAction {
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
void destructor();
}; };
struct pWidget : public pObject { struct pSizable : public pObject {
Sizable &sizable;
pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {}
};
struct pLayout : public pSizable {
Layout &layout;
pLayout(Layout &layout) : pSizable(layout), layout(layout) {}
};
struct pWidget : public pSizable {
Widget &widget; Widget &widget;
bool enabled(); bool enabled();
Font& font();
Geometry minimumGeometry(); Geometry minimumGeometry();
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(const string &font);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setVisible(bool visible); void setVisible(bool visible);
pWidget(Widget &widget) : widget(widget) {} pWidget(Widget &widget) : pSizable(widget), widget(widget) {}
void constructor(); void constructor();
}; };

View File

@ -2,10 +2,6 @@ bool pWidget::enabled() {
return false; return false;
} }
Font& pWidget::font() {
throw;
}
Geometry pWidget::minimumGeometry() { Geometry pWidget::minimumGeometry() {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
@ -16,7 +12,7 @@ void pWidget::setEnabled(bool enabled) {
void pWidget::setFocused() { void pWidget::setFocused() {
} }
void pWidget::setFont(Font &font) { void pWidget::setFont(const string &font) {
} }
void pWidget::setGeometry(const Geometry &geometry) { void pWidget::setGeometry(const Geometry &geometry) {

View File

@ -23,6 +23,15 @@ Geometry pWindow::geometry() {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
void pWindow::remove(Layout &layout) {
}
void pWindow::remove(Menu &menu) {
}
void pWindow::remove(Widget &widget) {
}
void pWindow::setBackgroundColor(const Color &color) { void pWindow::setBackgroundColor(const Color &color) {
} }
@ -35,7 +44,7 @@ void pWindow::setFullScreen(bool fullScreen) {
void pWindow::setGeometry(const Geometry &geometry) { void pWindow::setGeometry(const Geometry &geometry) {
} }
void pWindow::setMenuFont(Font &font) { void pWindow::setMenuFont(const string &font) {
} }
void pWindow::setMenuVisible(bool visible) { void pWindow::setMenuVisible(bool visible) {
@ -44,7 +53,7 @@ void pWindow::setMenuVisible(bool visible) {
void pWindow::setResizable(bool resizable) { void pWindow::setResizable(bool resizable) {
} }
void pWindow::setStatusFont(Font &font) { void pWindow::setStatusFont(const string &font) {
} }
void pWindow::setStatusText(const string &text) { void pWindow::setStatusText(const string &text) {
@ -59,7 +68,7 @@ void pWindow::setTitle(const string &text) {
void pWindow::setVisible(bool visible) { void pWindow::setVisible(bool visible) {
} }
void pWindow::setWidgetFont(Font &font) { void pWindow::setWidgetFont(const string &font) {
} }
void pWindow::constructor() { void pWindow::constructor() {

View File

@ -3,7 +3,7 @@ bool pCheckItem::checked() {
} }
void pCheckItem::setChecked(bool checked) { void pCheckItem::setChecked(bool checked) {
if(parentMenu) CheckMenuItem(parentMenu, id, checked ? MF_CHECKED : MF_UNCHECKED); if(parentMenu) CheckMenuItem(parentMenu->p.hmenu, id, checked ? MF_CHECKED : MF_UNCHECKED);
} }
void pCheckItem::setText(const string &text) { void pCheckItem::setText(const string &text) {
@ -12,3 +12,7 @@ void pCheckItem::setText(const string &text) {
void pCheckItem::constructor() { void pCheckItem::constructor() {
} }
void pCheckItem::destructor() {
if(parentMenu) parentMenu->remove(checkItem);
}

View File

@ -4,3 +4,7 @@ void pItem::setText(const string &text) {
void pItem::constructor() { void pItem::constructor() {
} }
void pItem::destructor() {
if(parentMenu) parentMenu->remove(item);
}

View File

@ -1,7 +1,13 @@
void pMenu::append(Action &action) { void pMenu::append(Action &action) {
action.p.parentMenu = &menu;
if(parentWindow) parentWindow->p.updateMenu(); if(parentWindow) parentWindow->p.updateMenu();
} }
void pMenu::remove(Action &action) {
if(parentWindow) parentWindow->p.updateMenu();
action.p.parentMenu = 0;
}
void pMenu::setText(const string &text) { void pMenu::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu(); if(parentWindow) parentWindow->p.updateMenu();
} }
@ -12,20 +18,21 @@ void pMenu::constructor() {
//Windows actions lack the ability to toggle visibility. //Windows actions lack the ability to toggle visibility.
//To support this, menus must be destroyed and recreated when toggling any action's visibility. //To support this, menus must be destroyed and recreated when toggling any action's visibility.
void pMenu::update(Window &parentWindow, HMENU parentMenu) { void pMenu::update(Window &parentWindow, Menu *parentMenu) {
this->parentWindow = &parentWindow;
this->parentMenu = parentMenu; this->parentMenu = parentMenu;
this->parentWindow = &parentWindow;
if(hmenu) DestroyMenu(hmenu); if(hmenu) DestroyMenu(hmenu);
hmenu = CreatePopupMenu(); hmenu = CreatePopupMenu();
foreach(action, menu.state.action) { foreach(action, menu.state.action) {
action.p.parentMenu = &menu;
action.p.parentWindow = &parentWindow; action.p.parentWindow = &parentWindow;
action.p.parentMenu = hmenu;
unsigned enabled = action.state.enabled ? 0 : MF_GRAYED; unsigned enabled = action.state.enabled ? 0 : MF_GRAYED;
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
Menu &item = (Menu&)action; Menu &item = (Menu&)action;
item.p.update(parentWindow, hmenu); item.p.update(parentWindow, &menu);
AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text));
} else if(dynamic_cast<Separator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
Separator &item = (Separator&)action; Separator &item = (Separator&)action;
@ -44,3 +51,12 @@ void pMenu::update(Window &parentWindow, HMENU parentMenu) {
} }
} }
} }
void pMenu::destructor() {
if(parentMenu) {
parentMenu->remove(menu);
} else if(parentWindow) {
//belongs to window's main menubar
parentWindow->remove(menu);
}
}

View File

@ -7,7 +7,7 @@ void pRadioItem::setChecked() {
//CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi
//phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range)
//to check id, we use: lo == hi == id (only ID, but in range) //to check id, we use: lo == hi == id (only ID, but in range)
if(item.p.parentMenu) CheckMenuRadioItem(item.p.parentMenu, item.p.id, item.p.id, item.p.id + (id != item.p.id), MF_BYCOMMAND); if(item.p.parentMenu) CheckMenuRadioItem(item.p.parentMenu->p.hmenu, item.p.id, item.p.id, item.p.id + (id != item.p.id), MF_BYCOMMAND);
} }
} }
@ -20,3 +20,7 @@ void pRadioItem::setText(const string &text) {
void pRadioItem::constructor() { void pRadioItem::constructor() {
} }
void pRadioItem::destructor() {
if(parentMenu) parentMenu->remove(radioItem);
}

View File

@ -1,2 +1,6 @@
void pSeparator::constructor() { void pSeparator::constructor() {
} }
void pSeparator::destructor() {
if(parentMenu) parentMenu->remove(separator);
}

View File

@ -1,12 +1,37 @@
static HFONT Font_createFont(const string &family, unsigned size, bool bold, bool italic, bool underline) { Geometry pFont::geometry(const string &description, const string &text) {
HFONT hfont = pFont::create(description);
Geometry geometry = pFont::geometry(hfont, text);
pFont::free(hfont);
return geometry;
}
HFONT pFont::create(const string &description) {
lstring part;
part.split(",", description);
foreach(item, part) item.trim(" ");
string family = part[0];
unsigned size = decimal(part[1]);
bool bold = part[2].position("Bold");
bool italic = part[2].position("Italic");
if(family == "") family = "Tahoma";
if(size == 0) size = 8;
return CreateFont( return CreateFont(
-(size * 96.0 / 72.0 + 0.5), -(size * 96.0 / 72.0 + 0.5),
0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, underline, 0, 0, 0, 0, 0, 0, 0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, 0, 0, 0, 0, 0, 0, 0,
utf16_t(family) utf16_t(family)
); );
} }
Geometry pFont::geometry(const string &text) { void pFont::free(HFONT hfont) {
DeleteObject(hfont);
}
Geometry pFont::geometry(HFONT hfont, const string &text_) {
//temporary fix: empty text string returns height of zero; bad for eg Button height
string text = (text_ == "" ? " " : text_);
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
SelectObject(hdc, hfont); SelectObject(hdc, hfont);
RECT rc = { 0, 0, 0, 0 }; RECT rc = { 0, 0, 0, 0 };
@ -14,38 +39,3 @@ Geometry pFont::geometry(const string &text) {
ReleaseDC(0, hdc); ReleaseDC(0, hdc);
return { 0, 0, rc.right, rc.bottom }; return { 0, 0, rc.right, rc.bottom };
} }
unsigned pFont::height() {
return geometry(" ").height;
}
void pFont::setBold(bool bold) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);
}
void pFont::setFamily(const string &family) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);
}
void pFont::setItalic(bool italic) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);
}
void pFont::setSize(unsigned size) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);
}
void pFont::setUnderline(bool underline) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);
}
void pFont::constructor() {
hfont = Font_createFont("Tahoma", 8, false, false, false);
font.setFamily("Tahoma");
font.setSize(8);
}

View File

@ -1,6 +1,6 @@
array<pObject*> pObject::objects; array<pObject*> pObject::objects;
pObject::pObject() { pObject::pObject(Object &object) : object(object) {
static unsigned uniqueId = 100; static unsigned uniqueId = 100;
objects.append(this); objects.append(this);
id = uniqueId++; id = uniqueId++;

View File

@ -1,4 +1,4 @@
#include "windows.hpp" #include "platform.hpp"
#include "object.cpp" #include "object.cpp"
#include "font.cpp" #include "font.cpp"
@ -34,8 +34,6 @@
static void OS_keyboardProc(HWND, UINT, WPARAM, LPARAM); static void OS_keyboardProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM);
pOS::State *pOS::state = 0;
Geometry pOS::availableGeometry() { Geometry pOS::availableGeometry() {
RECT rc; RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
@ -169,11 +167,6 @@ void pOS::initialize() {
CoInitialize(0); CoInitialize(0);
InitCommonControls(); InitCommonControls();
state = new State;
state->defaultFont.setFamily("Tahoma");
state->defaultFont.setSize(8);
WNDCLASS wc; WNDCLASS wc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
@ -253,8 +246,9 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
switch(msg) { switch(msg) {
case WM_CLOSE: { case WM_CLOSE: {
window.state.ignore = false;
if(window.onClose) window.onClose(); if(window.onClose) window.onClose();
window.setVisible(false); if(window.state.ignore == false) window.setVisible(false);
return TRUE; return TRUE;
} }
@ -449,13 +443,13 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
HorizontalScrollBar &horizontalScrollBar = (HorizontalScrollBar&)*object; HorizontalScrollBar &horizontalScrollBar = (HorizontalScrollBar&)*object;
if(horizontalScrollBar.state.position != info.nPos) { if(horizontalScrollBar.state.position != info.nPos) {
horizontalScrollBar.state.position = info.nPos; horizontalScrollBar.state.position = info.nPos;
horizontalScrollBar.onChange(); if(horizontalScrollBar.onChange) horizontalScrollBar.onChange();
} }
} else { } else {
VerticalScrollBar &verticalScrollBar = (VerticalScrollBar&)*object; VerticalScrollBar &verticalScrollBar = (VerticalScrollBar&)*object;
if(verticalScrollBar.state.position != info.nPos) { if(verticalScrollBar.state.position != info.nPos) {
verticalScrollBar.state.position = info.nPos; verticalScrollBar.state.position = info.nPos;
verticalScrollBar.onChange(); if(verticalScrollBar.onChange) verticalScrollBar.onChange();
} }
} }

View File

@ -4,22 +4,29 @@ struct pMenu;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pFont {
static Geometry geometry(const string &description, const string &text);
static HFONT create(const string &description);
static void free(HFONT hfont);
static Geometry geometry(HFONT hfont, const string &text);
};
struct pObject { struct pObject {
unsigned id; Object &object;
uintptr_t id;
bool locked; bool locked;
static array<pObject*> objects; static array<pObject*> objects;
pObject(); pObject(Object &object);
static pObject* find(unsigned id); static pObject* find(unsigned id);
virtual void unused() {} virtual ~pObject() {}
void constructor() {}
void destructor() {}
}; };
struct pOS : public pObject { struct pOS : public pObject {
struct State {
Font defaultFont;
};
static State *state;
static Geometry availableGeometry(); static Geometry availableGeometry();
static Geometry desktopGeometry(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
@ -33,22 +40,6 @@ struct pOS : public pObject {
static void initialize(); static void initialize();
}; };
struct pFont : public pObject {
Font &font;
HFONT hfont;
Geometry geometry(const string &text);
unsigned height();
void setBold(bool bold);
void setFamily(const string &family);
void setItalic(bool italic);
void setSize(unsigned size);
void setUnderline(bool underline);
pFont(Font &font) : font(font) {}
void constructor();
};
struct pTimer : public pObject { struct pTimer : public pObject {
Timer &timer; Timer &timer;
UINT_PTR htimer; UINT_PTR htimer;
@ -56,7 +47,7 @@ struct pTimer : public pObject {
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setInterval(unsigned milliseconds); void setInterval(unsigned milliseconds);
pTimer(Timer &timer) : timer(timer) {} pTimer(Timer &timer) : pObject(timer), timer(timer) {}
void constructor(); void constructor();
}; };
@ -72,6 +63,7 @@ struct pWindow : public pObject {
HWND hwnd; HWND hwnd;
HMENU hmenu; HMENU hmenu;
HWND hstatus; HWND hstatus;
HFONT hstatusfont;
HBRUSH brush; HBRUSH brush;
COLORREF brushColor; COLORREF brushColor;
@ -82,34 +74,38 @@ struct pWindow : public pObject {
bool focused(); bool focused();
Geometry frameMargin(); Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void remove(Layout &layout);
void remove(Menu &menu);
void remove(Widget &widget);
void setBackgroundColor(const Color &color); void setBackgroundColor(const Color &color);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setMenuFont(Font &font); void setMenuFont(const string &font);
void setMenuVisible(bool visible); void setMenuVisible(bool visible);
void setResizable(bool resizable); void setResizable(bool resizable);
void setStatusFont(Font &font); void setStatusFont(const string &font);
void setStatusText(const string &text); void setStatusText(const string &text);
void setStatusVisible(bool visible); void setStatusVisible(bool visible);
void setTitle(const string &text); void setTitle(const string &text);
void setVisible(bool visible); void setVisible(bool visible);
void setWidgetFont(Font &font); void setWidgetFont(const string &font);
pWindow(Window &window) : window(window) {} pWindow(Window &window) : pObject(window), window(window) {}
void constructor(); void constructor();
void destructor();
void updateMenu(); void updateMenu();
}; };
struct pAction : public pObject { struct pAction : public pObject {
Action &action; Action &action;
HMENU parentMenu; Menu *parentMenu;
Window *parentWindow; Window *parentWindow;
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setVisible(bool visible); void setVisible(bool visible);
pAction(Action &action) : action(action) {} pAction(Action &action) : pObject(action), action(action) {}
void constructor(); void constructor();
}; };
@ -118,11 +114,13 @@ struct pMenu : public pAction {
HMENU hmenu; HMENU hmenu;
void append(Action &action); void append(Action &action);
void remove(Action &action);
void setText(const string &text); void setText(const string &text);
pMenu(Menu &menu) : pAction(menu), menu(menu) {} pMenu(Menu &menu) : pAction(menu), menu(menu) {}
void constructor(); void constructor();
void update(Window &parentWindow, HMENU parentMenu); void destructor();
void update(Window &parentWindow, Menu *parentMenu = 0);
}; };
struct pSeparator : public pAction { struct pSeparator : public pAction {
@ -130,6 +128,7 @@ struct pSeparator : public pAction {
pSeparator(Separator &separator) : pAction(separator), separator(separator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
void destructor();
}; };
struct pItem : public pAction { struct pItem : public pAction {
@ -139,6 +138,7 @@ struct pItem : public pAction {
pItem(Item &item) : pAction(item), item(item) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
void destructor();
}; };
struct pCheckItem : public pAction { struct pCheckItem : public pAction {
@ -150,6 +150,7 @@ struct pCheckItem : public pAction {
pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
void destructor();
}; };
struct pRadioItem : public pAction { struct pRadioItem : public pAction {
@ -162,25 +163,41 @@ struct pRadioItem : public pAction {
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
void destructor();
}; };
struct pWidget : public pObject { struct pSizable : public pObject {
Sizable &sizable;
pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {}
};
struct pLayout : public pSizable {
Layout &layout;
pLayout(Layout &layout) : pSizable(layout), layout(layout) {}
};
struct pWidget : public pSizable {
Widget &widget; Widget &widget;
Window *parentWindow;
HWND hwnd; HWND hwnd;
HFONT hfont;
bool enabled(); bool enabled();
Font& font();
virtual Geometry minimumGeometry(); virtual Geometry minimumGeometry();
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(const string &font);
virtual void setGeometry(const Geometry &geometry); virtual void setGeometry(const Geometry &geometry);
void setVisible(bool visible); void setVisible(bool visible);
pWidget(Widget &widget) : widget(widget) {} pWidget(Widget &widget) : pSizable(widget), widget(widget) { parentWindow = &Window::None; }
void constructor(); void constructor();
void destructor();
virtual void orphan();
void setDefaultFont(); void setDefaultFont();
virtual void setParent(Window &parent); void synchronize();
}; };
struct pButton : public pWidget { struct pButton : public pWidget {
@ -191,7 +208,8 @@ struct pButton : public pWidget {
pButton(Button &button) : pWidget(button), button(button) {} pButton(Button &button) : pWidget(button), button(button) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pCanvas : public pWidget { struct pCanvas : public pWidget {
@ -204,7 +222,8 @@ struct pCanvas : public pWidget {
pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pCheckBox : public pWidget { struct pCheckBox : public pWidget {
@ -217,7 +236,8 @@ struct pCheckBox : public pWidget {
pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pComboBox : public pWidget { struct pComboBox : public pWidget {
@ -231,8 +251,9 @@ struct pComboBox : public pWidget {
pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {}
void constructor(); void constructor();
void destructor();
void orphan();
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setParent(Window &parent);
}; };
struct pHexEdit : public pWidget { struct pHexEdit : public pWidget {
@ -247,8 +268,9 @@ struct pHexEdit : public pWidget {
pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {}
void constructor(); void constructor();
void destructor();
void orphan();
bool keyPress(unsigned key); bool keyPress(unsigned key);
void setParent(Window &parent);
}; };
struct pHorizontalScrollBar : public pWidget { struct pHorizontalScrollBar : public pWidget {
@ -261,7 +283,8 @@ struct pHorizontalScrollBar : public pWidget {
pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pHorizontalSlider : public pWidget { struct pHorizontalSlider : public pWidget {
@ -274,7 +297,8 @@ struct pHorizontalSlider : public pWidget {
pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pLabel : public pWidget { struct pLabel : public pWidget {
@ -285,7 +309,8 @@ struct pLabel : public pWidget {
pLabel(Label &label) : pWidget(label), label(label) {} pLabel(Label &label) : pWidget(label), label(label) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pLineEdit : public pWidget { struct pLineEdit : public pWidget {
@ -298,7 +323,8 @@ struct pLineEdit : public pWidget {
pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pListView : public pWidget { struct pListView : public pWidget {
@ -321,8 +347,9 @@ struct pListView : public pWidget {
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}
void constructor(); void constructor();
void destructor();
void orphan();
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setParent(Window &parent);
}; };
struct pProgressBar : public pWidget { struct pProgressBar : public pWidget {
@ -333,7 +360,8 @@ struct pProgressBar : public pWidget {
pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pRadioBox : public pWidget { struct pRadioBox : public pWidget {
@ -347,7 +375,8 @@ struct pRadioBox : public pWidget {
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pTextEdit : public pWidget { struct pTextEdit : public pWidget {
@ -361,7 +390,8 @@ struct pTextEdit : public pWidget {
pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pVerticalScrollBar : public pWidget { struct pVerticalScrollBar : public pWidget {
@ -374,7 +404,8 @@ struct pVerticalScrollBar : public pWidget {
pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pVerticalSlider : public pWidget { struct pVerticalSlider : public pWidget {
@ -387,7 +418,8 @@ struct pVerticalSlider : public pWidget {
pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };
struct pViewport : public pWidget { struct pViewport : public pWidget {
@ -397,5 +429,6 @@ struct pViewport : public pWidget {
pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {}
void constructor(); void constructor();
void setParent(Window &parent); void destructor();
void orphan();
}; };

View File

@ -1,7 +1,6 @@
Geometry pButton::minimumGeometry() { Geometry pButton::minimumGeometry() {
Font &font = this->font(); Geometry geometry = pFont::geometry(hfont, button.state.text);
Geometry geometry = font.geometry(button.state.text); return { 0, 0, geometry.width + 20, geometry.height + 10 };
return { 0, 0, geometry.width + 20, font.p.height() + 10 };
} }
void pButton::setText(const string &text) { void pButton::setText(const string &text) {
@ -9,14 +8,18 @@ void pButton::setText(const string &text) {
} }
void pButton::constructor() { void pButton::constructor() {
setParent(Window::None); hwnd = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0);
}
void pButton::setParent(Window &parent) {
if(hwnd) DestroyWindow(hwnd);
hwnd = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_TABSTOP | WS_VISIBLE, 0, 0, 0, 0, parent.p.hwnd, (HMENU)id, GetModuleHandle(0), 0);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&button); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&button);
setDefaultFont(); setDefaultFont();
setText(button.state.text); setText(button.state.text);
widget.setVisible(widget.visible()); synchronize();
}
void pButton::destructor() {
DestroyWindow(hwnd);
}
void pButton::orphan() {
destructor();
constructor();
} }

View File

@ -44,12 +44,16 @@ void pCanvas::update() {
void pCanvas::constructor() { void pCanvas::constructor() {
bufferRGB = new uint32_t[256 * 256](); bufferRGB = new uint32_t[256 * 256]();
setParent(Window::None); hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas);
synchronize();
} }
void pCanvas::setParent(Window &parent) { void pCanvas::destructor() {
if(hwnd) DestroyWindow(hwnd); DestroyWindow(hwnd);
hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, parent.p.hwnd, (HMENU)id, GetModuleHandle(0), 0); }
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas);
widget.setVisible(widget.visible()); void pCanvas::orphan() {
destructor();
constructor();
} }

Some files were not shown because too many files have changed in this diff Show More