mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-25 21:19:07 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8c591ce44a | ||
|
e2cc164f70 | ||
|
d09e54149b | ||
|
8e4f1be189 | ||
|
f529a84fd1 | ||
|
567d415290 | ||
|
435a194ccd | ||
|
df9de289b9 |
@@ -1,5 +1,5 @@
|
||||
bsnes
|
||||
Version: 0.034
|
||||
Version: 0.035
|
||||
Author: byuu
|
||||
|
||||
========
|
||||
|
@@ -133,7 +133,7 @@ obj/bsnesrc.$(obj): ui/bsnes.rc; windres ui/bsnes.rc obj/bsnesrc.$(obj)
|
||||
### libraries ###
|
||||
#################
|
||||
|
||||
obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/*
|
||||
obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/* lib/ruby/video/* lib/ruby/audio/* lib/ruby/input/*
|
||||
$(call compile,$(rubydef) $(rubyflags))
|
||||
obj/hiro.$(obj): lib/hiro/hiro.cpp lib/hiro/* lib/hiro/gtk/* lib/hiro/win/*
|
||||
$(call compile,$(if $(call streq,$(platform),x),`pkg-config --cflags gtk+-2.0`))
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#define BSNES_VERSION "0.034"
|
||||
#define BSNES_VERSION "0.035"
|
||||
#define BSNES_TITLE "bsnes v" BSNES_VERSION
|
||||
|
||||
#define BUSCORE sBus
|
||||
|
@@ -65,7 +65,6 @@ void Cartridge::load_begin(CartridgeType cart_type) {
|
||||
|
||||
info.header_index = 0xffc0;
|
||||
info.mapper = LoROM;
|
||||
info.name[0] = 0;
|
||||
info.region = NTSC;
|
||||
|
||||
info.rom_size = 0;
|
||||
|
@@ -18,8 +18,7 @@ public:
|
||||
VERSION = 0x1b,
|
||||
ICKSUM = 0x1c,
|
||||
CKSUM = 0x1e,
|
||||
RESL = 0x3c,
|
||||
RESH = 0x3d,
|
||||
RESETV = 0x3c,
|
||||
};
|
||||
|
||||
enum Region {
|
||||
@@ -70,7 +69,6 @@ public:
|
||||
|
||||
uint32 crc32;
|
||||
char filename[PATH_MAX * 4];
|
||||
char name[128];
|
||||
bool patched;
|
||||
|
||||
Region region;
|
||||
@@ -121,6 +119,7 @@ public:
|
||||
void load_end();
|
||||
bool unload();
|
||||
|
||||
unsigned score_header(unsigned);
|
||||
void find_header();
|
||||
void read_header();
|
||||
void read_extended_header();
|
||||
|
@@ -46,7 +46,9 @@ char* Cartridge::get_base_filename(char *filename) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
char* Cartridge::get_path_filename(char *filename, const char *path, const char *source, const char *extension) {
|
||||
@@ -154,16 +156,16 @@ bool Cartridge::apply_patch(const uint8_t *pdata, const unsigned psize, uint8_t
|
||||
if(result == ups::input_crc32_invalid) apply = true;
|
||||
if(result == ups::output_crc32_invalid) apply = true;
|
||||
}
|
||||
|
||||
|
||||
//if patch application was successful, replace old data, size with new data, size
|
||||
if(apply == true) {
|
||||
delete[] data;
|
||||
data = new uint8_t[size = outsize];
|
||||
memcpy(data, outdata, outsize);
|
||||
} else {
|
||||
dprintf("* Warning: patch application failed!");
|
||||
}
|
||||
|
||||
if(outdata) delete[] outdata;
|
||||
if(outdata) delete[] outdata;
|
||||
return apply;
|
||||
}
|
||||
|
||||
bool Cartridge::save_file(const char *fn, uint8 *data, uint size) {
|
||||
|
@@ -120,70 +120,95 @@ void Cartridge::read_header() {
|
||||
|
||||
//0, 1, 13 = NTSC; 2 - 12 = PAL
|
||||
info.region = (region <= 1 || region >= 13) ? NTSC : PAL;
|
||||
}
|
||||
|
||||
memcpy(&info.name, &rom[info.header_index + CART_NAME], 21);
|
||||
info.name[21] = 0;
|
||||
trim(info.name);
|
||||
unsigned Cartridge::score_header(unsigned addr) {
|
||||
if(cart.rom_size < addr + 64) return 0; //image too small to contain header at this location?
|
||||
uint8 *rom = cart.rom;
|
||||
int score = 0;
|
||||
|
||||
//convert undisplayable characters (half-width katakana, etc) to '?' characters
|
||||
for(int i = 0; i < 21; i++) {
|
||||
if(info.name[i] & 0x80) info.name[i] = '?';
|
||||
}
|
||||
uint16 resetvector = rom[addr + RESETV] | (rom[addr + RESETV + 1] << 8);
|
||||
uint16 checksum = rom[addr + CKSUM] | (rom[addr + CKSUM + 1] << 8);
|
||||
uint16 ichecksum = rom[addr + ICKSUM] | (rom[addr + ICKSUM + 1] << 8);
|
||||
|
||||
//always display something
|
||||
if(!info.name[0]) strcpy(info.name, "(untitled)");
|
||||
uint8 resetop = rom[(addr & ~0x7fff) | (resetvector & 0x7fff)]; //first opcode executed upon reset
|
||||
uint8 mapper = rom[addr + MAPPER] & ~0x10; //mask off irrelevent FastROM-capable bit
|
||||
|
||||
//$00:[000-7fff] contains uninitialized RAM and MMIO.
|
||||
//reset vector must point to ROM at $00:[8000-ffff] to be considered valid.
|
||||
if(resetvector < 0x8000) return 0;
|
||||
|
||||
//some images duplicate the header in multiple locations, and others have completely
|
||||
//invalid header information that cannot be relied upon.
|
||||
//below code will analyze the first opcode executed at the specified reset vector to
|
||||
//determine the probability that this is the correct header.
|
||||
|
||||
//most likely opcodes
|
||||
if(resetop == 0x78 //sei
|
||||
|| resetop == 0x18 //clc (clc; xce)
|
||||
|| resetop == 0x38 //sec (sec; xce)
|
||||
|| resetop == 0x9c //stz $nnnn (stz $4200)
|
||||
|| resetop == 0x4c //jmp $nnnn
|
||||
|| resetop == 0x5c //jml $nnnnnn
|
||||
) score += 8;
|
||||
|
||||
//plausible opcodes
|
||||
if(resetop == 0xc2 //rep #$nn
|
||||
|| resetop == 0xe2 //sep #$nn
|
||||
|| resetop == 0xad //lda $nnnn
|
||||
|| resetop == 0xae //ldx $nnnn
|
||||
|| resetop == 0xac //ldy $nnnn
|
||||
|| resetop == 0xaf //lda $nnnnnn
|
||||
|| resetop == 0xa9 //lda #$nn
|
||||
|| resetop == 0xa2 //ldx #$nn
|
||||
|| resetop == 0xa0 //ldy #$nn
|
||||
|| resetop == 0x20 //jsr $nnnn
|
||||
|| resetop == 0x22 //jsl $nnnnnn
|
||||
) score += 4;
|
||||
|
||||
//implausible opcodes
|
||||
if(resetop == 0x40 //rti
|
||||
|| resetop == 0x60 //rts
|
||||
|| resetop == 0x6b //rtl
|
||||
|| resetop == 0xcd //cmp $nnnn
|
||||
|| resetop == 0xec //cpx $nnnn
|
||||
|| resetop == 0xcc //cpy $nnnn
|
||||
) score -= 4;
|
||||
|
||||
//least likely opcodes
|
||||
if(resetop == 0x00 //brk #$nn
|
||||
|| resetop == 0x02 //cop #$nn
|
||||
|| resetop == 0xdb //stp
|
||||
|| resetop == 0x42 //wdm
|
||||
|| resetop == 0xff //sbc $nnnnnn,x
|
||||
) score -= 8;
|
||||
|
||||
//at times, both the header and reset vector's first opcode will match ...
|
||||
//fallback and rely on info validity in these cases to determine more likely header.
|
||||
|
||||
//a valid checksum is the biggest indicator of a valid header.
|
||||
if((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0)) score += 4;
|
||||
|
||||
if(addr == 0x007fc0 && mapper == 0x20) score += 2; //0x20 is usually LoROM
|
||||
if(addr == 0x00ffc0 && mapper == 0x21) score += 2; //0x21 is usually HiROM
|
||||
if(addr == 0x007fc0 && mapper == 0x22) score += 2; //0x22 is usually ExLoROM
|
||||
if(addr == 0x40ffc0 && mapper == 0x25) score += 2; //0x25 is usually ExHiROM
|
||||
|
||||
if(rom[addr + COMPANY] == 0x33) score += 2; //0x33 indicates extended header
|
||||
if(rom[addr + ROM_TYPE] < 0x08) score++;
|
||||
if(rom[addr + ROM_SIZE] < 0x10) score++;
|
||||
if(rom[addr + RAM_SIZE] < 0x08) score++;
|
||||
if(rom[addr + REGION] < 14) score++;
|
||||
|
||||
if(score < 0) score = 0;
|
||||
return score;
|
||||
}
|
||||
|
||||
void Cartridge::find_header() {
|
||||
int32 score_lo = 0, score_hi = 0, score_ex = 0;
|
||||
uint8_t *rom = cart.rom;
|
||||
|
||||
if(cart.rom_size < 0x010000) {
|
||||
//cart too small to be anything but lorom
|
||||
info.header_index = 0x007fc0;
|
||||
return;
|
||||
}
|
||||
|
||||
if((rom[0x7fc0 + MAPPER] & ~0x10) == 0x20) score_lo++;
|
||||
if((rom[0xffc0 + MAPPER] & ~0x10) == 0x21) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + ROM_TYPE] < 0x08) score_lo++;
|
||||
if(rom[0xffc0 + ROM_TYPE] < 0x08) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + ROM_SIZE] < 0x10) score_lo++;
|
||||
if(rom[0xffc0 + ROM_SIZE] < 0x10) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + RAM_SIZE] < 0x08) score_lo++;
|
||||
if(rom[0xffc0 + RAM_SIZE] < 0x08) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + REGION] < 14) score_lo++;
|
||||
if(rom[0xffc0 + REGION] < 14) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + COMPANY] < 3) score_lo++;
|
||||
if(rom[0xffc0 + COMPANY] < 3) score_hi++;
|
||||
|
||||
if(rom[0x7fc0 + RESH] & 0x80) score_lo += 2;
|
||||
if(rom[0xffc0 + RESH] & 0x80) score_hi += 2;
|
||||
|
||||
uint16 cksum, icksum;
|
||||
cksum = rom[0x7fc0 + CKSUM] | (rom[0x7fc0 + CKSUM + 1] << 8);
|
||||
icksum = rom[0x7fc0 + ICKSUM] | (rom[0x7fc0 + ICKSUM + 1] << 8);
|
||||
if((cksum + icksum) == 0xffff && (cksum != 0) && (icksum != 0)) {
|
||||
score_lo += 8;
|
||||
}
|
||||
|
||||
cksum = rom[0xffc0 + CKSUM] | (rom[0xffc0 + CKSUM + 1] << 8);
|
||||
icksum = rom[0xffc0 + ICKSUM] | (rom[0xffc0 + ICKSUM + 1] << 8);
|
||||
if((cksum + icksum) == 0xffff && (cksum != 0) && (icksum != 0)) {
|
||||
score_hi += 8;
|
||||
}
|
||||
|
||||
if(cart.rom_size < 0x401000) {
|
||||
score_ex = 0;
|
||||
} else {
|
||||
if(rom[0x7fc0 + MAPPER] == 0x32) score_lo++;
|
||||
else score_ex += 12;
|
||||
}
|
||||
unsigned score_lo = score_header(0x007fc0);
|
||||
unsigned score_hi = score_header(0x00ffc0);
|
||||
unsigned score_ex = score_header(0x40ffc0);
|
||||
if(score_ex) score_ex += 4; //favor ExHiROM on images > 32mbits
|
||||
|
||||
if(score_lo >= score_hi && score_lo >= score_ex) {
|
||||
info.header_index = 0x007fc0;
|
||||
|
@@ -1,3 +1,3 @@
|
||||
::@make platform=win compiler=mingw32-gcc
|
||||
@make platform=win compiler=mingw32-gcc enable_gzip=true enable_jma=true
|
||||
@make platform=win compiler=mingw32-gcc
|
||||
::@make platform=win compiler=mingw32-gcc enable_gzip=true enable_jma=true
|
||||
@pause
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
void sDSP::brr_decode(voice_t &v) {
|
||||
//state.t_brr_byte = ram[v.brr_addr + v.brr_offset] cached from previous clock cycle
|
||||
int nybbles = (state.t_brr_byte << 8) + memory::apuram.read(uint16(v.brr_addr + v.brr_offset + 1));
|
||||
int nybbles = (state.t_brr_byte << 8) + memory::apuram[(uint16)(v.brr_addr + v.brr_offset + 1)];
|
||||
|
||||
const int filter = (state.t_brr_header >> 2) & 3;
|
||||
const int scale = (state.t_brr_header >> 4);
|
||||
|
@@ -13,8 +13,8 @@ int sDSP::echo_output(bool channel) {
|
||||
|
||||
void sDSP::echo_read(bool channel) {
|
||||
unsigned addr = state.t_echo_ptr + channel * 2;
|
||||
uint8 lo = memory::apuram.read(uint16(addr + 0));
|
||||
uint8 hi = memory::apuram.read(uint16(addr + 1));
|
||||
uint8 lo = memory::apuram[(uint16)(addr + 0)];
|
||||
uint8 hi = memory::apuram[(uint16)(addr + 1)];
|
||||
int s = (int16)((hi << 8) + lo);
|
||||
state.echo_hist[channel].write(state.echo_hist_pos, s >> 1);
|
||||
}
|
||||
@@ -23,8 +23,8 @@ void sDSP::echo_write(bool channel) {
|
||||
if(!(state.t_echo_disabled & 0x20)) {
|
||||
unsigned addr = state.t_echo_ptr + channel * 2;
|
||||
int s = state.t_echo_out[channel];
|
||||
memory::apuram.write(uint16(addr + 0), (uint8)(s >> 0));
|
||||
memory::apuram.write(uint16(addr + 1), (uint8)(s >> 8));
|
||||
memory::apuram[(uint16)(addr + 0)] = s;
|
||||
memory::apuram[(uint16)(addr + 1)] = s >> 8;
|
||||
}
|
||||
|
||||
state.t_echo_out[channel] = 0;
|
||||
|
@@ -24,8 +24,8 @@ void sDSP::voice_2(voice_t &v) {
|
||||
//read sample pointer (ignored if not needed)
|
||||
uint16 addr = state.t_dir_addr;
|
||||
if(!v.kon_delay) addr += 2;
|
||||
uint8 lo = memory::apuram.read(uint16(addr + 0));
|
||||
uint8 hi = memory::apuram.read(uint16(addr + 1));
|
||||
uint8 lo = memory::apuram[(uint16)(addr + 0)];
|
||||
uint8 hi = memory::apuram[(uint16)(addr + 1)];
|
||||
state.t_brr_next_addr = ((hi << 8) + lo);
|
||||
|
||||
state.t_adsr0 = VREG(adsr0);
|
||||
@@ -45,8 +45,8 @@ void sDSP::voice_3a(voice_t &v) {
|
||||
}
|
||||
|
||||
void sDSP::voice_3b(voice_t &v) {
|
||||
state.t_brr_byte = memory::apuram.read(uint16(v.brr_addr + v.brr_offset));
|
||||
state.t_brr_header = memory::apuram.read(uint16(v.brr_addr));
|
||||
state.t_brr_byte = memory::apuram[(uint16)(v.brr_addr + v.brr_offset)];
|
||||
state.t_brr_header = memory::apuram[(uint16)(v.brr_addr)];
|
||||
}
|
||||
|
||||
void sDSP::voice_3c(voice_t &v) {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
void hiro_pbutton_tick(pButton *p) {
|
||||
if(p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
|
||||
if(p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
|
||||
}
|
||||
|
||||
void pButton::create(uint style, uint width, uint height, const char *text) {
|
||||
void pButton::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
button = gtk_button_new_with_label(text ? text : "");
|
||||
set_default_font(button);
|
||||
gtk_widget_set_size_request(button, width, height);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pButton : public pFormControl {
|
||||
public:
|
||||
Button &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pButton(Button&);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
void hiro_pcanvas_expose(pCanvas *p) {
|
||||
uint32_t *f = p->fbuffer;
|
||||
uint32_t *r = p->rbuffer;
|
||||
for(uint y = p->canvas->allocation.height; y; y--) {
|
||||
for(uint x = p->canvas->allocation.width; x; x--) {
|
||||
for(unsigned y = p->canvas->allocation.height; y; y--) {
|
||||
for(unsigned x = p->canvas->allocation.width; x; x--) {
|
||||
uint32_t p = *f++;
|
||||
*r++ = ((p << 16) & 0xff0000) + (p & 0x00ff00) + ((p >> 16) & 0x0000ff);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ void hiro_pcanvas_expose(pCanvas *p) {
|
||||
GDK_RGB_DITHER_NONE, (guchar*)p->rbuffer, p->bpitch);
|
||||
}
|
||||
|
||||
void pCanvas::create(uint style, uint width, uint height) {
|
||||
void pCanvas::create(unsigned style, unsigned width, unsigned height) {
|
||||
canvas = gtk_drawing_area_new();
|
||||
resize(width, height);
|
||||
GdkColor color;
|
||||
@@ -54,7 +54,7 @@ pCanvas::~pCanvas() {
|
||||
|
||||
/* internal */
|
||||
|
||||
void pCanvas::resize(uint width, uint height) {
|
||||
void pCanvas::resize(unsigned width, unsigned height) {
|
||||
if(fbuffer) free(fbuffer);
|
||||
if(rbuffer) free(rbuffer);
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pCanvas : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
void redraw();
|
||||
uint32_t* buffer();
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
//GTK+ RGB drawing function draws in xBGR format, so two buffers are needed ...
|
||||
uint32_t *fbuffer; //one for the xRGB image
|
||||
uint32_t *rbuffer; //one for the xBGR image
|
||||
uint bpitch;
|
||||
void resize(uint width, uint height);
|
||||
unsigned bpitch;
|
||||
void resize(unsigned width, unsigned height);
|
||||
GtkWidget* gtk_handle();
|
||||
};
|
||||
|
@@ -1,8 +1,8 @@
|
||||
void hiro_pcheckbox_tick(pCheckbox *p) {
|
||||
if(!p->locked && p->self.on_tick) p->self.on_tick(Event(Event::Tick, p->checked(), &p->self));
|
||||
if(!p->locked && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, p->checked(), &p->self));
|
||||
}
|
||||
|
||||
void pCheckbox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pCheckbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
checkbox = gtk_check_button_new_with_label(text ? text : "");
|
||||
set_default_font(checkbox);
|
||||
gtk_widget_set_size_request(checkbox, width, height);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pCheckbox : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check(bool state = true);
|
||||
void uncheck();
|
||||
|
@@ -1,8 +1,8 @@
|
||||
void hiro_pcombobox_change(pCombobox *p) {
|
||||
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->get_selection(), &p->self));
|
||||
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->get_selection(), &p->self));
|
||||
}
|
||||
|
||||
void pCombobox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pCombobox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
combobox = gtk_combo_box_new_text();
|
||||
set_default_font(combobox);
|
||||
gtk_widget_set_size_request(combobox, width, height);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pCombobox : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void add_item(const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
@@ -11,6 +11,6 @@ public:
|
||||
|
||||
/* internal */
|
||||
GtkWidget *combobox;
|
||||
uint counter;
|
||||
unsigned counter;
|
||||
GtkWidget* gtk_handle();
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pEditbox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pEditbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
multiline = bool(style & Editbox::Multiline);
|
||||
|
||||
if(multiline == false) {
|
||||
@@ -38,7 +38,7 @@ void pEditbox::set_text(const char *text) {
|
||||
}
|
||||
}
|
||||
|
||||
uint pEditbox::get_text(char *text, uint length) {
|
||||
unsigned pEditbox::get_text(char *text, unsigned length) {
|
||||
if(multiline == false) {
|
||||
const char *temp = gtk_entry_get_text(GTK_ENTRY(editbox));
|
||||
return strlcpy(text, temp ? temp : "", length);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
class pEditbox : public pFormControl {
|
||||
public:
|
||||
Editbox &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
uint get_text(char *text, uint length = -1U);
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
unsigned get_text(char *text, unsigned length = -1U);
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pEditbox(Editbox&);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pFormControl::resize(uint width, uint height) {
|
||||
void pFormControl::resize(unsigned width, unsigned height) {
|
||||
gtk_widget_set_size_request(gtk_handle(), width, height);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pFormControl : public pWidget {
|
||||
public:
|
||||
virtual void resize(uint width, uint height);
|
||||
virtual void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void enable(bool = true);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pFrame::create(uint style, uint width, uint height, const char *text) {
|
||||
void pFrame::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
frame = gtk_frame_new(text ? text : "");
|
||||
set_default_font(frame);
|
||||
gtk_widget_set_size_request(frame, width, height);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pFrame : public pFormControl {
|
||||
public:
|
||||
Frame &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pFrame(Frame&);
|
||||
|
@@ -158,11 +158,11 @@ bool pHiro::file_save(Window *focus, char *filename, const char *path, const cha
|
||||
return strcmp(filename, ""); //return true if filename exists
|
||||
}
|
||||
|
||||
uint pHiro::screen_width() {
|
||||
unsigned pHiro::screen_width() {
|
||||
return gdk_screen_width();
|
||||
}
|
||||
|
||||
uint pHiro::screen_height() {
|
||||
unsigned pHiro::screen_height() {
|
||||
return gdk_screen_height();
|
||||
}
|
||||
|
||||
|
@@ -43,8 +43,8 @@ public:
|
||||
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
|
||||
uint screen_width();
|
||||
uint screen_height();
|
||||
unsigned screen_width();
|
||||
unsigned screen_height();
|
||||
|
||||
void enable_screensaver();
|
||||
void disable_screensaver();
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
void set_default_path(const char*);
|
||||
bool is_screensaver_enabled;
|
||||
void screensaver_tick();
|
||||
uint16_t translate_key(uint key);
|
||||
uint16_t translate_key(unsigned key);
|
||||
};
|
||||
|
||||
pHiro& phiro();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
uint16_t pHiro::translate_key(uint key) {
|
||||
uint16_t pHiro::translate_key(unsigned key) {
|
||||
switch(key) {
|
||||
case GDK_Escape: return keyboard::escape;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pLabel::create(uint style, uint width, uint height, const char *text) {
|
||||
void pLabel::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
label = gtk_label_new(text ? text : "");
|
||||
set_default_font(label);
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pLabel : public pFormControl {
|
||||
public:
|
||||
Label &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pLabel(Label&);
|
||||
|
@@ -1,13 +1,13 @@
|
||||
void hiro_plistbox_change(pListbox *p) {
|
||||
if(p->listbox_selection == p->get_selection()) return;
|
||||
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->listbox_selection = p->get_selection(), &p->self));
|
||||
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->listbox_selection = p->get_selection(), &p->self));
|
||||
}
|
||||
|
||||
void hiro_plistbox_activate(pListbox *p) {
|
||||
if(p->self.on_activate) p->self.on_activate(Event(Event::Activate, p->listbox_selection = p->get_selection(), &p->self));
|
||||
if(p->self.on_activate) p->self.on_activate(event_t(event_t::Activate, p->listbox_selection = p->get_selection(), &p->self));
|
||||
}
|
||||
|
||||
void pListbox::create(uint style, uint width, uint height, const char *columns, const char *text) {
|
||||
void pListbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) {
|
||||
bool header = style & Listbox::Header;
|
||||
GtkPolicyType hscroll = (style & Listbox::HorizontalScrollAlways) ? GTK_POLICY_ALWAYS :
|
||||
(style & Listbox::HorizontalScrollNever) ? GTK_POLICY_NEVER :
|
||||
@@ -24,7 +24,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
|
||||
split(list, "\t", columns);
|
||||
|
||||
GType *v = (GType*)malloc(count(list) * sizeof(GType));
|
||||
for(uint i = 0; i < count(list); i++) v[i] = G_TYPE_STRING;
|
||||
for(unsigned i = 0; i < count(list); i++) v[i] = G_TYPE_STRING;
|
||||
store = gtk_list_store_newv(count(list), v);
|
||||
free(v);
|
||||
|
||||
@@ -37,7 +37,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
|
||||
|
||||
//alternate colors for each listbox entry if there are multiple columns ...
|
||||
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(listbox), count(list) >= 2 ? true : false);
|
||||
for(uint i = 0; i < count(list); i++) {
|
||||
for(unsigned i = 0; i < count(list); i++) {
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
column = gtk_tree_view_column_new_with_attributes(list[i], renderer, "text", i, (void*)0);
|
||||
column_list[column_list.size()] = column;
|
||||
@@ -46,7 +46,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
|
||||
|
||||
if(text && *text) {
|
||||
split(list, "\n", text);
|
||||
for(uint i = 0; i < count(list); i++) add_item(list[i]);
|
||||
for(unsigned i = 0; i < count(list); i++) add_item(list[i]);
|
||||
}
|
||||
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(listbox), header);
|
||||
@@ -62,7 +62,7 @@ void pListbox::autosize_columns() {
|
||||
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listbox));
|
||||
}
|
||||
|
||||
void pListbox::set_column_width(uint column, uint width) {
|
||||
void pListbox::set_column_width(unsigned column, unsigned width) {
|
||||
gtk_tree_view_column_set_min_width(column_list[column], width);
|
||||
gtk_tree_view_column_set_max_width(column_list[column], width);
|
||||
}
|
||||
@@ -71,14 +71,14 @@ void pListbox::add_item(const char *text) {
|
||||
lstring list;
|
||||
split(list, "\t", text);
|
||||
gtk_list_store_append(store, &iter);
|
||||
for(uint i = 0; i < count(list); i++) {
|
||||
for(unsigned i = 0; i < count(list); i++) {
|
||||
gtk_list_store_set(store, &iter, i, list[i](), -1);
|
||||
}
|
||||
}
|
||||
|
||||
void pListbox::set_item(uint index, const char *text) {
|
||||
void pListbox::set_item(unsigned index, const char *text) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
|
||||
for(uint i = 0; i <= index; i++) {
|
||||
for(unsigned i = 0; i <= index; i++) {
|
||||
i == 0 ?
|
||||
gtk_tree_model_get_iter_first(model, &iter) :
|
||||
gtk_tree_model_iter_next(model, &iter);
|
||||
@@ -86,7 +86,7 @@ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
|
||||
|
||||
lstring list;
|
||||
split(list, "\t", text);
|
||||
for(uint i = 0; i < count(list); i++) {
|
||||
for(unsigned i = 0; i < count(list); i++) {
|
||||
gtk_list_store_set(store, &iter, i, list[i](), -1);
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listbox)
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) { return -1; }
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) { return 0; }
|
||||
for(uint i = 1; i < 100000; i++) {
|
||||
for(unsigned i = 1; i < 100000; i++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) { return -1; }
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) { return i; }
|
||||
}
|
||||
@@ -111,12 +111,12 @@ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
|
||||
if(index < 0) { goto end; }
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) { goto end; }
|
||||
if(index == 0) { gtk_tree_selection_select_iter(selection, &iter); goto end; }
|
||||
for(uint i = 1; i < 100000; i++) {
|
||||
for(unsigned i = 1; i < 100000; i++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) { goto end; }
|
||||
if(index == i) { gtk_tree_selection_select_iter(selection, &iter); goto end; }
|
||||
}
|
||||
end:
|
||||
if(current != index) ;//{ owner->message(Message::Changed, (uintptr_t)this); }
|
||||
if(current != index); //{ owner->message(Message::Changed, (uintptr_t)this); }
|
||||
}
|
||||
|
||||
void pListbox::reset() {
|
||||
|
@@ -1,10 +1,10 @@
|
||||
class pListbox : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
|
||||
void autosize_columns();
|
||||
void set_column_width(uint column, uint width);
|
||||
void set_column_width(unsigned column, unsigned width);
|
||||
void add_item(const char *text);
|
||||
void set_item(uint index, const char *text);
|
||||
void set_item(unsigned index, const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
void reset();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
void hiro_pmenucheckitem_tick(pMenuCheckItem *p) {
|
||||
if(!p->locked && p->self.on_tick) p->self.on_tick(Event(Event::Tick, p->checked(), &p->self));
|
||||
if(!p->locked && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, p->checked(), &p->self));
|
||||
}
|
||||
|
||||
void pMenuCheckItem::create(const char *text) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
void hiro_pmenuitem_tick(pMenuItem *p) {
|
||||
if(p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
|
||||
if(p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
|
||||
}
|
||||
|
||||
void pMenuItem::create(const char *text) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
void hiro_pmenuradioitem_tick(pMenuRadioItem *p) {
|
||||
//GTK+ sends two messages: one for the activated radio item,
|
||||
//and one for the deactivated radio item. ignore the latter.
|
||||
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
|
||||
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
|
||||
}
|
||||
|
||||
void pMenuRadioItem::create(MenuRadioItemGroup &group, const char *text) {
|
||||
|
@@ -1,15 +1,15 @@
|
||||
void pProgressbar::create(uint style, uint width, uint height) {
|
||||
void pProgressbar::create(unsigned style, unsigned width, unsigned height) {
|
||||
progressbar = gtk_progress_bar_new();
|
||||
gtk_widget_set_size_request(progressbar, width, height);
|
||||
gtk_widget_show(progressbar);
|
||||
}
|
||||
|
||||
uint pProgressbar::get_progress() {
|
||||
uint progress = (uint)(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)) * 100.0);
|
||||
unsigned pProgressbar::get_progress() {
|
||||
unsigned progress = (unsigned)(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)) * 100.0);
|
||||
return max(0U, min(progress, 100U));
|
||||
}
|
||||
|
||||
void pProgressbar::set_progress(uint progress) {
|
||||
void pProgressbar::set_progress(unsigned progress) {
|
||||
progress = max(0U, min(progress, 100U));
|
||||
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), (double)progress / 100.0);
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
class pProgressbar : public pFormControl {
|
||||
public:
|
||||
Progressbar &self;
|
||||
void create(uint style, uint width, uint height);
|
||||
uint get_progress();
|
||||
void set_progress(uint progress);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
unsigned get_progress();
|
||||
void set_progress(unsigned progress);
|
||||
|
||||
pProgressbar(Progressbar&);
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
void hiro_pradiobox_tick(pRadiobox *p) {
|
||||
//GTK+ sends two messages: one for the activated radiobox,
|
||||
//and one for the deactivated radiobox. ignore the latter.
|
||||
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
|
||||
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
|
||||
}
|
||||
|
||||
void pRadiobox::create(RadioboxGroup &group, uint style, uint width, uint height, const char *text) {
|
||||
void pRadiobox::create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
if(group.size() == 0 || group[0] == &self) {
|
||||
radiobox = gtk_radio_button_new_with_label(0, text ? text : "");
|
||||
} else {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pRadiobox : public pFormControl {
|
||||
public:
|
||||
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
|
||||
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check();
|
||||
bool checked();
|
||||
|
@@ -1,9 +1,9 @@
|
||||
void hiro_pslider_change(pSlider *p) {
|
||||
if(p->slider_position == p->get_position()) return;
|
||||
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->slider_position = p->get_position(), &p->self));
|
||||
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->slider_position = p->get_position(), &p->self));
|
||||
}
|
||||
|
||||
void pSlider::create(uint style, uint width, uint height, uint length) {
|
||||
void pSlider::create(unsigned style, unsigned width, unsigned height, unsigned length) {
|
||||
if(length < 1) length = 1;
|
||||
if(style & Slider::Vertical) {
|
||||
slider = gtk_vscale_new_with_range(0, length - 1, 1);
|
||||
@@ -16,11 +16,11 @@ void pSlider::create(uint style, uint width, uint height, uint length) {
|
||||
g_signal_connect_swapped(G_OBJECT(slider), "value-changed", G_CALLBACK(hiro_pslider_change), (gpointer)this);
|
||||
}
|
||||
|
||||
uint pSlider::get_position() {
|
||||
return (uint)gtk_range_get_value(GTK_RANGE(slider));
|
||||
unsigned pSlider::get_position() {
|
||||
return (unsigned)gtk_range_get_value(GTK_RANGE(slider));
|
||||
}
|
||||
|
||||
void pSlider::set_position(uint position) {
|
||||
void pSlider::set_position(unsigned position) {
|
||||
gtk_range_set_value(GTK_RANGE(slider), position);
|
||||
}
|
||||
|
||||
|
@@ -1,14 +1,14 @@
|
||||
class pSlider : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, uint length);
|
||||
uint get_position();
|
||||
void set_position(uint position);
|
||||
void create(unsigned style, unsigned width, unsigned height, unsigned length);
|
||||
unsigned get_position();
|
||||
void set_position(unsigned position);
|
||||
|
||||
Slider &self;
|
||||
pSlider(Slider&);
|
||||
|
||||
/* internal */
|
||||
GtkWidget *slider;
|
||||
uint slider_position;
|
||||
unsigned slider_position;
|
||||
GtkWidget* gtk_handle();
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
static gint hiro_pwindow_close(pWindow *p) {
|
||||
uintptr_t r = p->self.on_close ? p->self.on_close(Event(Event::Close, 0, &p->self)) : true;
|
||||
uintptr_t r = p->self.on_close ? p->self.on_close(event_t(event_t::Close, 0, &p->self)) : true;
|
||||
return !bool(r);
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ static gboolean hiro_pwindow_expose(pWindow *p) {
|
||||
}
|
||||
|
||||
static gint hiro_pwindow_keydown(GtkWidget *w, GdkEventKey *key, pWindow *p) {
|
||||
if(p && p->self.on_keydown) p->self.on_keydown(Event(Event::KeyDown, phiro().translate_key(key->keyval), &p->self));
|
||||
if(p && p->self.on_keydown) p->self.on_keydown(event_t(event_t::KeyDown, phiro().translate_key(key->keyval), &p->self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint hiro_pwindow_keyup(GtkWidget *w, GdkEventKey *key, pWindow *p) {
|
||||
if(p && p->self.on_keyup) p->self.on_keyup(Event(Event::KeyUp, phiro().translate_key(key->keyval), &p->self));
|
||||
if(p && p->self.on_keyup) p->self.on_keyup(event_t(event_t::KeyUp, phiro().translate_key(key->keyval), &p->self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void pWindow::create(uint style, uint width, uint height, const char *text) {
|
||||
void pWindow::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_set_colormap(window, phiro().colormap);
|
||||
|
||||
@@ -81,12 +81,12 @@ void pWindow::close() {
|
||||
gtk_widget_destroy(window);
|
||||
}
|
||||
|
||||
void pWindow::move(uint x, uint y) {
|
||||
void pWindow::move(unsigned x, unsigned y) {
|
||||
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE);
|
||||
gtk_window_move(GTK_WINDOW(window), x, y);
|
||||
}
|
||||
|
||||
void pWindow::resize(uint width, uint height) {
|
||||
void pWindow::resize(unsigned width, unsigned height) {
|
||||
gtk_widget_set_size_request(formcontainer, width, height);
|
||||
state.width = width;
|
||||
state.height = height;
|
||||
@@ -132,14 +132,14 @@ void pWindow::unfullscreen() {
|
||||
//is unreliable, as it will usually report the previous window size.
|
||||
//therefore, calculate it manually by using state information.
|
||||
|
||||
uint pWindow::get_width() {
|
||||
unsigned pWindow::get_width() {
|
||||
if(state.is_fullscreen == false) return state.width;
|
||||
return gdk_screen_width();
|
||||
}
|
||||
|
||||
uint pWindow::get_height() {
|
||||
unsigned pWindow::get_height() {
|
||||
if(state.is_fullscreen == false) return state.height;
|
||||
uint height = gdk_screen_height();
|
||||
unsigned height = gdk_screen_height();
|
||||
|
||||
//do not include menubar height in client area height
|
||||
if(menu.visible()) {
|
||||
@@ -198,7 +198,7 @@ void pWindow::set_text(const char *text) {
|
||||
gtk_window_set_title(GTK_WINDOW(window), text ? text : "");
|
||||
}
|
||||
|
||||
void pWindow::attach(Window &window, uint x, uint y) {
|
||||
void pWindow::attach(Window &window, unsigned x, unsigned y) {
|
||||
window.p.owner = this;
|
||||
|
||||
//GTK+ does not support attaching a window to another window,
|
||||
@@ -216,15 +216,15 @@ void pWindow::attach(MenuGroup &menugroup) {
|
||||
gtk_widget_show(menubar);
|
||||
}
|
||||
|
||||
void pWindow::attach(FormControl &formcontrol, uint x, uint y) {
|
||||
void pWindow::attach(FormControl &formcontrol, unsigned x, unsigned y) {
|
||||
gtk_fixed_put(GTK_FIXED(formcontainer), formcontrol.p.gtk_handle(), x, y);
|
||||
}
|
||||
|
||||
void pWindow::move(Window &window, uint x, uint y) {
|
||||
void pWindow::move(Window &window, unsigned x, unsigned y) {
|
||||
gtk_fixed_move(GTK_FIXED(formcontainer), window.p.gtk_handle(), x, y);
|
||||
}
|
||||
|
||||
void pWindow::move(FormControl &formcontrol, uint x, uint y) {
|
||||
void pWindow::move(FormControl &formcontrol, unsigned x, unsigned y) {
|
||||
gtk_fixed_move(GTK_FIXED(formcontainer), formcontrol.p.gtk_handle(), x, y);
|
||||
}
|
||||
|
||||
|
@@ -1,24 +1,24 @@
|
||||
class pWindow : public pWidget {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void close();
|
||||
void move(uint x, uint y);
|
||||
void resize(uint width, uint height);
|
||||
void move(unsigned x, unsigned y);
|
||||
void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void fullscreen();
|
||||
void unfullscreen();
|
||||
uint get_width();
|
||||
uint get_height();
|
||||
unsigned get_width();
|
||||
unsigned get_height();
|
||||
void set_opacity(uint8_t opacity);
|
||||
void set_background_color(uint8_t r, uint8_t g, uint8_t b);
|
||||
void set_icon(unsigned width, unsigned height, const uint32_t *data);
|
||||
void set_text(const char *text = "");
|
||||
void attach(Window &window, uint x, uint y);
|
||||
void attach(Window &window, unsigned x, unsigned y);
|
||||
void attach(MenuGroup &menugroup);
|
||||
void attach(FormControl &formcontrol, uint x, uint y);
|
||||
void move(Window &window, uint x, uint y);
|
||||
void move(FormControl &formcontrol, uint x, uint y);
|
||||
void attach(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
void move(Window &window, unsigned x, unsigned y);
|
||||
void move(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
|
||||
class Statusbar {
|
||||
public:
|
||||
@@ -55,9 +55,9 @@ public:
|
||||
GtkWidget* gtk_handle();
|
||||
struct {
|
||||
bool is_fullscreen;
|
||||
uint width;
|
||||
uint height;
|
||||
uint alpha;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned alpha;
|
||||
} state;
|
||||
|
||||
void menu_show(bool = true);
|
||||
|
@@ -18,8 +18,8 @@ bool Hiro::pending() { return p.pending(); }
|
||||
bool Hiro::folder_select(Window *focus, char *filename, const char *path) { return p.folder_select(focus, filename, path); }
|
||||
bool Hiro::file_open(Window *focus, char *filename, const char *path, const char *filter) { return p.file_open(focus, filename, path, filter); }
|
||||
bool Hiro::file_save(Window *focus, char *filename, const char *path, const char *filter) { return p.file_save(focus, filename, path, filter); }
|
||||
uint Hiro::screen_width() { return p.screen_width(); }
|
||||
uint Hiro::screen_height() { return p.screen_height(); }
|
||||
unsigned Hiro::screen_width() { return p.screen_width(); }
|
||||
unsigned Hiro::screen_height() { return p.screen_height(); }
|
||||
void Hiro::enable_screensaver() { p.enable_screensaver(); }
|
||||
void Hiro::disable_screensaver() { p.disable_screensaver(); }
|
||||
Hiro& Hiro::handle() { static Hiro hiro; return hiro; }
|
||||
@@ -39,25 +39,25 @@ Widget::~Widget() { delete &p; }
|
||||
|
||||
/* Widget -> Window */
|
||||
|
||||
void Window::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Window::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Window::close() { p.close(); }
|
||||
void Window::move(uint x, uint y) { p.move(x, y); }
|
||||
void Window::resize(uint width, uint height) { p.resize(width, height); }
|
||||
void Window::move(unsigned x, unsigned y) { p.move(x, y); }
|
||||
void Window::resize(unsigned width, unsigned height) { p.resize(width, height); }
|
||||
void Window::focus() { p.focus(); }
|
||||
bool Window::focused() { return p.focused(); }
|
||||
void Window::fullscreen() { p.fullscreen(); }
|
||||
void Window::unfullscreen() { p.unfullscreen(); }
|
||||
uint Window::get_width() { return p.get_width(); }
|
||||
uint Window::get_height() { return p.get_height(); }
|
||||
unsigned Window::get_width() { return p.get_width(); }
|
||||
unsigned Window::get_height() { return p.get_height(); }
|
||||
void Window::set_opacity(uint8_t opacity) { p.set_opacity(opacity); }
|
||||
void Window::set_background_color(uint8_t r, uint8_t g, uint8_t b) { p.set_background_color(r, g, b); }
|
||||
void Window::set_icon(unsigned width, unsigned height, const uint32_t *data) { p.set_icon(width, height, data); }
|
||||
void Window::set_text(const char *text) { p.set_text(text); }
|
||||
void Window::attach(Window &window, uint x, uint y) { p.attach(window, x, y); }
|
||||
void Window::attach(Window &window, unsigned x, unsigned y) { p.attach(window, x, y); }
|
||||
void Window::attach(MenuGroup &menugroup) { p.attach(menugroup); }
|
||||
void Window::attach(FormControl &formcontrol, uint x, uint y) { p.attach(formcontrol, x, y); }
|
||||
void Window::move(Window &window, uint x, uint y) { p.move(window, x, y); }
|
||||
void Window::move(FormControl &formcontrol, uint x, uint y) { p.move(formcontrol, x, y); }
|
||||
void Window::attach(FormControl &formcontrol, unsigned x, unsigned y) { p.attach(formcontrol, x, y); }
|
||||
void Window::move(Window &window, unsigned x, unsigned y) { p.move(window, x, y); }
|
||||
void Window::move(FormControl &formcontrol, unsigned x, unsigned y) { p.move(formcontrol, x, y); }
|
||||
|
||||
void Window::Menubar::show(bool state) { p.menu.show(state); }
|
||||
void Window::Menubar::hide() { p.menu.hide(); }
|
||||
@@ -139,7 +139,7 @@ MenuSeparator::MenuSeparator() :
|
||||
|
||||
/* Widget -> FormControl */
|
||||
|
||||
void FormControl::resize(uint width, uint height) { p.resize(width, height); }
|
||||
void FormControl::resize(unsigned width, unsigned height) { p.resize(width, height); }
|
||||
void FormControl::focus() { p.focus(); }
|
||||
bool FormControl::focused() { return p.focused(); }
|
||||
void FormControl::enable(bool state) { p.enable(state); }
|
||||
@@ -156,7 +156,7 @@ FormControl::FormControl(pFormControl &p_) :
|
||||
|
||||
/* Widget -> FormControl -> Frame */
|
||||
|
||||
void Frame::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Frame::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Frame::set_text(const char *text) { p.set_text(text); }
|
||||
Frame::Frame() :
|
||||
base_from_member<pFrame&>(*new pFrame(*this)),
|
||||
@@ -165,7 +165,7 @@ Frame::Frame() :
|
||||
|
||||
/* Widget -> FormControl -> Canvas */
|
||||
|
||||
void Canvas::create(uint style, uint width, uint height) { p.create(style, width, height); }
|
||||
void Canvas::create(unsigned style, unsigned width, unsigned height) { p.create(style, width, height); }
|
||||
void Canvas::redraw() { p.redraw(); }
|
||||
uint32_t* Canvas::buffer() { return p.buffer(); }
|
||||
Canvas::Canvas() :
|
||||
@@ -175,7 +175,7 @@ Canvas::Canvas() :
|
||||
|
||||
/* Widget -> FormControl -> Label */
|
||||
|
||||
void Label::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Label::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Label::set_text(const char *text) { p.set_text(text); }
|
||||
Label::Label() :
|
||||
base_from_member<pLabel&>(*new pLabel(*this)),
|
||||
@@ -184,7 +184,7 @@ Label::Label() :
|
||||
|
||||
/* Widget -> FormControl -> Button */
|
||||
|
||||
void Button::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Button::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Button::set_text(const char *text) { p.set_text(text); }
|
||||
Button::Button() :
|
||||
base_from_member<pButton&>(*new pButton(*this)),
|
||||
@@ -193,7 +193,7 @@ Button::Button() :
|
||||
|
||||
/* Widget -> FormControl -> Checkbox */
|
||||
|
||||
void Checkbox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Checkbox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Checkbox::set_text(const char *text) { p.set_text(text); }
|
||||
void Checkbox::check(bool state) { state ? p.check() : p.uncheck(); }
|
||||
void Checkbox::uncheck() { p.uncheck(); }
|
||||
@@ -205,7 +205,7 @@ Checkbox::Checkbox() :
|
||||
|
||||
/* Widget -> FormControl -> Radiobox */
|
||||
|
||||
void Radiobox::create(RadioboxGroup &group, uint style, uint width, uint height, const char *text) { p.create(group, style, width, height, text); }
|
||||
void Radiobox::create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text) { p.create(group, style, width, height, text); }
|
||||
void Radiobox::set_text(const char *text) { p.set_text(text); }
|
||||
void Radiobox::check() { p.check(); }
|
||||
bool Radiobox::checked() { return p.checked(); }
|
||||
@@ -216,8 +216,8 @@ Radiobox::Radiobox() :
|
||||
|
||||
/* Widget -> FormControl -> Editbox */
|
||||
|
||||
void Editbox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
uint Editbox::get_text(char *text, uint length) { return p.get_text(text, length); }
|
||||
void Editbox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
unsigned Editbox::get_text(char *text, unsigned length) { return p.get_text(text, length); }
|
||||
void Editbox::set_text(const char *text) { p.set_text(text); }
|
||||
Editbox::Editbox() :
|
||||
base_from_member<pEditbox&>(*new pEditbox(*this)),
|
||||
@@ -226,11 +226,11 @@ Editbox::Editbox() :
|
||||
|
||||
/* Widget -> FormControl -> Listbox */
|
||||
|
||||
void Listbox::create(uint style, uint width, uint height, const char *columns, const char *text) { p.create(style, width, height, columns, text); }
|
||||
void Listbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) { p.create(style, width, height, columns, text); }
|
||||
void Listbox::autosize_columns() { p.autosize_columns(); }
|
||||
void Listbox::set_column_width(uint column, uint width) { p.set_column_width(column, width); }
|
||||
void Listbox::set_column_width(unsigned column, unsigned width) { p.set_column_width(column, width); }
|
||||
void Listbox::add_item(const char *text) { p.add_item(text); }
|
||||
void Listbox::set_item(uint index, const char *text) { p.set_item(index, text); }
|
||||
void Listbox::set_item(unsigned index, const char *text) { p.set_item(index, text); }
|
||||
int Listbox::get_selection() { return p.get_selection(); }
|
||||
void Listbox::set_selection(int index) { p.set_selection(index); }
|
||||
void Listbox::reset() { p.reset(); }
|
||||
@@ -241,7 +241,7 @@ Listbox::Listbox() :
|
||||
|
||||
/* Widget -> FormControl -> Combobox */
|
||||
|
||||
void Combobox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
|
||||
void Combobox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
|
||||
void Combobox::add_item(const char *text) { p.add_item(text); }
|
||||
int Combobox::get_selection() { return p.get_selection(); }
|
||||
void Combobox::set_selection(int index) { p.set_selection(index); }
|
||||
@@ -253,9 +253,9 @@ Combobox::Combobox() :
|
||||
|
||||
/* Widget -> FormControl -> Progressbar */
|
||||
|
||||
void Progressbar::create(uint style, uint width, uint height) { p.create(style, width, height); }
|
||||
uint Progressbar::get_progress() { return p.get_progress(); }
|
||||
void Progressbar::set_progress(uint progress) { p.set_progress(progress); }
|
||||
void Progressbar::create(unsigned style, unsigned width, unsigned height) { p.create(style, width, height); }
|
||||
unsigned Progressbar::get_progress() { return p.get_progress(); }
|
||||
void Progressbar::set_progress(unsigned progress) { p.set_progress(progress); }
|
||||
Progressbar::Progressbar() :
|
||||
base_from_member<pProgressbar&>(*new pProgressbar(*this)),
|
||||
FormControl(base_from_member<pProgressbar&>::value),
|
||||
@@ -263,9 +263,9 @@ Progressbar::Progressbar() :
|
||||
|
||||
/* Widget -> FormControl -> Slider */
|
||||
|
||||
void Slider::create(uint style, uint width, uint height, uint length) { p.create(style, width, height, length); }
|
||||
uint Slider::get_position() { return p.get_position(); }
|
||||
void Slider::set_position(uint position) { p.set_position(position); }
|
||||
void Slider::create(unsigned style, unsigned width, unsigned height, unsigned length) { p.create(style, width, height, length); }
|
||||
unsigned Slider::get_position() { return p.get_position(); }
|
||||
void Slider::set_position(unsigned position) { p.set_position(position); }
|
||||
Slider::Slider() :
|
||||
base_from_member<pSlider&>(*new pSlider(*this)),
|
||||
FormControl(base_from_member<pSlider&>::value),
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
hiro
|
||||
version: 0.005 (2008-05-25)
|
||||
version: 0.006 (2008-08-12)
|
||||
author: byuu
|
||||
license: public domain
|
||||
*/
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/string.hpp>
|
||||
#include <nall/utility.hpp>
|
||||
typedef unsigned int uint;
|
||||
|
||||
namespace libhiro {
|
||||
|
||||
@@ -89,8 +88,8 @@ class Widget;
|
||||
typedef nall::array<MenuRadioItem*> MenuRadioItemGroup;
|
||||
typedef nall::array<Radiobox*> RadioboxGroup;
|
||||
|
||||
struct Event {
|
||||
enum Type {
|
||||
struct event_t {
|
||||
enum type_t {
|
||||
Close,
|
||||
Block,
|
||||
KeyDown,
|
||||
@@ -102,7 +101,7 @@ struct Event {
|
||||
uintptr_t param;
|
||||
Widget *widget;
|
||||
|
||||
Event(Type type_, uintptr_t param_ = 0, Widget *widget_ = 0) :
|
||||
event_t(type_t type_, uintptr_t param_ = 0, Widget *widget_ = 0) :
|
||||
type(type_), param(param_), widget(widget_) {}
|
||||
};
|
||||
|
||||
@@ -117,8 +116,8 @@ public:
|
||||
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
|
||||
uint screen_width();
|
||||
uint screen_height();
|
||||
unsigned screen_width();
|
||||
unsigned screen_height();
|
||||
|
||||
void enable_screensaver();
|
||||
void disable_screensaver();
|
||||
@@ -182,26 +181,26 @@ public:
|
||||
AutoCenter = 1 << 1,
|
||||
};
|
||||
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void close();
|
||||
void move(uint x, uint y);
|
||||
void resize(uint width, uint height);
|
||||
void move(unsigned x, unsigned y);
|
||||
void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void fullscreen();
|
||||
void unfullscreen();
|
||||
uint get_width();
|
||||
uint get_height();
|
||||
unsigned get_width();
|
||||
unsigned get_height();
|
||||
void set_opacity(uint8_t opacity);
|
||||
void set_background_color(uint8_t r, uint8_t g, uint8_t b);
|
||||
void set_icon(unsigned width, unsigned height, const uint32_t *data);
|
||||
void set_status_text(const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void attach(Window &window, uint x, uint y);
|
||||
void attach(Window &window, unsigned x, unsigned y);
|
||||
void attach(MenuGroup &menugroup);
|
||||
void attach(FormControl &formcontrol, uint x, uint y);
|
||||
void move(Window &window, uint x, uint y);
|
||||
void move(FormControl &formcontrol, uint x, uint y);
|
||||
void attach(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
void move(Window &window, unsigned x, unsigned y);
|
||||
void move(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
|
||||
class Menubar {
|
||||
public:
|
||||
@@ -224,10 +223,10 @@ public:
|
||||
Statusbar(pWindow&);
|
||||
} status;
|
||||
|
||||
nall::function<uintptr_t (Event)> on_close;
|
||||
nall::function<uintptr_t (Event)> on_block;
|
||||
nall::function<uintptr_t (Event)> on_keydown;
|
||||
nall::function<uintptr_t (Event)> on_keyup;
|
||||
nall::function<uintptr_t (event_t)> on_close;
|
||||
nall::function<uintptr_t (event_t)> on_block;
|
||||
nall::function<uintptr_t (event_t)> on_keydown;
|
||||
nall::function<uintptr_t (event_t)> on_keyup;
|
||||
|
||||
Window();
|
||||
|
||||
@@ -268,7 +267,7 @@ public:
|
||||
MenuItem& create(const char *text);
|
||||
MenuItem();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
private:
|
||||
pFriends;
|
||||
@@ -283,7 +282,7 @@ public:
|
||||
bool checked();
|
||||
MenuCheckItem();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
private:
|
||||
pFriends;
|
||||
@@ -297,7 +296,7 @@ public:
|
||||
bool checked();
|
||||
MenuRadioItem();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
private:
|
||||
pFriends;
|
||||
@@ -316,7 +315,7 @@ private:
|
||||
|
||||
class FormControl : private nall::base_from_member<pFormControl&>, public Widget {
|
||||
public:
|
||||
void resize(uint width, uint height);
|
||||
void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void enable(bool = true);
|
||||
@@ -335,7 +334,7 @@ private:
|
||||
|
||||
class Frame : private nall::base_from_member<pFrame&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
Frame();
|
||||
@@ -347,7 +346,7 @@ private:
|
||||
|
||||
class Canvas : private nall::base_from_member<pCanvas&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
void redraw();
|
||||
uint32_t* buffer();
|
||||
|
||||
@@ -360,7 +359,7 @@ private:
|
||||
|
||||
class Label : private nall::base_from_member<pLabel&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
Label();
|
||||
@@ -372,10 +371,10 @@ private:
|
||||
|
||||
class Button : private nall::base_from_member<pButton&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
Button();
|
||||
|
||||
@@ -386,13 +385,13 @@ private:
|
||||
|
||||
class Checkbox : private nall::base_from_member<pCheckbox&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check(bool = true);
|
||||
void uncheck();
|
||||
bool checked();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
Checkbox();
|
||||
|
||||
@@ -403,12 +402,12 @@ private:
|
||||
|
||||
class Radiobox : private nall::base_from_member<pRadiobox&>, public FormControl {
|
||||
public:
|
||||
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
|
||||
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check();
|
||||
bool checked();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_tick;
|
||||
nall::function<uintptr_t (event_t)> on_tick;
|
||||
|
||||
Radiobox();
|
||||
|
||||
@@ -432,8 +431,8 @@ public:
|
||||
VerticalScrollNever = 1 << 6,
|
||||
};
|
||||
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
uint get_text(char *text, uint length = -1U);
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
unsigned get_text(char *text, unsigned length = -1U);
|
||||
void set_text(const char *text = "");
|
||||
|
||||
Editbox();
|
||||
@@ -457,17 +456,17 @@ public:
|
||||
VerticalScrollNever = 1 << 5,
|
||||
};
|
||||
|
||||
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
|
||||
void autosize_columns();
|
||||
void set_column_width(uint column, uint width);
|
||||
void set_column_width(unsigned column, unsigned width);
|
||||
void add_item(const char *text);
|
||||
void set_item(uint index, const char *text);
|
||||
void set_item(unsigned index, const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
void reset();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_change;
|
||||
nall::function<uintptr_t (Event)> on_activate;
|
||||
nall::function<uintptr_t (event_t)> on_change;
|
||||
nall::function<uintptr_t (event_t)> on_activate;
|
||||
|
||||
Listbox();
|
||||
|
||||
@@ -478,13 +477,13 @@ private:
|
||||
|
||||
class Combobox : private nall::base_from_member<pCombobox&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void add_item(const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
void reset();
|
||||
|
||||
nall::function<uintptr_t (Event)> on_change;
|
||||
nall::function<uintptr_t (event_t)> on_change;
|
||||
|
||||
Combobox();
|
||||
|
||||
@@ -495,9 +494,9 @@ private:
|
||||
|
||||
class Progressbar : private nall::base_from_member<pProgressbar&>, public FormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height);
|
||||
uint get_progress();
|
||||
void set_progress(uint progress);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
unsigned get_progress();
|
||||
void set_progress(unsigned progress);
|
||||
|
||||
Progressbar();
|
||||
|
||||
@@ -513,11 +512,11 @@ public:
|
||||
Vertical = 1 << 1,
|
||||
};
|
||||
|
||||
void create(uint style, uint width, uint height, uint length);
|
||||
uint get_position();
|
||||
void set_position(uint position);
|
||||
void create(unsigned style, unsigned width, unsigned height, unsigned length);
|
||||
unsigned get_position();
|
||||
void set_position(unsigned position);
|
||||
|
||||
nall::function<uintptr_t (Event)> on_change;
|
||||
nall::function<uintptr_t (event_t)> on_change;
|
||||
|
||||
Slider();
|
||||
|
||||
|
@@ -1,237 +0,0 @@
|
||||
#include "../hiro.h"
|
||||
using namespace libhiro;
|
||||
|
||||
#include <nall/algorithm.hpp>
|
||||
using nall::min;
|
||||
using nall::max;
|
||||
|
||||
bool kill_ = false;
|
||||
|
||||
uint32_t windowicon[16 * 16] = {
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
|
||||
};
|
||||
|
||||
class SubWindow : public Window {
|
||||
public:
|
||||
Button button;
|
||||
|
||||
uintptr_t tick(Event) {
|
||||
hide();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
create(0, 595, 80);
|
||||
|
||||
button.create(0, 595, 80, "SubWindow (click to hide)");
|
||||
button.on_tick = bind(&SubWindow::tick, this);
|
||||
attach(button, 0, 0);
|
||||
}
|
||||
} subwindow;
|
||||
|
||||
class MainWindow : public Window {
|
||||
public:
|
||||
MenuGroup menu_file;
|
||||
MenuGroup menu_file_disk;
|
||||
MenuItem menu_file_disk_load;
|
||||
MenuItem menu_file_disk_save;
|
||||
MenuSeparator menu_file_separator;
|
||||
MenuItem menu_file_exit;
|
||||
MenuGroup menu_help;
|
||||
MenuCheckItem menu_help_check1, menu_help_check2;
|
||||
MenuSeparator menu_help_separator1;
|
||||
MenuRadioItem menu_help_radio1, menu_help_radio2, menu_help_radio3;
|
||||
MenuSeparator menu_help_separator2;
|
||||
MenuItem menu_help_about;
|
||||
Label label;
|
||||
Editbox editbox, editbox_multi;
|
||||
Button button_ok;
|
||||
Button button_exit;
|
||||
Checkbox check1, check2;
|
||||
Radiobox radio1, radio2;
|
||||
Progressbar progress;
|
||||
Combobox combobox;
|
||||
Listbox listbox;
|
||||
Slider hslider, vslider;
|
||||
Frame frame;
|
||||
Canvas canvas;
|
||||
|
||||
uintptr_t change(Event e) {
|
||||
printf("change(%d)\n", (uint)e.param);
|
||||
}
|
||||
|
||||
uintptr_t activate(Event e) {
|
||||
printf("activate(%d)\n", (uint)e.param);
|
||||
}
|
||||
|
||||
uintptr_t tick(Event e) {
|
||||
printf("tick(%d)\n", e.param);
|
||||
if(e.widget == &button_ok) {
|
||||
char t[4096];
|
||||
editbox.get_text(t, 4096);
|
||||
printf("'%s'\n", t);
|
||||
}
|
||||
if(e.widget == &menu_file_disk_load) {
|
||||
char t[4096] = "";
|
||||
hiro().file_open(0, t, "", "Source files\t*.cpp,*.h\nAll Files\t*.*");
|
||||
printf("'%s'\n", t);
|
||||
}
|
||||
if(e.widget == &menu_file_disk_save) {
|
||||
char t[4096] = "";
|
||||
hiro().file_save(0, t, "", "Source files\t*.cpp,*.h\nAll Files\t*.*");
|
||||
printf("'%s'\n", t);
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t keydown(Event e) {
|
||||
static bool fs = false;
|
||||
if(e.param == nall::keyboard::f11) {
|
||||
fs = !fs;
|
||||
fs ? fullscreen() : unfullscreen();
|
||||
printf("%d -> %4d, %4d\n", fs, get_width(), get_height());
|
||||
} else if(e.param == nall::keyboard::escape) {
|
||||
menu.show(!menu.visible());
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t close(Event) {
|
||||
printf("close()\n");
|
||||
return kill_ = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
create(Window::AutoCenter, 605, 320, "hiro test application");
|
||||
//set_opacity(224);
|
||||
//set_background_color(0, 0, 0);
|
||||
set_icon(16, 16, windowicon);
|
||||
|
||||
attach(menu_file.create("File"));
|
||||
menu_file.attach(menu_file_disk.create("Disk"));
|
||||
menu_file_disk.attach(menu_file_disk_load.create("Load ..."));
|
||||
menu_file_disk.attach(menu_file_disk_save.create("Save ..."));
|
||||
menu_file.attach(menu_file_separator.create());
|
||||
menu_file.attach(menu_file_exit.create("Exit"));
|
||||
attach(menu_help.create("Help"));
|
||||
menu_help.attach(menu_help_check1.create("Check 1"));
|
||||
menu_help.attach(menu_help_check2.create("Check 2"));
|
||||
menu_help.attach(menu_help_separator1.create());
|
||||
{ MenuRadioItemGroup group;
|
||||
group.add(&menu_help_radio1);
|
||||
group.add(&menu_help_radio2);
|
||||
group.add(&menu_help_radio3);
|
||||
menu_help.attach(menu_help_radio1.create(group, "Radio 1"));
|
||||
menu_help.attach(menu_help_radio2.create(group, "Radio 2"));
|
||||
menu_help.attach(menu_help_radio3.create(group, "Radio 3"));
|
||||
} menu_help.attach(menu_help_separator2.create());
|
||||
menu_help.attach(menu_help_about.create("About ..."));
|
||||
menu_help_about.disable();
|
||||
label.create(0, 200, 35, "hiro test application\n~ byuu");
|
||||
editbox.create(0, 200, 25);
|
||||
button_ok.create(0, 100, 30, "Ok");
|
||||
button_exit.create(0, 100, 30, "Exit");
|
||||
editbox_multi.create(Editbox::Multiline | Editbox::VerticalScrollAlways, 200, 95);
|
||||
check1.create(0, 100, 20, "Check 1");
|
||||
check2.create(0, 100, 20, "Check 2");
|
||||
{ RadioboxGroup group;
|
||||
group.add(&radio1);
|
||||
group.add(&radio2);
|
||||
radio1.create(group, 0, 100, 20, "Radio 1");
|
||||
radio2.create(group, 0, 100, 20, "Radio 2");
|
||||
} progress.create(0, 200, 30);
|
||||
progress.set_progress(50);
|
||||
combobox.create(0, 200, 30);
|
||||
combobox.add_item("Option 1");
|
||||
combobox.add_item("Option 2");
|
||||
combobox.add_item("Option 3");
|
||||
listbox.create(Listbox::Header | Listbox::VerticalScrollAlways, 200, 100, "Name\tValue");
|
||||
listbox.add_item("a\ttrue");
|
||||
listbox.add_item("b\tfalse");
|
||||
hslider.create(Slider::Horizontal, 425, 25, 10);
|
||||
vslider.create(Slider::Vertical, 25, 200, 10);
|
||||
frame.create(0, 155, 225, "Canvas:");
|
||||
|
||||
canvas.create(0, 135, 195);
|
||||
for(uint y = 0; y < 195; y++) {
|
||||
uint32_t *p = canvas.buffer() + y * 135;
|
||||
for(uint x = 0; x < 135; x++) {
|
||||
double dx = 128.0 / 135.0 * double(x);
|
||||
double dy = 128.0 / 195.0 * double(y);
|
||||
uint32_t c = uint32_t(dx) + uint32_t(dy);
|
||||
*p++ = (max(0U, min(c, 255U)) ^ 0xff) << 16;
|
||||
}
|
||||
}
|
||||
|
||||
status.show();
|
||||
status.set_text("Statusbar");
|
||||
|
||||
on_close = bind(&MainWindow::close, this);
|
||||
on_keydown = bind(&MainWindow::keydown, this);
|
||||
|
||||
menu_file_disk_load.on_tick =
|
||||
menu_file_disk_save.on_tick = bind(&MainWindow::tick, this);
|
||||
menu_file_exit.on_tick = on_close;
|
||||
menu_help_check1.on_tick = menu_help_check2.on_tick =
|
||||
menu_help_radio1.on_tick = menu_help_radio2.on_tick =
|
||||
menu_help_radio3.on_tick = bind(&MainWindow::tick, this);
|
||||
menu_help_about.on_tick = bind(&MainWindow::tick, this);
|
||||
button_ok.on_tick = bind(&MainWindow::tick, this);
|
||||
button_exit.on_tick = bind(&MainWindow::close, this);
|
||||
check1.on_tick = check2.on_tick =
|
||||
radio1.on_tick = radio2.on_tick = bind(&MainWindow::tick, this);
|
||||
combobox.on_change = bind(&MainWindow::change, this);
|
||||
listbox.on_change = bind(&MainWindow::change, this);
|
||||
listbox.on_activate = bind(&MainWindow::activate, this);
|
||||
hslider.on_change = bind(&MainWindow::change, this);
|
||||
vslider.on_change = bind(&MainWindow::change, this);
|
||||
|
||||
attach(label, 5, 5);
|
||||
attach(editbox, 5, 40);
|
||||
attach(button_ok, 5, 70);
|
||||
attach(button_exit, 105, 70);
|
||||
attach(editbox_multi, 210, 5);
|
||||
attach(check1, 5, 105);
|
||||
attach(check2, 105, 105);
|
||||
attach(radio1, 5, 125);
|
||||
attach(radio2, 105, 125);
|
||||
attach(progress, 5, 145);
|
||||
attach(combobox, 5, 175);
|
||||
attach(listbox, 210, 105);
|
||||
attach(hslider, 5, 205);
|
||||
attach(vslider, 415, 5);
|
||||
|
||||
attach(frame, 445, 5);
|
||||
attach(canvas, 455, 25);
|
||||
|
||||
attach(subwindow, 5, 235);
|
||||
}
|
||||
} window;
|
||||
|
||||
int main() {
|
||||
hiro().init();
|
||||
hiro().disable_screensaver();
|
||||
|
||||
subwindow.setup();
|
||||
window.setup();
|
||||
window.show();
|
||||
|
||||
window.check1.check();
|
||||
|
||||
while(kill_ == false) hiro().run();
|
||||
|
||||
hiro().term();
|
||||
return 0;
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
void pButton::create(uint style, uint width, uint height, const char *text) {
|
||||
void pButton::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pButton : public pFormControl {
|
||||
public:
|
||||
Button &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pButton(Button&);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pCanvas::create(uint style, uint width, uint height) {
|
||||
void pCanvas::create(unsigned style, unsigned width, unsigned height) {
|
||||
hwnd = CreateWindow(L"hiro_window", L"", WS_CHILD,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
@@ -35,7 +35,7 @@ pCanvas::~pCanvas() {
|
||||
|
||||
/* internal */
|
||||
|
||||
void pCanvas::resize(uint width, uint height) {
|
||||
void pCanvas::resize(unsigned width, unsigned height) {
|
||||
if(ibuffer) free(ibuffer);
|
||||
|
||||
ipitch = width * sizeof(uint32_t);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pCanvas : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
void redraw();
|
||||
uint32_t* buffer();
|
||||
|
||||
@@ -11,6 +11,6 @@ public:
|
||||
/* internal */
|
||||
BITMAPINFO bmi;
|
||||
uint32_t *ibuffer;
|
||||
uint ipitch, iwidth, iheight;
|
||||
void resize(uint width, uint height);
|
||||
unsigned ipitch, iwidth, iheight;
|
||||
void resize(unsigned width, unsigned height);
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pCheckbox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pCheckbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_CHECKBOX,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pCheckbox : public pFormControl {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check(bool state = true);
|
||||
void uncheck();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pCombobox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pCombobox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"COMBOBOX", L"",
|
||||
WS_CHILD | WS_TABSTOP | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
|
||||
0, 0, width, 200,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pCombobox : public pFormControl {
|
||||
public:
|
||||
Combobox &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void add_item(const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
|
@@ -1,12 +1,12 @@
|
||||
void pEditbox::create(uint style, uint width, uint height, const char *text) {
|
||||
void pEditbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
bool multiline = style & Editbox::Multiline;
|
||||
bool readonly = style & Editbox::Readonly;
|
||||
uint vscroll = (style & Editbox::VerticalScrollAlways) ? WS_VSCROLL :
|
||||
(style & Editbox::VerticalScrollNever) ? 0 :
|
||||
ES_AUTOVSCROLL;
|
||||
uint hscroll = (style & Editbox::HorizontalScrollAlways) ? WS_HSCROLL :
|
||||
(style & Editbox::HorizontalScrollNever) ? 0 :
|
||||
ES_AUTOHSCROLL;
|
||||
bool readonly = style & Editbox::Readonly;
|
||||
unsigned vscroll = (style & Editbox::VerticalScrollAlways) ? WS_VSCROLL :
|
||||
(style & Editbox::VerticalScrollNever) ? 0 :
|
||||
ES_AUTOVSCROLL;
|
||||
unsigned hscroll = (style & Editbox::HorizontalScrollAlways) ? WS_HSCROLL :
|
||||
(style & Editbox::HorizontalScrollNever) ? 0 :
|
||||
ES_AUTOHSCROLL;
|
||||
|
||||
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
|
||||
WS_CHILD | WS_VISIBLE | vscroll | hscroll |
|
||||
@@ -25,10 +25,11 @@ void pEditbox::set_text(const char *text) {
|
||||
SetWindowText(hwnd, utf16(temp));
|
||||
}
|
||||
|
||||
uint pEditbox::get_text(char *text, uint length) {
|
||||
wchar_t buffer[length * 2 + 1];
|
||||
GetWindowText(hwnd, buffer, length * 2);
|
||||
unsigned pEditbox::get_text(char *text, unsigned length) {
|
||||
wchar_t *buffer = new wchar_t[length + 1];
|
||||
GetWindowText(hwnd, buffer, length);
|
||||
string temp = (const char*)utf8(buffer);
|
||||
delete[] buffer;
|
||||
replace(temp, "\r", "");
|
||||
strlcpy(text, temp, length);
|
||||
return strlen(text);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
class pEditbox : public pFormControl {
|
||||
public:
|
||||
Editbox &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
uint get_text(char *text, uint length = -1U);
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
unsigned get_text(char *text, unsigned length = -1U);
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pEditbox(Editbox&);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pFormControl::resize(uint width, uint height) {
|
||||
void pFormControl::resize(unsigned width, unsigned height) {
|
||||
SetWindowPos(hwnd, 0, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pFormControl : public pWidget {
|
||||
public:
|
||||
virtual void resize(uint width, uint height);
|
||||
virtual void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void enable(bool = true);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pFrame::create(uint style, uint width, uint height, const char *text) {
|
||||
void pFrame::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pFrame : public pFormControl {
|
||||
public:
|
||||
Frame &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pFrame(Frame&);
|
||||
|
@@ -200,11 +200,11 @@ bool pHiro::file_save(Window *focus, char *filename, const char *path, const cha
|
||||
return result;
|
||||
}
|
||||
|
||||
uint pHiro::screen_width() {
|
||||
unsigned pHiro::screen_width() {
|
||||
return GetSystemMetrics(SM_CXSCREEN);
|
||||
}
|
||||
|
||||
uint pHiro::screen_height() {
|
||||
unsigned pHiro::screen_height() {
|
||||
return GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ pHiro& phiro() {
|
||||
|
||||
/* internal */
|
||||
|
||||
HFONT pHiro::create_font(const char *name, uint size) {
|
||||
HFONT pHiro::create_font(const char *name, unsigned size) {
|
||||
return CreateFont(
|
||||
-(size * 96.0 / 72.0 + 0.5), //96 = DPI
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -238,9 +238,9 @@ HFONT pHiro::create_font(const char *name, uint size) {
|
||||
);
|
||||
}
|
||||
|
||||
Widget* pHiro::get_widget(uint instance) {
|
||||
Widget* pHiro::get_widget(unsigned instance) {
|
||||
Widget *widget = 0;
|
||||
for(uint i = 0; i < widget_list.size(); i++) {
|
||||
for(unsigned i = 0; i < widget_list.size(); i++) {
|
||||
if(widget_list[i]->p.instance != instance) continue;
|
||||
widget = widget_list[i];
|
||||
break;
|
||||
@@ -274,26 +274,26 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
case WM_CLOSE: {
|
||||
if(!p || p->self.type != Widget::WindowType) break;
|
||||
Window &w = ((pWindow*)p)->self;
|
||||
if(w.on_close) return (bool)w.on_close(Event(Event::Close, 0, &w));
|
||||
if(w.on_close) return (bool)w.on_close(event_t(event_t::Close, 0, &w));
|
||||
return TRUE; //true = destroy window
|
||||
} break;
|
||||
|
||||
case WM_ENTERMENULOOP: {
|
||||
if(!p || p->self.type != Widget::WindowType) break;
|
||||
Window &w = ((pWindow*)p)->self;
|
||||
if(w.on_block) w.on_block(Event(Event::Block, 0, &w));
|
||||
if(w.on_block) w.on_block(event_t(event_t::Block, 0, &w));
|
||||
} break;
|
||||
|
||||
case WM_KEYDOWN: {
|
||||
if(!p || p->self.type != Widget::WindowType) break;
|
||||
Window &w = ((pWindow*)p)->self;
|
||||
if(w.on_keydown) w.on_keydown(Event(Event::KeyDown, translate_key(wparam), &w));
|
||||
if(w.on_keydown) w.on_keydown(event_t(event_t::KeyDown, translate_key(wparam), &w));
|
||||
} break;
|
||||
|
||||
case WM_KEYUP: {
|
||||
if(!p || p->self.type != Widget::WindowType) break;
|
||||
Window &w = ((pWindow*)p)->self;
|
||||
if(w.on_keyup) w.on_keyup(Event(Event::KeyUp, translate_key(wparam), &w));
|
||||
if(w.on_keyup) w.on_keyup(event_t(event_t::KeyUp, translate_key(wparam), &w));
|
||||
} break;
|
||||
|
||||
case WM_ERASEBKGND: {
|
||||
@@ -322,39 +322,39 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
switch(widget->type) {
|
||||
case Widget::MenuItemType: {
|
||||
MenuItem &w = (MenuItem&)*widget;
|
||||
if(w.on_tick) w.on_tick(Event(Event::Tick, 0, &w));
|
||||
if(w.on_tick) w.on_tick(event_t(event_t::Tick, 0, &w));
|
||||
} break;
|
||||
case Widget::MenuCheckItemType: {
|
||||
MenuCheckItem &w = (MenuCheckItem&)*widget;
|
||||
w.check(!w.checked()); //invert check state
|
||||
if(w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
|
||||
if(w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
|
||||
} break;
|
||||
case Widget::MenuRadioItemType: {
|
||||
MenuRadioItem &w = (MenuRadioItem&)*widget;
|
||||
bool checked = w.checked();
|
||||
w.check();
|
||||
if(!checked && w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
|
||||
if(!checked && w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
|
||||
} break;
|
||||
case Widget::ButtonType: {
|
||||
Button &w = (Button&)*widget;
|
||||
if(w.on_tick) w.on_tick(Event(Event::Tick, 0, &w));
|
||||
if(w.on_tick) w.on_tick(event_t(event_t::Tick, 0, &w));
|
||||
} break;
|
||||
case Widget::CheckboxType: {
|
||||
Checkbox &w = (Checkbox&)*widget;
|
||||
w.check(!w.checked()); //invert check state
|
||||
if(w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
|
||||
if(w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
|
||||
} break;
|
||||
case Widget::RadioboxType: {
|
||||
Radiobox &w = (Radiobox&)*widget;
|
||||
bool checked = w.checked();
|
||||
w.check();
|
||||
if(!checked && w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
|
||||
if(!checked && w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
|
||||
} break;
|
||||
case Widget::ComboboxType: {
|
||||
Combobox &combobox = (Combobox&)*widget;
|
||||
if(HIWORD(wparam) == CBN_SELCHANGE) {
|
||||
if(combobox.p.combobox_selection == combobox.get_selection()) break;
|
||||
if(combobox.on_change) combobox.on_change(Event(Event::Change, combobox.p.combobox_selection = combobox.get_selection(), &combobox));
|
||||
if(combobox.on_change) combobox.on_change(event_t(event_t::Change, combobox.p.combobox_selection = combobox.get_selection(), &combobox));
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -369,7 +369,7 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
case Widget::SliderType: {
|
||||
Slider &slider = (Slider&)*widget;
|
||||
if(slider.p.slider_position == slider.get_position()) break;
|
||||
if(slider.on_change) slider.on_change(Event(Event::Change, slider.p.slider_position = slider.get_position(), &slider));
|
||||
if(slider.on_change) slider.on_change(event_t(event_t::Change, slider.p.slider_position = slider.get_position(), &slider));
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
@@ -386,9 +386,9 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
&& ListView_GetItemState(listbox.p.hwnd, ((LPNMLISTVIEW)lparam)->iItem, LVIS_FOCUSED)
|
||||
&& ListView_GetItemState(listbox.p.hwnd, ((LPNMLISTVIEW)lparam)->iItem, LVIS_SELECTED)
|
||||
) {
|
||||
if(listbox.on_change) listbox.on_change(Event(Event::Change, listbox.get_selection(), &listbox));
|
||||
if(listbox.on_change) listbox.on_change(event_t(event_t::Change, listbox.get_selection(), &listbox));
|
||||
} else if(((LPNMHDR)lparam)->code == LVN_ITEMACTIVATE) {
|
||||
if(listbox.on_activate) listbox.on_activate(Event(Event::Activate, listbox.get_selection(), &listbox));
|
||||
if(listbox.on_activate) listbox.on_activate(event_t(event_t::Activate, listbox.get_selection(), &listbox));
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
@@ -51,8 +51,8 @@ public:
|
||||
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
|
||||
|
||||
uint screen_width();
|
||||
uint screen_height();
|
||||
unsigned screen_width();
|
||||
unsigned screen_height();
|
||||
|
||||
void enable_screensaver();
|
||||
void disable_screensaver();
|
||||
@@ -66,12 +66,12 @@ public:
|
||||
HWND default_hwnd; //default parent window for all windowless controls
|
||||
HFONT default_font; //default font for all controls
|
||||
HBRUSH black_brush; //used for Canvas background
|
||||
HFONT create_font(const char *name, uint size);
|
||||
HFONT create_font(const char *name, unsigned size);
|
||||
|
||||
array<Widget*> widget_list;
|
||||
Widget* get_widget(uint instance);
|
||||
Widget* get_widget(unsigned instance);
|
||||
LRESULT wndproc(HWND, UINT, WPARAM, LPARAM);
|
||||
uint16_t translate_key(uint key);
|
||||
uint16_t translate_key(unsigned key);
|
||||
};
|
||||
|
||||
pHiro& phiro();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
uint16_t pHiro::translate_key(uint key) {
|
||||
uint16_t pHiro::translate_key(unsigned key) {
|
||||
switch(key) {
|
||||
case VK_ESCAPE: return keyboard::escape;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pLabel::create(uint style, uint width, uint height, const char *text) {
|
||||
void pLabel::create(unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
hwnd = CreateWindow(L"STATIC", utf16(text), WS_CHILD | WS_VISIBLE,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class pLabel : public pFormControl {
|
||||
public:
|
||||
Label &self;
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
|
||||
pLabel(Label&);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pListbox::create(uint style, uint width, uint height, const char *columns, const char *text) {
|
||||
void pListbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) {
|
||||
bool header = style & Listbox::Header;
|
||||
unsigned hscroll = (style & Listbox::HorizontalScrollAlways) ? WS_HSCROLL :
|
||||
(style & Listbox::HorizontalScrollNever) ? 0 :
|
||||
@@ -41,7 +41,7 @@ void pListbox::autosize_columns() {
|
||||
}
|
||||
}
|
||||
|
||||
void pListbox::set_column_width(uint column, uint width) {
|
||||
void pListbox::set_column_width(unsigned column, unsigned width) {
|
||||
ListView_SetColumnWidth(hwnd, column, width);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void pListbox::add_item(const char *text) {
|
||||
}
|
||||
}
|
||||
|
||||
void pListbox::set_item(uint index, const char *text) {
|
||||
void pListbox::set_item(unsigned index, const char *text) {
|
||||
lstring list;
|
||||
split(list, "\t", text ? text : "");
|
||||
for(unsigned i = 0; i < count(list); i++) {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
class pListbox : public pFormControl {
|
||||
public:
|
||||
Listbox &self;
|
||||
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
|
||||
void autosize_columns();
|
||||
void set_column_width(uint column, uint width);
|
||||
void set_column_width(unsigned column, unsigned width);
|
||||
void add_item(const char *text);
|
||||
void set_item(uint index, const char *text);
|
||||
void set_item(unsigned index, const char *text);
|
||||
int get_selection();
|
||||
void set_selection(int index);
|
||||
void reset();
|
||||
@@ -13,5 +13,5 @@ public:
|
||||
pListbox(Listbox&);
|
||||
|
||||
/* internal */
|
||||
uint column_count;
|
||||
unsigned column_count;
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@ void pMenuGroup::create(const char *text_) {
|
||||
void pMenuGroup::attach(MenuControl &menucontrol) {
|
||||
switch(menucontrol.type) {
|
||||
case Widget::MenuGroupType: {
|
||||
AppendMenu(group, MF_STRING | MF_POPUP, (uint)((MenuGroup&)menucontrol).p.group, utf16(menucontrol.p.text));
|
||||
AppendMenu(group, MF_STRING | MF_POPUP, (unsigned)((MenuGroup&)menucontrol).p.group, utf16(menucontrol.p.text));
|
||||
} break;
|
||||
|
||||
case Widget::MenuItemType:
|
||||
|
@@ -5,7 +5,7 @@ void pMenuRadioItem::create(MenuRadioItemGroup &group_, const char *text_) {
|
||||
}
|
||||
|
||||
void pMenuRadioItem::check() {
|
||||
for(uint i = 0; i < group.size(); i++) {
|
||||
for(unsigned i = 0; i < group.size(); i++) {
|
||||
CheckMenuItem(parent, group[i]->p.instance, (group[i] == &self) ? MF_CHECKED : MF_UNCHECKED);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pProgressbar::create(uint style, uint width, uint height) {
|
||||
void pProgressbar::create(unsigned style, unsigned width, unsigned height) {
|
||||
hwnd = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
|
||||
0, 0, width, height,
|
||||
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
@@ -6,12 +6,12 @@ void pProgressbar::create(uint style, uint width, uint height) {
|
||||
SendMessage(hwnd, PBM_SETSTEP, MAKEWPARAM(1, 0), 0);
|
||||
}
|
||||
|
||||
uint pProgressbar::get_progress() {
|
||||
uint progress = SendMessage(hwnd, PBM_GETPOS, 0, 0);
|
||||
unsigned pProgressbar::get_progress() {
|
||||
unsigned progress = SendMessage(hwnd, PBM_GETPOS, 0, 0);
|
||||
return max(0U, min(progress, 100U));
|
||||
}
|
||||
|
||||
void pProgressbar::set_progress(uint progress) {
|
||||
void pProgressbar::set_progress(unsigned progress) {
|
||||
progress = max(0U, min(progress, 100U));
|
||||
SendMessage(hwnd, PBM_SETPOS, (WPARAM)progress, 0);
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
class pProgressbar : public pFormControl {
|
||||
public:
|
||||
Progressbar &self;
|
||||
void create(uint style, uint width, uint height);
|
||||
uint get_progress();
|
||||
void set_progress(uint progress);
|
||||
void create(unsigned style, unsigned width, unsigned height);
|
||||
unsigned get_progress();
|
||||
void set_progress(unsigned progress);
|
||||
|
||||
pProgressbar(Progressbar&);
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pRadiobox::create(RadioboxGroup &group_, uint style, uint width, uint height, const char *text) {
|
||||
void pRadiobox::create(RadioboxGroup &group_, unsigned style, unsigned width, unsigned height, const char *text) {
|
||||
group = group_;
|
||||
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_RADIOBUTTON,
|
||||
0, 0, width, height, phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
|
||||
@@ -11,7 +11,7 @@ void pRadiobox::set_text(const char *text) {
|
||||
}
|
||||
|
||||
void pRadiobox::check() {
|
||||
for(uint i = 0; i < group.size(); i++) {
|
||||
for(unsigned i = 0; i < group.size(); i++) {
|
||||
SendMessage(group[i]->p.hwnd, BM_SETCHECK, (WPARAM)(group[i] == &self), 0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
class pRadiobox : public pFormControl {
|
||||
public:
|
||||
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
|
||||
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void set_text(const char *text = "");
|
||||
void check();
|
||||
bool checked();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pSlider::create(uint style, uint width, uint height, uint length) {
|
||||
void pSlider::create(unsigned style, unsigned width, unsigned height, unsigned length) {
|
||||
if(length < 1) length = 1;
|
||||
|
||||
hwnd = CreateWindow(TRACKBAR_CLASS, L"",
|
||||
@@ -11,11 +11,11 @@ void pSlider::create(uint style, uint width, uint height, uint length) {
|
||||
SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)0);
|
||||
}
|
||||
|
||||
uint pSlider::get_position() {
|
||||
unsigned pSlider::get_position() {
|
||||
return SendMessage(hwnd, TBM_GETPOS, 0, 0);
|
||||
}
|
||||
|
||||
void pSlider::set_position(uint position) {
|
||||
void pSlider::set_position(unsigned position) {
|
||||
SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)(slider_position = position));
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,12 @@
|
||||
class pSlider : public pFormControl {
|
||||
public:
|
||||
Slider &self;
|
||||
void create(uint style, uint width, uint height, uint length);
|
||||
uint get_position();
|
||||
void set_position(uint position);
|
||||
void create(unsigned style, unsigned width, unsigned height, unsigned length);
|
||||
unsigned get_position();
|
||||
void set_position(unsigned position);
|
||||
|
||||
pSlider(Slider&);
|
||||
|
||||
/* internal */
|
||||
uint slider_position;
|
||||
unsigned slider_position;
|
||||
};
|
||||
|
@@ -24,4 +24,4 @@ pWidget::~pWidget() {
|
||||
|
||||
//100 is the standard start index for control IDs in the Windows API
|
||||
//avoids duplicate IDs when they are not explicitly set (and are thus 0)
|
||||
uint pWidget::instance_counter = 100;
|
||||
unsigned pWidget::instance_counter = 100;
|
||||
|
@@ -14,6 +14,6 @@ public:
|
||||
//Windows API controls often require a unique ID for each control to identify it.
|
||||
//Simulate this with an instance counter, so that each Widget has a unique ID.
|
||||
//In each pWidget() constructor, instance = instance_counter++; is called.
|
||||
static uint instance_counter;
|
||||
uint instance;
|
||||
static unsigned instance_counter;
|
||||
unsigned instance;
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
void pWindow::create(uint style, uint width_, uint height_, const char *text) {
|
||||
void pWindow::create(unsigned style, unsigned width_, unsigned height_, const char *text) {
|
||||
auto_center = style & Window::AutoCenter;
|
||||
|
||||
RECT rc;
|
||||
@@ -24,12 +24,12 @@ void pWindow::close() {
|
||||
CloseWindow(hwnd);
|
||||
}
|
||||
|
||||
void pWindow::move(uint x, uint y) {
|
||||
void pWindow::move(unsigned x, unsigned y) {
|
||||
if(is_fullscreen == true) return;
|
||||
SetWindowPos(hwnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void pWindow::resize(uint width_, uint height_) {
|
||||
void pWindow::resize(unsigned width_, unsigned height_) {
|
||||
int screen_width = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screen_height = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
@@ -119,13 +119,13 @@ void pWindow::unfullscreen() {
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
uint pWindow::get_width() {
|
||||
unsigned pWindow::get_width() {
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
return rc.right - rc.left;
|
||||
}
|
||||
|
||||
uint pWindow::get_height() {
|
||||
unsigned pWindow::get_height() {
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
if(status.visible() == false) return rc.bottom - rc.top;
|
||||
@@ -197,7 +197,7 @@ void pWindow::set_text(const char *text) {
|
||||
SetWindowText(hwnd, utf16(text));
|
||||
}
|
||||
|
||||
void pWindow::attach(Window &window, uint x, uint y) {
|
||||
void pWindow::attach(Window &window, unsigned x, unsigned y) {
|
||||
if(!window.p.hwnd) return;
|
||||
|
||||
//toplevel window size is larger, because it includes window borders
|
||||
@@ -214,11 +214,11 @@ void pWindow::attach(Window &window, uint x, uint y) {
|
||||
}
|
||||
|
||||
void pWindow::attach(MenuGroup &menugroup) {
|
||||
AppendMenu(hmenu, MF_STRING | MF_POPUP, (uint)menugroup.p.group, utf16(menugroup.p.text));
|
||||
AppendMenu(hmenu, MF_STRING | MF_POPUP, (unsigned)menugroup.p.group, utf16(menugroup.p.text));
|
||||
if(menu_visible() == false) menu_show();
|
||||
}
|
||||
|
||||
void pWindow::attach(FormControl &formcontrol, uint x, uint y) {
|
||||
void pWindow::attach(FormControl &formcontrol, unsigned x, unsigned y) {
|
||||
SetWindowPos(formcontrol.p.hwnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
SetParent(formcontrol.p.hwnd, hwnd);
|
||||
//SetParent() sets Z-order to topmost ...
|
||||
@@ -227,11 +227,11 @@ void pWindow::attach(FormControl &formcontrol, uint x, uint y) {
|
||||
SetWindowPos(formcontrol.p.hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
||||
}
|
||||
|
||||
void pWindow::move(Window &window, uint x, uint y) {
|
||||
void pWindow::move(Window &window, unsigned x, unsigned y) {
|
||||
SetWindowPos(window.p.hwnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void pWindow::move(FormControl &formcontrol, uint x, uint y) {
|
||||
void pWindow::move(FormControl &formcontrol, unsigned x, unsigned y) {
|
||||
SetWindowPos(formcontrol.p.hwnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
|
@@ -1,24 +1,24 @@
|
||||
class pWindow : public pWidget {
|
||||
public:
|
||||
void create(uint style, uint width, uint height, const char *text = "");
|
||||
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
|
||||
void close();
|
||||
void move(uint x, uint y);
|
||||
void resize(uint width, uint height);
|
||||
void move(unsigned x, unsigned y);
|
||||
void resize(unsigned width, unsigned height);
|
||||
void focus();
|
||||
bool focused();
|
||||
void fullscreen();
|
||||
void unfullscreen();
|
||||
uint get_width();
|
||||
uint get_height();
|
||||
unsigned get_width();
|
||||
unsigned get_height();
|
||||
void set_opacity(uint8_t opacity);
|
||||
void set_background_color(uint8_t r, uint8_t g, uint8_t b);
|
||||
void set_icon(unsigned width, unsigned height, const uint32_t *data);
|
||||
void set_text(const char *text = "");
|
||||
void attach(Window &window, uint x, uint y);
|
||||
void attach(Window &window, unsigned x, unsigned y);
|
||||
void attach(MenuGroup &menugroup);
|
||||
void attach(FormControl &formcontrol, uint x, uint y);
|
||||
void move(Window &window, uint x, uint y);
|
||||
void move(FormControl &formcontrol, uint x, uint y);
|
||||
void attach(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
void move(Window &window, unsigned x, unsigned y);
|
||||
void move(FormControl &formcontrol, unsigned x, unsigned y);
|
||||
|
||||
class Statusbar {
|
||||
public:
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
uint8_t opacity;
|
||||
bool is_fullscreen;
|
||||
bool auto_center;
|
||||
uint width, height;
|
||||
unsigned width, height;
|
||||
|
||||
uintptr_t handle();
|
||||
|
||||
|
@@ -65,7 +65,7 @@ void NTSCFilter::adjust(
|
||||
|
||||
NTSCFilter::NTSCFilter() {
|
||||
ntsc = 0;
|
||||
adjust(0, 0, 0, 0, 0, true);
|
||||
adjust(0, 0, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
NTSCFilter::~NTSCFilter() {
|
||||
|
@@ -9,16 +9,27 @@ namespace nall {
|
||||
|
||||
class dictionary : noncopyable {
|
||||
public:
|
||||
const char* operator[](const char *input) const {
|
||||
string operator[](const char *input) {
|
||||
for(unsigned i = 0; i < index_input.size(); i++) {
|
||||
if(!strcmp(input, index_input[i])) return index_output[i];
|
||||
if(index_input[i] == input) return index_output[i];
|
||||
}
|
||||
return input; //no match, return input rather than null string
|
||||
|
||||
//no match, use input; remove input identifier, if one exists
|
||||
if(strbegin(input, "{{")) {
|
||||
int pos = strpos(input, "}}");
|
||||
if(pos >= 0) {
|
||||
string temp = substr(input, pos + 2);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
bool import(const char *filename) {
|
||||
string data;
|
||||
if(fread(data, filename) == false) return false;
|
||||
ltrim_once(data, "\xef\xbb\xbf"); //remove UTF-8 marker, if it exists
|
||||
replace(data, "\r", "");
|
||||
|
||||
lstring line;
|
||||
@@ -37,17 +48,13 @@ public:
|
||||
trim_once(part[0], "\"");
|
||||
trim_once(part[1], "\"");
|
||||
|
||||
unsigned i = index_input.size();
|
||||
index_input[i] = strdup(part[0]);
|
||||
index_output[i] = strdup(part[1]);
|
||||
unsigned n = index_input.size();
|
||||
index_input[n] = part[0];
|
||||
index_output[n] = part[1];
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
for(unsigned i = 0; i < index_input.size(); i++) {
|
||||
free(index_input[i]);
|
||||
free(index_output[i]);
|
||||
}
|
||||
index_input.reset();
|
||||
index_output.reset();
|
||||
}
|
||||
@@ -56,9 +63,9 @@ public:
|
||||
reset();
|
||||
}
|
||||
|
||||
private:
|
||||
array<char*> index_input;
|
||||
array<char*> index_output;
|
||||
protected:
|
||||
lstring index_input;
|
||||
lstring index_output;
|
||||
};
|
||||
|
||||
} //namespace nall
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#ifndef NALL_FILE_HPP
|
||||
#define NALL_FILE_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/utility.hpp>
|
||||
|
||||
namespace nall {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define NALL_UPS_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nall/algorithm.hpp>
|
||||
#include <nall/crc32.hpp>
|
||||
#include <nall/new.hpp>
|
||||
|
@@ -1,9 +1,17 @@
|
||||
class Audio {
|
||||
public:
|
||||
enum Setting {
|
||||
//AudioInterface settings
|
||||
Volume,
|
||||
Resample,
|
||||
ResampleOutputFrequency,
|
||||
ResampleInputFrequency,
|
||||
|
||||
//Audio settings
|
||||
Handle,
|
||||
Synchronize,
|
||||
Frequency,
|
||||
Latency,
|
||||
};
|
||||
|
||||
virtual bool cap(Setting) { return false; }
|
||||
|
@@ -17,7 +17,6 @@ public:
|
||||
snd_pcm_uframes_t period_size;
|
||||
int channels;
|
||||
const char *name;
|
||||
unsigned latency;
|
||||
} device;
|
||||
|
||||
struct {
|
||||
@@ -26,28 +25,59 @@ public:
|
||||
} buffer;
|
||||
|
||||
struct {
|
||||
bool synchronize;
|
||||
unsigned frequency;
|
||||
unsigned latency;
|
||||
} settings;
|
||||
|
||||
bool cap(Audio::Setting setting) {
|
||||
if(setting == Audio::Synchronize) return true;
|
||||
if(setting == Audio::Frequency) return true;
|
||||
if(setting == Audio::Latency) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t get(Audio::Setting setting) {
|
||||
if(setting == Audio::Synchronize) return settings.synchronize;
|
||||
if(setting == Audio::Frequency) return settings.frequency;
|
||||
if(setting == Audio::Latency) return settings.latency;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(Audio::Setting setting, uintptr_t param) {
|
||||
if(setting == Audio::Frequency) {
|
||||
settings.frequency = param;
|
||||
if(device.handle) {
|
||||
term();
|
||||
init();
|
||||
if(setting == Audio::Synchronize) {
|
||||
if(settings.synchronize != param) {
|
||||
settings.synchronize = param;
|
||||
if(device.handle) {
|
||||
term();
|
||||
init();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Frequency) {
|
||||
if(settings.frequency != param) {
|
||||
settings.frequency = param;
|
||||
if(device.handle) {
|
||||
term();
|
||||
init();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Latency) {
|
||||
if(settings.latency != param) {
|
||||
settings.latency = param;
|
||||
if(device.handle) {
|
||||
term();
|
||||
init();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,39 +86,109 @@ public:
|
||||
|
||||
buffer.data[buffer.length++] = left + (right << 16);
|
||||
if(buffer.length < device.period_size) return;
|
||||
|
||||
if(settings.synchronize == false) {
|
||||
snd_pcm_avail_update(device.handle);
|
||||
snd_pcm_sframes_t delay;
|
||||
snd_pcm_delay(device.handle, &delay);
|
||||
if(delay < 0) {
|
||||
snd_pcm_prepare(device.handle);
|
||||
} else if(delay > device.buffer_size - device.period_size) {
|
||||
buffer.length = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t *buffer_ptr = buffer.data;
|
||||
do {
|
||||
int i = 4;
|
||||
|
||||
while((buffer.length > 0) && i--) {
|
||||
snd_pcm_sframes_t written = snd_pcm_writei(device.handle, buffer_ptr, buffer.length);
|
||||
if(written < 0) {
|
||||
//no samples written
|
||||
snd_pcm_recover(device.handle, written, 1);
|
||||
} else if(written < buffer.length) {
|
||||
//only some samples written
|
||||
} else if(written <= buffer.length) {
|
||||
buffer.length -= written;
|
||||
buffer_ptr += written;
|
||||
} else {
|
||||
//all samples written
|
||||
buffer.length = 0;
|
||||
}
|
||||
} while(buffer.length > 0);
|
||||
}
|
||||
|
||||
if(i < 0) {
|
||||
if(buffer.data == buffer_ptr) {
|
||||
buffer.length--;
|
||||
buffer_ptr++;
|
||||
}
|
||||
memmove(buffer.data, buffer_ptr, buffer.length * sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
|
||||
bool init() {
|
||||
if(snd_pcm_open(&device.handle, device.name, SND_PCM_STREAM_PLAYBACK, 0) < 0) {
|
||||
//failed to initialize
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
/* //below code will not work with 24khz frequency rate (ALSA library bug)
|
||||
if(snd_pcm_set_params(device.handle, device.format, SND_PCM_ACCESS_RW_INTERLEAVED,
|
||||
device.channels, settings.frequency, 1, device.latency) < 0) {
|
||||
device.channels, settings.frequency, 1, settings.latency * 100) < 0) {
|
||||
//failed to set device parameters
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_get_params(device.handle, &device.buffer_size, &device.period_size) < 0) {
|
||||
device.period_size = device.latency * 1e-6 * settings.frequency / 4;
|
||||
device.period_size = settings.latency * 100 * 1e-6 * settings.frequency / 4;
|
||||
}*/
|
||||
|
||||
snd_pcm_hw_params_t *hwparams;
|
||||
snd_pcm_sw_params_t *swparams;
|
||||
unsigned rate = settings.frequency;
|
||||
unsigned buffer_time = settings.latency * 100;
|
||||
unsigned period_time = settings.latency * 100 / 4;
|
||||
|
||||
snd_pcm_hw_params_alloca(&hwparams);
|
||||
if(snd_pcm_hw_params_any(device.handle, hwparams) < 0) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_hw_params_set_access(device.handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0
|
||||
|| snd_pcm_hw_params_set_format(device.handle, hwparams, device.format) < 0
|
||||
|| snd_pcm_hw_params_set_channels(device.handle, hwparams, device.channels) < 0
|
||||
|| snd_pcm_hw_params_set_rate_near(device.handle, hwparams, &rate, 0) < 0
|
||||
|| snd_pcm_hw_params_set_period_time_near(device.handle, hwparams, &period_time, 0) < 0
|
||||
|| snd_pcm_hw_params_set_buffer_time_near(device.handle, hwparams, &buffer_time, 0) < 0
|
||||
) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_hw_params(device.handle, hwparams) < 0) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_get_params(device.handle, &device.buffer_size, &device.period_size) < 0) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
snd_pcm_sw_params_alloca(&swparams);
|
||||
if(snd_pcm_sw_params_current(device.handle, swparams) < 0) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_sw_params_set_start_threshold(device.handle, swparams,
|
||||
(device.buffer_size / device.period_size) * device.period_size) < 0
|
||||
) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(snd_pcm_sw_params(device.handle, swparams) < 0) {
|
||||
term();
|
||||
return false;
|
||||
}
|
||||
|
||||
buffer.data = new uint32_t[device.period_size];
|
||||
@@ -113,12 +213,13 @@ public:
|
||||
device.format = SND_PCM_FORMAT_S16_LE;
|
||||
device.channels = 2;
|
||||
device.name = "default";
|
||||
device.latency = 100000;
|
||||
|
||||
buffer.data = 0;
|
||||
buffer.length = 0;
|
||||
|
||||
settings.synchronize = false;
|
||||
settings.frequency = 22050;
|
||||
settings.latency = 60;
|
||||
}
|
||||
|
||||
~pAudioALSA() {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
audio.alsa (2008-06-01)
|
||||
audio.alsa (2008-08-12)
|
||||
authors: Nach, RedDwarf
|
||||
*/
|
||||
|
||||
|
@@ -17,21 +17,29 @@ public:
|
||||
WAVEFORMATEX wfx;
|
||||
|
||||
struct {
|
||||
unsigned rings;
|
||||
unsigned latency;
|
||||
|
||||
uint32_t *buffer;
|
||||
unsigned buffer_pos, ring_pos;
|
||||
unsigned buffer_size, ring_size;
|
||||
} data;
|
||||
unsigned bufferoffset;
|
||||
|
||||
unsigned readring;
|
||||
unsigned writering;
|
||||
int distance;
|
||||
} device;
|
||||
|
||||
struct {
|
||||
HWND handle;
|
||||
bool synchronize;
|
||||
unsigned frequency;
|
||||
unsigned latency;
|
||||
} settings;
|
||||
|
||||
bool cap(Audio::Setting setting) {
|
||||
if(setting == Audio::Handle) return true;
|
||||
if(setting == Audio::Synchronize) return true;
|
||||
if(setting == Audio::Frequency) return true;
|
||||
if(setting == Audio::Latency) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,6 +47,7 @@ public:
|
||||
if(setting == Audio::Handle) return (uintptr_t)settings.handle;
|
||||
if(setting == Audio::Synchronize) return settings.synchronize;
|
||||
if(setting == Audio::Frequency) return settings.frequency;
|
||||
if(setting == Audio::Latency) return settings.latency;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,53 +56,83 @@ public:
|
||||
settings.handle = (HWND)param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Synchronize) {
|
||||
settings.synchronize = param;
|
||||
if(ds) clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Frequency) {
|
||||
settings.frequency = param;
|
||||
if(ds) init();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Latency) {
|
||||
settings.latency = param;
|
||||
if(ds) init();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void sample(uint16_t l_sample, uint16_t r_sample) {
|
||||
data.buffer[data.buffer_pos++] = (l_sample << 0) + (r_sample << 16);
|
||||
if(data.buffer_pos < settings.frequency / 40) return;
|
||||
void sample(uint16_t left, uint16_t right) {
|
||||
device.buffer[device.bufferoffset++] = left + (right << 16);
|
||||
if(device.bufferoffset < device.latency) return;
|
||||
device.bufferoffset = 0;
|
||||
|
||||
DWORD ring_pos, pos, size;
|
||||
for(;;) {
|
||||
dsb_b->GetCurrentPosition(&pos, 0);
|
||||
ring_pos = pos / data.ring_size;
|
||||
if(settings.synchronize == false || ring_pos != data.ring_pos) break;
|
||||
Sleep(1);
|
||||
DWORD pos, size;
|
||||
void *output;
|
||||
|
||||
if(settings.synchronize == true) {
|
||||
//wait until playback buffer has an empty ring to write new audio data to
|
||||
while(device.distance >= device.rings - 1) {
|
||||
dsb_b->GetCurrentPosition(&pos, 0);
|
||||
unsigned activering = pos / (device.latency * 4);
|
||||
if(activering == device.readring) {
|
||||
if(video.get(Video::Synchronize) == false) Sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
//subtract number of played rings from ring distance counter
|
||||
device.distance -= (device.rings + activering - device.readring) % device.rings;
|
||||
device.readring = activering;
|
||||
|
||||
if(device.distance < 2) {
|
||||
//buffer underflow; set max distance to recover quickly
|
||||
device.distance = device.rings - 1;
|
||||
device.writering = (device.rings + device.readring - 1) % device.rings;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.ring_pos = ring_pos;
|
||||
void *output;
|
||||
if(dsb_b->Lock(((data.ring_pos + 2) % 3) * data.ring_size, data.ring_size,
|
||||
&output, &size, 0, 0, 0) == DS_OK) {
|
||||
memcpy(output, data.buffer, data.ring_size);
|
||||
device.writering = (device.writering + 1) % device.rings;
|
||||
device.distance = (device.distance + 1) % device.rings;
|
||||
|
||||
if(dsb_b->Lock(device.writering * device.latency * 4, device.latency * 4, &output, &size, 0, 0, 0) == DS_OK) {
|
||||
memcpy(output, device.buffer, device.latency * 4);
|
||||
dsb_b->Unlock(output, size, 0, 0);
|
||||
}
|
||||
|
||||
data.buffer_pos = 0;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
data.buffer_pos = 0;
|
||||
data.ring_pos = 0;
|
||||
if(data.buffer) memset(data.buffer, 0, data.buffer_size);
|
||||
if(!dsb_b) return;
|
||||
device.readring = 0;
|
||||
device.writering = device.rings - 1;
|
||||
device.distance = device.rings - 1;
|
||||
|
||||
device.bufferoffset = 0;
|
||||
if(device.buffer) memset(device.buffer, 0, device.latency * device.rings * 4);
|
||||
|
||||
if(!dsb_b) return;
|
||||
dsb_b->Stop();
|
||||
dsb_b->SetCurrentPosition(0);
|
||||
|
||||
DWORD size;
|
||||
void *output;
|
||||
dsb_b->Lock(0, data.ring_size * 3, &output, &size, 0, 0, 0);
|
||||
DWORD size;
|
||||
void *output;
|
||||
dsb_b->Lock(0, device.latency * device.rings * 4, &output, &size, 0, 0, 0);
|
||||
memset(output, 0, size);
|
||||
dsb_b->Unlock(output, size, 0, 0);
|
||||
|
||||
@@ -101,13 +140,12 @@ public:
|
||||
}
|
||||
|
||||
bool init() {
|
||||
clear();
|
||||
term();
|
||||
|
||||
data.ring_size = settings.frequency / 40 * sizeof(uint32_t);
|
||||
data.buffer_size = data.ring_size * 16;
|
||||
data.buffer = (uint32_t*)malloc(data.buffer_size);
|
||||
data.buffer_pos = 0;
|
||||
device.rings = 8;
|
||||
device.latency = settings.frequency * settings.latency / device.rings / 1000.0 + 0.5;
|
||||
device.buffer = new uint32_t[device.latency * device.rings];
|
||||
device.bufferoffset = 0;
|
||||
|
||||
DirectSoundCreate(0, &ds, 0);
|
||||
ds->SetCooperativeLevel((HWND)settings.handle, DSSCL_PRIORITY);
|
||||
@@ -129,10 +167,9 @@ public:
|
||||
dsb_p->SetFormat(&wfx);
|
||||
|
||||
memset(&dsbd, 0, sizeof(dsbd));
|
||||
dsbd.dwSize = sizeof(dsbd);
|
||||
dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLFREQUENCY |
|
||||
DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE;
|
||||
dsbd.dwBufferBytes = data.ring_size * 3;
|
||||
dsbd.dwSize = sizeof(dsbd);
|
||||
dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE;
|
||||
dsbd.dwBufferBytes = device.latency * device.rings * sizeof(uint32_t);
|
||||
dsbd.guid3DAlgorithm = GUID_NULL;
|
||||
dsbd.lpwfxFormat = &wfx;
|
||||
ds->CreateSoundBuffer(&dsbd, &dsb_b, 0);
|
||||
@@ -144,9 +181,9 @@ public:
|
||||
}
|
||||
|
||||
void term() {
|
||||
if(data.buffer) {
|
||||
free(data.buffer);
|
||||
data.buffer = 0;
|
||||
if(device.buffer) {
|
||||
delete[] device.buffer;
|
||||
device.buffer = 0;
|
||||
}
|
||||
|
||||
if(dsb_b) { dsb_b->Stop(); dsb_b->Release(); dsb_b = 0; }
|
||||
@@ -159,22 +196,23 @@ public:
|
||||
dsb_p = 0;
|
||||
dsb_b = 0;
|
||||
|
||||
data.buffer = 0;
|
||||
data.buffer_pos = 0;
|
||||
data.ring_pos = 0;
|
||||
data.buffer_size = 0;
|
||||
data.ring_size = 0;
|
||||
device.buffer = 0;
|
||||
device.bufferoffset = 0;
|
||||
device.readring = 0;
|
||||
device.writering = 0;
|
||||
device.distance = 0;
|
||||
|
||||
settings.handle = GetDesktopWindow();
|
||||
settings.synchronize = false;
|
||||
settings.frequency = 22050;
|
||||
settings.latency = 120;
|
||||
}
|
||||
};
|
||||
|
||||
bool AudioDS::cap(Setting setting) { return p.cap(setting); }
|
||||
uintptr_t AudioDS::get(Setting setting) { return p.get(setting); }
|
||||
bool AudioDS::set(Setting setting, uintptr_t param) { return p.set(setting, param); }
|
||||
void AudioDS::sample(uint16_t l_sample, uint16_t r_sample) { p.sample(l_sample, r_sample); }
|
||||
void AudioDS::sample(uint16_t left, uint16_t right) { p.sample(left, right); }
|
||||
void AudioDS::clear() { p.clear(); }
|
||||
bool AudioDS::init() { return p.init(); }
|
||||
void AudioDS::term() { p.term(); }
|
||||
|
@@ -29,17 +29,20 @@ public:
|
||||
struct {
|
||||
bool synchronize;
|
||||
unsigned frequency;
|
||||
unsigned latency;
|
||||
} settings;
|
||||
|
||||
bool cap(Audio::Setting setting) {
|
||||
if(setting == Audio::Synchronize) return true;
|
||||
if(setting == Audio::Frequency) return true;
|
||||
if(setting == Audio::Latency) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t get(Audio::Setting setting) {
|
||||
if(setting == Audio::Synchronize) return settings.synchronize;
|
||||
if(setting == Audio::Frequency) return settings.frequency;
|
||||
if(setting == Audio::Latency) return settings.latency;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,10 +51,20 @@ public:
|
||||
settings.synchronize = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Frequency) {
|
||||
settings.frequency = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Latency) {
|
||||
if(settings.latency != param) {
|
||||
settings.latency = param;
|
||||
update_latency();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -61,7 +74,7 @@ public:
|
||||
|
||||
ALuint albuffer = 0;
|
||||
int processed = 0;
|
||||
for(;;) {
|
||||
while(true) {
|
||||
alGetSourcei(device.source, AL_BUFFERS_PROCESSED, &processed);
|
||||
while(processed--) {
|
||||
alSourceUnqueueBuffers(device.source, 1, &albuffer);
|
||||
@@ -85,8 +98,14 @@ public:
|
||||
buffer.length = 0;
|
||||
}
|
||||
|
||||
bool init() {
|
||||
void update_latency() {
|
||||
if(buffer.data) delete[] buffer.data;
|
||||
buffer.size = settings.frequency * settings.latency / 1000.0 + 0.5;
|
||||
buffer.data = new uint32_t[buffer.size];
|
||||
}
|
||||
|
||||
bool init() {
|
||||
update_latency();
|
||||
device.queue_length = 0;
|
||||
|
||||
bool success = false;
|
||||
@@ -95,18 +114,17 @@ public:
|
||||
alcMakeContextCurrent(device.context);
|
||||
alGenSources(1, &device.source);
|
||||
|
||||
//disable unused 3D features
|
||||
alSourcef (device.source, AL_PITCH, 1.0);
|
||||
alSourcef (device.source, AL_GAIN, 1.0);
|
||||
alSource3f(device.source, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alSource3f(device.source, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
alSource3f(device.source, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||
alSourcef (device.source, AL_ROLLOFF_FACTOR, 0.0);
|
||||
alSourcei (device.source, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||
//alSourcef (device.source, AL_PITCH, 1.0);
|
||||
//alSourcef (device.source, AL_GAIN, 1.0);
|
||||
//alSource3f(device.source, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
//alSource3f(device.source, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
//alSource3f(device.source, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||
//alSourcef (device.source, AL_ROLLOFF_FACTOR, 0.0);
|
||||
//alSourcei (device.source, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||
|
||||
alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alListener3f(AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
ALfloat listener_orientation[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
|
||||
ALfloat listener_orientation[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
|
||||
alListenerfv(AL_ORIENTATION, listener_orientation);
|
||||
|
||||
success = true;
|
||||
@@ -163,15 +181,15 @@ public:
|
||||
device.handle = 0;
|
||||
device.context = 0;
|
||||
device.format = AL_FORMAT_STEREO16;
|
||||
device.latency = 40;
|
||||
device.queue_length = 0;
|
||||
|
||||
buffer.data = 0;
|
||||
buffer.length = 0;
|
||||
buffer.size = device.latency * 32;
|
||||
buffer.size = 0;
|
||||
|
||||
settings.synchronize = true;
|
||||
settings.frequency = 22050;
|
||||
settings.latency = 40;
|
||||
}
|
||||
|
||||
~pAudioOpenAL() {
|
||||
|
@@ -2,6 +2,8 @@ class Input {
|
||||
public:
|
||||
enum Setting {
|
||||
Handle,
|
||||
KeyboardSupport,
|
||||
JoypadSupport,
|
||||
AnalogAxisResistance,
|
||||
};
|
||||
|
||||
|
@@ -30,6 +30,8 @@ public:
|
||||
|
||||
bool cap(Input::Setting setting) {
|
||||
if(setting == Input::Handle) return true;
|
||||
if(setting == Input::KeyboardSupport) return true;
|
||||
if(setting == Input::JoypadSupport) return true;
|
||||
if(setting == Input::AnalogAxisResistance) return true;
|
||||
return false;
|
||||
}
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
} settings;
|
||||
|
||||
bool cap(Input::Setting setting) {
|
||||
if(setting == Input::KeyboardSupport) return true;
|
||||
if(setting == Input::JoypadSupport) return true;
|
||||
if(setting == Input::AnalogAxisResistance) return true;
|
||||
return false;
|
||||
}
|
||||
|
@@ -16,6 +16,19 @@ public:
|
||||
Display *display;
|
||||
char keymap[32];
|
||||
|
||||
bool cap(Input::Setting setting) {
|
||||
if(setting == Input::KeyboardSupport) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t get(Input::Setting setting) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(Input::Setting setting, uintptr_t param) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool key_down(uint16_t key) {
|
||||
using namespace nall;
|
||||
#define map(i) (keymap[i >> 3] & (1 << (i & 7)))
|
||||
@@ -161,6 +174,9 @@ public:
|
||||
pInputX(InputX &self_) : self(self_) {}
|
||||
};
|
||||
|
||||
bool InputX::cap(Setting setting) { return p.cap(setting); }
|
||||
uintptr_t InputX::get(Setting setting) { return p.get(setting); }
|
||||
bool InputX::set(Setting setting, uintptr_t param) { return p.set(setting, param); }
|
||||
bool InputX::key_down(uint16_t key) { return p.key_down(key); }
|
||||
void InputX::clear() { p.clear(); }
|
||||
void InputX::poll() { p.poll(); }
|
||||
|
@@ -2,6 +2,10 @@ class pInputX;
|
||||
|
||||
class InputX : public Input {
|
||||
public:
|
||||
bool cap(Setting);
|
||||
uintptr_t get(Setting);
|
||||
bool set(Setting, uintptr_t);
|
||||
|
||||
bool key_down(uint16_t key);
|
||||
|
||||
void clear();
|
||||
|
@@ -12,55 +12,99 @@ InputInterface input;
|
||||
void VideoInterface::driver(const char *driver) {
|
||||
if(p) term();
|
||||
|
||||
if(!strcmp(driver, "none")) p = new Video();
|
||||
if(driver == "") driver = default_driver();
|
||||
|
||||
if(0);
|
||||
|
||||
#ifdef VIDEO_DIRECT3D
|
||||
else if(!strcmp(driver, "direct3d")) p = new VideoD3D();
|
||||
else if(!strcmp(driver, "Direct3D")) p = new VideoD3D();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_DIRECTDRAW
|
||||
else if(!strcmp(driver, "directdraw")) p = new VideoDD();
|
||||
else if(!strcmp(driver, "DirectDraw")) p = new VideoDD();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_GDI
|
||||
else if(!strcmp(driver, "gdi")) p = new VideoGDI();
|
||||
else if(!strcmp(driver, "GDI")) p = new VideoGDI();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_GLX
|
||||
else if(!strcmp(driver, "glx")) p = new VideoGLX();
|
||||
else if(!strcmp(driver, "OpenGL")) p = new VideoGLX();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_SDL
|
||||
else if(!strcmp(driver, "sdl")) p = new VideoSDL();
|
||||
else if(!strcmp(driver, "SDL")) p = new VideoSDL();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_WGL
|
||||
else if(!strcmp(driver, "wgl")) p = new VideoWGL();
|
||||
else if(!strcmp(driver, "OpenGL")) p = new VideoWGL();
|
||||
#endif
|
||||
|
||||
#ifdef VIDEO_XV
|
||||
else if(!strcmp(driver, "xv")) p = new VideoXv();
|
||||
else if(!strcmp(driver, "X-Video")) p = new VideoXv();
|
||||
#endif
|
||||
|
||||
else //select the *safest* available driver, not the fastest
|
||||
else p = new Video();
|
||||
}
|
||||
|
||||
//select the *safest* available driver, not the fastest
|
||||
const char* VideoInterface::default_driver() {
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
return "Direct3D";
|
||||
#elif defined(VIDEO_WGL)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_DIRECTDRAW)
|
||||
return "DirectDraw";
|
||||
#elif defined(VIDEO_GDI)
|
||||
return "GDI";
|
||||
#elif defined(VIDEO_SDL)
|
||||
return "SDL";
|
||||
#elif defined(VIDEO_XV)
|
||||
return "X-Video";
|
||||
#elif defined(VIDEO_GLX)
|
||||
return "OpenGL";
|
||||
#else
|
||||
return "None";
|
||||
#endif
|
||||
}
|
||||
|
||||
//returns list of available drivers, sorted from most to least optimal
|
||||
const char* VideoInterface::driver_list() {
|
||||
return
|
||||
|
||||
//Windows
|
||||
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
p = new VideoD3D();
|
||||
#elif defined(VIDEO_WGL)
|
||||
p = new VideoWGL();
|
||||
#elif defined(VIDEO_DIRECTDRAW)
|
||||
p = new VideoDD();
|
||||
#elif defined(VIDEO_GDI)
|
||||
p = new VideoGDI();
|
||||
#elif defined(VIDEO_SDL)
|
||||
p = new VideoSDL();
|
||||
#elif defined(VIDEO_XV)
|
||||
p = new VideoXv();
|
||||
#elif defined(VIDEO_GLX)
|
||||
p = new VideoGLX();
|
||||
#else
|
||||
p = new Video();
|
||||
"Direct3D;"
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_WGL)
|
||||
"OpenGL;"
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECTDRAW)
|
||||
"DirectDraw;"
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GDI)
|
||||
"GDI;"
|
||||
#endif
|
||||
|
||||
//Linux
|
||||
|
||||
#if defined(VIDEO_GLX)
|
||||
"OpenGL;"
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XV)
|
||||
"X-Video;"
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_SDL)
|
||||
"SDL;"
|
||||
#endif
|
||||
|
||||
"None";
|
||||
}
|
||||
|
||||
bool VideoInterface::init() {
|
||||
@@ -90,95 +134,140 @@ VideoInterface::~VideoInterface() { term(); }
|
||||
void AudioInterface::driver(const char *driver) {
|
||||
if(p) term();
|
||||
|
||||
if(!strcmp(driver, "none")) p = new Audio();
|
||||
if(driver == "") driver = default_driver();
|
||||
|
||||
if(0);
|
||||
|
||||
#ifdef AUDIO_ALSA
|
||||
else if(!strcmp(driver, "alsa")) p = new AudioALSA();
|
||||
else if(!strcmp(driver, "ALSA")) p = new AudioALSA();
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_AO
|
||||
else if(!strcmp(driver, "ao")) p = new AudioAO();
|
||||
else if(!strcmp(driver, "libao")) p = new AudioAO();
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_DIRECTSOUND
|
||||
else if(!strcmp(driver, "directsound")) p = new AudioDS();
|
||||
else if(!strcmp(driver, "DirectSound")) p = new AudioDS();
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_OPENAL
|
||||
else if(!strcmp(driver, "openal")) p = new AudioOpenAL();
|
||||
else if(!strcmp(driver, "OpenAL")) p = new AudioOpenAL();
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_OSS
|
||||
else if(!strcmp(driver, "oss")) p = new AudioOSS();
|
||||
else if(!strcmp(driver, "OSS")) p = new AudioOSS();
|
||||
#endif
|
||||
|
||||
else //select the *safest* available driver, not the fastest
|
||||
else p = new Audio();
|
||||
}
|
||||
|
||||
//select the *safest* available driver, not the fastest
|
||||
const char* AudioInterface::default_driver() {
|
||||
#if defined(AUDIO_DIRECTSOUND)
|
||||
return "DirectSound";
|
||||
#elif defined(AUDIO_ALSA)
|
||||
return "ALSA";
|
||||
#elif defined(AUDIO_OPENAL)
|
||||
return "OpenAL";
|
||||
#elif defined(AUDIO_AO)
|
||||
return "libao";
|
||||
#elif defined(AUDIO_OSS)
|
||||
return "OSS";
|
||||
#else
|
||||
return "None";
|
||||
#endif
|
||||
}
|
||||
|
||||
//returns list of available drivers, sorted from most to least optimal
|
||||
const char* AudioInterface::driver_list() {
|
||||
return
|
||||
|
||||
//Windows
|
||||
|
||||
#if defined(AUDIO_DIRECTSOUND)
|
||||
p = new AudioDS();
|
||||
#elif defined(AUDIO_AO)
|
||||
p = new AudioAO();
|
||||
#elif defined(AUDIO_ALSA)
|
||||
p = new AudioALSA();
|
||||
#elif defined(AUDIO_OPENAL)
|
||||
p = new AudioOpenAL();
|
||||
#elif defined(AUDIO_OSS)
|
||||
p = new AudioOSS();
|
||||
#else
|
||||
p = new Audio();
|
||||
"DirectSound;"
|
||||
#endif
|
||||
|
||||
//Linux
|
||||
|
||||
#if defined(AUDIO_ALSA)
|
||||
"ALSA;"
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_OPENAL)
|
||||
"OpenAL;"
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_OSS)
|
||||
"OSS;"
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_AO)
|
||||
"libao;"
|
||||
#endif
|
||||
|
||||
"None";
|
||||
}
|
||||
|
||||
bool AudioInterface::init() {
|
||||
if(!p) driver();
|
||||
return p->init();
|
||||
}
|
||||
|
||||
void AudioInterface::term() {
|
||||
if(p) {
|
||||
delete p;
|
||||
p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioInterface::cap(Audio::Setting setting) { return p ? p->cap(setting) : false; }
|
||||
uintptr_t AudioInterface::get(Audio::Setting setting) { return p ? p->get(setting) : false; }
|
||||
bool AudioInterface::set(Audio::Setting setting, uintptr_t param) { return p ? p->set(setting, param) : false; }
|
||||
void AudioInterface::sample(uint16_t left, uint16_t right) { if(p) p->sample(left, right); }
|
||||
void AudioInterface::clear() { if(p) p->clear(); }
|
||||
AudioInterface::AudioInterface() : p(0) {}
|
||||
AudioInterface::~AudioInterface() { term(); }
|
||||
#include "ruby_audio.cpp"
|
||||
|
||||
/* InputInterface */
|
||||
|
||||
void InputInterface::driver(const char *driver) {
|
||||
if(p) term();
|
||||
|
||||
if(!strcmp(driver, "none")) p = new Input();
|
||||
if(driver == "") driver = default_driver();
|
||||
|
||||
if(0);
|
||||
|
||||
#ifdef INPUT_DIRECTINPUT
|
||||
else if(!strcmp(driver, "directinput")) p = new InputDI();
|
||||
else if(!strcmp(driver, "DirectInput")) p = new InputDI();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_SDL
|
||||
else if(!strcmp(driver, "sdl")) p = new InputSDL();
|
||||
else if(!strcmp(driver, "SDL")) p = new InputSDL();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_X
|
||||
else if(!strcmp(driver, "x")) p = new InputX();
|
||||
else if(!strcmp(driver, "X-Windows")) p = new InputX();
|
||||
#endif
|
||||
|
||||
else //select the *safest* available driver, not the fastest
|
||||
else p = new Input();
|
||||
}
|
||||
|
||||
//select the *safest* available driver, not the fastest
|
||||
const char* InputInterface::default_driver() {
|
||||
#if defined(INPUT_DIRECTINPUT)
|
||||
return "DirectInput";
|
||||
#elif defined(INPUT_SDL)
|
||||
return "SDL";
|
||||
#elif defined(INPUT_X)
|
||||
return "X-Windows";
|
||||
#else
|
||||
return "none";
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* InputInterface::driver_list() {
|
||||
return
|
||||
|
||||
//Windows
|
||||
|
||||
#if defined(INPUT_DIRECTINPUT)
|
||||
p = new InputDI();
|
||||
#elif defined(INPUT_SDL)
|
||||
p = new InputSDL();
|
||||
#elif defined(INPUT_X)
|
||||
p = new InputX();
|
||||
#else
|
||||
p = new Input();
|
||||
"DirectInput;"
|
||||
#endif
|
||||
|
||||
//Linux
|
||||
|
||||
#if defined(INPUT_SDL)
|
||||
"SDL;"
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_X)
|
||||
"X-Windows;"
|
||||
#endif
|
||||
|
||||
"None";
|
||||
}
|
||||
|
||||
bool InputInterface::init() {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
ruby
|
||||
version: 0.03 (2008-05-04)
|
||||
version: 0.04 (2008-08-20)
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define RUBY_H
|
||||
|
||||
#include <nall/algorithm.hpp>
|
||||
#include <nall/bit.hpp>
|
||||
#include <nall/input.hpp>
|
||||
#include <nall/new.hpp>
|
||||
#include <nall/stdint.hpp>
|
||||
@@ -24,6 +25,8 @@ namespace ruby {
|
||||
class VideoInterface {
|
||||
public:
|
||||
void driver(const char *driver = "");
|
||||
const char* default_driver();
|
||||
const char* driver_list();
|
||||
bool init();
|
||||
void term();
|
||||
|
||||
@@ -44,6 +47,8 @@ private:
|
||||
class AudioInterface {
|
||||
public:
|
||||
void driver(const char *driver = "");
|
||||
const char* default_driver();
|
||||
const char* driver_list();
|
||||
bool init();
|
||||
void term();
|
||||
|
||||
@@ -57,11 +62,22 @@ public:
|
||||
|
||||
private:
|
||||
Audio *p;
|
||||
|
||||
unsigned volume;
|
||||
|
||||
//resample unit
|
||||
double hermite(double mu, double a, double b, double c, double d);
|
||||
bool resample_enabled;
|
||||
double r_outfreq, r_infreq;
|
||||
double r_step, r_frac;
|
||||
int r_left[4], r_right[4];
|
||||
};
|
||||
|
||||
class InputInterface {
|
||||
public:
|
||||
void driver(const char *driver = "");
|
||||
const char* default_driver();
|
||||
const char* driver_list();
|
||||
bool init();
|
||||
void term();
|
||||
|
||||
|
135
src/lib/ruby/ruby_audio.cpp
Normal file
135
src/lib/ruby/ruby_audio.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
bool AudioInterface::init() {
|
||||
if(!p) driver();
|
||||
return p->init();
|
||||
}
|
||||
|
||||
void AudioInterface::term() {
|
||||
if(p) {
|
||||
delete p;
|
||||
p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioInterface::cap(Audio::Setting setting) {
|
||||
if(setting == Audio::Volume) return true;
|
||||
if(setting == Audio::Resample) return true;
|
||||
if(setting == Audio::ResampleOutputFrequency) return true;
|
||||
if(setting == Audio::ResampleInputFrequency) return true;
|
||||
|
||||
return p ? p->cap(setting) : false;
|
||||
}
|
||||
|
||||
uintptr_t AudioInterface::get(Audio::Setting setting) {
|
||||
if(setting == Audio::Volume) return volume;
|
||||
if(setting == Audio::Resample) return resample_enabled;
|
||||
if(setting == Audio::ResampleOutputFrequency) return r_outfreq;
|
||||
if(setting == Audio::ResampleInputFrequency) return r_infreq;
|
||||
|
||||
return p ? p->get(setting) : false;
|
||||
}
|
||||
|
||||
bool AudioInterface::set(Audio::Setting setting, uintptr_t param) {
|
||||
if(setting == Audio::Volume) {
|
||||
volume = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::Resample) {
|
||||
resample_enabled = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::ResampleOutputFrequency) {
|
||||
r_outfreq = max(1, param);
|
||||
r_step = (double)r_infreq / (double)r_outfreq;
|
||||
r_frac = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Audio::ResampleInputFrequency) {
|
||||
r_infreq = max(1, param);
|
||||
r_step = (double)r_infreq / (double)r_outfreq;
|
||||
r_frac = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return p ? p->set(setting, param) : false;
|
||||
}
|
||||
|
||||
//4-tap hermite interpolation
|
||||
double AudioInterface::hermite(double mu1, double a, double b, double c, double d) {
|
||||
const double tension = 0.0; //-1 = low, 0 = normal, 1 = high
|
||||
const double bias = 0.0; //-1 = left, 0 = even, 1 = right
|
||||
|
||||
double mu2, mu3, m0, m1, a0, a1, a2, a3;
|
||||
|
||||
mu2 = mu1 * mu1;
|
||||
mu3 = mu2 * mu1;
|
||||
|
||||
m0 = (b - a) * (1 + bias) * (1 - tension) / 2;
|
||||
m0 += (c - b) * (1 - bias) * (1 - tension) / 2;
|
||||
m1 = (c - b) * (1 + bias) * (1 - tension) / 2;
|
||||
m1 += (d - c) * (1 - bias) * (1 - tension) / 2;
|
||||
|
||||
a0 = +2 * mu3 - 3 * mu2 + 1;
|
||||
a1 = mu3 - 2 * mu2 + mu1;
|
||||
a2 = mu3 - mu2;
|
||||
a3 = -2 * mu3 + 3 * mu2;
|
||||
|
||||
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
|
||||
}
|
||||
|
||||
void AudioInterface::sample(uint16_t left, uint16_t right) {
|
||||
int s_left = (int16_t)left;
|
||||
int s_right = (int16_t)right;
|
||||
|
||||
if(volume != 100) {
|
||||
s_left = sclamp<16>((double)s_left * (double)volume / 100.0);
|
||||
s_right = sclamp<16>((double)s_right * (double)volume / 100.0);
|
||||
}
|
||||
|
||||
r_left [0] = r_left [1];
|
||||
r_left [1] = r_left [2];
|
||||
r_left [2] = r_left [3];
|
||||
r_left [3] = s_left;
|
||||
|
||||
r_right[0] = r_right[1];
|
||||
r_right[1] = r_right[2];
|
||||
r_right[2] = r_right[3];
|
||||
r_right[3] = s_right;
|
||||
|
||||
if(resample_enabled == false) {
|
||||
if(p) p->sample(left, right);
|
||||
return;
|
||||
}
|
||||
|
||||
while(r_frac <= 1.0) {
|
||||
int output_left = sclamp<16>(hermite(r_frac, r_left [0], r_left [1], r_left [2], r_left [3]));
|
||||
int output_right = sclamp<16>(hermite(r_frac, r_right[0], r_right[1], r_right[2], r_right[3]));
|
||||
r_frac += r_step;
|
||||
if(p) p->sample(output_left, output_right);
|
||||
}
|
||||
|
||||
r_frac -= 1.0;
|
||||
}
|
||||
|
||||
void AudioInterface::clear() {
|
||||
r_frac = 0;
|
||||
r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
|
||||
r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
|
||||
if(p) p->clear();
|
||||
}
|
||||
|
||||
AudioInterface::AudioInterface() {
|
||||
p = 0;
|
||||
volume = 100;
|
||||
resample_enabled = false;
|
||||
r_outfreq = r_infreq = 1;
|
||||
r_step = r_frac = 0;
|
||||
r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
|
||||
r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
|
||||
}
|
||||
|
||||
AudioInterface::~AudioInterface() {
|
||||
term();
|
||||
}
|
@@ -71,15 +71,18 @@ public:
|
||||
settings.handle = (HWND)param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Video::Synchronize) {
|
||||
settings.synchronize = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Video::Filter) {
|
||||
settings.filter = param;
|
||||
update_filter();
|
||||
if(lpd3d) update_filter();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -172,7 +175,7 @@ public:
|
||||
|
||||
void unlock() {
|
||||
surface->UnlockRect();
|
||||
if(caps.stretchrect == false)surface->Release();
|
||||
if(caps.stretchrect == false) surface->Release();
|
||||
}
|
||||
|
||||
void refresh(unsigned width, unsigned height) {
|
||||
@@ -204,11 +207,10 @@ public:
|
||||
device->EndScene();
|
||||
|
||||
if(settings.synchronize) {
|
||||
D3DRASTER_STATUS status;
|
||||
for(;;) {
|
||||
while(true) {
|
||||
D3DRASTER_STATUS status;
|
||||
device->GetRasterStatus(0, &status);
|
||||
if(bool(status.InVBlank) == true) break;
|
||||
//Sleep(1);
|
||||
if(status.InVBlank == true) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,11 +67,10 @@ public:
|
||||
|
||||
void refresh(unsigned r_width, unsigned r_height) {
|
||||
if(settings.synchronize) {
|
||||
for(;;) {
|
||||
while(true) {
|
||||
BOOL in_vblank;
|
||||
lpdd7->GetVerticalBlankStatus(&in_vblank);
|
||||
if(bool(in_vblank) == true) break;
|
||||
//Sleep(1);
|
||||
if(in_vblank == true) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
video.glx
|
||||
author: byuu
|
||||
license: public domain
|
||||
date: 2008-02-06
|
||||
last updated: 2008-08-20
|
||||
|
||||
Design notes:
|
||||
SGI's GLX is the X11/Xlib interface to OpenGL.
|
||||
@@ -33,7 +33,7 @@ namespace ruby {
|
||||
#include "glx.h"
|
||||
|
||||
//returns true once window is mapped (created and displayed onscreen)
|
||||
static Bool x_wait_for_map_notify(Display *d, XEvent *e, char *arg) {
|
||||
static Bool glx_wait_for_map_notify(Display *d, XEvent *e, char *arg) {
|
||||
return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
Display *display;
|
||||
int screen;
|
||||
Window xwindow;
|
||||
Colormap colormap;
|
||||
GLXContext glxcontext;
|
||||
GLXWindow glxwindow;
|
||||
GLuint gltexture;
|
||||
@@ -57,17 +58,20 @@ public:
|
||||
|
||||
struct {
|
||||
Window handle;
|
||||
bool synchronize;
|
||||
unsigned filter;
|
||||
} settings;
|
||||
|
||||
bool cap(Video::Setting setting) {
|
||||
if(setting == Video::Handle) return true;
|
||||
if(setting == Video::Synchronize) return true;
|
||||
if(setting == Video::Filter) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t get(Video::Setting setting) {
|
||||
if(setting == Video::Handle) return settings.handle;
|
||||
if(setting == Video::Synchronize) return settings.synchronize;
|
||||
if(setting == Video::Filter) return settings.filter;
|
||||
return false;
|
||||
}
|
||||
@@ -77,10 +81,23 @@ public:
|
||||
settings.handle = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(setting == Video::Synchronize) {
|
||||
if(settings.synchronize != param) {
|
||||
settings.synchronize = param;
|
||||
if(glxcontext) {
|
||||
term();
|
||||
init();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(setting == Video::Filter) {
|
||||
settings.filter = param;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -157,37 +174,37 @@ public:
|
||||
//require GLX 1.2+ API
|
||||
if(glx.version_major < 1 || (glx.version_major == 1 && glx.version_minor < 2)) return false;
|
||||
|
||||
buffer = new(zeromemory) uint32_t[1024 * 1024 * sizeof(uint32_t)];
|
||||
buffer = new(zeromemory) uint32_t[1024 * 1024];
|
||||
|
||||
XWindowAttributes wa;
|
||||
XGetWindowAttributes(display, settings.handle, &wa);
|
||||
XWindowAttributes window_attributes;
|
||||
XGetWindowAttributes(display, settings.handle, &window_attributes);
|
||||
|
||||
//let GLX determine the best Visual to use for GL output; provide a few hints
|
||||
//note: some video drivers will override double buffering attribute
|
||||
int elements = 0;
|
||||
int attributelist[] = {
|
||||
GLX_RGBA,
|
||||
GLX_DOUBLEBUFFER,
|
||||
None
|
||||
};
|
||||
XVisualInfo *vi = glXChooseVisual(display, screen, attributelist);
|
||||
int attributelist[] = { GLX_RGBA, None };
|
||||
int attributelist_sync[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
|
||||
XVisualInfo *vi = glXChooseVisual(display, screen,
|
||||
settings.synchronize ? attributelist_sync : attributelist);
|
||||
|
||||
//Window settings.handle has already been realized, most likely with DefaultVisual.
|
||||
//GLX requires that the GL output window has the same Visual as the GLX context.
|
||||
//it is not possible to change the Visual of an already realized (created) window.
|
||||
//therefore a new child window, using the same GLX Visual, must be created and binded to settings.handle.
|
||||
Colormap colormap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone);
|
||||
XSetWindowAttributes swa;
|
||||
swa.colormap = colormap;
|
||||
swa.border_pixel = 0;
|
||||
swa.event_mask = StructureNotifyMask;
|
||||
colormap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone);
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = colormap;
|
||||
attributes.border_pixel = 0;
|
||||
attributes.event_mask = StructureNotifyMask;
|
||||
xwindow = XCreateWindow(display, /* parent = */ settings.handle,
|
||||
/* x = */ 0, /* y = */ 0, wa.width, wa.height,
|
||||
/* x = */ 0, /* y = */ 0, window_attributes.width, window_attributes.height,
|
||||
/* border_width = */ 0, vi->depth, InputOutput, vi->visual,
|
||||
CWColormap | CWBorderPixel | CWEventMask, &swa);
|
||||
CWColormap | CWBorderPixel | CWEventMask, &attributes);
|
||||
XSetWindowBackground(display, xwindow, /* color = */ 0);
|
||||
XMapWindow(display, xwindow);
|
||||
XEvent event;
|
||||
XIfEvent(display, &event, x_wait_for_map_notify, (char*)xwindow); //wait for window to appear onscreen
|
||||
//window must be realized (appear onscreen) before we make the context current
|
||||
XIfEvent(display, &event, glx_wait_for_map_notify, (char*)xwindow);
|
||||
|
||||
glxcontext = glXCreateContext(display, vi, /* sharelist = */ 0, /* direct = */ GL_TRUE);
|
||||
glXMakeCurrent(display, glxwindow = xwindow, glxcontext);
|
||||
@@ -233,6 +250,16 @@ public:
|
||||
glxcontext = 0;
|
||||
}
|
||||
|
||||
if(xwindow) {
|
||||
XUnmapWindow(display, xwindow);
|
||||
xwindow = 0;
|
||||
}
|
||||
|
||||
if(colormap) {
|
||||
XFreeColormap(display, colormap);
|
||||
colormap = 0;
|
||||
}
|
||||
|
||||
if(buffer) {
|
||||
delete[] buffer;
|
||||
buffer = 0;
|
||||
@@ -241,7 +268,9 @@ public:
|
||||
|
||||
pVideoGLX(VideoGLX &self_) : self(self_) {
|
||||
settings.handle = 0;
|
||||
settings.synchronize = false;
|
||||
xwindow = 0;
|
||||
colormap = 0;
|
||||
glxcontext = 0;
|
||||
glxwindow = 0;
|
||||
gltexture = 0;
|
||||
|
@@ -53,9 +53,32 @@ public:
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if(SDL_MUSTLOCK(buffer)) SDL_LockSurface(buffer);
|
||||
uint32_t *data = (uint32_t*)buffer->pixels;
|
||||
for(unsigned y = 0; y < 1024; y++) {
|
||||
for(unsigned x = 0; x < 1024; x++) {
|
||||
*data++ |= 0xff000000;
|
||||
}
|
||||
data += (buffer->pitch >> 2) - 1024;
|
||||
}
|
||||
if(SDL_MUSTLOCK(buffer)) SDL_UnlockSurface(buffer);
|
||||
refresh(1024, 1024);
|
||||
}
|
||||
|
||||
void refresh(unsigned width, unsigned height) {
|
||||
//ruby input is X8R8G8B8, top 8-bits are ignored.
|
||||
//as SDL forces us to use a 32-bit buffer, we must set alpha to 255 (full opacity)
|
||||
//to prevent blending against the window beneath when X window visual is 32-bits.
|
||||
if(SDL_MUSTLOCK(buffer)) SDL_LockSurface(buffer);
|
||||
uint32_t *data = (uint32_t*)buffer->pixels;
|
||||
for(unsigned y = 0; y < height; y++) {
|
||||
for(unsigned x = 0; x < width; x++) {
|
||||
*data++ |= 0xff000000;
|
||||
}
|
||||
data += (buffer->pitch >> 2) - width;
|
||||
}
|
||||
if(SDL_MUSTLOCK(buffer)) SDL_UnlockSurface(buffer);
|
||||
|
||||
XWindowAttributes attributes;
|
||||
XGetWindowAttributes(display, settings.handle, &attributes);
|
||||
|
||||
@@ -81,10 +104,11 @@ public:
|
||||
sprintf(env, "SDL_WINDOWID=%ld", settings.handle);
|
||||
putenv(env);
|
||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||
//screen depth must be 32, as 24bpp with a 32-bit X window visual produces no output.
|
||||
screen = SDL_SetVideoMode(2560, 1600, 32, SDL_HWSURFACE);
|
||||
//buffer depth must be 32, as this is the input format used by all ruby drivers.
|
||||
buffer = SDL_CreateRGBSurface(SDL_HWSURFACE,
|
||||
1024, 1024,
|
||||
32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000
|
||||
1024, 1024, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user