diff --git a/.gitignore b/.gitignore index 0f6fafdf..1a533585 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ -purify/purify -purify/ananke.dll -purify/phoenix.dll -purify/purify.exe ananke/libananke.so diff --git a/higan/Makefile b/Makefile old mode 100755 new mode 100644 similarity index 99% rename from higan/Makefile rename to Makefile index 73fc1968..1222d8cd --- a/higan/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ fc := fc sfc := sfc gb := gb gba := gba -# nds := nds profile := accuracy target := ethos diff --git a/ananke/Makefile b/ananke/Makefile index 46d0160e..b3402b57 100644 --- a/ananke/Makefile +++ b/ananke/Makefile @@ -1,17 +1,19 @@ -include nall/Makefile -include phoenix/Makefile +include ../nall/Makefile +include ../phoenix/Makefile path := /usr/local/lib -flags := -I. -O3 -fomit-frame-pointer +flags := $(flags) -O3 -fomit-frame-pointer -I.. all: - $(cpp) $(flags) -fPIC -o obj/ananke.o -c ananke.cpp + $(compiler) $(cppflags) $(flags) -fPIC -o obj/ananke.o -c ananke.cpp ifeq ($(platform),x) - $(cpp) $(flags) -shared -Wl,-soname,libananke.so.1 -o libananke.so obj/ananke.o + $(compiler) $(link) -shared -Wl,-soname,libananke.so.1 -o libananke.so obj/ananke.o +else ifeq ($(platform),osx) + $(compiler) $(link) -shared -dynamiclib -undefined suppress -flat_namespace -o libananke.dylib obj/ananke.o else ifeq ($(platform),win) - $(cpp) $(flags) -fPIC -o obj/phoenix.o -c phoenix/phoenix.cpp $(phoenixflags) - $(cpp) $(flags) -shared -o phoenix.dll obj/phoenix.o $(phoenixlink) - $(cpp) $(flags) -shared -o ananke.dll obj/ananke.o -L. -lphoenix + $(compiler) $(phoenixflags) -fPIC -o obj/phoenix.o -c ../phoenix/phoenix.cpp + $(compiler) $(link) -shared -o phoenix.dll obj/phoenix.o $(phoenixlink) + $(compiler) $(link) -shared -o ananke.dll obj/ananke.o -L. -lphoenix endif resource: force @@ -26,23 +28,19 @@ ifeq ($(platform),x) if [ ! -d ~/.config/ananke ]; then mkdir ~/.config/ananke; fi sudo cp libananke.so $(path)/libananke.so.1 sudo ln -s $(path)/libananke.so.1 $(path)/libananke.so +else ifeq ($(platform),osx) + if [ ! -d ~/Library/Application\ Support/ananke ]; then mkdir ~/Library/Application\ Support/ananke; fi + sudo cp libananke.dylib $(path)/libananke.1.dylib + sudo ln -s $(path)/libananke.1.dylib $(path)/libananke.dylib endif uninstall: ifeq ($(platform),x) if [ -f $(path)/libananke.so ]; then sudo rm $(path)/libananke.so; fi if [ -f $(path)/libananke.so.1 ]; then sudo rm $(path)/libananke.so.1; fi -endif - -sync: -ifeq ($(shell id -un),byuu) - if [ -d ./nall ]; then rm -r ./nall; fi - if [ -d ./phoenix ]; then rm -r ./phoenix; fi - cp -r ../nall ./nall - cp -r ../phoenix ./phoenix - rm -r nall/test - rm -r phoenix/nall - rm -r phoenix/test +else ifeq ($(platform),osx) + if [ -f $(path)/libananke.dylib ]; then sudo rm $(path)/libananke.dylib; fi + if [ -f $(path)/libananke.1.dylib ]; then sudo rm $(path)/libananke.1.dylib; fi endif force: diff --git a/ananke/ananke.cpp b/ananke/ananke.cpp index 326e8b0c..f4452dc4 100644 --- a/ananke/ananke.cpp +++ b/ananke/ananke.cpp @@ -93,7 +93,7 @@ struct Ananke { FileDialog *fileDialog = nullptr; Ananke::Ananke() { - libraryPath = string::read({configpath(), "higan/library.cfg"}).strip(); + libraryPath = string::read({configpath(), "higan/library.bml"}).strip().ltrim<1>("Path: ").replace("\\", "/"); if(libraryPath.empty()) libraryPath = {userpath(), "Emulation/"}; if(libraryPath.endswith("/") == false) libraryPath.append("/"); } @@ -117,9 +117,13 @@ bool Ananke::supported(const string &filename) { string Ananke::open(string filename) { if(filename.empty()) { - if(!fileDialog) fileDialog = new FileDialog; + if(!fileDialog) { + fileDialog = new FileDialog; + fileDialog->setGeometry(config.geometry); + } fileDialog->setPath(config.path); filename = fileDialog->open(); + config.geometry = fileDialog->geometry().text(); } if(filename.empty()) return ""; diff --git a/ananke/archive.cpp b/ananke/archive.cpp index 3d8add55..b979187c 100644 --- a/ananke/archive.cpp +++ b/ananke/archive.cpp @@ -2,10 +2,10 @@ vector Ananke::extractROM() { unzip archive; if(archive.open(information.archive)) { for(auto &file : archive.file) { - if( - file.name.endswith(".fc") || file.name.endswith(".nes") + if(file.name.endswith(".fc") || file.name.endswith(".nes") || file.name.endswith(".sfc") || file.name.endswith(".smc") - || file.name.endswith(".gb") || file.name.endswith(".gbc") + || file.name.endswith(".st") || file.name.endswith(".bs") + || file.name.endswith(".gb") || file.name.endswith(".gbc") || file.name.endswith(".gba") ) { information.name = notdir(file.name); diff --git a/ananke/bsx-satellaview.cpp b/ananke/bsx-satellaview.cpp index cee3a3f4..6333fecf 100644 --- a/ananke/bsx-satellaview.cpp +++ b/ananke/bsx-satellaview.cpp @@ -27,10 +27,11 @@ string Ananke::createBsxSatellaviewHeuristic(vector &buffer) { ".bs/" }; directory::create(pathname); - file::create({pathname, "unverified"}); file::write({pathname, "manifest.bml"}, { - "cartridge\n" + "unverified\n", + "\n", + "cartridge\n", " rom name=program.rom size=0x", hex(buffer.size()), " type=FlashROM\n", "\n", "information\n", diff --git a/ananke/configuration.cpp b/ananke/configuration.cpp index ada3814e..5b3448e8 100644 --- a/ananke/configuration.cpp +++ b/ananke/configuration.cpp @@ -1,13 +1,17 @@ -struct Configuration : configuration { +struct Settings : Configuration::Document { string path; + string geometry; - Configuration() { - append(path = userpath(), "Path"); + Settings() { + Configuration::Node node; + node.append(path = userpath(), "Path"); + node.append(geometry = "64,64,480,600", "Geometry"); + append(node, "Settings"); directory::create({configpath(), "ananke/"}); - load({configpath(), "ananke/settings.cfg"}); + load({configpath(), "ananke/settings.bml"}); } - ~Configuration() { - save({configpath(), "ananke/settings.cfg"}); + ~Settings() { + save({configpath(), "ananke/settings.bml"}); } } config; diff --git a/ananke/database/bsx-satellaview.hpp b/ananke/database/bsx-satellaview.hpp index 4ff0fd7b..4a89539a 100644 --- a/ananke/database/bsx-satellaview.hpp +++ b/ananke/database/bsx-satellaview.hpp @@ -1,6 +1,6 @@ string BsxSatellaview = R"( -database revision=2013-01-16 +database revision=2013-01-22 release cartridge diff --git a/ananke/database/sufami-turbo.hpp b/ananke/database/sufami-turbo.hpp index bc0d02dd..b1b3821d 100644 --- a/ananke/database/sufami-turbo.hpp +++ b/ananke/database/sufami-turbo.hpp @@ -1,6 +1,6 @@ string SufamiTurbo = R"( -database revision=2013-01-16 +database revision=2013-01-22 release cartridge linkable diff --git a/ananke/database/super-famicom.hpp b/ananke/database/super-famicom.hpp index 7daa7840..f254844e 100644 --- a/ananke/database/super-famicom.hpp +++ b/ananke/database/super-famicom.hpp @@ -1,6 +1,6 @@ string SuperFamicom = R"( -database revision=2013-01-16 +database revision=2013-01-22 release cartridge region=NTSC @@ -164,7 +164,7 @@ release map id=rom address=00-1f,80-9f:8000-ffff map id=rom address=40-5f,c0-df:0000-ffff map id=ram address=20-3f,a0-bf:6000-7fff mask=0xe000 - bsxslot + satellaview map id=rom address=20-3f,a0-bf:8000-ffff map id=rom address=60-7d,e0-ff:0000-ffff information @@ -185,13 +185,12 @@ release rom name=program.rom size=0x40000 map id=rom address=00-1f,80-9f:8000-ffff mask=0x8000 sufamiturbo - slot id=A - map id=rom address=20-3f,a0-bf:8000-ffff mask=0x8000 - map id=ram address=60-6f,e0-ef:0000-ffff - slot id=B - map id=rom address=40-5f,c0-df:0000-7fff mask=0x8000 - map id=rom address=40-5f,c0-df:8000-ffff mask=0x8000 - map id=ram address=70-7d,f0-ff:0000-ffff + map id=rom address=20-3f,a0-bf:8000-ffff mask=0x8000 + map id=ram address=60-6f,e0-ef:0000-ffff + sufamiturbo + map id=rom address=40-5f,c0-df:0000-7fff mask=0x8000 + map id=rom address=40-5f,c0-df:8000-ffff mask=0x8000 + map id=ram address=70-7d,f0-ff:0000-ffff information title: スーファミターボ name: Sufami Turbo diff --git a/ananke/famicom.cpp b/ananke/famicom.cpp index 0ab66577..a54039cd 100644 --- a/ananke/famicom.cpp +++ b/ananke/famicom.cpp @@ -13,10 +13,9 @@ string Ananke::createFamicomHeuristic(vector &buffer) { ".fc/" }; directory::create(pathname); - file::create({pathname, "unverified"}); FamicomCartridge info(buffer.data(), buffer.size()); - string markup = info.markup(); + string markup = {"unverified\n\n", info.markup}; markup.append("\ninformation\n title: ", nall::basename(information.name), "\n"); if(!information.manifest.empty()) markup = information.manifest; //override with embedded beat manifest, if one exists diff --git a/ananke/file-dialog.cpp b/ananke/file-dialog.cpp index 8f6c701c..c0183d48 100644 --- a/ananke/file-dialog.cpp +++ b/ananke/file-dialog.cpp @@ -10,27 +10,11 @@ struct FileDialog : Window { Button openButton; string open() { - setModal(); setVisible(); fileList.setFocused(); filename = ""; - bool backspace = false; - - dialogActive = true; - while(dialogActive) { - OS::processEvents(); - if(Keyboard::pressed(Keyboard::Scancode::Escape)) onClose(); - if(Keyboard::pressed(Keyboard::Scancode::Backspace)) { - if(backspace == false) { - backspace = true; - if(fileList.focused()) upButton.onActivate(); - } - } else { - backspace = false; - } - usleep(20 * 1000); - } + setModal(); return filename; } @@ -68,7 +52,6 @@ struct FileDialog : Window { } FileDialog() { - setFrameGeometry({64, 64, 480, 600}); setTitle("Load Image"); layout.setMargin(5); @@ -111,14 +94,12 @@ struct FileDialog : Window { }; onClose = [&] { - dialogActive = false; setModal(false); setVisible(false); }; } private: - bool dialogActive; string pathname; string filename; lstring filenameList; diff --git a/ananke/game-boy-advance.cpp b/ananke/game-boy-advance.cpp index 7d1da2e4..b7dc4bd4 100644 --- a/ananke/game-boy-advance.cpp +++ b/ananke/game-boy-advance.cpp @@ -19,10 +19,9 @@ string Ananke::createGameBoyAdvanceHeuristic(vector &buffer) { ".gba/" }; directory::create(pathname); - file::create({pathname, "unverified"}); GameBoyAdvanceCartridge info(buffer.data(), buffer.size()); - string markup = info.markup; + string markup = {"unverified\n\n", info.markup}; markup.append("\ninformation\n title: ", nall::basename(information.name), "\n"); if(!information.manifest.empty()) markup = information.manifest; //override with embedded beat manifest, if one exists diff --git a/ananke/game-boy.cpp b/ananke/game-boy.cpp index 639b72d2..b95bf9a1 100644 --- a/ananke/game-boy.cpp +++ b/ananke/game-boy.cpp @@ -21,9 +21,8 @@ string Ananke::createGameBoyHeuristic(vector &buffer) { ".", (info.info.cgb ? "gbc" : "gb"), "/" }; directory::create(pathname); - file::create({pathname, "unverified"}); - string markup = info.markup; + string markup = {"unverified\n\n", info.markup}; markup.append("\ninformation\n title: ", nall::basename(information.name), "\n"); if(!information.manifest.empty()) markup = information.manifest; //override with embedded beat manifest, if one exists diff --git a/ananke/nall/Makefile b/ananke/nall/Makefile deleted file mode 100644 index f422f49d..00000000 --- a/ananke/nall/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# Makefile -# author: byuu -# license: public domain - -[A-Z] = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -[a-z] = a b c d e f g h i j k l m n o p q r s t u v w x y z -[0-9] = 0 1 2 3 4 5 6 7 8 9 -[markup] = ` ~ ! @ \# $$ % ^ & * ( ) - _ = + [ { ] } \ | ; : ' " , < . > / ? -[all] = $([A-Z]) $([a-z]) $([0-9]) $([markup]) -[space] := -[space] += - -##### -# platform detection -##### - -ifeq ($(platform),) - uname := $(shell uname -a) - ifeq ($(uname),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Windows,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring CYGWIN,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Darwin,$(uname)),) - platform := osx - delete = rm -f $1 - else - platform := x - delete = rm -f $1 - endif -endif - -ifeq ($(compiler),) - ifeq ($(platform),win) - compiler := g++ - else ifeq ($(platform),osx) - compiler := g++-mp-4.7 - else - compiler := g++-4.7 - endif -endif - -c := $(compiler) -x c -std=gnu99 -cpp := $(compiler) -std=gnu++11 - -ifeq ($(arch),x86) - c := $(c) -m32 - cpp := $(cpp) -m32 -endif - -ifeq ($(prefix),) - prefix := /usr/local -endif - -##### -# function rwildcard(directory, pattern) -##### -rwildcard = \ - $(strip \ - $(filter $(if $2,$2,%), \ - $(foreach f, \ - $(wildcard $1*), \ - $(eval t = $(call rwildcard,$f/)) \ - $(if $t,$t,$f) \ - ) \ - ) \ - ) - -##### -# function strtr(source, from, to) -##### -strtr = \ - $(eval __temp := $1) \ - $(strip \ - $(foreach c, \ - $(join $(addsuffix :,$2),$3), \ - $(eval __temp := \ - $(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) - -##### -# function strupper(source) -##### -strupper = $(call strtr,$1,$([a-z]),$([A-Z])) - -##### -# function strlower(source) -##### -strlower = $(call strtr,$1,$([A-Z]),$([a-z])) - -##### -# function strlen(source) -##### -strlen = \ - $(eval __temp := $(subst $([space]),_,$1)) \ - $(words \ - $(strip \ - $(foreach c, \ - $([all]), \ - $(eval __temp := \ - $(subst $c,$c ,$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) \ - ) - -##### -# function streq(source) -##### -streq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),,1) - -##### -# function strne(source) -##### -strne = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),1,) diff --git a/ananke/nall/algorithm.hpp b/ananke/nall/algorithm.hpp deleted file mode 100644 index 037f0bb7..00000000 --- a/ananke/nall/algorithm.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NALL_ALGORITHM_HPP -#define NALL_ALGORITHM_HPP - -#undef min -#undef max - -namespace nall { - template T min(const T &t, const U &u) { - return t < u ? t : u; - } - - template T max(const T &t, const U &u) { - return t > u ? t : u; - } -} - -#endif diff --git a/ananke/nall/any.hpp b/ananke/nall/any.hpp deleted file mode 100644 index 7661a2a4..00000000 --- a/ananke/nall/any.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef NALL_ANY_HPP -#define NALL_ANY_HPP - -#include -#include - -namespace nall { - struct any { - bool empty() const { return container; } - const std::type_info& type() const { return container ? container->type() : typeid(void); } - - template any& operator=(const T& value_) { - typedef typename type_if< - std::is_array::value, - typename std::remove_extent::type>::type*, - T - >::type auto_t; - - if(type() == typeid(auto_t)) { - static_cast*>(container)->value = (auto_t)value_; - } else { - if(container) delete container; - container = new holder((auto_t)value_); - } - - return *this; - } - - any() : container(nullptr) {} - ~any() { if(container) delete container; } - template any(const T& value_) : container(nullptr) { operator=(value_); } - - private: - struct placeholder { - virtual const std::type_info& type() const = 0; - } *container; - - template struct holder : placeholder { - T value; - const std::type_info& type() const { return typeid(T); } - holder(const T& value_) : value(value_) {} - }; - - template friend T any_cast(any&); - template friend T any_cast(const any&); - template friend T* any_cast(any*); - template friend const T* any_cast(const any*); - }; - - template T any_cast(any &value) { - typedef typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T any_cast(const any &value) { - typedef const typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T* any_cast(any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } - - template const T* any_cast(const any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } -} - -#endif diff --git a/ananke/nall/atoi.hpp b/ananke/nall/atoi.hpp deleted file mode 100644 index 26756c79..00000000 --- a/ananke/nall/atoi.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_ATOI_HPP -#define NALL_ATOI_HPP - -#include - -namespace nall { - -//note: this header is intended to form the base for user-defined literals; -//once they are supported by GCC. eg: -//unsigned operator "" b(const char *s) { return binary(s); } -//-> signed data = 1001b; -//(0b1001 is nicer, but is not part of the C++ standard) - -constexpr inline uintmax_t binary_(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? binary_(s + 1, (sum << 1) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t octal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '7' ? octal_(s + 1, (sum << 3) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t decimal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '9' ? decimal_(s + 1, (sum * 10) + *s - '0') : - sum - ); -} - -constexpr inline uintmax_t hex_(const char *s, uintmax_t sum = 0) { - return ( - *s >= 'A' && *s <= 'F' ? hex_(s + 1, (sum << 4) | *s - 'A' + 10) : - *s >= 'a' && *s <= 'f' ? hex_(s + 1, (sum << 4) | *s - 'a' + 10) : - *s >= '0' && *s <= '9' ? hex_(s + 1, (sum << 4) | *s - '0') : - sum - ); -} - -// - -constexpr inline uintmax_t binary(const char *s) { - return ( - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '%' ? binary_(s + 1) : - binary_(s) - ); -} - -constexpr inline uintmax_t octal(const char *s) { - return ( - octal_(s) - ); -} - -constexpr inline intmax_t integer(const char *s) { - return ( - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -constexpr inline uintmax_t decimal(const char *s) { - return ( - decimal_(s) - ); -} - -constexpr inline uintmax_t hex(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '$' ? hex_(s + 1) : - hex_(s) - ); -} - -constexpr inline intmax_t numeral(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '0' ? octal_(s + 1) : - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -inline double fp(const char *s) { - return atof(s); -} - -} - -#endif diff --git a/ananke/nall/base64.hpp b/ananke/nall/base64.hpp deleted file mode 100644 index daf3fa60..00000000 --- a/ananke/nall/base64.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef NALL_BASE64_HPP -#define NALL_BASE64_HPP - -#include -#include - -namespace nall { - struct base64 { - static bool encode(char *&output, const uint8_t* input, unsigned inlength) { - output = new char[inlength * 8 / 6 + 8](); - - unsigned i = 0, o = 0; - while(i < inlength) { - switch(i % 3) { - - case 0: { - output[o++] = enc(input[i] >> 2); - output[o] = enc((input[i] & 3) << 4); - break; - } - - case 1: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 4)); - output[o] = enc((input[i] & 15) << 2); - break; - } - - case 2: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 6)); - output[o++] = enc(input[i] & 63); - break; - } - - } - - i++; - } - - return true; - } - - static string encode(const string &data) { - char *buffer = nullptr; - encode(buffer, (const uint8_t*)(const char*)data, data.length()); - string result = buffer; - delete[] buffer; - return result; - } - - static bool decode(uint8_t *&output, unsigned &outlength, const char *input) { - unsigned inlength = strlen(input), infix = 0; - output = new uint8_t[inlength + 1](); - - unsigned i = 0, o = 0; - while(i < inlength) { - uint8_t x = dec(input[i]); - - switch(i++ & 3) { - - case 0: { - output[o] = x << 2; - break; - } - - case 1: { - output[o++] |= x >> 4; - output[o] = (x & 15) << 4; - break; - } - - case 2: { - output[o++] |= x >> 2; - output[o] = (x & 3) << 6; - break; - } - - case 3: { - output[o++] |= x; - break; - } - - } - } - - outlength = o; - return true; - } - - static string decode(const string &data) { - uint8_t *buffer = nullptr; - unsigned size = 0; - decode(buffer, size, (const char*)data); - string result = (const char*)buffer; - delete[] buffer; - return result; - } - - private: - static char enc(uint8_t n) { - //base64 for URL encodings (URL = -_, MIME = +/) - static char lookup_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - return lookup_table[n & 63]; - } - - static uint8_t dec(char n) { - if(n >= 'A' && n <= 'Z') return n - 'A'; - if(n >= 'a' && n <= 'z') return n - 'a' + 26; - if(n >= '0' && n <= '9') return n - '0' + 52; - if(n == '-') return 62; - if(n == '_') return 63; - return 0; - } - }; -} - -#endif diff --git a/ananke/nall/beat/archive.hpp b/ananke/nall/beat/archive.hpp deleted file mode 100644 index ef7294cf..00000000 --- a/ananke/nall/beat/archive.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef NALL_BEAT_ARCHIVE_HPP -#define NALL_BEAT_ARCHIVE_HPP - -#include - -namespace nall { - -struct beatArchive : beatBase { - bool create(const string &beatname, string pathname, const string &metadata = "") { - if(fp.open(beatname, file::mode::write) == false) return false; - if(pathname.endswith("/") == false) pathname.append("/"); - - checksum = ~0; - writeString("BPA1"); - writeNumber(metadata.length()); - writeString(metadata); - - lstring list; - ls(list, pathname, pathname); - for(auto &name : list) { - if(name.endswith("/")) { - name.rtrim<1>("/"); - writeNumber(0 | ((name.length() - 1) << 1)); - writeString(name); - } else { - file stream; - if(stream.open({pathname, name}, file::mode::read) == false) return false; - writeNumber(1 | ((name.length() - 1) << 1)); - writeString(name); - unsigned size = stream.size(); - writeNumber(size); - uint32_t checksum = ~0; - while(size--) { - uint8_t data = stream.read(); - write(data); - checksum = crc32_adjust(checksum, data); - } - writeChecksum(~checksum); - } - } - - writeChecksum(~checksum); - fp.close(); - return true; - } - - bool unpack(const string &beatname, string pathname) { - if(fp.open(beatname, file::mode::read) == false) return false; - if(pathname.endswith("/") == false) pathname.append("/"); - - checksum = ~0; - if(readString(4) != "BPA1") return false; - unsigned length = readNumber(); - while(length--) read(); - - directory::create(pathname); - while(fp.offset() < fp.size() - 4) { - unsigned data = readNumber(); - string name = readString((data >> 1) + 1); - if(name.position("\\") || name.position("../")) return false; //block path exploits - - if((data & 1) == 0) { - directory::create({pathname, name}); - } else { - file stream; - if(stream.open({pathname, name}, file::mode::write) == false) return false; - unsigned size = readNumber(); - uint32_t checksum = ~0; - while(size--) { - uint8_t data = read(); - stream.write(data); - checksum = crc32_adjust(checksum, data); - } - if(readChecksum(~checksum) == false) return false; - } - } - - return readChecksum(~checksum); - } -}; - -} - -#endif diff --git a/ananke/nall/beat/base.hpp b/ananke/nall/beat/base.hpp deleted file mode 100644 index 8e0001be..00000000 --- a/ananke/nall/beat/base.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef NALL_BEAT_BASE_HPP -#define NALL_BEAT_BASE_HPP - -namespace nall { - -struct beatBase { -protected: - file fp; - uint32_t checksum; - - void ls(lstring &list, const string &path, const string &basepath) { - lstring paths = directory::folders(path); - for(auto &pathname : paths) { - list.append(string{path, pathname}.ltrim<1>(basepath)); - ls(list, {path, pathname}, basepath); - } - - lstring files = directory::files(path); - for(auto &filename : files) { - list.append(string{path, filename}.ltrim<1>(basepath)); - } - } - - void write(uint8_t data) { - fp.write(data); - checksum = crc32_adjust(checksum, data); - } - - void writeNumber(uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) return write(0x80 | x); - write(x); - data--; - } - } - - void writeString(const string &text) { - unsigned length = text.length(); - for(unsigned n = 0; n < length; n++) write(text[n]); - } - - void writeChecksum(uint32_t checksum) { - write(checksum >> 0); - write(checksum >> 8); - write(checksum >> 16); - write(checksum >> 24); - } - - uint8_t read() { - uint8_t data = fp.read(); - checksum = crc32_adjust(checksum, data); - return data; - } - - uint64_t readNumber() { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - } - - string readString(unsigned length) { - string text; - text.reserve(length + 1); - for(unsigned n = 0; n < length; n++) { - text[n] = fp.read(); - checksum = crc32_adjust(checksum, text[n]); - } - text[length] = 0; - return text; - } - - bool readChecksum(uint32_t source) { - uint32_t checksum = 0; - checksum |= read() << 0; - checksum |= read() << 8; - checksum |= read() << 16; - checksum |= read() << 24; - return checksum == source; - } -}; - -} - -#endif diff --git a/ananke/nall/beat/delta.hpp b/ananke/nall/beat/delta.hpp deleted file mode 100644 index ce120537..00000000 --- a/ananke/nall/beat/delta.hpp +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef NALL_BEAT_DELTA_HPP -#define NALL_BEAT_DELTA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsdelta { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpsdelta::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpsdelta::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpsdelta::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpsdelta::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpsdelta::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t sourceChecksum = ~0, modifyChecksum = ~0; - unsigned sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - Node *sourceTree[65536], *targetTree[65536]; - for(unsigned n = 0; n < 65536; n++) sourceTree[n] = 0, targetTree[n] = 0; - - //source tree creation - for(unsigned offset = 0; offset < sourceSize; offset++) { - uint16_t symbol = sourceData[offset + 0]; - sourceChecksum = crc32_adjust(sourceChecksum, symbol); - if(offset < sourceSize - 1) symbol |= sourceData[offset + 1] << 8; - Node *node = new Node; - node->offset = offset; - node->next = sourceTree[symbol]; - sourceTree[symbol] = node; - } - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - while(outputOffset < targetSize) { - unsigned maxLength = 0, maxOffset = 0, mode = TargetRead; - - uint16_t symbol = targetData[outputOffset + 0]; - if(outputOffset < targetSize - 1) symbol |= targetData[outputOffset + 1] << 8; - - { //source read - unsigned length = 0, offset = outputOffset; - while(offset < sourceSize && offset < targetSize && sourceData[offset] == targetData[offset]) { - length++; - offset++; - } - if(length > maxLength) maxLength = length, mode = SourceRead; - } - - { //source copy - Node *node = sourceTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(x < sourceSize && y < targetSize && sourceData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = SourceCopy; - node = node->next; - } - } - - { //target copy - Node *node = targetTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(y < targetSize && targetData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = TargetCopy; - node = node->next; - } - - //target tree append - node = new Node; - node->offset = outputOffset; - node->next = targetTree[symbol]; - targetTree[symbol] = node; - } - - { //target read - if(maxLength < 4) { - maxLength = min((unsigned)Granularity, targetSize - outputOffset); - mode = TargetRead; - } - } - - if(mode != TargetRead) targetReadFlush(); - - switch(mode) { - case SourceRead: - encode(SourceRead | ((maxLength - 1) << 2)); - break; - case TargetRead: - //delay write to group sequential TargetRead commands into one - targetReadLength += maxLength; - break; - case SourceCopy: - case TargetCopy: - encode(mode | ((maxLength - 1) << 2)); - signed relativeOffset; - if(mode == SourceCopy) { - relativeOffset = maxOffset - sourceRelativeOffset; - sourceRelativeOffset = maxOffset + maxLength; - } else { - relativeOffset = maxOffset - targetRelativeOffset; - targetRelativeOffset = maxOffset + maxLength; - } - encode((relativeOffset < 0) | (abs(relativeOffset) << 1)); - break; - } - - outputOffset += maxLength; - } - - targetReadFlush(); - - sourceChecksum = ~sourceChecksum; - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/ananke/nall/beat/linear.hpp b/ananke/nall/beat/linear.hpp deleted file mode 100644 index 078aae34..00000000 --- a/ananke/nall/beat/linear.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_BEAT_LINEAR_HPP -#define NALL_BEAT_LINEAR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpslinear { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpslinear::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpslinear::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpslinear::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpslinear::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpslinear::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t modifyChecksum = ~0; - unsigned targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - while(outputOffset < targetSize) { - unsigned sourceLength = 0; - for(unsigned n = 0; outputOffset + n < min(sourceSize, targetSize); n++) { - if(sourceData[outputOffset + n] != targetData[outputOffset + n]) break; - sourceLength++; - } - - unsigned rleLength = 0; - for(unsigned n = 1; outputOffset + n < targetSize; n++) { - if(targetData[outputOffset] != targetData[outputOffset + n]) break; - rleLength++; - } - - if(rleLength >= 4) { - //write byte to repeat - targetReadLength++; - outputOffset++; - targetReadFlush(); - - //copy starting from repetition byte - encode(TargetCopy | ((rleLength - 1) << 2)); - unsigned relativeOffset = (outputOffset - 1) - targetRelativeOffset; - encode(relativeOffset << 1); - outputOffset += rleLength; - targetRelativeOffset = outputOffset - 1; - } else if(sourceLength >= 4) { - targetReadFlush(); - encode(SourceRead | ((sourceLength - 1) << 2)); - outputOffset += sourceLength; - } else { - targetReadLength += Granularity; - outputOffset += Granularity; - } - } - - targetReadFlush(); - - uint32_t sourceChecksum = crc32_calculate(sourceData, sourceSize); - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/ananke/nall/beat/metadata.hpp b/ananke/nall/beat/metadata.hpp deleted file mode 100644 index 58e6ab0a..00000000 --- a/ananke/nall/beat/metadata.hpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef NALL_BEAT_METADATA_HPP -#define NALL_BEAT_METADATA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsmetadata { - inline bool load(const string &filename); - inline bool save(const string &filename, const string &metadata); - inline string metadata() const; - -protected: - file sourceFile; - string metadataString; -}; - -bool bpsmetadata::load(const string &filename) { - if(sourceFile.open(filename, file::mode::read) == false) return false; - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - if(read() != 'B') return false; - if(read() != 'P') return false; - if(read() != 'S') return false; - if(read() != '1') return false; - decode(); - decode(); - unsigned metadataSize = decode(); - char data[metadataSize + 1]; - for(unsigned n = 0; n < metadataSize; n++) data[n] = read(); - data[metadataSize] = 0; - metadataString = (const char*)data; - - return true; -} - -bool bpsmetadata::save(const string &filename, const string &metadata) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - if(sourceFile.open() == false) return false; - sourceFile.seek(0); - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - uint32_t checksum = ~0; - - auto write = [&](uint8_t data) { - targetFile.write(data); - checksum = crc32_adjust(checksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - for(unsigned n = 0; n < 4; n++) write(read()); - encode(decode()); - encode(decode()); - unsigned sourceLength = decode(); - unsigned targetLength = metadata.length(); - encode(targetLength); - sourceFile.seek(sourceLength, file::index::relative); - for(unsigned n = 0; n < targetLength; n++) write(metadata[n]); - unsigned length = sourceFile.size() - sourceFile.offset() - 4; - for(unsigned n = 0; n < length; n++) write(read()); - uint32_t outputChecksum = ~checksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - targetFile.close(); - return true; -} - -string bpsmetadata::metadata() const { - return metadataString; -} - -} - -#endif diff --git a/ananke/nall/beat/multi.hpp b/ananke/nall/beat/multi.hpp deleted file mode 100644 index cddf5d6b..00000000 --- a/ananke/nall/beat/multi.hpp +++ /dev/null @@ -1,242 +0,0 @@ -#ifndef NALL_BEAT_MULTI_HPP -#define NALL_BEAT_MULTI_HPP - -#include -#include -#include - -namespace nall { - -struct bpsmulti { - enum : unsigned { - CreatePath = 0, - CreateFile = 1, - ModifyFile = 2, - MirrorFile = 3, - }; - - enum : unsigned { - OriginSource = 0, - OriginTarget = 1, - }; - - bool create(const string &patchName, const string &sourcePath, const string &targetPath, bool delta = false, const string &metadata = "") { - if(fp.open()) fp.close(); - fp.open(patchName, file::mode::write); - checksum = ~0; - - writeString("BPM1"); //signature - writeNumber(metadata.length()); - writeString(metadata); - - lstring sourceList, targetList; - ls(sourceList, sourcePath, sourcePath); - ls(targetList, targetPath, targetPath); - - for(auto &targetName : targetList) { - if(targetName.endswith("/")) { - targetName.rtrim<1>("/"); - writeNumber(CreatePath | ((targetName.length() - 1) << 2)); - writeString(targetName); - } else if(auto position = sourceList.find(targetName)) { //if sourceName == targetName - file sp, dp; - sp.open({sourcePath, targetName}, file::mode::read); - dp.open({targetPath, targetName}, file::mode::read); - - bool identical = sp.size() == dp.size(); - uint32_t cksum = ~0; - - for(unsigned n = 0; n < sp.size(); n++) { - uint8_t byte = sp.read(); - if(identical && byte != dp.read()) identical = false; - cksum = crc32_adjust(cksum, byte); - } - - if(identical) { - writeNumber(MirrorFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - writeNumber(OriginSource); - writeChecksum(~cksum); - } else { - writeNumber(ModifyFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - writeNumber(OriginSource); - - if(delta == false) { - bpslinear patch; - patch.source({sourcePath, targetName}); - patch.target({targetPath, targetName}); - patch.create({temppath(), "temp.bps"}); - } else { - bpsdelta patch; - patch.source({sourcePath, targetName}); - patch.target({targetPath, targetName}); - patch.create({temppath(), "temp.bps"}); - } - - auto buffer = file::read({temppath(), "temp.bps"}); - writeNumber(buffer.size()); - for(auto &byte : buffer) write(byte); - } - } else { - writeNumber(CreateFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - auto buffer = file::read({targetPath, targetName}); - writeNumber(buffer.size()); - for(auto &byte : buffer) write(byte); - writeChecksum(crc32_calculate(buffer.data(), buffer.size())); - } - } - - //checksum - writeChecksum(~checksum); - fp.close(); - return true; - } - - bool apply(const string &patchName, const string &sourcePath, const string &targetPath) { - directory::remove(targetPath); //start with a clean directory - directory::create(targetPath); - - if(fp.open()) fp.close(); - fp.open(patchName, file::mode::read); - checksum = ~0; - - if(readString(4) != "BPM1") return false; - auto metadataLength = readNumber(); - while(metadataLength--) read(); - - while(fp.offset() < fp.size() - 4) { - auto encoding = readNumber(); - unsigned action = encoding & 3; - unsigned targetLength = (encoding >> 2) + 1; - string targetName = readString(targetLength); - - if(action == CreatePath) { - directory::create({targetPath, targetName, "/"}); - } else if(action == CreateFile) { - file fp; - fp.open({targetPath, targetName}, file::mode::write); - auto fileSize = readNumber(); - while(fileSize--) fp.write(read()); - uint32_t cksum = readChecksum(); - } else if(action == ModifyFile) { - auto encoding = readNumber(); - string originPath = encoding & 1 ? targetPath : sourcePath; - string sourceName = (encoding >> 1) == 0 ? targetName : readString(encoding >> 1); - auto patchSize = readNumber(); - vector buffer; - buffer.resize(patchSize); - for(unsigned n = 0; n < patchSize; n++) buffer[n] = read(); - bpspatch patch; - patch.modify(buffer.data(), buffer.size()); - patch.source({originPath, sourceName}); - patch.target({targetPath, targetName}); - if(patch.apply() != bpspatch::result::success) return false; - } else if(action == MirrorFile) { - auto encoding = readNumber(); - string originPath = encoding & 1 ? targetPath : sourcePath; - string sourceName = (encoding >> 1) == 0 ? targetName : readString(encoding >> 1); - file::copy({originPath, sourceName}, {targetPath, targetName}); - uint32_t cksum = readChecksum(); - } - } - - uint32_t cksum = ~checksum; - if(read() != (uint8_t)(cksum >> 0)) return false; - if(read() != (uint8_t)(cksum >> 8)) return false; - if(read() != (uint8_t)(cksum >> 16)) return false; - if(read() != (uint8_t)(cksum >> 24)) return false; - - fp.close(); - return true; - } - -protected: - file fp; - uint32_t checksum; - - //create() functions - void ls(lstring &list, const string &path, const string &basepath) { - lstring paths = directory::folders(path); - for(auto &pathname : paths) { - list.append(string{path, pathname}.ltrim<1>(basepath)); - ls(list, {path, pathname}, basepath); - } - - lstring files = directory::files(path); - for(auto &filename : files) { - list.append(string{path, filename}.ltrim<1>(basepath)); - } - } - - void write(uint8_t data) { - fp.write(data); - checksum = crc32_adjust(checksum, data); - } - - void writeNumber(uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - } - - void writeString(const string &text) { - unsigned length = text.length(); - for(unsigned n = 0; n < length; n++) write(text[n]); - } - - void writeChecksum(uint32_t cksum) { - write(cksum >> 0); - write(cksum >> 8); - write(cksum >> 16); - write(cksum >> 24); - } - - //apply() functions - uint8_t read() { - uint8_t data = fp.read(); - checksum = crc32_adjust(checksum, data); - return data; - } - - uint64_t readNumber() { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - } - - string readString(unsigned length) { - string text; - text.reserve(length + 1); - for(unsigned n = 0; n < length; n++) text[n] = read(); - text[length] = 0; - return text; - } - - uint32_t readChecksum() { - uint32_t checksum = 0; - checksum |= read() << 0; - checksum |= read() << 8; - checksum |= read() << 16; - checksum |= read() << 24; - return checksum; - } -}; - -} - -#endif diff --git a/ananke/nall/beat/patch.hpp b/ananke/nall/beat/patch.hpp deleted file mode 100644 index 8c6de75b..00000000 --- a/ananke/nall/beat/patch.hpp +++ /dev/null @@ -1,219 +0,0 @@ -#ifndef NALL_BEAT_PATCH_HPP -#define NALL_BEAT_PATCH_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpspatch { - inline bool modify(const uint8_t *data, unsigned size); - inline void source(const uint8_t *data, unsigned size); - inline void target(uint8_t *data, unsigned size); - - inline bool modify(const string &filename); - inline bool source(const string &filename); - inline bool target(const string &filename); - - inline string metadata() const; - inline unsigned size() const; - - enum result : unsigned { - unknown, - success, - patch_too_small, - patch_invalid_header, - source_too_small, - target_too_small, - source_checksum_invalid, - target_checksum_invalid, - patch_checksum_invalid, - }; - - inline result apply(); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - - filemap modifyFile; - const uint8_t *modifyData; - unsigned modifySize; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - uint8_t *targetData; - unsigned targetSize; - - unsigned modifySourceSize; - unsigned modifyTargetSize; - unsigned modifyMarkupSize; - string metadataString; -}; - -bool bpspatch::modify(const uint8_t *data, unsigned size) { - if(size < 19) return false; - modifyData = data; - modifySize = size; - - unsigned offset = 4; - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = modifyData[offset++]; - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - - char buffer[modifyMarkupSize + 1]; - for(unsigned n = 0; n < modifyMarkupSize; n++) buffer[n] = modifyData[offset++]; - buffer[modifyMarkupSize] = 0; - metadataString = (const char*)buffer; - - return true; -} - -void bpspatch::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpspatch::target(uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpspatch::modify(const string &filename) { - if(modifyFile.open(filename, filemap::mode::read) == false) return false; - return modify(modifyFile.data(), modifyFile.size()); -} - -bool bpspatch::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpspatch::target(const string &filename) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(modifyTargetSize); - fp.close(); - - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -string bpspatch::metadata() const { - return metadataString; -} - -unsigned bpspatch::size() const { - return modifyTargetSize; -} - -bpspatch::result bpspatch::apply() { - if(modifySize < 19) return result::patch_too_small; - - uint32_t modifyChecksum = ~0, targetChecksum = ~0; - unsigned modifyOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto read = [&]() -> uint8_t { - uint8_t data = modifyData[modifyOffset++]; - modifyChecksum = crc32_adjust(modifyChecksum, data); - return data; - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - auto write = [&](uint8_t data) { - targetData[outputOffset++] = data; - targetChecksum = crc32_adjust(targetChecksum, data); - }; - - if(read() != 'B') return result::patch_invalid_header; - if(read() != 'P') return result::patch_invalid_header; - if(read() != 'S') return result::patch_invalid_header; - if(read() != '1') return result::patch_invalid_header; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - for(unsigned n = 0; n < modifyMarkupSize; n++) read(); - - if(modifySourceSize > sourceSize) return result::source_too_small; - if(modifyTargetSize > targetSize) return result::target_too_small; - - while(modifyOffset < modifySize - 12) { - unsigned length = decode(); - unsigned mode = length & 3; - length = (length >> 2) + 1; - - switch(mode) { - case SourceRead: - while(length--) write(sourceData[outputOffset]); - break; - case TargetRead: - while(length--) write(read()); - break; - case SourceCopy: - case TargetCopy: - signed offset = decode(); - bool negative = offset & 1; - offset >>= 1; - if(negative) offset = -offset; - - if(mode == SourceCopy) { - sourceRelativeOffset += offset; - while(length--) write(sourceData[sourceRelativeOffset++]); - } else { - targetRelativeOffset += offset; - while(length--) write(targetData[targetRelativeOffset++]); - } - break; - } - } - - uint32_t modifySourceChecksum = 0, modifyTargetChecksum = 0, modifyModifyChecksum = 0; - for(unsigned n = 0; n < 32; n += 8) modifySourceChecksum |= read() << n; - for(unsigned n = 0; n < 32; n += 8) modifyTargetChecksum |= read() << n; - uint32_t checksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) modifyModifyChecksum |= read() << n; - - uint32_t sourceChecksum = crc32_calculate(sourceData, modifySourceSize); - targetChecksum = ~targetChecksum; - - if(sourceChecksum != modifySourceChecksum) return result::source_checksum_invalid; - if(targetChecksum != modifyTargetChecksum) return result::target_checksum_invalid; - if(checksum != modifyModifyChecksum) return result::patch_checksum_invalid; - - return result::success; -} - -} - -#endif diff --git a/ananke/nall/bit.hpp b/ananke/nall/bit.hpp deleted file mode 100644 index 63403eb0..00000000 --- a/ananke/nall/bit.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef NALL_BIT_HPP -#define NALL_BIT_HPP - -#include - -namespace nall { - template - inline uintmax_t uclamp(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), y = b * 2 - 1 }; - return y + ((x - y) & -(x < y)); //min(x, y); - } - - template - inline uintmax_t uclip(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return (x & m); - } - - template - inline intmax_t sclamp(const intmax_t x) { - enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 }; - return (x > m) ? m : (x < -b) ? -b : x; - } - - template - inline intmax_t sclip(const intmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return ((x & m) ^ b) - b; - } - - namespace bit { - constexpr inline uintmax_t mask(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) : - *s == ' ' || *s == '_' ? mask(s + 1, sum) : - *s ? mask(s + 1, sum << 1) : - sum - ); - } - - constexpr inline uintmax_t test(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) : - *s == ' ' || *s == '_' ? test(s + 1, sum) : - *s ? test(s + 1, sum << 1) : - sum - ); - } - - //lowest(0b1110) == 0b0010 - constexpr inline uintmax_t lowest(const uintmax_t x) { - return x & -x; - } - - //clear_lowest(0b1110) == 0b1100 - constexpr inline uintmax_t clear_lowest(const uintmax_t x) { - return x & (x - 1); - } - - //set_lowest(0b0101) == 0b0111 - constexpr inline uintmax_t set_lowest(const uintmax_t x) { - return x | (x + 1); - } - - //count number of bits set in a byte - inline unsigned count(uintmax_t x) { - unsigned count = 0; - do count += x & 1; while(x >>= 1); - return count; - } - - //round up to next highest single bit: - //round(15) == 16, round(16) == 16, round(17) == 32 - inline uintmax_t round(uintmax_t x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } - } -} - -#endif diff --git a/ananke/nall/bmp.hpp b/ananke/nall/bmp.hpp deleted file mode 100644 index 33cdf4dc..00000000 --- a/ananke/nall/bmp.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef NALL_BMP_HPP -#define NALL_BMP_HPP - -#include - -//BMP reader / writer -//author: byuu -//note: only 24-bit RGB and 32-bit ARGB uncompressed images supported - -namespace nall { - -struct bmp { - inline static bool read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height); - inline static bool write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha = false); -}; - -bool bmp::read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height) { - file fp; - if(fp.open(filename, file::mode::read) == false) return false; - if(fp.size() < 0x36) return false; - - if(fp.readm(2) != 0x424d) return false; - fp.seek(0x000a); - unsigned offset = fp.readl(4); - unsigned dibsize = fp.readl(4); - if(dibsize != 40) return false; - signed headerWidth = fp.readl(4); - if(headerWidth < 0) return false; - signed headerHeight = fp.readl(4); - fp.readl(2); - unsigned bitsPerPixel = fp.readl(2); - if(bitsPerPixel != 24 && bitsPerPixel != 32) return false; - unsigned compression = fp.readl(4); - if(compression != 0) return false; - fp.seek(offset); - - bool noFlip = headerHeight < 0; - width = headerWidth, height = abs(headerHeight); - data = new uint32_t[width * height]; - - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - for(unsigned y = 0; y < height; y++) { - uint32_t *p = noFlip ? data + y * width : data + (height - 1 - y) * width; - for(unsigned x = 0; x < width; x++, p++) { - *p = fp.readl(bytesPerPixel); - if(bytesPerPixel == 3) *p |= 255 << 24; - } - if(paddingLength) fp.readl(paddingLength); - } - - fp.close(); - return true; -} - -bool bmp::write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - - unsigned bitsPerPixel = alpha ? 32 : 24; - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - unsigned imageSize = alignedWidth * height; - unsigned fileSize = 0x36 + imageSize; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - fp.writem(0x424d, 2); //signature - fp.writel(fileSize, 4); //file size - fp.writel(0, 2); //reserved - fp.writel(0, 2); //reserved - fp.writel(0x36, 4); //offset - - fp.writel(40, 4); //DIB size - fp.writel(width, 4); //width - fp.writel(-height, 4); //height - fp.writel(1, 2); //color planes - fp.writel(bitsPerPixel, 2); //bits per pixel - fp.writel(0, 4); //compression method (BI_RGB) - fp.writel(imageSize, 4); //image data size - fp.writel(3780, 4); //horizontal resolution - fp.writel(3780, 4); //vertical resolution - fp.writel(0, 4); //palette size - fp.writel(0, 4); //important color count - - for(unsigned y = 0; y < height; y++) { - const uint32_t *p = (const uint32_t*)((const uint8_t*)data + y * pitch); - for(unsigned x = 0; x < width; x++) fp.writel(*p++, bytesPerPixel); - if(paddingLength) fp.writel(0, paddingLength); - } - - fp.close(); - return true; -} - -} - -#endif diff --git a/ananke/nall/compositor.hpp b/ananke/nall/compositor.hpp deleted file mode 100644 index 6b9245f6..00000000 --- a/ananke/nall/compositor.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_COMPOSITOR_HPP -#define NALL_COMPOSITOR_HPP - -#include - -namespace nall { - -struct compositor { - inline static bool enabled(); - inline static bool enable(bool status); - - #if defined(PLATFORM_X) - enum class Compositor : unsigned { Unknown, Metacity, Xfwm4 }; - inline static Compositor detect(); - - inline static bool enabled_metacity(); - inline static bool enable_metacity(bool status); - - inline static bool enabled_xfwm4(); - inline static bool enable_xfwm4(bool status); - #endif -}; - -#if defined(PLATFORM_X) - -//Metacity - -bool compositor::enabled_metacity() { - FILE *fp = popen("gconftool-2 --get /apps/metacity/general/compositing_manager", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_metacity(bool status) { - FILE *fp; - if(status) { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager true", "r"); - } else { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager false", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//Xfwm4 - -bool compositor::enabled_xfwm4() { - FILE *fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing'", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_xfwm4(bool status) { - FILE *fp; - if(status) { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'true'", "r"); - } else { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'false'", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//General - -compositor::Compositor compositor::detect() { - Compositor result = Compositor::Unknown; - - FILE *fp; - char buffer[512]; - - fp = popen("pidof metacity", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Metacity; - pclose(fp); - - fp = popen("pidof xfwm4", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Xfwm4; - pclose(fp); - - return result; -} - -bool compositor::enabled() { - switch(detect()) { - case Compositor::Metacity: return enabled_metacity(); - case Compositor::Xfwm4: return enabled_xfwm4(); - default: return false; - } -} - -bool compositor::enable(bool status) { - switch(detect()) { - case Compositor::Metacity: return enable_metacity(status); - case Compositor::Xfwm4: return enable_xfwm4(status); - default: return false; - } -} - -#elif defined(PLATFORM_WINDOWS) - -bool compositor::enabled() { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmIsCompositionEnabled = (HRESULT (WINAPI*)(BOOL*))GetProcAddress(module, "DwmIsCompositionEnabled"); - if(pDwmIsCompositionEnabled == 0) return false; - - BOOL result; - if(pDwmIsCompositionEnabled(&result) != S_OK) return false; - return result; -} - -bool compositor::enable(bool status) { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmEnableComposition = (HRESULT (WINAPI*)(UINT))GetProcAddress(module, "DwmEnableComposition"); - if(pDwmEnableComposition == 0) return false; - - if(pDwmEnableComposition(status) != S_OK) return false; - return true; -} - -#else - -bool compositor::enabled() { - return false; -} - -bool compositor::enable(bool) { - return false; -} - -#endif - -} - -#endif diff --git a/ananke/nall/config.hpp b/ananke/nall/config.hpp deleted file mode 100644 index 94be7dc1..00000000 --- a/ananke/nall/config.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_CONFIG_HPP -#define NALL_CONFIG_HPP - -#include -#include -#include - -namespace nall { - namespace configuration_traits { - template struct is_boolean { enum { value = false }; }; - template<> struct is_boolean { enum { value = true }; }; - - template struct is_signed { enum { value = false }; }; - template<> struct is_signed { enum { value = true }; }; - - template struct is_unsigned { enum { value = false }; }; - template<> struct is_unsigned { enum { value = true }; }; - - template struct is_double { enum { value = false }; }; - template<> struct is_double { enum { value = true }; }; - - template struct is_string { enum { value = false }; }; - template<> struct is_string { enum { value = true }; }; - } - - class configuration { - public: - enum type_t { boolean_t, signed_t, unsigned_t, double_t, string_t, unknown_t }; - struct item_t { - uintptr_t data; - string name; - string desc; - type_t type; - - inline string get() const { - switch(type) { - case boolean_t: return { *(bool*)data }; - case signed_t: return { *(signed*)data }; - case unsigned_t: return { *(unsigned*)data }; - case double_t: return { *(double*)data }; - case string_t: return { "\"", *(string*)data, "\"" }; - } - return "???"; - } - - inline void set(string s) { - switch(type) { - case boolean_t: *(bool*)data = (s == "true"); break; - case signed_t: *(signed*)data = integer(s); break; - case unsigned_t: *(unsigned*)data = decimal(s); break; - case double_t: *(double*)data = fp(s); break; - case string_t: s.trim("\""); *(string*)data = s; break; - } - } - }; - vector list; - - template - inline void append(T &data, const char *name, const char *desc = "") { - item_t item = { (uintptr_t)&data, name, desc }; - if(configuration_traits::is_boolean::value) item.type = boolean_t; - else if(configuration_traits::is_signed::value) item.type = signed_t; - else if(configuration_traits::is_unsigned::value) item.type = unsigned_t; - else if(configuration_traits::is_double::value) item.type = double_t; - else if(configuration_traits::is_string::value) item.type = string_t; - else item.type = unknown_t; - list.append(item); - } - - //deprecated - template - inline void attach(T &data, const char *name, const char *desc = "") { - append(data, name, desc); - } - - inline virtual bool load(const string &filename) { - string data; - if(data.readfile(filename) == true) { - data.replace("\r", ""); - lstring line; - line.split("\n", data); - - for(unsigned i = 0; i < line.size(); i++) { - if(auto position = qstrpos(line[i], "#")) line[i][position()] = 0; - if(!qstrpos(line[i], " = ")) continue; - - lstring part; - part.qsplit(" = ", line[i]); - part[0].trim(); - part[1].trim(); - - for(unsigned n = 0; n < list.size(); n++) { - if(part[0] == list[n].name) { - list[n].set(part[1]); - break; - } - } - } - - return true; - } else { - return false; - } - } - - inline virtual bool save(const string &filename) const { - file fp; - if(fp.open(filename, file::mode::write)) { - for(unsigned i = 0; i < list.size(); i++) { - string output; - output.append(list[i].name, " = ", list[i].get()); - if(list[i].desc != "") output.append(" # ", list[i].desc); - output.append("\r\n"); - fp.print(output); - } - - fp.close(); - return true; - } else { - return false; - } - } - }; -} - -#endif diff --git a/ananke/nall/crc16.hpp b/ananke/nall/crc16.hpp deleted file mode 100644 index cd6e72fd..00000000 --- a/ananke/nall/crc16.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NALL_CRC16_HPP -#define NALL_CRC16_HPP - -#include - -namespace nall { - inline uint16_t crc16_adjust(uint16_t crc16, uint8_t data) { - for(unsigned n = 0; n < 8; n++) { - if((crc16 & 1) ^ (data & 1)) crc16 = (crc16 >> 1) ^ 0x8408; - else crc16 >>= 1; - data >>= 1; - } - return crc16; - } - - inline uint16_t crc16_calculate(const uint8_t *data, unsigned length) { - uint16_t crc16 = ~0; - for(unsigned n = 0; n < length; n++) { - crc16 = crc16_adjust(crc16, data[n]); - } - return ~crc16; - } -} - -#endif diff --git a/ananke/nall/crc32.hpp b/ananke/nall/crc32.hpp deleted file mode 100644 index ad36fbf6..00000000 --- a/ananke/nall/crc32.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef NALL_CRC32_HPP -#define NALL_CRC32_HPP - -#include - -namespace nall { - const uint32_t crc32_table[256] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; - - inline uint32_t crc32_adjust(uint32_t crc32, uint8_t input) { - return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff]; - } - - inline uint32_t crc32_calculate(const uint8_t *data, unsigned length) { - uint32_t crc32 = ~0; - for(unsigned i = 0; i < length; i++) { - crc32 = crc32_adjust(crc32, data[i]); - } - return ~crc32; - } -} - -#endif diff --git a/ananke/nall/directory.hpp b/ananke/nall/directory.hpp deleted file mode 100644 index 5617ee4e..00000000 --- a/ananke/nall/directory.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#ifndef NALL_DIRECTORY_HPP -#define NALL_DIRECTORY_HPP - -#include -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include -#else - #include - #include - #include -#endif - -namespace nall { - -struct directory { - static bool create(const string &pathname, unsigned permissions = 0755); //recursive - static bool remove(const string &pathname); //recursive - static bool exists(const string &pathname); - - static lstring folders(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname, pattern); - folders.sort(); - return folders; - } - - static lstring files(const string &pathname, const string &pattern = "*") { - lstring files = directory::ufiles(pathname, pattern); - files.sort(); - return files; - } - - static lstring contents(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files - lstring files = directory::ufiles(pathname, pattern); - folders.sort(); - files.sort(); - for(auto &file : files) folders.append(file); - return folders; - } - - static lstring ifolders(const string &pathname, const string &pattern = "*") { - lstring folders = ufolders(pathname, pattern); - folders.isort(); - return folders; - } - - static lstring ifiles(const string &pathname, const string &pattern = "*") { - lstring files = ufiles(pathname, pattern); - files.isort(); - return files; - } - - static lstring icontents(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files - lstring files = directory::ufiles(pathname, pattern); - folders.isort(); - files.isort(); - for(auto &file : files) folders.append(file); - return folders; - } - -private: - //internal functions; these return unsorted lists - static lstring ufolders(const string &pathname, const string &pattern = "*"); - static lstring ufiles(const string &pathname, const string &pattern = "*"); -}; - -#if defined(PLATFORM_WINDOWS) - inline bool directory::create(const string &pathname, unsigned permissions) { - string path; - lstring list = string{pathname}.transform("\\", "/").rtrim<1>("/").split("/"); - bool result = true; - for(auto &part : list) { - path.append(part, "/"); - result &= (_wmkdir(utf16_t(path)) == 0); - } - return result; - } - - inline bool directory::remove(const string &pathname) { - lstring list = directory::contents(pathname); - for(auto &name : list) { - if(name.endswith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); - } - return _wrmdir(utf16_t(pathname)) == 0; - } - - inline bool directory::exists(const string &pathname) { - string name = pathname; - name.trim<1>("\""); - DWORD result = GetFileAttributes(utf16_t(name)); - if(result == INVALID_FILE_ATTRIBUTES) return false; - return (result & FILE_ATTRIBUTE_DIRECTORY); - } - - inline lstring directory::ufolders(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - while(FindNextFile(handle, &data) != false) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - } - FindClose(handle); - } - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::ufiles(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - while(FindNextFile(handle, &data) != false) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - FindClose(handle); - } - return list; - } -#else - inline bool directory::create(const string &pathname, unsigned permissions) { - string path; - lstring list = string{pathname}.rtrim<1>("/").split("/"); - bool result = true; - for(auto &part : list) { - path.append(part, "/"); - result &= (mkdir(path, permissions) == 0); - } - return result; - } - - inline bool directory::remove(const string &pathname) { - lstring list = directory::contents(pathname); - for(auto &name : list) { - if(name.endswith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); - } - return rmdir(pathname) == 0; - } - - inline bool directory::exists(const string &pathname) { - DIR *dp = opendir(pathname); - if(!dp) return false; - closedir(dp); - return true; - } - - inline lstring directory::ufolders(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if(ep->d_type & DT_DIR) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::ufiles(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if((ep->d_type & DT_DIR) == 0) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - return list; - } -#endif - -} - -#endif diff --git a/ananke/nall/dl.hpp b/ananke/nall/dl.hpp deleted file mode 100644 index 3bd7d4d2..00000000 --- a/ananke/nall/dl.hpp +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NALL_DL_HPP -#define NALL_DL_HPP - -//dynamic linking support - -#include -#include -#include -#include - -#if defined(PLATFORM_X) || defined(PLATFORM_OSX) - #include -#elif defined(PLATFORM_WINDOWS) - #include - #include -#endif - -namespace nall { - struct library { - bool opened() const { return handle; } - bool open(const char*, const char* = ""); - bool open_absolute(const char*); - void* sym(const char*); - void close(); - - library() : handle(0) {} - ~library() { close(); } - - library& operator=(const library&) = delete; - library(const library&) = delete; - - private: - uintptr_t handle; - }; - - #if defined(PLATFORM_X) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".so"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_OSX) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".dylib"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_WINDOWS) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - string filepath(path, *path && !strend(path, "/") && !strend(path, "\\") ? "\\" : "", name, ".dll"); - handle = (uintptr_t)LoadLibraryW(utf16_t(filepath)); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)LoadLibraryW(utf16_t(name)); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return (void*)GetProcAddress((HMODULE)handle, name); - } - - inline void library::close() { - if(!handle) return; - FreeLibrary((HMODULE)handle); - handle = 0; - } - #else - inline bool library::open(const char*, const char*) { return false; } - inline void* library::sym(const char*) { return 0; } - inline void library::close() {} - #endif -}; - -#endif diff --git a/ananke/nall/dsp/buffer.hpp b/ananke/nall/dsp/buffer.hpp deleted file mode 100644 index 4386d0e9..00000000 --- a/ananke/nall/dsp/buffer.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct Buffer { - double **sample; - uint16_t rdoffset; - uint16_t wroffset; - unsigned channels; - - void setChannels(unsigned channels) { - for(unsigned c = 0; c < this->channels; c++) { - if(sample[c]) delete[] sample[c]; - } - if(sample) delete[] sample; - - this->channels = channels; - if(channels == 0) return; - - sample = new double*[channels]; - for(unsigned c = 0; c < channels; c++) { - sample[c] = new double[65536](); - } - } - - inline double& read(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(rdoffset + offset)]; - } - - inline double& write(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(wroffset + offset)]; - } - - inline void clear() { - for(unsigned c = 0; c < channels; c++) { - for(unsigned n = 0; n < 65536; n++) { - sample[c][n] = 0; - } - } - rdoffset = 0; - wroffset = 0; - } - - Buffer() { - channels = 0; - } - - ~Buffer() { - setChannels(0); - } -}; - -#endif diff --git a/ananke/nall/dsp/core.hpp b/ananke/nall/dsp/core.hpp deleted file mode 100644 index a5b967b1..00000000 --- a/ananke/nall/dsp/core.hpp +++ /dev/null @@ -1,167 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include -#include - -namespace nall { - -//precision: can be float, double or long double -#define real float - -struct DSP; - -struct Resampler { - DSP &dsp; - real frequency; - - virtual void setFrequency() = 0; - virtual void clear() = 0; - virtual void sample() = 0; - Resampler(DSP &dsp) : dsp(dsp) {} -}; - -struct DSP { - enum class ResampleEngine : unsigned { - Nearest, - Linear, - Cosine, - Cubic, - Hermite, - Average, - Sinc, - }; - - inline void setChannels(unsigned channels); - inline void setPrecision(unsigned precision); - inline void setFrequency(real frequency); //inputFrequency - inline void setVolume(real volume); - inline void setBalance(real balance); - - inline void setResampler(ResampleEngine resamplingEngine); - inline void setResamplerFrequency(real frequency); //outputFrequency - - inline void sample(signed channel[]); - inline bool pending(); - inline void read(signed channel[]); - - inline void clear(); - inline DSP(); - inline ~DSP(); - -protected: - friend class ResampleNearest; - friend class ResampleLinear; - friend class ResampleCosine; - friend class ResampleCubic; - friend class ResampleAverage; - friend class ResampleHermite; - friend class ResampleSinc; - - struct Settings { - unsigned channels; - unsigned precision; - real frequency; - real volume; - real balance; - - //internal - real intensity; - real intensityInverse; - } settings; - - Resampler *resampler; - inline void write(real channel[]); - - #include "buffer.hpp" - Buffer buffer; - Buffer output; - - inline void adjustVolume(); - inline void adjustBalance(); - inline signed clamp(const unsigned bits, const signed x); -}; - -#include "resample/nearest.hpp" -#include "resample/linear.hpp" -#include "resample/cosine.hpp" -#include "resample/cubic.hpp" -#include "resample/hermite.hpp" -#include "resample/average.hpp" -#include "resample/sinc.hpp" -#include "settings.hpp" - -void DSP::sample(signed channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - buffer.write(c) = (real)channel[c] * settings.intensityInverse; - } - buffer.wroffset++; - resampler->sample(); -} - -bool DSP::pending() { - return output.rdoffset != output.wroffset; -} - -void DSP::read(signed channel[]) { - adjustVolume(); - adjustBalance(); - - for(unsigned c = 0; c < settings.channels; c++) { - channel[c] = clamp(settings.precision, output.read(c) * settings.intensity); - } - output.rdoffset++; -} - -void DSP::write(real channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - output.write(c) = channel[c]; - } - output.wroffset++; -} - -void DSP::adjustVolume() { - for(unsigned c = 0; c < settings.channels; c++) { - output.read(c) *= settings.volume; - } -} - -void DSP::adjustBalance() { - if(settings.channels != 2) return; //TODO: support > 2 channels - if(settings.balance < 0.0) output.read(1) *= 1.0 + settings.balance; - if(settings.balance > 0.0) output.read(0) *= 1.0 - settings.balance; -} - -signed DSP::clamp(const unsigned bits, const signed x) { - const signed b = 1U << (bits - 1); - const signed m = (1U << (bits - 1)) - 1; - return (x > m) ? m : (x < -b) ? -b : x; -} - -void DSP::clear() { - buffer.clear(); - output.clear(); - resampler->clear(); -} - -DSP::DSP() { - setResampler(ResampleEngine::Hermite); - setResamplerFrequency(44100.0); - - setChannels(2); - setPrecision(16); - setFrequency(44100.0); - setVolume(1.0); - setBalance(0.0); - - clear(); -} - -DSP::~DSP() { - if(resampler) delete resampler; -} - -#undef real - -} - -#endif diff --git a/ananke/nall/dsp/resample/average.hpp b/ananke/nall/dsp/resample/average.hpp deleted file mode 100644 index 867b13bf..00000000 --- a/ananke/nall/dsp/resample/average.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleAverage : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline void sampleLinear(); - ResampleAverage(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleAverage::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleAverage::clear() { - fraction = 0.0; -} - -void ResampleAverage::sample() { - //can only average if input frequency >= output frequency - if(step < 1.0) return sampleLinear(); - - fraction += 1.0; - - real scalar = 1.0; - if(fraction > step) scalar = 1.0 - (fraction - step); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) += dsp.buffer.read(c) * scalar; - } - - if(fraction >= step) { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) /= step; - } - dsp.output.wroffset++; - - fraction -= step; - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = dsp.buffer.read(c) * fraction; - } - } - - dsp.buffer.rdoffset++; -} - -void ResampleAverage::sampleLinear() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/cosine.hpp b/ananke/nall/dsp/resample/cosine.hpp deleted file mode 100644 index 3363d5f6..00000000 --- a/ananke/nall/dsp/resample/cosine.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCosine : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCosine(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCosine::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCosine::clear() { - fraction = 0.0; -} - -void ResampleCosine::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/cubic.hpp b/ananke/nall/dsp/resample/cubic.hpp deleted file mode 100644 index bc4cc955..00000000 --- a/ananke/nall/dsp/resample/cubic.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCubic : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCubic(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCubic::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCubic::clear() { - fraction = 0.0; -} - -void ResampleCubic::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - real mu = fraction; - - real A = d - c - a + b; - real B = a - b - A; - real C = c - a; - real D = b; - - channel[n] = A * (mu * 3) + B * (mu * 2) + C * mu + D; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/hermite.hpp b/ananke/nall/dsp/resample/hermite.hpp deleted file mode 100644 index 0cc9ba0e..00000000 --- a/ananke/nall/dsp/resample/hermite.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleHermite : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleHermite(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleHermite::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleHermite::clear() { - fraction = 0.0; -} - -void ResampleHermite::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - const real tension = 0.0; //-1 = low, 0 = normal, +1 = high - const real bias = 0.0; //-1 = left, 0 = even, +1 = right - - real mu1, mu2, mu3, m0, m1, a0, a1, a2, a3; - - mu1 = fraction; - mu2 = mu1 * mu1; - mu3 = mu2 * mu1; - - m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - a0 = +2 * mu3 - 3 * mu2 + 1; - a1 = mu3 - 2 * mu2 + mu1; - a2 = mu3 - mu2; - a3 = -2 * mu3 + 3 * mu2; - - channel[n] = (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c); - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/lib/sinc.hpp b/ananke/nall/dsp/resample/lib/sinc.hpp deleted file mode 100644 index 3e953679..00000000 --- a/ananke/nall/dsp/resample/lib/sinc.hpp +++ /dev/null @@ -1,600 +0,0 @@ -// If these types are changed to anything other than "float", you should comment out the SSE detection directives below -// so that the SSE code is not used. - -typedef float resample_coeff_t; // note: sizeof(resample_coeff_t) must be == to a power of 2, and not larger than 16 -typedef float resample_samp_t; - - -// ...but don't comment this single RESAMPLE_SSEREGPARM define out when disabling SSE. -#define RESAMPLE_SSEREGPARM - -#if defined(__SSE__) - #define SINCRESAMPLE_USE_SSE 1 - #ifndef __x86_64__ - #undef RESAMPLE_SSEREGPARM - #define RESAMPLE_SSEREGPARM __attribute__((sseregparm)) - #endif -#else - // TODO: altivec here -#endif - -namespace ResampleUtility -{ - inline void kaiser_window(double* io, int count, double beta); - inline void gen_sinc(double* out, int size, double cutoff, double kaiser); - inline void gen_sinc_os(double* out, int size, double cutoff, double kaiser); - inline void normalize(double* io, int size, double gain = 1.0); - - inline void* make_aligned(void* ptr, unsigned boundary); // boundary must be a power of 2 -} - -class SincResampleHR -{ - private: - - inline void Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count); - - unsigned ratio; - unsigned num_convolutions; - - resample_coeff_t *coeffs; - std::vector coeffs_mem; - - // second half of ringbuffer should be copy of first half. - resample_samp_t *rb; - std::vector rb_mem; - - signed rb_readpos; - signed rb_writepos; - signed rb_in; - signed rb_eff_size; - - friend class SincResample; -}; - -class SincResample -{ - public: - - enum - { - QUALITY_LOW = 0, - QUALITY_MEDIUM = 2, - QUALITY_HIGH = 4 - }; - - inline SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality = QUALITY_HIGH); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline void Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min); - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) RESAMPLE_SSEREGPARM; - - unsigned num_convolutions; - unsigned num_phases; - - unsigned step_int; - double step_fract; - - double input_pos_fract; - - - std::vector coeffs; // Pointers into coeff_mem. - std::vector coeff_mem; - - - std::vector rb; // second half should be copy of first half. - signed rb_readpos; - signed rb_writepos; - signed rb_in; - - bool hr_used; - SincResampleHR hr; -}; - - -// -// Code: -// -//#include "resample.hpp" - -#if 0 -namespace bit -{ - inline unsigned round(unsigned x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } -} -#endif - -void SincResampleHR::Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d) -{ - const unsigned align_boundary = 16; - std::vector coeffs_tmp; - double cutoff; // 1.0 = f/2 - - ratio = ratio_arg; - - //num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) + 1) &~ 1; // round up to be even - num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) | 1); - - cutoff = (1.0 / ratio) - (d / num_convolutions); - -//printf("%d %d %.20f\n", ratio, num_convolutions, cutoff); - assert(num_convolutions > ratio); - - - // Generate windowed sinc of POWER - coeffs_tmp.resize(num_convolutions); - //ResampleUtility::gen_sinc(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::gen_sinc_os(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeffs_tmp[0], num_convolutions); - - // Copy from coeffs_tmp to coeffs~ - // We multiply many coefficients at a time in the mac loop, so make sure the last few that don't really - // exist are allocated, zero'd mem. - - coeffs_mem.resize(((num_convolutions + 7) &~ 7) * sizeof(resample_coeff_t) + (align_boundary - 1)); - coeffs = (resample_coeff_t *)ResampleUtility::make_aligned(&coeffs_mem[0], align_boundary); - - - for(unsigned i = 0; i < num_convolutions; i++) - coeffs[i] = coeffs_tmp[i]; - - rb_eff_size = nall::bit::round(num_convolutions * 2) >> 1; - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; - - rb_mem.resize(rb_eff_size * 2 * sizeof(resample_samp_t) + (align_boundary - 1)); - rb = (resample_samp_t *)ResampleUtility::make_aligned(&rb_mem[0], align_boundary); -} - - -inline bool SincResampleHR::output_avail(void) -{ - return(rb_in >= (signed)num_convolutions); -} - -inline void SincResampleHR::write(resample_samp_t sample) -{ - assert(!output_avail()); - - rb[rb_writepos] = sample; - rb[rb_writepos + rb_eff_size] = sample; - rb_writepos = (rb_writepos + 1) & (rb_eff_size - 1); - rb_in++; -} - -resample_samp_t SincResampleHR::mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count) -{ -#if SINCRESAMPLE_USE_SSE - __m128 accum_veca[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - resample_samp_t accum; - - for(unsigned c = 0; c < count; c += 8) - { - for(unsigned i = 0; i < 2; i++) - { - __m128 co[2]; - __m128 w[2]; - - co[i] = _mm_load_ps(&coeff[c + i * 4]); - w[i] = _mm_load_ps(&wave[c + i * 4]); - - w[i] = _mm_mul_ps(w[i], co[i]); - - accum_veca[i] = _mm_add_ps(w[i], accum_veca[i]); - } - } - - __m128 accum_vec = _mm_add_ps(accum_veca[0], accum_veca[1]); //_mm_add_ps(_mm_add_ps(accum_veca[0], accum_veca[1]), _mm_add_ps(accum_veca[2], accum_veca[3])); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); - - return accum; -#else - resample_samp_t accum[4] = { 0, 0, 0, 0 }; - - for(unsigned c = 0; c < count; c+= 4) - { - accum[0] += wave[c + 0] * coeff[c + 0]; - accum[1] += wave[c + 1] * coeff[c + 1]; - accum[2] += wave[c + 2] * coeff[c + 2]; - accum[3] += wave[c + 3] * coeff[c + 3]; - } - - return (accum[0] + accum[1]) + (accum[2] + accum[3]); // don't mess with parentheses(assuming compiler doesn't already, which it may... - -#endif -} - - -resample_samp_t SincResampleHR::read(void) -{ - assert(output_avail()); - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[0], num_convolutions); - - rb_readpos = (rb_readpos + ratio) & (rb_eff_size - 1); - rb_in -= ratio; - - return ret; -} - - -SincResample::SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality) -{ - const struct - { - double beta; - double d; - unsigned pn_nume; - unsigned phases_min; - } qtab[5] = - { - { 5.658, 3.62, 4096, 4 }, - { 6.764, 4.32, 8192, 4 }, - { 7.865, 5.0, 16384, 8 }, - { 8.960, 5.7, 32768, 16 }, - { 10.056, 6.4, 65536, 32 } - }; - - // Sanity checks - assert(ceil(input_rate) > 0); - assert(ceil(output_rate) > 0); - assert(ceil(input_rate / output_rate) <= 1024); - assert(ceil(output_rate / input_rate) <= 1024); - - // The simplistic number-of-phases calculation code doesn't work well enough for when desired_bandwidth is close to 1.0 and when - // upsampling. - assert(desired_bandwidth >= 0.25 && desired_bandwidth < 0.96); - assert(quality >= 0 && quality <= 4); - - hr_used = false; - -#if 1 - // Round down to the nearest multiple of 4(so wave buffer remains aligned) - // It also adjusts the effective intermediate sampling rate up slightly, so that the upper frequencies below f/2 - // aren't overly attenuated so much. In the future, we might want to do an FFT or something to choose the intermediate rate more accurately - // to virtually eliminate over-attenuation. - unsigned ioratio_rd = (unsigned)floor(input_rate / (output_rate * (1.0 + (1.0 - desired_bandwidth) / 2) )) & ~3; - - if(ioratio_rd >= 8) - { - hr.Init(ioratio_rd, desired_bandwidth, qtab[quality].beta, qtab[quality].d); //10.056, 6.4); - hr_used = true; - - input_rate /= ioratio_rd; - } -#endif - - Init(input_rate, output_rate, desired_bandwidth, qtab[quality].beta, qtab[quality].d, qtab[quality].pn_nume, qtab[quality].phases_min); -} - -void SincResample::Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min) -{ - const unsigned max_mult_atatime = 8; // multiply "granularity". must be power of 2. - const unsigned max_mult_minus1 = (max_mult_atatime - 1); - const unsigned conv_alignment_bytes = 16; // must be power of 2 - const double input_to_output_ratio = input_rate / output_rate; - const double output_to_input_ratio = output_rate / input_rate; - double cutoff; // 1.0 = input_rate / 2 - std::vector coeff_init_buffer; - - // Round up num_convolutions to be even. - if(output_rate > input_rate) - num_convolutions = ((unsigned)ceil(d / (1.0 - desired_bandwidth)) + 1) & ~1; - else - num_convolutions = ((unsigned)ceil(d / (output_to_input_ratio * (1.0 - desired_bandwidth))) + 1) & ~1; - - if(output_rate > input_rate) // Upsampling - cutoff = desired_bandwidth; - else // Downsampling - cutoff = output_to_input_ratio * desired_bandwidth; - - // Round up to be even. - num_phases = (std::max(pn_nume / num_convolutions, phases_min) + 1) &~1; - - // Adjust cutoff to account for the multiple phases. - cutoff = cutoff / num_phases; - - assert((num_convolutions & 1) == 0); - assert((num_phases & 1) == 0); - -// fprintf(stderr, "num_convolutions=%u, num_phases=%u, total expected coeff byte size=%lu\n", num_convolutions, num_phases, -// (long)((num_phases + 2) * ((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * sizeof(float) + conv_alignment_bytes)); - - coeff_init_buffer.resize(num_phases * num_convolutions); - - coeffs.resize(num_phases + 1 + 1); - - coeff_mem.resize((num_phases + 1 + 1) * ((num_convolutions + max_mult_minus1) &~ max_mult_minus1) * sizeof(resample_coeff_t) + conv_alignment_bytes); - - // Assign aligned pointers into coeff_mem - { - resample_coeff_t *base_ptr = (resample_coeff_t *)ResampleUtility::make_aligned(&coeff_mem[0], conv_alignment_bytes); - - for(unsigned phase = 0; phase < (num_phases + 1 + 1); phase++) - { - coeffs[phase] = base_ptr + (((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * phase); - } - } - - ResampleUtility::gen_sinc(&coeff_init_buffer[0], num_phases * num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeff_init_buffer[0], num_phases * num_convolutions, num_phases); - - // Reorder coefficients to allow for more efficient convolution. - for(int phase = -1; phase < ((int)num_phases + 1); phase++) - { - for(int conv = 0; conv < (int)num_convolutions; conv++) - { - double coeff; - - if(phase == -1 && conv == 0) - coeff = 0; - else if(phase == (int)num_phases && conv == ((int)num_convolutions - 1)) - coeff = 0; - else - coeff = coeff_init_buffer[conv * num_phases + phase]; - - coeffs[phase + 1][conv] = coeff; - } - } - - // Free a bit of mem - coeff_init_buffer.resize(0); - - step_int = floor(input_to_output_ratio); - step_fract = input_to_output_ratio - step_int; - - input_pos_fract = 0; - - // Do NOT use rb.size() later in the code, since it'll include the padding. - // We should only need one "max_mult_minus1" here, not two, since it won't matter if it over-reads(due to doing "max_mult_atatime" multiplications at a time - // rather than just 1, in which case this over-read wouldn't happen), from the first half into the duplicated half, - // since those corresponding coefficients will be zero anyway; this is just to handle the case of reading off the end of the duplicated half to - // prevent illegal memory accesses. - rb.resize(num_convolutions * 2 + max_mult_minus1); - - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; -} - -resample_samp_t SincResample::mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) -{ - resample_samp_t accum = 0; -#if SINCRESAMPLE_USE_SSE - __m128 accum_vec_a[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - __m128 accum_vec_b[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - for(unsigned c = 0; c < count; c += 8) //8) //4) - { - __m128 coeff_a[2]; - __m128 coeff_b[2]; - __m128 w[2]; - __m128 result_a[2], result_b[2]; - - for(unsigned i = 0; i < 2; i++) - { - coeff_a[i] = _mm_load_ps(&coeffs_a[c + (i * 4)]); - coeff_b[i] = _mm_load_ps(&coeffs_b[c + (i * 4)]); - w[i] = _mm_loadu_ps(&wave[c + (i * 4)]); - - result_a[i] = _mm_mul_ps(coeff_a[i], w[i]); - result_b[i] = _mm_mul_ps(coeff_b[i], w[i]); - - accum_vec_a[i] = _mm_add_ps(result_a[i], accum_vec_a[i]); - accum_vec_b[i] = _mm_add_ps(result_b[i], accum_vec_b[i]); - } - } - - __m128 accum_vec, av_a, av_b; - __m128 mult_a_vec = _mm_set1_ps(1.0 - ffract); - __m128 mult_b_vec = _mm_set1_ps(ffract); - - av_a = _mm_mul_ps(mult_a_vec, /*accum_vec_a[0]);*/ _mm_add_ps(accum_vec_a[0], accum_vec_a[1])); - av_b = _mm_mul_ps(mult_b_vec, /*accum_vec_b[0]);*/ _mm_add_ps(accum_vec_b[0], accum_vec_b[1])); - - accum_vec = _mm_add_ps(av_a, av_b); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); -#else - resample_coeff_t mult_a = 1.0 - ffract; - resample_coeff_t mult_b = ffract; - - for(unsigned c = 0; c < count; c += 4) - { - accum += wave[c + 0] * (coeffs_a[c + 0] * mult_a + coeffs_b[c + 0] * mult_b); - accum += wave[c + 1] * (coeffs_a[c + 1] * mult_a + coeffs_b[c + 1] * mult_b); - accum += wave[c + 2] * (coeffs_a[c + 2] * mult_a + coeffs_b[c + 2] * mult_b); - accum += wave[c + 3] * (coeffs_a[c + 3] * mult_a + coeffs_b[c + 3] * mult_b); - } -#endif - - return accum; -} - -inline bool SincResample::output_avail(void) -{ - return(rb_in >= (int)num_convolutions); -} - -resample_samp_t SincResample::read(void) -{ - assert(output_avail()); - double phase = input_pos_fract * num_phases - 0.5; - signed phase_int = (signed)floor(phase); - double phase_fract = phase - phase_int; - unsigned phase_a = num_phases - 1 - phase_int; - unsigned phase_b = phase_a - 1; - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[phase_a + 1][0], &coeffs[phase_b + 1][0], phase_fract, num_convolutions); - - unsigned int_increment = step_int; - - input_pos_fract += step_fract; - int_increment += floor(input_pos_fract); - input_pos_fract -= floor(input_pos_fract); - - rb_readpos = (rb_readpos + int_increment) % num_convolutions; - rb_in -= int_increment; - - return ret; -} - -inline void SincResample::write(resample_samp_t sample) -{ - assert(!output_avail()); - - if(hr_used) - { - hr.write(sample); - - if(hr.output_avail()) - { - sample = hr.read(); - } - else - { - return; - } - } - - rb[rb_writepos + 0 * num_convolutions] = sample; - rb[rb_writepos + 1 * num_convolutions] = sample; - rb_writepos = (rb_writepos + 1) % num_convolutions; - rb_in++; -} - -void ResampleUtility::kaiser_window( double* io, int count, double beta) -{ - int const accuracy = 24; //16; //12; - - double* end = io + count; - - double beta2 = beta * beta * (double) -0.25; - double to_fract = beta2 / ((double) count * count); - double i = 0; - double rescale = 0; // Doesn't need an initializer, to shut up gcc - - for ( ; io < end; ++io, i += 1 ) - { - double x = i * i * to_fract - beta2; - double u = x; - double k = x + 1; - - double n = 2; - do - { - u *= x / (n * n); - n += 1; - k += u; - } - while ( k <= u * (1 << accuracy) ); - - if ( !i ) - rescale = 1 / k; // otherwise values get large - - *io *= k * rescale; - } -} - -void ResampleUtility::gen_sinc(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 0 ); // size must be even - - int const half_size = size / 2; - double* const mid = &out [half_size]; - - // Generate right half of sinc - for ( int i = 0; i < half_size; i++ ) - { - double angle = (i * 2 + 1) * (M_PI / 2); - mid [i] = sin( angle * cutoff ) / angle; - } - - kaiser_window( mid, half_size, kaiser ); - - // Mirror for left half - for ( int i = 0; i < half_size; i++ ) - out [i] = mid [half_size - 1 - i]; -} - -void ResampleUtility::gen_sinc_os(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 1); // size must be odd - - for(int i = 0; i < size; i++) - { - if(i == (size / 2)) - out[i] = 2 * M_PI * (cutoff / 2); //0.078478; //1.0; //sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - else - out[i] = sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - -// out[i] *= 0.3635819 - 0.4891775 * cos(2 * M_PI * i / (size - 1)) + 0.1365995 * cos(4 * M_PI * i / (size - 1)) - 0.0106411 * cos(6 * M_PI * i / (size - 1)); -//0.42 - 0.5 * cos(2 * M_PI * i / (size - 1)) + 0.08 * cos(4 * M_PI * i / (size - 1)); - -// printf("%d %f\n", i, out[i]); - } - - kaiser_window(&out[size / 2], size / 2 + 1, kaiser); - - // Mirror for left half - for ( int i = 0; i < size / 2; i++ ) - out [i] = out [size - 1 - i]; - -} - -void ResampleUtility::normalize(double* io, int size, double gain) -{ - double sum = 0; - for ( int i = 0; i < size; i++ ) - sum += io [i]; - - double scale = gain / sum; - for ( int i = 0; i < size; i++ ) - io [i] *= scale; -} - -void* ResampleUtility::make_aligned(void* ptr, unsigned boundary) -{ - unsigned char* null_ptr = (unsigned char *)NULL; - unsigned char* uc_ptr = (unsigned char *)ptr; - - uc_ptr += (boundary - ((uc_ptr - null_ptr) & (boundary - 1))) & (boundary - 1); - - //while((uc_ptr - null_ptr) & (boundary - 1)) - // uc_ptr++; - - //printf("%16llx %16llx\n", (unsigned long long)ptr, (unsigned long long)uc_ptr); - - assert((uc_ptr - (unsigned char *)ptr) < boundary && (uc_ptr >= (unsigned char *)ptr)); - - return uc_ptr; -} diff --git a/ananke/nall/dsp/resample/linear.hpp b/ananke/nall/dsp/resample/linear.hpp deleted file mode 100644 index 3c2dc9e6..00000000 --- a/ananke/nall/dsp/resample/linear.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleLinear : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleLinear(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleLinear::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleLinear::clear() { - fraction = 0.0; -} - -void ResampleLinear::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/nearest.hpp b/ananke/nall/dsp/resample/nearest.hpp deleted file mode 100644 index 14b401eb..00000000 --- a/ananke/nall/dsp/resample/nearest.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleNearest : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleNearest(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleNearest::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleNearest::clear() { - fraction = 0.0; -} - -void ResampleNearest::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = mu < 0.5 ? a : b; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/ananke/nall/dsp/resample/sinc.hpp b/ananke/nall/dsp/resample/sinc.hpp deleted file mode 100644 index a77a1eeb..00000000 --- a/ananke/nall/dsp/resample/sinc.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include "lib/sinc.hpp" - -struct ResampleSinc : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline ResampleSinc(DSP &dsp); - -private: - inline void remakeSinc(); - SincResample *sinc_resampler[8]; -}; - -void ResampleSinc::setFrequency() { - remakeSinc(); -} - -void ResampleSinc::clear() { - remakeSinc(); -} - -void ResampleSinc::sample() { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - sinc_resampler[c]->write(dsp.buffer.read(c)); - } - - if(sinc_resampler[0]->output_avail()) { - do { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = sinc_resampler[c]->read(); - } - dsp.output.wroffset++; - } while(sinc_resampler[0]->output_avail()); - } - - dsp.buffer.rdoffset++; -} - -ResampleSinc::ResampleSinc(DSP &dsp) : Resampler(dsp) { - for(unsigned n = 0; n < 8; n++) sinc_resampler[n] = 0; -} - -void ResampleSinc::remakeSinc() { - assert(dsp.settings.channels < 8); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - if(sinc_resampler[c]) delete sinc_resampler[c]; - sinc_resampler[c] = new SincResample(dsp.settings.frequency, frequency, 0.85, SincResample::QUALITY_HIGH); - } -} - -#endif diff --git a/ananke/nall/emulation/super-famicom-usart.hpp b/ananke/nall/emulation/super-famicom-usart.hpp deleted file mode 100644 index 68dea605..00000000 --- a/ananke/nall/emulation/super-famicom-usart.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_EMULATION_SUPER_FAMICOM_USART_HPP -#define NALL_EMULATION_SUPER_FAMICOM_USART_HPP - -#include -#include -#include -#include - -#include -#include -#include - -#define usartproc dllexport - -static nall::function usart_quit; -static nall::function usart_usleep; -static nall::function usart_readable; -static nall::function usart_read; -static nall::function usart_writable; -static nall::function usart_write; - -extern "C" usartproc void usart_init( - nall::function quit, - nall::function usleep, - nall::function readable, - nall::function read, - nall::function writable, - nall::function write -) { - usart_quit = quit; - usart_usleep = usleep; - usart_readable = readable; - usart_read = read; - usart_writable = writable; - usart_write = write; -} - -extern "C" usartproc void usart_main(int, char**); - -// - -static nall::serial usart; -static bool usart_is_virtual = true; -static bool usart_sigint = false; - -static bool usart_virtual() { - return usart_is_virtual; -} - -// - -static bool usarthw_quit() { - return usart_sigint; -} - -static void usarthw_usleep(unsigned milliseconds) { - usleep(milliseconds); -} - -static bool usarthw_readable() { - return usart.readable(); -} - -static uint8_t usarthw_read() { - while(true) { - uint8_t buffer[1]; - signed length = usart.read((uint8_t*)&buffer, 1); - if(length > 0) return buffer[0]; - } -} - -static bool usarthw_writable() { - return usart.writable(); -} - -static void usarthw_write(uint8_t data) { - uint8_t buffer[1] = { data }; - usart.write((uint8_t*)&buffer, 1); -} - -static void sigint(int) { - signal(SIGINT, SIG_DFL); - usart_sigint = true; -} - -int main(int argc, char **argv) { - setpriority(PRIO_PROCESS, 0, -20); //requires superuser privileges; otherwise priority = +0 - signal(SIGINT, sigint); - - if(usart.open("/dev/ttyACM0", 57600, true) == false) { - printf("error: unable to open USART hardware device\n"); - return 0; - } - - usart_is_virtual = false; - usart_init(usarthw_quit, usarthw_usleep, usarthw_readable, usarthw_read, usarthw_writable, usarthw_write); - usart_main(argc, argv); - usart.close(); - - return 0; -} - -#endif diff --git a/ananke/nall/file.hpp b/ananke/nall/file.hpp deleted file mode 100644 index 80b918a8..00000000 --- a/ananke/nall/file.hpp +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef NALL_FILE_HPP -#define NALL_FILE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - inline FILE* fopen_utf8(const string &utf8_filename, const char *mode) { - #if !defined(_WIN32) - return fopen(utf8_filename, mode); - #else - return _wfopen(utf16_t(utf8_filename), utf16_t(mode)); - #endif - } - - struct file { - enum class mode : unsigned { read, write, modify, append, readwrite = modify, writeread = append }; - enum class index : unsigned { absolute, relative }; - enum class time : unsigned { create, modify, access }; - - static bool copy(const string &sourcename, const string &targetname) { - file rd, wr; - if(rd.open(sourcename, mode::read) == false) return false; - if(wr.open(targetname, mode::write) == false) return false; - for(unsigned n = 0; n < rd.size(); n++) wr.write(rd.read()); - return true; - } - - static bool move(const string &sourcename, const string &targetname) { - #if !defined(_WIN32) - return rename(sourcename, targetname) == 0; - #else - return _wrename(utf16_t(sourcename), utf16_t(targetname)) == 0; - #endif - } - - static bool remove(const string &filename) { - return unlink(filename) == 0; - } - - static bool truncate(const string &filename, unsigned size) { - #if !defined(_WIN32) - return truncate(filename, size) == 0; - #else - bool result = false; - FILE *fp = fopen(filename, "rb+"); - if(fp) { - result = _chsize(fileno(fp), size) == 0; - fclose(fp); - } - return result; - #endif - } - - static vector read(const string &filename) { - vector memory; - file fp; - if(fp.open(filename, mode::read)) { - memory.resize(fp.size()); - fp.read(memory.data(), memory.size()); - } - return memory; - } - - static bool read(const string &filename, uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::read) == false) return false; - fp.read(data, size); - fp.close(); - return true; - } - - static bool write(const string &filename, const string &text) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.print(text); - fp.close(); - return true; - } - - static bool write(const string &filename, const vector &buffer) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.write(buffer.data(), buffer.size()); - fp.close(); - return true; - } - - static bool write(const string &filename, const uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.write(data, size); - fp.close(); - return true; - } - - static bool create(const string &filename) { - //create an empty file (will replace existing files) - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.close(); - return true; - } - - static string sha256(const string &filename) { - auto buffer = read(filename); - return nall::sha256(buffer.data(), buffer.size()); - } - - uint8_t read() { - if(!fp) return 0xff; //file not open - if(file_mode == mode::write) return 0xff; //reads not permitted - if(file_offset >= file_size) return 0xff; //cannot read past end of file - buffer_sync(); - return buffer[(file_offset++) & buffer_mask]; - } - - uintmax_t readl(unsigned length = 1) { - uintmax_t data = 0; - for(int i = 0; i < length; i++) { - data |= (uintmax_t)read() << (i << 3); - } - return data; - } - - uintmax_t readm(unsigned length = 1) { - uintmax_t data = 0; - while(length--) { - data <<= 8; - data |= read(); - } - return data; - } - - void read(uint8_t *buffer, unsigned length) { - while(length--) *buffer++ = read(); - } - - void write(uint8_t data) { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //writes not permitted - buffer_sync(); - buffer[(file_offset++) & buffer_mask] = data; - buffer_dirty = true; - if(file_offset > file_size) file_size = file_offset; - } - - void writel(uintmax_t data, unsigned length = 1) { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) { - for(int i = length - 1; i >= 0; i--) { - write(data >> (i << 3)); - } - } - - void write(const uint8_t *buffer, unsigned length) { - while(length--) write(*buffer++); - } - - template void print(Args... args) { - string data(args...); - const char *p = data; - while(*p) write(*p++); - } - - void flush() { - buffer_flush(); - fflush(fp); - } - - void seek(int offset, index index_ = index::absolute) { - if(!fp) return; //file not open - buffer_flush(); - - uintmax_t req_offset = file_offset; - switch(index_) { - case index::absolute: req_offset = offset; break; - case index::relative: req_offset += offset; break; - } - - if(req_offset < 0) req_offset = 0; //cannot seek before start of file - if(req_offset > file_size) { - if(file_mode == mode::read) { //cannot seek past end of file - req_offset = file_size; - } else { //pad file to requested location - file_offset = file_size; - while(file_size < req_offset) write(0x00); - } - } - - file_offset = req_offset; - } - - unsigned offset() const { - if(!fp) return 0; //file not open - return file_offset; - } - - unsigned size() const { - if(!fp) return 0; //file not open - return file_size; - } - - bool truncate(unsigned size) { - if(!fp) return false; //file not open - #if !defined(_WIN32) - return ftruncate(fileno(fp), size) == 0; - #else - return _chsize(fileno(fp), size) == 0; - #endif - } - - bool end() { - if(!fp) return true; //file not open - return file_offset >= file_size; - } - - static bool exists(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - return stat64(filename, &data) == 0; - #else - struct __stat64 data; - return _wstat64(utf16_t(filename), &data) == 0; - #endif - } - - static uintmax_t size(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - return S_ISREG(data.st_mode) ? data.st_size : 0u; - } - - static time_t timestamp(const string &filename, file::time mode = file::time::create) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - switch(mode) { default: - case file::time::create: return data.st_ctime; - case file::time::modify: return data.st_mtime; - case file::time::access: return data.st_atime; - } - } - - bool open() const { - return fp; - } - - bool open(const string &filename, mode mode_) { - if(fp) return false; - - switch(file_mode = mode_) { - #if !defined(_WIN32) - case mode::read: fp = fopen(filename, "rb" ); break; - case mode::write: fp = fopen(filename, "wb+"); break; //need read permission for buffering - case mode::readwrite: fp = fopen(filename, "rb+"); break; - case mode::writeread: fp = fopen(filename, "wb+"); break; - #else - case mode::read: fp = _wfopen(utf16_t(filename), L"rb" ); break; - case mode::write: fp = _wfopen(utf16_t(filename), L"wb+"); break; - case mode::readwrite: fp = _wfopen(utf16_t(filename), L"rb+"); break; - case mode::writeread: fp = _wfopen(utf16_t(filename), L"wb+"); break; - #endif - } - if(!fp) return false; - buffer_offset = -1; //invalidate buffer - file_offset = 0; - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - return true; - } - - void close() { - if(!fp) return; - buffer_flush(); - fclose(fp); - fp = 0; - } - - file() { - memset(buffer, 0, sizeof buffer); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - fp = 0; - file_offset = 0; - file_size = 0; - file_mode = mode::read; - } - - ~file() { - close(); - } - - file& operator=(const file&) = delete; - file(const file&) = delete; - - private: - enum { buffer_size = 1 << 12, buffer_mask = buffer_size - 1 }; - char buffer[buffer_size]; - int buffer_offset; - bool buffer_dirty; - FILE *fp; - unsigned file_offset; - unsigned file_size; - mode file_mode; - - void buffer_sync() { - if(!fp) return; //file not open - if(buffer_offset != (file_offset & ~buffer_mask)) { - buffer_flush(); - buffer_offset = file_offset & ~buffer_mask; - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fread(buffer, 1, length, fp); - } - } - - void buffer_flush() { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //buffer cannot be written to - if(buffer_offset < 0) return; //buffer unused - if(buffer_dirty == false) return; //buffer unmodified since read - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fwrite(buffer, 1, length, fp); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - } - }; -} - -#endif diff --git a/ananke/nall/filemap.hpp b/ananke/nall/filemap.hpp deleted file mode 100644 index f57d933c..00000000 --- a/ananke/nall/filemap.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifndef NALL_FILEMAP_HPP -#define NALL_FILEMAP_HPP - -#include -#include -#include - -#include -#include -#if defined(_WIN32) - #include -#else - #include - #include - #include - #include - #include -#endif - -namespace nall { - class filemap { - public: - enum class mode : unsigned { read, write, readwrite, writeread }; - - bool open() const { return p_open(); } - bool open(const char *filename, mode mode_) { return p_open(filename, mode_); } - void close() { return p_close(); } - unsigned size() const { return p_size; } - uint8_t* data() { return p_handle; } - const uint8_t* data() const { return p_handle; } - filemap() : p_size(0), p_handle(0) { p_ctor(); } - filemap(const char *filename, mode mode_) : p_size(0), p_handle(0) { p_ctor(); p_open(filename, mode_); } - ~filemap() { p_dtor(); } - - private: - unsigned p_size; - uint8_t *p_handle; - - #if defined(_WIN32) - //============= - //MapViewOfFile - //============= - - HANDLE p_filehandle, p_maphandle; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int desired_access, creation_disposition, flprotect, map_access; - - switch(mode_) { - default: return false; - case mode::read: - desired_access = GENERIC_READ; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READONLY; - map_access = FILE_MAP_READ; - break; - case mode::write: - //write access requires read access - desired_access = GENERIC_WRITE; - creation_disposition = CREATE_ALWAYS; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::readwrite: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::writeread: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = CREATE_NEW; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - } - - p_filehandle = CreateFileW(utf16_t(filename), desired_access, FILE_SHARE_READ, NULL, - creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL); - if(p_filehandle == INVALID_HANDLE_VALUE) return false; - - p_size = GetFileSize(p_filehandle, NULL); - - p_maphandle = CreateFileMapping(p_filehandle, NULL, flprotect, 0, p_size, NULL); - if(p_maphandle == INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - return false; - } - - p_handle = (uint8_t*)MapViewOfFile(p_maphandle, map_access, 0, 0, p_size); - return p_handle; - } - - void p_close() { - if(p_handle) { - UnmapViewOfFile(p_handle); - p_handle = 0; - } - - if(p_maphandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_maphandle); - p_maphandle = INVALID_HANDLE_VALUE; - } - - if(p_filehandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - } - } - - void p_ctor() { - p_filehandle = INVALID_HANDLE_VALUE; - p_maphandle = INVALID_HANDLE_VALUE; - } - - void p_dtor() { - close(); - } - - #else - //==== - //mmap - //==== - - int p_fd; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int open_flags, mmap_flags; - - switch(mode_) { - default: return false; - case mode::read: - open_flags = O_RDONLY; - mmap_flags = PROT_READ; - break; - case mode::write: - open_flags = O_RDWR | O_CREAT; //mmap() requires read access - mmap_flags = PROT_WRITE; - break; - case mode::readwrite: - open_flags = O_RDWR; - mmap_flags = PROT_READ | PROT_WRITE; - break; - case mode::writeread: - open_flags = O_RDWR | O_CREAT; - mmap_flags = PROT_READ | PROT_WRITE; - break; - } - - p_fd = ::open(filename, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); - if(p_fd < 0) return false; - - struct stat p_stat; - fstat(p_fd, &p_stat); - p_size = p_stat.st_size; - - p_handle = (uint8_t*)mmap(0, p_size, mmap_flags, MAP_SHARED, p_fd, 0); - if(p_handle == MAP_FAILED) { - p_handle = 0; - ::close(p_fd); - p_fd = -1; - return false; - } - - return p_handle; - } - - void p_close() { - if(p_handle) { - munmap(p_handle, p_size); - p_handle = 0; - } - - if(p_fd >= 0) { - ::close(p_fd); - p_fd = -1; - } - } - - void p_ctor() { - p_fd = -1; - } - - void p_dtor() { - p_close(); - } - - #endif - }; -} - -#endif diff --git a/ananke/nall/function.hpp b/ananke/nall/function.hpp deleted file mode 100644 index ca574b8c..00000000 --- a/ananke/nall/function.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef NALL_FUNCTION_HPP -#define NALL_FUNCTION_HPP - -namespace nall { - template class function; - - template class function { - struct container { - virtual R operator()(P... p) const = 0; - virtual container* copy() const = 0; - virtual ~container() {} - } *callback; - - struct global : container { - R (*function)(P...); - R operator()(P... p) const { return function(std::forward

(p)...); } - container* copy() const { return new global(function); } - global(R (*function)(P...)) : function(function) {} - }; - - template struct member : container { - R (C::*function)(P...); - C *object; - R operator()(P... p) const { return (object->*function)(std::forward

(p)...); } - container* copy() const { return new member(function, object); } - member(R (C::*function)(P...), C *object) : function(function), object(object) {} - }; - - template struct lambda : container { - mutable L object; - R operator()(P... p) const { return object(std::forward

(p)...); } - container* copy() const { return new lambda(object); } - lambda(const L& object) : object(object) {} - }; - - public: - operator bool() const { return callback; } - R operator()(P... p) const { return (*callback)(std::forward

(p)...); } - void reset() { if(callback) { delete callback; callback = nullptr; } } - - function& operator=(const function &source) { - if(this != &source) { - if(callback) { delete callback; callback = nullptr; } - if(source.callback) callback = source.callback->copy(); - } - return *this; - } - - function(const function &source) : callback(nullptr) { operator=(source); } - function() : callback(nullptr) {} - function(void *function) : callback(nullptr) { if(function) callback = new global((R (*)(P...))function); } - function(R (*function)(P...)) { callback = new global(function); } - template function(R (C::*function)(P...), C *object) { callback = new member(function, object); } - template function(R (C::*function)(P...) const, C *object) { callback = new member((R (C::*)(P...))function, object); } - template function(const L& object) { callback = new lambda(object); } - ~function() { if(callback) delete callback; } - }; -} - -#endif diff --git a/ananke/nall/gzip.hpp b/ananke/nall/gzip.hpp deleted file mode 100644 index a72a3faf..00000000 --- a/ananke/nall/gzip.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef NALL_GZIP_HPP -#define NALL_GZIP_HPP - -#include -#include - -namespace nall { - -struct gzip { - string filename; - uint8_t *data; - unsigned size; - - inline bool decompress(const string &filename); - inline bool decompress(const uint8_t *data, unsigned size); - - inline gzip(); - inline ~gzip(); -}; - -bool gzip::decompress(const string &filename) { - if(auto memory = file::read(filename)) { - return decompress(memory.data(), memory.size()); - } - return false; -} - -bool gzip::decompress(const uint8_t *data, unsigned size) { - if(size < 18) return false; - if(data[0] != 0x1f) return false; - if(data[1] != 0x8b) return false; - unsigned cm = data[2]; - unsigned flg = data[3]; - unsigned mtime = data[4]; - mtime |= data[5] << 8; - mtime |= data[6] << 16; - mtime |= data[7] << 24; - unsigned xfl = data[8]; - unsigned os = data[9]; - unsigned p = 10; - unsigned isize = data[size - 4]; - isize |= data[size - 3] << 8; - isize |= data[size - 2] << 16; - isize |= data[size - 1] << 24; - filename = ""; - - if(flg & 0x04) { //FEXTRA - unsigned xlen = data[p + 0]; - xlen |= data[p + 1] << 8; - p += 2 + xlen; - } - - if(flg & 0x08) { //FNAME - char buffer[PATH_MAX]; - for(unsigned n = 0; n < PATH_MAX; n++, p++) { - buffer[n] = data[p]; - if(data[p] == 0) break; - } - if(data[p++]) return false; - filename = buffer; - } - - if(flg & 0x10) { //FCOMMENT - while(data[p++]); - } - - if(flg & 0x02) { //FHCRC - p += 2; - } - - this->size = isize; - this->data = new uint8_t[this->size]; - return inflate(this->data, this->size, data + p, size - p - 8); -} - -gzip::gzip() : data(nullptr) { -} - -gzip::~gzip() { - if(data) delete[] data; -} - -} - -#endif diff --git a/ananke/nall/http.hpp b/ananke/nall/http.hpp deleted file mode 100644 index 48aeb097..00000000 --- a/ananke/nall/http.hpp +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef NALL_HTTP_HPP -#define NALL_HTTP_HPP - -#if !defined(_WIN32) - #include - #include - #include - #include -#else - #include - #include - #include -#endif - -#include -#include - -namespace nall { - -struct http { - string hostname; - addrinfo *serverinfo; - int serversocket; - string header; - - inline void download(const string &path, uint8_t *&data, unsigned &size) { - data = 0; - size = 0; - - send({ - "GET ", path, " HTTP/1.1\r\n" - "Host: ", hostname, "\r\n" - "Connection: close\r\n" - "\r\n" - }); - - header = downloadHeader(); - downloadContent(data, size); - } - - inline bool connect(string host, unsigned port) { - hostname = host; - - addrinfo hints; - memset(&hints, 0, sizeof(addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - - int status = getaddrinfo(hostname, string(port), &hints, &serverinfo); - if(status != 0) return false; - - serversocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); - if(serversocket == -1) return false; - - int result = ::connect(serversocket, serverinfo->ai_addr, serverinfo->ai_addrlen); - if(result == -1) return false; - - return true; - } - - inline bool send(const string &data) { - return send((const uint8_t*)(const char*)data, data.length()); - } - - inline bool send(const uint8_t *data, unsigned size) { - while(size) { - int length = ::send(serversocket, (const char*)data, size, 0); - if(length == -1) return false; - data += length; - size -= length; - } - return true; - } - - inline string downloadHeader() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n\r\n") == false); - return output; - } - - inline string downloadChunkLength() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n") == false); - return output; - } - - inline void downloadContent(uint8_t *&data, unsigned &size) { - unsigned capacity = 0; - - if(header.iposition("\r\nTransfer-Encoding: chunked\r\n")) { - while(true) { - unsigned length = hex(downloadChunkLength()); - if(length == 0) break; - capacity += length; - data = (uint8_t*)realloc(data, capacity); - - char buffer[length]; - while(length) { - int packetlength = recv(serversocket, buffer, length, 0); - if(packetlength <= 0) break; - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } - } else if(auto position = header.iposition("\r\nContent-Length: ")) { - unsigned length = decimal((const char*)header + position() + 18); - while(length) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, min(256, length), 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } else { - while(true) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, 256, 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - } - } - - data = (uint8_t*)realloc(data, capacity + 1); - data[capacity] = 0; - } - - inline void disconnect() { - close(serversocket); - freeaddrinfo(serverinfo); - serverinfo = 0; - serversocket = -1; - } - - #ifdef _WIN32 - inline int close(int sock) { - return closesocket(sock); - } - - inline http() { - int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) { - WSADATA wsaData; - if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - WSACleanup(); - return; - } - } else { - close(sock); - } - } - #endif -}; - -} - -#endif diff --git a/ananke/nall/image.hpp b/ananke/nall/image.hpp deleted file mode 100644 index e334b6e0..00000000 --- a/ananke/nall/image.hpp +++ /dev/null @@ -1,539 +0,0 @@ -#ifndef NALL_IMAGE_HPP -#define NALL_IMAGE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - -struct image { - uint8_t *data; - unsigned width; - unsigned height; - unsigned pitch; - - bool endian; //0 = little, 1 = big - unsigned depth; - unsigned stride; - - struct Channel { - uint64_t mask; - unsigned depth; - unsigned shift; - - inline bool operator==(const Channel &source) { - return mask == source.mask && depth == source.depth && shift == source.shift; - } - - inline bool operator!=(const Channel &source) { - return !operator==(source); - } - } alpha, red, green, blue; - - typedef double (*interpolation)(double, double, double, double, double); - static inline unsigned bitDepth(uint64_t color); - static inline unsigned bitShift(uint64_t color); - static inline uint64_t normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth); - - inline bool operator==(const image &source); - inline bool operator!=(const image &source); - - inline image& operator=(const image &source); - inline image& operator=(image &&source); - inline image(const image &source); - inline image(image &&source); - inline image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline image(const string &filename); - inline image(const uint8_t *data, unsigned size); - inline image(); - inline ~image(); - - inline uint64_t read(const uint8_t *data) const; - inline void write(uint8_t *data, uint64_t value) const; - - inline void free(); - inline bool empty() const; - inline void allocate(unsigned width, unsigned height); - inline void clear(uint64_t color); - inline bool load(const string &filename); -//inline bool loadBMP(const uint8_t *data, unsigned size); - inline bool loadPNG(const uint8_t *data, unsigned size); - inline void scale(unsigned width, unsigned height, interpolation op); - inline void transform(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline void alphaBlend(uint64_t alphaColor); - -protected: - inline uint64_t interpolate(double mu, const uint64_t *s, interpolation op); - inline void scaleX(unsigned width, interpolation op); - inline void scaleY(unsigned height, interpolation op); - inline bool loadBMP(const string &filename); - inline bool loadPNG(const string &filename); -}; - -//static - -unsigned image::bitDepth(uint64_t color) { - unsigned depth = 0; - if(color) while((color & 1) == 0) color >>= 1; - while((color & 1) == 1) { color >>= 1; depth++; } - return depth; -} - -unsigned image::bitShift(uint64_t color) { - unsigned shift = 0; - if(color) while((color & 1) == 0) { color >>= 1; shift++; } - return shift; -} - -uint64_t image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) { - while(sourceDepth < targetDepth) { - color = (color << sourceDepth) | color; - sourceDepth += sourceDepth; - } - if(targetDepth < sourceDepth) color >>= (sourceDepth - targetDepth); - return color; -} - -//public - -bool image::operator==(const image &source) { - if(width != source.width) return false; - if(height != source.height) return false; - if(pitch != source.pitch) return false; - - if(endian != source.endian) return false; - if(stride != source.stride) return false; - - if(alpha != source.alpha) return false; - if(red != source.red) return false; - if(green != source.green) return false; - if(blue != source.blue) return false; - - return memcmp(data, source.data, width * height * stride) == 0; -} - -bool image::operator!=(const image &source) { - return !operator==(source); -} - -image& image::operator=(const image &source) { - free(); - - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = new uint8_t[width * height * stride]; - memcpy(data, source.data, width * height * stride); - return *this; -} - -image& image::operator=(image &&source) { - free(); - - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = source.data; - source.data = nullptr; - return *this; -} - -image::image(const image &source) : data(nullptr) { - operator=(source); -} - -image::image(image &&source) : data(nullptr) { - operator=(std::forward(source)); -} - -image::image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = endian; - this->depth = depth; - this->stride = (depth / 8) + ((depth & 7) > 0); - - alpha.mask = alphaMask, red.mask = redMask, green.mask = greenMask, blue.mask = blueMask; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::image(const string &filename) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - load(filename); -} - -image::image(const uint8_t *data, unsigned size) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - loadPNG(data, size); -} - -image::image() : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::~image() { - free(); -} - -uint64_t image::read(const uint8_t *data) const { - uint64_t result = 0; - if(endian == 0) { - for(signed n = stride - 1; n >= 0; n--) result = (result << 8) | data[n]; - } else { - for(signed n = 0; n < stride; n++) result = (result << 8) | data[n]; - } - return result; -} - -void image::write(uint8_t *data, uint64_t value) const { - if(endian == 0) { - for(signed n = 0; n < stride; n++) { data[n] = value; value >>= 8; } - } else { - for(signed n = stride - 1; n >= 0; n--) { data[n] = value; value >>= 8; } - } -} - -void image::free() { - if(data) delete[] data; - data = nullptr; -} - -bool image::empty() const { - if(data == nullptr) return true; - if(width == 0 || height == 0) return true; - return false; -} - -void image::allocate(unsigned width, unsigned height) { - if(data != nullptr && this->width == width && this->height == height) return; - free(); - data = new uint8_t[width * height * stride](); - pitch = width * stride; - this->width = width; - this->height = height; -} - -void image::clear(uint64_t color) { - uint8_t *dp = data; - for(unsigned n = 0; n < width * height; n++) { - write(dp, color); - dp += stride; - } -} - -bool image::load(const string &filename) { - if(loadBMP(filename) == true) return true; - if(loadPNG(filename) == true) return true; - return false; -} - -void image::scale(unsigned outputWidth, unsigned outputHeight, interpolation op) { - if(width != outputWidth) scaleX(outputWidth, op); - if(height != outputHeight) scaleY(outputHeight, op); -} - -void image::transform(bool outputEndian, unsigned outputDepth, uint64_t outputAlphaMask, uint64_t outputRedMask, uint64_t outputGreenMask, uint64_t outputBlueMask) { - image output(outputEndian, outputDepth, outputAlphaMask, outputRedMask, outputGreenMask, outputBlueMask); - output.allocate(width, height); - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = output.data + output.pitch * y; - uint8_t *sp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(sp); - sp += stride; - - uint64_t a = (color & alpha.mask) >> alpha.shift; - uint64_t r = (color & red.mask) >> red.shift; - uint64_t g = (color & green.mask) >> green.shift; - uint64_t b = (color & blue.mask) >> blue.shift; - - a = normalize(a, alpha.depth, output.alpha.depth); - r = normalize(r, red.depth, output.red.depth); - g = normalize(g, green.depth, output.green.depth); - b = normalize(b, blue.depth, output.blue.depth); - - output.write(dp, (a << output.alpha.shift) | (r << output.red.shift) | (g << output.green.shift) | (b << output.blue.shift)); - dp += output.stride; - } - } - - operator=(std::move(output)); -} - -void image::alphaBlend(uint64_t alphaColor) { - uint64_t alphaR = (alphaColor & red.mask) >> red.shift; - uint64_t alphaG = (alphaColor & green.mask) >> green.shift; - uint64_t alphaB = (alphaColor & blue.mask) >> blue.shift; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(dp); - - uint64_t colorA = (color & alpha.mask) >> alpha.shift; - uint64_t colorR = (color & red.mask) >> red.shift; - uint64_t colorG = (color & green.mask) >> green.shift; - uint64_t colorB = (color & blue.mask) >> blue.shift; - double alphaScale = (double)colorA / (double)((1 << alpha.depth) - 1); - - colorA = (1 << alpha.depth) - 1; - colorR = (colorR * alphaScale) + (alphaR * (1.0 - alphaScale)); - colorG = (colorG * alphaScale) + (alphaG * (1.0 - alphaScale)); - colorB = (colorB * alphaScale) + (alphaB * (1.0 - alphaScale)); - - write(dp, (colorA << alpha.shift) | (colorR << red.shift) | (colorG << green.shift) | (colorB << blue.shift)); - dp += stride; - } - } -} - -//protected - -uint64_t image::interpolate(double mu, const uint64_t *s, double (*op)(double, double, double, double, double)) { - uint64_t aa = (s[0] & alpha.mask) >> alpha.shift, ar = (s[0] & red.mask) >> red.shift, - ag = (s[0] & green.mask) >> green.shift, ab = (s[0] & blue.mask) >> blue.shift; - uint64_t ba = (s[1] & alpha.mask) >> alpha.shift, br = (s[1] & red.mask) >> red.shift, - bg = (s[1] & green.mask) >> green.shift, bb = (s[1] & blue.mask) >> blue.shift; - uint64_t ca = (s[2] & alpha.mask) >> alpha.shift, cr = (s[2] & red.mask) >> red.shift, - cg = (s[2] & green.mask) >> green.shift, cb = (s[2] & blue.mask) >> blue.shift; - uint64_t da = (s[3] & alpha.mask) >> alpha.shift, dr = (s[3] & red.mask) >> red.shift, - dg = (s[3] & green.mask) >> green.shift, db = (s[3] & blue.mask) >> blue.shift; - - int64_t A = op(mu, aa, ba, ca, da); - int64_t R = op(mu, ar, br, cr, dr); - int64_t G = op(mu, ag, bg, cg, dg); - int64_t B = op(mu, ab, bb, cb, db); - - A = max(0, min(A, (1 << alpha.depth) - 1)); - R = max(0, min(R, (1 << red.depth) - 1)); - G = max(0, min(G, (1 << green.depth) - 1)); - B = max(0, min(B, (1 << blue.depth) - 1)); - - return (A << alpha.shift) | (R << red.shift) | (G << green.shift) | (B << blue.shift); -} - -void image::scaleX(unsigned outputWidth, interpolation op) { - uint8_t *outputData = new uint8_t[outputWidth * height * stride]; - unsigned outputPitch = outputWidth * stride; - double step = (double)width / (double)outputWidth; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = outputData + outputPitch * y; - uint8_t *sp = data + pitch * y; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; //B,C (0,1) = center of kernel { 0, 0, 1, 2 } - s[1] = s[0]; - s[2] = sp + stride < terminal ? read(sp += stride) : s[1]; - s[3] = sp + stride < terminal ? read(sp += stride) : s[2]; - - for(unsigned x = 0; x < width; x++) { - while(fraction <= 1.0) { - if(dp >= outputData + outputPitch * height) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += stride; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + stride < terminal) s[3] = read(sp += stride); - fraction -= 1.0; - } - } - - free(); - data = outputData; - width = outputWidth; - pitch = width * stride; -} - -void image::scaleY(unsigned outputHeight, interpolation op) { - uint8_t *outputData = new uint8_t[width * outputHeight * stride]; - double step = (double)height / (double)outputHeight; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned x = 0; x < width; x++) { - uint8_t *dp = outputData + stride * x; - uint8_t *sp = data + stride * x; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; - s[1] = s[0]; - s[2] = sp + pitch < terminal ? read(sp += pitch) : s[1]; - s[3] = sp + pitch < terminal ? read(sp += pitch) : s[2]; - - for(unsigned y = 0; y < height; y++) { - while(fraction <= 1.0) { - if(dp >= outputData + pitch * outputHeight) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += pitch; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + pitch < terminal) s[3] = read(sp += pitch); - fraction -= 1.0; - } - } - - free(); - data = outputData; - height = outputHeight; -} - -bool image::loadBMP(const string &filename) { - uint32_t *outputData; - unsigned outputWidth, outputHeight; - if(bmp::read(filename, outputData, outputWidth, outputHeight) == false) return false; - - allocate(outputWidth, outputHeight); - const uint32_t *sp = outputData; - uint8_t *dp = data; - - for(unsigned y = 0; y < outputHeight; y++) { - for(unsigned x = 0; x < outputWidth; x++) { - uint32_t color = *sp++; - uint64_t a = normalize((uint8_t)(color >> 24), 8, alpha.depth); - uint64_t r = normalize((uint8_t)(color >> 16), 8, red.depth); - uint64_t g = normalize((uint8_t)(color >> 8), 8, green.depth); - uint64_t b = normalize((uint8_t)(color >> 0), 8, blue.depth); - write(dp, (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift)); - dp += stride; - } - } - - delete[] outputData; - return true; -} - -bool image::loadPNG(const uint8_t *pngData, unsigned pngSize) { - png source; - if(source.decode(pngData, pngSize) == false) return false; - - allocate(source.info.width, source.info.height); - const uint8_t *sp = source.data; - uint8_t *dp = data; - - auto decode = [&]() -> uint64_t { - uint64_t p, r, g, b, a; - - switch(source.info.colorType) { - case 0: //L - r = g = b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 2: //R,G,B - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 3: //P - p = source.readbits(sp); - r = source.info.palette[p][0]; - g = source.info.palette[p][1]; - b = source.info.palette[p][2]; - a = (1 << source.info.bitDepth) - 1; - break; - case 4: //L,A - r = g = b = source.readbits(sp); - a = source.readbits(sp); - break; - case 6: //R,G,B,A - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = source.readbits(sp); - break; - } - - a = normalize(a, source.info.bitDepth, alpha.depth); - r = normalize(r, source.info.bitDepth, red.depth); - g = normalize(g, source.info.bitDepth, green.depth); - b = normalize(b, source.info.bitDepth, blue.depth); - - return (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift); - }; - - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - write(dp, decode()); - dp += stride; - } - } - - return true; -} - -bool image::loadPNG(const string &filename) { - filemap map; - if(map.open(filename, filemap::mode::read) == false) return false; - return loadPNG(map.data(), map.size()); -} - -} - -#endif diff --git a/ananke/nall/inflate.hpp b/ananke/nall/inflate.hpp deleted file mode 100644 index cbbf6d29..00000000 --- a/ananke/nall/inflate.hpp +++ /dev/null @@ -1,358 +0,0 @@ -#ifndef NALL_INFLATE_HPP -#define NALL_INFLATE_HPP - -#include - -namespace nall { - -namespace puff { - inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen - ); -} - -inline bool inflate( - uint8_t *target, unsigned targetLength, - const uint8_t *source, unsigned sourceLength -) { - unsigned long tl = targetLength, sl = sourceLength; - int result = puff::puff((unsigned char*)target, &tl, (unsigned char*)source, &sl); - return result == 0; -} - -namespace puff { - -//zlib/contrib/puff.c -//version 2.1* -//author: Mark Adler -//license: zlib -//ported by: byuu - -//* I have corrected a bug in fixed(), where it was accessing uninitialized -// memory: calling construct() with lencode prior to initializing lencode.count - -enum { - MAXBITS = 15, - MAXLCODES = 286, - MAXDCODES = 30, - FIXLCODES = 288, - MAXCODES = MAXLCODES + MAXDCODES, -}; - -struct state { - unsigned char *out; - unsigned long outlen; - unsigned long outcnt; - - unsigned char *in; - unsigned long inlen; - unsigned long incnt; - int bitbuf; - int bitcnt; - - jmp_buf env; -}; - -struct huffman { - short *count; - short *symbol; -}; - -inline int bits(state *s, int need) { - long val; - - val = s->bitbuf; - while(s->bitcnt < need) { - if(s->incnt == s->inlen) longjmp(s->env, 1); - val |= (long)(s->in[s->incnt++]) << s->bitcnt; - s->bitcnt += 8; - } - - s->bitbuf = (int)(val >> need); - s->bitcnt -= need; - - return (int)(val & ((1L << need) - 1)); -} - -inline int stored(state *s) { - unsigned len; - - s->bitbuf = 0; - s->bitcnt = 0; - - if(s->incnt + 4 > s->inlen) return 2; - len = s->in[s->incnt++]; - len |= s->in[s->incnt++] << 8; - if(s->in[s->incnt++] != (~len & 0xff) || - s->in[s->incnt++] != ((~len >> 8) & 0xff) - ) return 2; - - if(s->incnt + len > s->inlen) return 2; - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) s->out[s->outcnt++] = s->in[s->incnt++]; - } else { - s->outcnt += len; - s->incnt += len; - } - - return 0; -} - -inline int decode(state *s, huffman *h) { - int len, code, first, count, index, bitbuf, left; - short *next; - - bitbuf = s->bitbuf; - left = s->bitcnt; - code = first = index = 0; - len = 1; - next = h->count + 1; - while(true) { - while(left--) { - code |= bitbuf & 1; - bitbuf >>= 1; - count = *next++; - if(code - count < first) { - s->bitbuf = bitbuf; - s->bitcnt = (s->bitcnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS + 1) - len; - if(left == 0) break; - if(s->incnt == s->inlen) longjmp(s->env, 1); - bitbuf = s->in[s->incnt++]; - if(left > 8) left = 8; - } - - return -10; -} - -inline int construct(huffman *h, short *length, int n) { - int symbol, len, left; - short offs[MAXBITS + 1]; - - for(len = 0; len <= MAXBITS; len++) h->count[len] = 0; - for(symbol = 0; symbol < n; symbol++) h->count[length[symbol]]++; - if(h->count[0] == n) return 0; - - left = 1; - for(len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= h->count[len]; - if(left < 0) return left; - } - - offs[1] = 0; - for(len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; - - for(symbol = 0; symbol < n; symbol++) { - if(length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; - } - - return left; -} - -inline int codes(state *s, huffman *lencode, huffman *distcode) { - int symbol, len; - unsigned dist; - static const short lens[29] = { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 - }; - static const short lext[29] = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 - }; - static const short dists[30] = { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577 - }; - static const short dext[30] = { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13 - }; - - do { - symbol = decode(s, lencode); - if(symbol < 0) return symbol; - if(symbol < 256) { - if(s->out != 0) { - if(s->outcnt == s->outlen) return 1; - s->out[s->outcnt] = symbol; - } - s->outcnt++; - } else if(symbol > 256) { - symbol -= 257; - if(symbol >= 29) return -10; - len = lens[symbol] + bits(s, lext[symbol]); - - symbol = decode(s, distcode); - if(symbol < 0) return symbol; - dist = dists[symbol] + bits(s, dext[symbol]); - #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - if(dist > s->outcnt) return -11; - #endif - - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) { - s->out[s->outcnt] = - #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - dist > s->outcnt ? 0 : - #endif - s->out[s->outcnt - dist]; - s->outcnt++; - } - } else { - s->outcnt += len; - } - } - } while(symbol != 256); - - return 0; -} - -inline int fixed(state *s) { - static int virgin = 1; - static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; - static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - static huffman lencode, distcode; - - if(virgin) { - int symbol = 0; - short lengths[FIXLCODES]; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - for(; symbol < 144; symbol++) lengths[symbol] = 8; - for(; symbol < 256; symbol++) lengths[symbol] = 9; - for(; symbol < 280; symbol++) lengths[symbol] = 7; - for(; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; - construct(&lencode, lengths, FIXLCODES); - - for(symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; - construct(&distcode, lengths, MAXDCODES); - - virgin = 0; - } - - return codes(s, &lencode, &distcode); -} - -inline int dynamic(state *s) { - int nlen, ndist, ncode, index, err; - short lengths[MAXCODES]; - short lencnt[MAXBITS + 1], lensym[MAXLCODES]; - short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - huffman lencode, distcode; - static const short order[19] = { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 - }; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - nlen = bits(s, 5) + 257; - ndist = bits(s, 5) + 1; - ncode = bits(s, 4) + 4; - if(nlen > MAXLCODES || ndist > MAXDCODES) return -3; - - for(index = 0; index < ncode; index++) lengths[order[index]] = bits(s, 3); - for(; index < 19; index++) lengths[order[index]] = 0; - - err = construct(&lencode, lengths, 19); - if(err != 0) return -4; - - index = 0; - while(index < nlen + ndist) { - int symbol, len; - - symbol = decode(s, &lencode); - if(symbol < 16) { - lengths[index++] = symbol; - } else { - len = 0; - if(symbol == 16) { - if(index == 0) return -5; - len = lengths[index - 1]; - symbol = 3 + bits(s, 2); - } else if(symbol == 17) { - symbol = 3 + bits(s, 3); - } else { - symbol = 11 + bits(s, 7); - } - if(index + symbol > nlen + ndist) return -6; - while(symbol--) lengths[index++] = len; - } - } - - if(lengths[256] == 0) return -9; - - err = construct(&lencode, lengths, nlen); - if(err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) return -7; - - err = construct(&distcode, lengths + nlen, ndist); - if(err < 0 || (err > 0 && ndist - distcode.count[0] != 1)) return -8; - - return codes(s, &lencode, &distcode); -} - -inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen -) { - state s; - int last, type, err; - - s.out = dest; - s.outlen = *destlen; - s.outcnt = 0; - - s.in = source; - s.inlen = *sourcelen; - s.incnt = 0; - s.bitbuf = 0; - s.bitcnt = 0; - - if(setjmp(s.env) != 0) { - err = 2; - } else { - do { - last = bits(&s, 1); - type = bits(&s, 2); - err = type == 0 ? stored(&s) - : type == 1 ? fixed(&s) - : type == 2 ? dynamic(&s) - : -1; - if(err != 0) break; - } while(!last); - } - - if(err <= 0) { - *destlen = s.outcnt; - *sourcelen = s.incnt; - } - - return err; -} - -} - -} - -#endif diff --git a/ananke/nall/input.hpp b/ananke/nall/input.hpp deleted file mode 100644 index cd765393..00000000 --- a/ananke/nall/input.hpp +++ /dev/null @@ -1,386 +0,0 @@ -#ifndef NALL_INPUT_HPP -#define NALL_INPUT_HPP - -#include -#include -#include - -#include -#include - -namespace nall { - -struct Keyboard; -Keyboard& keyboard(unsigned = 0); - -static const char KeyboardScancodeName[][64] = { - "Escape", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", - "PrintScreen", "ScrollLock", "Pause", "Tilde", - "Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num0", - "Dash", "Equal", "Backspace", - "Insert", "Delete", "Home", "End", "PageUp", "PageDown", - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", - "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "LeftBracket", "RightBracket", "Backslash", "Semicolon", "Apostrophe", "Comma", "Period", "Slash", - "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9", "Keypad0", - "Point", "Enter", "Add", "Subtract", "Multiply", "Divide", - "NumLock", "CapsLock", - "Up", "Down", "Left", "Right", - "Tab", "Return", "Spacebar", "Menu", - "Shift", "Control", "Alt", "Super", -}; - -struct Keyboard { - const unsigned ID; - enum { Base = 1 }; - enum { Count = 8, Size = 128 }; - - enum Scancode { - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, Tilde, - Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9, Num0, - Dash, Equal, Backspace, - Insert, Delete, Home, End, PageUp, PageDown, - A, B, C, D, E, F, G, H, I, J, K, L, M, - N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - LeftBracket, RightBracket, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - Point, Enter, Add, Subtract, Multiply, Divide, - NumLock, CapsLock, - Up, Down, Left, Right, - Tab, Return, Spacebar, Menu, - Shift, Control, Alt, Super, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed keyDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return scancode - keyboard(i).key(Escape); - } - return -1; - } - - static signed modifierDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return scancode - keyboard(i).key(Shift); - } - return -1; - } - - static bool isAnyKey(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return true; - } - return false; - } - - static bool isAnyModifier(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "KB")) return 0; - s.ltrim("KB"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == KeyboardScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "KB", ID, "::", KeyboardScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t key(unsigned id) const { return Base + Size * ID + id; } - bool isKey(unsigned id) const { return id >= key(Escape) && id <= key(Menu); } - bool isModifier(unsigned id) const { return id >= key(Shift) && id <= key(Super); } - bool belongsTo(uint16_t scancode) const { return isKey(scancode) || isModifier(scancode); } - - Keyboard(unsigned ID_) : ID(ID_) {} -}; - -inline Keyboard& keyboard(unsigned id) { - static Keyboard kb0(0), kb1(1), kb2(2), kb3(3), kb4(4), kb5(5), kb6(6), kb7(7); - switch(id) { default: - case 0: return kb0; case 1: return kb1; case 2: return kb2; case 3: return kb3; - case 4: return kb4; case 5: return kb5; case 6: return kb6; case 7: return kb7; - } -} - -static const char MouseScancodeName[][64] = { - "Xaxis", "Yaxis", "Zaxis", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", -}; - -struct Mouse; -Mouse& mouse(unsigned = 0); - -struct Mouse { - const unsigned ID; - enum { Base = Keyboard::Base + Keyboard::Size * Keyboard::Count }; - enum { Count = 8, Size = 16 }; - enum { Axes = 3, Buttons = 8 }; - - enum Scancode { - Xaxis, Yaxis, Zaxis, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return scancode - mouse(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return scancode - mouse(i).button(0); - } - return -1; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "MS")) return 0; - s.ltrim("MS"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == MouseScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "MS", ID, "::", MouseScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Xaxis + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(2); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(7); } - bool belongsTo(uint16_t scancode) const { return isAxis(scancode) || isButton(scancode); } - - Mouse(unsigned ID_) : ID(ID_) {} -}; - -inline Mouse& mouse(unsigned id) { - static Mouse ms0(0), ms1(1), ms2(2), ms3(3), ms4(4), ms5(5), ms6(6), ms7(7); - switch(id) { default: - case 0: return ms0; case 1: return ms1; case 2: return ms2; case 3: return ms3; - case 4: return ms4; case 5: return ms5; case 6: return ms6; case 7: return ms7; - } -} - -static const char JoypadScancodeName[][64] = { - "Hat0", "Hat1", "Hat2", "Hat3", "Hat4", "Hat5", "Hat6", "Hat7", - "Axis0", "Axis1", "Axis2", "Axis3", "Axis4", "Axis5", "Axis6", "Axis7", - "Axis8", "Axis9", "Axis10", "Axis11", "Axis12", "Axis13", "Axis14", "Axis15", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", - "Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15", - "Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23", - "Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31", -}; - -struct Joypad; -Joypad& joypad(unsigned = 0); - -struct Joypad { - const unsigned ID; - enum { Base = Mouse::Base + Mouse::Size * Mouse::Count }; - enum { Count = 8, Size = 64 }; - enum { Hats = 8, Axes = 16, Buttons = 32 }; - - enum Scancode { - Hat0, Hat1, Hat2, Hat3, Hat4, Hat5, Hat6, Hat7, - Axis0, Axis1, Axis2, Axis3, Axis4, Axis5, Axis6, Axis7, - Axis8, Axis9, Axis10, Axis11, Axis12, Axis13, Axis14, Axis15, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Button8, Button9, Button10, Button11, Button12, Button13, Button14, Button15, - Button16, Button17, Button18, Button19, Button20, Button21, Button22, Button23, - Button24, Button25, Button26, Button27, Button28, Button29, Button30, Button31, - Limit, - }; - - enum Hat { HatCenter = 0, HatUp = 1, HatRight = 2, HatDown = 4, HatLeft = 8 }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed hatDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return scancode - joypad(i).hat(0); - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return scancode - joypad(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return scancode - joypad(i).button(0); - } - return -1; - } - - static bool isAnyHat(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return true; - } - return false; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "JP")) return 0; - s.ltrim("JP"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == JoypadScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - } - } - return { "JP", ID, "::", JoypadScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t hat(unsigned id) const { return Base + Size * ID + Hat0 + id; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Axis0 + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isHat(unsigned id) const { return id >= hat(0) && id <= hat(7); } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(15); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(31); } - bool belongsTo(uint16_t scancode) const { return isHat(scancode) || isAxis(scancode) || isButton(scancode); } - - Joypad(unsigned ID_) : ID(ID_) {} -}; - -inline Joypad& joypad(unsigned id) { - static Joypad jp0(0), jp1(1), jp2(2), jp3(3), jp4(4), jp5(5), jp6(6), jp7(7); - switch(id) { default: - case 0: return jp0; case 1: return jp1; case 2: return jp2; case 3: return jp3; - case 4: return jp4; case 5: return jp5; case 6: return jp6; case 7: return jp7; - } -} - -struct Scancode { - enum { None = 0, Limit = Joypad::Base + Joypad::Size * Joypad::Count }; - - static uint16_t decode(const char *name) { - uint16_t code; - code = Keyboard::decode(name); - if(code) return code; - code = Mouse::decode(name); - if(code) return code; - code = Joypad::decode(name); - if(code) return code; - return None; - } - - static string encode(uint16_t code) { - for(unsigned i = 0; i < Keyboard::Count; i++) { - if(keyboard(i).belongsTo(code)) return keyboard(i).encode(code); - } - for(unsigned i = 0; i < Mouse::Count; i++) { - if(mouse(i).belongsTo(code)) return mouse(i).encode(code); - } - for(unsigned i = 0; i < Joypad::Count; i++) { - if(joypad(i).belongsTo(code)) return joypad(i).encode(code); - } - return "None"; - } -}; - -} - -#endif diff --git a/ananke/nall/intrinsics.hpp b/ananke/nall/intrinsics.hpp deleted file mode 100644 index 413ef593..00000000 --- a/ananke/nall/intrinsics.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef NALL_INTRINSICS_HPP -#define NALL_INTRINSICS_HPP - -struct Intrinsics { - enum class Compiler : unsigned { GCC, VisualC, Unknown }; - enum class Platform : unsigned { X, OSX, Windows, Unknown }; - enum class Endian : unsigned { LSB, MSB, Unknown }; - - static inline Compiler compiler(); - static inline Platform platform(); - static inline Endian endian(); -}; - -/* Compiler detection */ - -#if defined(__GNUC__) - #define COMPILER_GCC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::GCC; } -#elif defined(_MSC_VER) - #define COMPILER_VISUALC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::VisualC; } -#else - #warning "unable to detect compiler" - #define COMPILER_UNKNOWN - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Unknown; } -#endif - -/* Platform detection */ - -#if defined(linux) || defined(__sun__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define PLATFORM_X - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::X; } -#elif defined(__APPLE__) - #define PLATFORM_OSX - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::OSX; } -#elif defined(_WIN32) - #define PLATFORM_WINDOWS - #define PLATFORM_WIN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; } -#else - #warning "unable to detect platform" - #define PLATFORM_UNKNOWN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Unknown; } -#endif - -/* Endian detection */ - -#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64) - #define ENDIAN_LSB - #define ARCH_LSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; } -#elif defined(__powerpc__) || defined(_M_PPC) || defined(__BIG_ENDIAN__) - #define ENDIAN_MSB - #define ARCH_MSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::MSB; } -#else - #warning "unable to detect endian" - #define ENDIAN_UNKNOWN - #define ARCH_UNKNOWN - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::Unknown; } -#endif - -#endif diff --git a/ananke/nall/invoke.hpp b/ananke/nall/invoke.hpp deleted file mode 100644 index 9dfb7d0b..00000000 --- a/ananke/nall/invoke.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef NALL_INVOKE_HPP -#define NALL_INVOKE_HPP - -//void invoke(const string &name, const string& args...); -//if a program is specified, it is executed with the arguments provided -//if a file is specified, the file is opened using the program associated with said file type -//if a folder is specified, the folder is opened using the associated file explorer -//if a URL is specified, the default web browser is opened and pointed at the URL requested -//path environment variable is always consulted -//execution is asynchronous (non-blocking); use system() for synchronous execution - -#include -#ifdef _WIN32 - #include -#endif - -namespace nall { - -#ifdef _WIN32 - -template -inline void invoke(const string &name, Args&&... args) { - lstring argl(std::forward(args)...); - for(auto &arg : argl) if(arg.position(" ")) arg = {"\"", arg, "\""}; - string arguments = argl.concatenate(" "); - ShellExecuteW(NULL, NULL, utf16_t(name), utf16_t(arguments), NULL, SW_SHOWNORMAL); -} - -#else - -template -inline void invoke(const string &name, Args&&... args) { - pid_t pid = fork(); - if(pid == 0) { - const char *argv[1 + sizeof...(args) + 1], **argp = argv; - lstring argl(std::forward(args)...); - *argp++ = (const char*)name; - for(auto &arg : argl) *argp++ = (const char*)arg; - *argp++ = nullptr; - - if(execvp(name, (char* const*)argv) < 0) { - execlp("xdg-open", "xdg-open", (const char*)name, nullptr); - } - exit(0); - } -} - -#endif - -} - -#endif diff --git a/ananke/nall/ips.hpp b/ananke/nall/ips.hpp deleted file mode 100644 index 473d74c5..00000000 --- a/ananke/nall/ips.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef NALL_IPS_HPP -#define NALL_IPS_HPP - -#include -#include -#include - -namespace nall { - -struct ips { - inline bool apply(); - inline void source(const uint8_t *data, unsigned size); - inline void modify(const uint8_t *data, unsigned size); - inline ips(); - inline ~ips(); - - uint8_t *data; - unsigned size; - const uint8_t *sourceData; - unsigned sourceSize; - const uint8_t *modifyData; - unsigned modifySize; -}; - -bool ips::apply() { - if(modifySize < 8) return false; - if(modifyData[0] != 'P') return false; - if(modifyData[1] != 'A') return false; - if(modifyData[2] != 'T') return false; - if(modifyData[3] != 'C') return false; - if(modifyData[4] != 'H') return false; - - if(data) delete[] data; - data = new uint8_t[16 * 1024 * 1024 + 65536](); //maximum size of IPS patch + single-tag padding - size = sourceSize; - memcpy(data, sourceData, sourceSize); - unsigned offset = 5; - - while(true) { - unsigned address, length; - - if(offset > modifySize - 3) break; - address = modifyData[offset++] << 16; - address |= modifyData[offset++] << 8; - address |= modifyData[offset++] << 0; - - if(address == 0x454f46) { //EOF - if(offset == modifySize) return true; - if(offset == modifySize - 3) { - size = modifyData[offset++] << 16; - size |= modifyData[offset++] << 8; - size |= modifyData[offset++] << 0; - return true; - } - } - - if(offset > modifySize - 2) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - - if(length) { //Copy - if(offset > modifySize - length) break; - while(length--) data[address++] = modifyData[offset++]; - } else { //RLE - if(offset > modifySize - 3) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - if(length == 0) break; //illegal - while(length--) data[address++] = modifyData[offset]; - offset++; - } - - size = max(size, address); - } - - delete[] data; - data = nullptr; - return false; -} - -void ips::source(const uint8_t *data, unsigned size) { - sourceData = data, sourceSize = size; -} - -void ips::modify(const uint8_t *data, unsigned size) { - modifyData = data, modifySize = size; -} - -ips::ips() : data(nullptr), sourceData(nullptr), modifyData(nullptr) { -} - -ips::~ips() { - if(data) delete[] data; - if(sourceData) delete[] sourceData; - if(modifyData) delete[] modifyData; -} - -} - -#endif diff --git a/ananke/nall/lzss.hpp b/ananke/nall/lzss.hpp deleted file mode 100644 index fb3e0ba6..00000000 --- a/ananke/nall/lzss.hpp +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef NALL_LZSS_HPP -#define NALL_LZSS_HPP - -#include -#include -#include -#include - -namespace nall { - -//19:5 pulldown -//8:1 marker: d7-d0 -//length: { 4 - 35 }, offset: { 1 - 0x80000 } -//4-byte file size header -//little-endian encoding -struct lzss { - inline void source(const uint8_t *data, unsigned size); - inline bool source(const string &filename); - inline unsigned size() const; - inline bool compress(const string &filename); - inline bool decompress(uint8_t *targetData, unsigned targetSize); - inline bool decompress(const string &filename); - -protected: - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - } *tree[65536]; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - -public: - inline lzss() : sourceData(nullptr), sourceSize(0) {} -}; - -void lzss::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -bool lzss::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - sourceData = sourceFile.data(); - sourceSize = sourceFile.size(); - return true; -} - -unsigned lzss::size() const { - unsigned size = 0; - if(sourceSize < 4) return size; - for(unsigned n = 0; n < 32; n += 8) size |= sourceData[n >> 3] << n; - return size; -} - -bool lzss::compress(const string &filename) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - - for(unsigned n = 0; n < 32; n += 8) targetFile.write(sourceSize >> n); - for(unsigned n = 0; n < 65536; n++) tree[n] = 0; - - uint8_t buffer[25]; - unsigned sourceOffset = 0; - - while(sourceOffset < sourceSize) { - uint8_t mask = 0x00; - unsigned bufferOffset = 1; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - uint16_t symbol = sourceData[sourceOffset + 0]; - if(sourceOffset < sourceSize - 1) symbol |= sourceData[sourceOffset + 1] << 8; - Node *node = tree[symbol]; - unsigned maxLength = 0, maxOffset = 0; - - while(node) { - if(node->offset < sourceOffset - 0x80000) { - //out-of-range: all subsequent nodes will also be, so free up their memory - if(node->next) { delete node->next; node->next = 0; } - break; - } - - unsigned length = 0, x = sourceOffset, y = node->offset; - while(length < 35 && x < sourceSize && sourceData[x++] == sourceData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset; - if(length == 35) break; - - node = node->next; - } - - //attach current symbol to top of tree for subsequent searches - node = new Node; - node->offset = sourceOffset; - node->next = tree[symbol]; - tree[symbol] = node; - - if(maxLength < 4) { - buffer[bufferOffset++] = sourceData[sourceOffset++]; - } else { - unsigned output = ((maxLength - 4) << 19) | (sourceOffset - 1 - maxOffset); - for(unsigned n = 0; n < 24; n += 8) buffer[bufferOffset++] = output >> n; - mask |= 0x80 >> iteration; - sourceOffset += maxLength; - } - } - - buffer[0] = mask; - targetFile.write(buffer, bufferOffset); - } - - sourceFile.close(); - targetFile.close(); - return true; -} - -bool lzss::decompress(uint8_t *targetData, unsigned targetSize) { - if(targetSize < size()) return false; - - unsigned sourceOffset = 4, targetOffset = 0; - while(sourceOffset < sourceSize) { - uint8_t mask = sourceData[sourceOffset++]; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - if((mask & (0x80 >> iteration)) == 0) { - targetData[targetOffset++] = sourceData[sourceOffset++]; - } else { - unsigned code = 0; - for(unsigned n = 0; n < 24; n += 8) code |= sourceData[sourceOffset++] << n; - unsigned length = (code >> 19) + 4; - unsigned offset = targetOffset - 1 - (code & 0x7ffff); - while(length--) targetData[targetOffset++] = targetData[offset++]; - } - } - } -} - -bool lzss::decompress(const string &filename) { - if(sourceSize < 4) return false; - unsigned targetSize = size(); - - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(targetSize); - fp.close(); - - filemap targetFile; - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - uint8_t *targetData = targetFile.data(); - - bool result = decompress(targetData, targetSize); - sourceFile.close(); - targetFile.close(); - return result; -} - -} - -#endif diff --git a/ananke/nall/map.hpp b/ananke/nall/map.hpp deleted file mode 100644 index 938f0c2d..00000000 --- a/ananke/nall/map.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef NALL_MAP_HPP -#define NALL_MAP_HPP - -#include - -namespace nall { - -template -struct map { - struct pair { - LHS name; - RHS data; - }; - - inline void reset() { - list.reset(); - } - - inline unsigned size() const { - return list.size(); - } - - //O(log n) find - inline optional find(const LHS &name) const { - signed first = 0, last = size() - 1; - while(first <= last) { - signed middle = (first + last) / 2; - if(name < list[middle].name) last = middle - 1; //search lower half - else if(list[middle].name < name) first = middle + 1; //search upper half - else return { true, (unsigned)middle }; //match found - } - return { false, 0u }; - } - - //O(n) insert + O(log n) find - inline RHS& insert(const LHS &name, const RHS &data) { - if(auto position = find(name)) { - list[position()].data = data; - return list[position()].data; - } - signed offset = size(); - for(unsigned n = 0; n < size(); n++) { - if(name < list[n].name) { offset = n; break; } - } - list.insert(offset, { name, data }); - return list[offset].data; - } - - //O(log n) find - inline void modify(const LHS &name, const RHS &data) { - if(auto position = find(name)) list[position()].data = data; - } - - //O(n) remove + O(log n) find - inline void remove(const LHS &name) { - if(auto position = find(name)) list.remove(position()); - } - - //O(log n) find - inline RHS& operator[](const LHS &name) { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline const RHS& operator[](const LHS &name) const { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline RHS& operator()(const LHS &name) { - if(auto position = find(name)) return list[position()].data; - return insert(name, RHS()); - } - - inline const RHS& operator()(const LHS &name, const RHS &data) const { - if(auto position = find(name)) return list[position()].data; - return data; - } - - inline pair* begin() { return list.begin(); } - inline pair* end() { return list.end(); } - inline const pair* begin() const { return list.begin(); } - inline const pair* end() const { return list.end(); } - -protected: - vector list; -}; - -template -struct bidirectional_map { - const map &lhs; - const map &rhs; - - inline void reset() { - llist.reset(); - rlist.reset(); - } - - inline unsigned size() const { - return llist.size(); - } - - inline void insert(const LHS &ldata, const RHS &rdata) { - llist.insert(ldata, rdata); - rlist.insert(rdata, ldata); - } - - inline bidirectional_map() : lhs(llist), rhs(rlist) {} - -protected: - map llist; - map rlist; -}; - -} - -#endif diff --git a/ananke/nall/mosaic/bitstream.hpp b/ananke/nall/mosaic/bitstream.hpp deleted file mode 100644 index e2cb3bc5..00000000 --- a/ananke/nall/mosaic/bitstream.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct bitstream { - filemap fp; - uint8_t *data; - unsigned size; - bool readonly; - bool endian; - - inline bool read(uint64_t addr) const { - if(data == nullptr || (addr >> 3) >= size) return 0; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - return data[addr >> 3] & mask; - } - - inline void write(uint64_t addr, bool value) { - if(data == nullptr || readonly == true || (addr >> 3) >= size) return; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - if(value == 0) data[addr >> 3] &= ~mask; - if(value == 1) data[addr >> 3] |= mask; - } - - inline bool open(const string &filename) { - readonly = false; - if(fp.open(filename, filemap::mode::readwrite) == false) { - readonly = true; - if(fp.open(filename, filemap::mode::read) == false) { - return false; - } - } - data = fp.data(); - size = fp.size(); - return true; - } - - inline void close() { - fp.close(); - data = nullptr; - } - - inline bitstream() : data(nullptr), endian(1) { - } - - inline ~bitstream() { - close(); - } -}; - -} -} - -#endif diff --git a/ananke/nall/mosaic/context.hpp b/ananke/nall/mosaic/context.hpp deleted file mode 100644 index bc7a518a..00000000 --- a/ananke/nall/mosaic/context.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct context { - unsigned offset; - unsigned width; - unsigned height; - unsigned count; - - bool endian; //0 = lsb, 1 = msb - bool order; //0 = linear, 1 = planar - unsigned depth; //1 - 24bpp - - unsigned blockWidth; - unsigned blockHeight; - unsigned blockStride; - unsigned blockOffset; - vector block; - - unsigned tileWidth; - unsigned tileHeight; - unsigned tileStride; - unsigned tileOffset; - vector tile; - - unsigned mosaicWidth; - unsigned mosaicHeight; - unsigned mosaicStride; - unsigned mosaicOffset; - vector mosaic; - - unsigned paddingWidth; - unsigned paddingHeight; - unsigned paddingColor; - vector palette; - - inline unsigned objectWidth() const { return blockWidth * tileWidth * mosaicWidth + paddingWidth; } - inline unsigned objectHeight() const { return blockHeight * tileHeight * mosaicHeight + paddingHeight; } - inline unsigned objectSize() const { - unsigned size = blockStride * tileWidth * tileHeight * mosaicWidth * mosaicHeight - + blockOffset * tileHeight * mosaicWidth * mosaicHeight - + tileStride * mosaicWidth * mosaicHeight - + tileOffset * mosaicHeight; - return max(1u, size); - } - - inline unsigned eval(const string &expression) { - intmax_t result; - if(fixedpoint::eval(expression, result) == false) return 0u; - return result; - } - - inline void eval(vector &buffer, const string &expression_) { - string expression = expression_; - bool function = false; - for(auto &c : expression) { - if(c == '(') function = true; - if(c == ')') function = false; - if(c == ',' && function == true) c = ';'; - } - - lstring list = expression.split(","); - for(auto &item : list) { - item.trim(); - if(item.wildcard("f(?*) ?*")) { - item.ltrim<1>("f("); - lstring part = item.split<1>(") "); - lstring args = part[0].split<3>(";"); - for(auto &item : args) item.trim(); - - unsigned length = eval(args(0, "0")); - unsigned offset = eval(args(1, "0")); - unsigned stride = eval(args(2, "0")); - if(args.size() < 2) offset = buffer.size(); - if(args.size() < 3) stride = 1; - - for(unsigned n = 0; n < length; n++) { - string fn = part[1]; - fn.replace("n", decimal(n)); - fn.replace("o", decimal(offset)); - fn.replace("p", decimal(buffer.size())); - buffer.resize(offset + 1); - buffer[offset] = eval(fn); - offset += stride; - } - } else if(item.wildcard("base64*")) { - unsigned offset = 0; - item.ltrim<1>("base64"); - if(item.wildcard("(?*) *")) { - item.ltrim<1>("("); - lstring part = item.split<1>(") "); - offset = eval(part[0]); - item = part(1, ""); - } - item.trim(); - for(auto &c : item) { - if(c >= 'A' && c <= 'Z') buffer.append(offset + c - 'A' + 0); - if(c >= 'a' && c <= 'z') buffer.append(offset + c - 'a' + 26); - if(c >= '0' && c <= '9') buffer.append(offset + c - '0' + 52); - if(c == '-') buffer.append(offset + 62); - if(c == '_') buffer.append(offset + 63); - } - } else if(item.wildcard("file *")) { - item.ltrim<1>("file "); - item.trim(); - //... - } else if(item.empty() == false) { - buffer.append(eval(item)); - } - } - } - - inline void parse(const string &data) { - reset(); - - lstring lines = data.split("\n"); - for(auto &line : lines) { - lstring part = line.split<1>(":"); - if(part.size() != 2) continue; - part[0].trim(); - part[1].trim(); - - if(part[0] == "offset") offset = eval(part[1]); - if(part[0] == "width") width = eval(part[1]); - if(part[0] == "height") height = eval(part[1]); - if(part[0] == "count") count = eval(part[1]); - - if(part[0] == "endian") endian = eval(part[1]); - if(part[0] == "order") order = eval(part[1]); - if(part[0] == "depth") depth = eval(part[1]); - - if(part[0] == "blockWidth") blockWidth = eval(part[1]); - if(part[0] == "blockHeight") blockHeight = eval(part[1]); - if(part[0] == "blockStride") blockStride = eval(part[1]); - if(part[0] == "blockOffset") blockOffset = eval(part[1]); - if(part[0] == "block") eval(block, part[1]); - - if(part[0] == "tileWidth") tileWidth = eval(part[1]); - if(part[0] == "tileHeight") tileHeight = eval(part[1]); - if(part[0] == "tileStride") tileStride = eval(part[1]); - if(part[0] == "tileOffset") tileOffset = eval(part[1]); - if(part[0] == "tile") eval(tile, part[1]); - - if(part[0] == "mosaicWidth") mosaicWidth = eval(part[1]); - if(part[0] == "mosaicHeight") mosaicHeight = eval(part[1]); - if(part[0] == "mosaicStride") mosaicStride = eval(part[1]); - if(part[0] == "mosaicOffset") mosaicOffset = eval(part[1]); - if(part[0] == "mosaic") eval(mosaic, part[1]); - - if(part[0] == "paddingWidth") paddingWidth = eval(part[1]); - if(part[0] == "paddingHeight") paddingHeight = eval(part[1]); - if(part[0] == "paddingColor") paddingColor = eval(part[1]); - if(part[0] == "palette") eval(palette, part[1]); - } - - sanitize(); - } - - inline bool load(const string &filename) { - string filedata; - if(filedata.readfile(filename) == false) return false; - parse(filedata); - return true; - } - - inline void sanitize() { - if(depth < 1) depth = 1; - if(depth > 24) depth = 24; - - if(blockWidth < 1) blockWidth = 1; - if(blockHeight < 1) blockHeight = 1; - - if(tileWidth < 1) tileWidth = 1; - if(tileHeight < 1) tileHeight = 1; - - if(mosaicWidth < 1) mosaicWidth = 1; - if(mosaicHeight < 1) mosaicHeight = 1; - } - - inline void reset() { - offset = 0; - width = 0; - height = 0; - count = 0; - - endian = 1; - order = 0; - depth = 1; - - blockWidth = 1; - blockHeight = 1; - blockStride = 0; - blockOffset = 0; - block.reset(); - - tileWidth = 1; - tileHeight = 1; - tileStride = 0; - tileOffset = 0; - tile.reset(); - - mosaicWidth = 1; - mosaicHeight = 1; - mosaicStride = 0; - mosaicOffset = 0; - mosaic.reset(); - - paddingWidth = 0; - paddingHeight = 0; - paddingColor = 0x000000; - palette.reset(); - } - - inline context() { - reset(); - } -}; - -} -} - -#endif diff --git a/ananke/nall/mosaic/parser.hpp b/ananke/nall/mosaic/parser.hpp deleted file mode 100644 index b2c0b8ef..00000000 --- a/ananke/nall/mosaic/parser.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct parser { - image canvas; - - //export from bitstream to canvas - inline void load(bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - canvas.allocate(width, height); - canvas.clear(ctx.paddingColor); - parse(1, stream, offset, ctx, width, height); - } - - //import from canvas to bitstream - inline bool save(bitstream &stream, uint64_t offset, context &ctx) { - if(stream.readonly) return false; - parse(0, stream, offset, ctx, canvas.width, canvas.height); - return true; - } - - inline parser() : canvas(0, 32, 0u, 255u << 16, 255u << 8, 255u << 0) { - } - -private: - inline uint32_t read(unsigned x, unsigned y) const { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return 0u; - uint32_t *buffer = (uint32_t*)canvas.data; - return buffer[addr]; - } - - inline void write(unsigned x, unsigned y, uint32_t data) { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return; - uint32_t *buffer = (uint32_t*)canvas.data; - buffer[addr] = data; - } - - inline void parse(bool load, bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - stream.endian = ctx.endian; - unsigned canvasWidth = width / (ctx.mosaicWidth * ctx.tileWidth * ctx.blockWidth + ctx.paddingWidth); - unsigned canvasHeight = height / (ctx.mosaicHeight * ctx.tileHeight * ctx.blockHeight + ctx.paddingHeight); - unsigned bitsPerBlock = ctx.depth * ctx.blockWidth * ctx.blockHeight; - - unsigned objectOffset = 0; - for(unsigned objectY = 0; objectY < canvasHeight; objectY++) { - for(unsigned objectX = 0; objectX < canvasWidth; objectX++) { - if(objectOffset >= ctx.count && ctx.count > 0) break; - unsigned objectIX = objectX * ctx.objectWidth(); - unsigned objectIY = objectY * ctx.objectHeight(); - objectOffset++; - - unsigned mosaicOffset = 0; - for(unsigned mosaicY = 0; mosaicY < ctx.mosaicHeight; mosaicY++) { - for(unsigned mosaicX = 0; mosaicX < ctx.mosaicWidth; mosaicX++) { - unsigned mosaicData = ctx.mosaic(mosaicOffset, mosaicOffset); - unsigned mosaicIX = (mosaicData % ctx.mosaicWidth) * (ctx.tileWidth * ctx.blockWidth); - unsigned mosaicIY = (mosaicData / ctx.mosaicWidth) * (ctx.tileHeight * ctx.blockHeight); - mosaicOffset++; - - unsigned tileOffset = 0; - for(unsigned tileY = 0; tileY < ctx.tileHeight; tileY++) { - for(unsigned tileX = 0; tileX < ctx.tileWidth; tileX++) { - unsigned tileData = ctx.tile(tileOffset, tileOffset); - unsigned tileIX = (tileData % ctx.tileWidth) * ctx.blockWidth; - unsigned tileIY = (tileData / ctx.tileWidth) * ctx.blockHeight; - tileOffset++; - - unsigned blockOffset = 0; - for(unsigned blockY = 0; blockY < ctx.blockHeight; blockY++) { - for(unsigned blockX = 0; blockX < ctx.blockWidth; blockX++) { - if(load) { - unsigned palette = 0; - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - palette |= stream.read(offset + ctx.block(index, index)) << n; - } - - write( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY, - ctx.palette(palette, palette) - ); - } else /* save */ { - uint32_t palette = read( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY - ); - - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - stream.write(offset + ctx.block(index, index), palette & 1); - palette >>= 1; - } - } - } //blockX - } //blockY - - offset += ctx.blockStride; - } //tileX - - offset += ctx.blockOffset; - } //tileY - - offset += ctx.tileStride; - } //mosaicX - - offset += ctx.tileOffset; - } //mosaicY - - offset += ctx.mosaicStride; - } //objectX - - offset += ctx.mosaicOffset; - } //objectY - } -}; - -} -} - -#endif diff --git a/ananke/nall/nall.hpp b/ananke/nall/nall.hpp deleted file mode 100644 index a7887695..00000000 --- a/ananke/nall/nall.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NALL_HPP -#define NALL_HPP - -//include the most common nall headers with one statement -//does not include the most obscure components with high cost and low usage - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include - #include -#endif - -#if defined(PLATFORM_X) - #include -#endif - -#endif diff --git a/ananke/nall/platform.hpp b/ananke/nall/platform.hpp deleted file mode 100644 index a45a6723..00000000 --- a/ananke/nall/platform.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef NALL_PLATFORM_HPP -#define NALL_PLATFORM_HPP - -#if defined(_WIN32) - //minimum version needed for _wstat64, etc - #undef __MSVCRT_VERSION__ - #define __MSVCRT_VERSION__ 0x0601 - #include -#endif - -//========================= -//standard platform headers -//========================= - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#if defined(_WIN32) - #include - #include - #include - #include - #undef interface - #define dllexport __declspec(dllexport) -#else - #include - #include - #define dllexport -#endif - -//================== -//warning supression -//================== - -//Visual C++ -#if defined(_MSC_VER) - //disable libc "deprecation" warnings - #pragma warning(disable:4996) -#endif - -//================ -//POSIX compliance -//================ - -#if defined(_MSC_VER) - #define PATH_MAX _MAX_PATH - #define va_copy(dest, src) ((dest) = (src)) -#endif - -#if defined(_WIN32) - #define getcwd _getcwd - #define putenv _putenv - #define vsnprintf _vsnprintf - inline void usleep(unsigned milliseconds) { Sleep(milliseconds / 1000); } -#endif - -//================ -//inline expansion -//================ - -#if defined(__GNUC__) - #define noinline __attribute__((noinline)) - #define inline inline - #define alwaysinline inline __attribute__((always_inline)) -#elif defined(_MSC_VER) - #define noinline __declspec(noinline) - #define inline inline - #define alwaysinline inline __forceinline -#else - #define noinline - #define inline inline - #define alwaysinline inline -#endif - -#endif diff --git a/ananke/nall/png.hpp b/ananke/nall/png.hpp deleted file mode 100644 index f5ebaab4..00000000 --- a/ananke/nall/png.hpp +++ /dev/null @@ -1,337 +0,0 @@ -#ifndef NALL_PNG_HPP -#define NALL_PNG_HPP - -//PNG image decoder -//author: byuu - -#include -#include - -namespace nall { - -struct png { - //colorType: - //0 = L - //2 = R,G,B - //3 = P - //4 = L,A - //6 = R,G,B,A - struct Info { - unsigned width; - unsigned height; - unsigned bitDepth; - unsigned colorType; - unsigned compressionMethod; - unsigned filterType; - unsigned interlaceMethod; - - unsigned bytesPerPixel; - unsigned pitch; - - uint8_t palette[256][3]; - } info; - - uint8_t *data; - unsigned size; - - inline bool decode(const string &filename); - inline bool decode(const uint8_t *sourceData, unsigned sourceSize); - inline unsigned readbits(const uint8_t *&data); - unsigned bitpos; - - inline png(); - inline ~png(); - -protected: - enum class FourCC : unsigned { - IHDR = 0x49484452, - PLTE = 0x504c5445, - IDAT = 0x49444154, - IEND = 0x49454e44, - }; - - inline unsigned interlace(unsigned pass, unsigned index); - inline unsigned inflateSize(); - inline bool deinterlace(const uint8_t *&inputData, unsigned pass); - inline bool filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height); - inline unsigned read(const uint8_t *data, unsigned length); -}; - -bool png::decode(const string &filename) { - if(auto memory = file::read(filename)) { - return decode(memory.data(), memory.size()); - } - return false; -} - -bool png::decode(const uint8_t *sourceData, unsigned sourceSize) { - if(sourceSize < 8) return false; - if(read(sourceData + 0, 4) != 0x89504e47) return false; - if(read(sourceData + 4, 4) != 0x0d0a1a0a) return false; - - uint8_t *compressedData = 0; - unsigned compressedSize = 0; - - unsigned offset = 8; - while(offset < sourceSize) { - unsigned length = read(sourceData + offset + 0, 4); - unsigned fourCC = read(sourceData + offset + 4, 4); - unsigned checksum = read(sourceData + offset + 8 + length, 4); - - if(fourCC == (unsigned)FourCC::IHDR) { - info.width = read(sourceData + offset + 8, 4); - info.height = read(sourceData + offset + 12, 4); - info.bitDepth = read(sourceData + offset + 16, 1); - info.colorType = read(sourceData + offset + 17, 1); - info.compressionMethod = read(sourceData + offset + 18, 1); - info.filterType = read(sourceData + offset + 19, 1); - info.interlaceMethod = read(sourceData + offset + 20, 1); - - if(info.bitDepth == 0 || info.bitDepth > 16) return false; - if(info.bitDepth & (info.bitDepth - 1)) return false; //not a power of two - if(info.compressionMethod != 0) return false; - if(info.filterType != 0) return false; - if(info.interlaceMethod != 0 && info.interlaceMethod != 1) return false; - - switch(info.colorType) { - case 0: info.bytesPerPixel = info.bitDepth * 1; break; //L - case 2: info.bytesPerPixel = info.bitDepth * 3; break; //R,G,B - case 3: info.bytesPerPixel = info.bitDepth * 1; break; //P - case 4: info.bytesPerPixel = info.bitDepth * 2; break; //L,A - case 6: info.bytesPerPixel = info.bitDepth * 4; break; //R,G,B,A - default: return false; - } - - if(info.colorType == 2 || info.colorType == 4 || info.colorType == 6) - if(info.bitDepth != 8 && info.bitDepth != 16) return false; - if(info.colorType == 3 && info.bitDepth == 16) return false; - - info.bytesPerPixel = (info.bytesPerPixel + 7) / 8; - info.pitch = (int)info.width * info.bytesPerPixel; - } - - if(fourCC == (unsigned)FourCC::PLTE) { - if(length % 3) return false; - for(unsigned n = 0, p = offset + 8; n < length / 3; n++) { - info.palette[n][0] = sourceData[p++]; - info.palette[n][1] = sourceData[p++]; - info.palette[n][2] = sourceData[p++]; - } - } - - if(fourCC == (unsigned)FourCC::IDAT) { - compressedData = (uint8_t*)realloc(compressedData, compressedSize + length); - memcpy(compressedData + compressedSize, sourceData + offset + 8, length); - compressedSize += length; - } - - if(fourCC == (unsigned)FourCC::IEND) { - break; - } - - offset += 4 + 4 + length + 4; - } - - unsigned interlacedSize = inflateSize(); - uint8_t *interlacedData = new uint8_t[interlacedSize]; - - bool result = inflate(interlacedData, interlacedSize, compressedData + 2, compressedSize - 6); - delete[] compressedData; - - if(result == false) { - delete[] interlacedData; - return false; - } - - size = info.width * info.height * info.bytesPerPixel; - data = new uint8_t[size]; - - if(info.interlaceMethod == 0) { - if(filter(data, interlacedData, info.width, info.height) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } else { - const uint8_t *passData = interlacedData; - for(unsigned pass = 0; pass < 7; pass++) { - if(deinterlace(passData, pass) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } - } - - delete[] interlacedData; - return true; -} - -unsigned png::interlace(unsigned pass, unsigned index) { - static const unsigned data[7][4] = { - //x-distance, y-distance, x-origin, y-origin - { 8, 8, 0, 0 }, - { 8, 8, 4, 0 }, - { 4, 8, 0, 4 }, - { 4, 4, 2, 0 }, - { 2, 4, 0, 2 }, - { 2, 2, 1, 0 }, - { 1, 2, 0, 1 }, - }; - return data[pass][index]; -} - -unsigned png::inflateSize() { - if(info.interlaceMethod == 0) { - return info.width * info.height * info.bytesPerPixel + info.height; - } - - unsigned size = 0; - for(unsigned pass = 0; pass < 7; pass++) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) continue; - size += width * height * info.bytesPerPixel + height; - } - return size; -} - -bool png::deinterlace(const uint8_t *&inputData, unsigned pass) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) return true; - - unsigned outputSize = width * height * info.bytesPerPixel; - uint8_t *outputData = new uint8_t[outputSize]; - bool result = filter(outputData, inputData, width, height); - - const uint8_t *rd = outputData; - for(unsigned y = yo; y < info.height; y += yd) { - uint8_t *wr = data + y * info.pitch; - for(unsigned x = xo; x < info.width; x += xd) { - for(unsigned b = 0; b < info.bytesPerPixel; b++) { - wr[x * info.bytesPerPixel + b] = *rd++; - } - } - } - - inputData += outputSize + height; - delete[] outputData; - return result; -} - -bool png::filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height) { - uint8_t *wr = outputData; - const uint8_t *rd = inputData; - int bpp = info.bytesPerPixel, pitch = width * bpp; - for(int y = 0; y < height; y++) { - uint8_t filter = *rd++; - - switch(filter) { - case 0x00: //None - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x]; - } - break; - - case 0x01: //Subtract - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (x - bpp < 0 ? 0 : wr[x - bpp]); - } - break; - - case 0x02: //Above - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (y - 1 < 0 ? 0 : wr[x - pitch]); - } - break; - - case 0x03: //Average - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - - wr[x] = rd[x] + (uint8_t)((a + b) / 2); - } - break; - - case 0x04: //Paeth - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - short c = x - bpp < 0 || y - 1 < 0 ? 0 : wr[x - pitch - bpp]; - - short p = a + b - c; - short pa = p > a ? p - a : a - p; - short pb = p > b ? p - b : b - p; - short pc = p > c ? p - c : c - p; - - uint8_t paeth = (uint8_t)((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); - - wr[x] = rd[x] + paeth; - } - break; - - default: //Invalid - return false; - } - - rd += pitch; - wr += pitch; - } - - return true; -} - -unsigned png::read(const uint8_t *data, unsigned length) { - unsigned result = 0; - while(length--) result = (result << 8) | (*data++); - return result; -} - -unsigned png::readbits(const uint8_t *&data) { - unsigned result = 0; - switch(info.bitDepth) { - case 1: - result = (*data >> bitpos) & 1; - bitpos++; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 2: - result = (*data >> bitpos) & 3; - bitpos += 2; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 4: - result = (*data >> bitpos) & 15; - bitpos += 4; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 8: - result = *data++; - break; - case 16: - result = (data[0] << 8) | (data[1] << 0); - data += 2; - break; - } - return result; -} - -png::png() : data(nullptr) { - bitpos = 0; -} - -png::~png() { - if(data) delete[] data; -} - -} - -#endif diff --git a/ananke/nall/priority-queue.hpp b/ananke/nall/priority-queue.hpp deleted file mode 100644 index 1aedc6f1..00000000 --- a/ananke/nall/priority-queue.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef NALL_PRIORITY_QUEUE_HPP -#define NALL_PRIORITY_QUEUE_HPP - -#include -#include -#include -#include - -namespace nall { - template void priority_queue_nocallback(type_t) {} - - //priority queue implementation using binary min-heap array; - //does not require normalize() function. - //O(1) find (tick) - //O(log n) append (enqueue) - //O(log n) remove (dequeue) - template class priority_queue { - public: - inline void tick(unsigned ticks) { - basecounter += ticks; - while(heapsize && gte(basecounter, heap[0].counter)) callback(dequeue()); - } - - //counter is relative to current time (eg enqueue(64, ...) fires in 64 ticks); - //counter cannot exceed std::numeric_limits::max() >> 1. - void enqueue(unsigned counter, type_t event) { - unsigned child = heapsize++; - counter += basecounter; - - while(child) { - unsigned parent = (child - 1) >> 1; - if(gte(counter, heap[parent].counter)) break; - - heap[child].counter = heap[parent].counter; - heap[child].event = heap[parent].event; - child = parent; - } - - heap[child].counter = counter; - heap[child].event = event; - } - - type_t dequeue() { - type_t event(heap[0].event); - unsigned parent = 0; - unsigned counter = heap[--heapsize].counter; - - while(true) { - unsigned child = (parent << 1) + 1; - if(child >= heapsize) break; - if(child + 1 < heapsize && gte(heap[child].counter, heap[child + 1].counter)) child++; - if(gte(heap[child].counter, counter)) break; - - heap[parent].counter = heap[child].counter; - heap[parent].event = heap[child].event; - parent = child; - } - - heap[parent].counter = counter; - heap[parent].event = heap[heapsize].event; - return event; - } - - void reset() { - basecounter = 0; - heapsize = 0; - } - - void serialize(serializer &s) { - s.integer(basecounter); - s.integer(heapsize); - for(unsigned n = 0; n < heapcapacity; n++) { - s.integer(heap[n].counter); - s.integer(heap[n].event); - } - } - - priority_queue(unsigned size, function callback_ = &priority_queue_nocallback) - : callback(callback_) { - heap = new heap_t[size]; - heapcapacity = size; - reset(); - } - - ~priority_queue() { - delete[] heap; - } - - priority_queue& operator=(const priority_queue&) = delete; - priority_queue(const priority_queue&) = delete; - - private: - function callback; - unsigned basecounter; - unsigned heapsize; - unsigned heapcapacity; - struct heap_t { - unsigned counter; - type_t event; - } *heap; - - //return true if x is greater than or equal to y - inline bool gte(unsigned x, unsigned y) { - return x - y < (std::numeric_limits::max() >> 1); - } - }; -} - -#endif diff --git a/ananke/nall/property.hpp b/ananke/nall/property.hpp deleted file mode 100644 index 1ddb5c9b..00000000 --- a/ananke/nall/property.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef NALL_PROPERTY_HPP -#define NALL_PROPERTY_HPP - -//nall::property implements ownership semantics into container classes -//example: property::readonly implies that only owner has full -//access to type; and all other code has readonly access. -// -//property can be used either of two ways: -//struct foo { -// property::readonly x; -// property::readwrite y; -//}; -//-or- -//struct foo : property { -// readonly x; -// readwrite y; -//}; - -//return types are const T& (byref) instead of T (byval) to avoid major speed -//penalties for objects with expensive copy constructors - -//operator-> provides access to underlying object type: -//readonly foo; -//foo->bar(); -//... will call Object::bar(); - -//operator='s reference is constant so as to avoid leaking a reference handle -//that could bypass access restrictions - -//both constant and non-constant operators are provided, though it may be -//necessary to cast first, for instance: -//struct foo : property { readonly bar; } object; -//int main() { int value = const_cast(object); } - -//writeonly is useful for objects that have non-const reads, but const writes. -//however, to avoid leaking handles, the interface is very restricted. the only -//way to write is via operator=, which requires conversion via eg copy -//constructor. example: -//struct foo { -// foo(bool value) { ... } -//}; -//writeonly bar; -//bar = true; - -namespace nall { - template struct property { - template struct readonly { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - private: - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - friend C; - }; - - template struct writeonly { - void operator=(const T& value_) { value = value_; } - private: - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - T value; - friend C; - }; - - template struct readwrite { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - }; - }; -} - -#endif diff --git a/ananke/nall/public-cast.hpp b/ananke/nall/public-cast.hpp deleted file mode 100644 index 331800e1..00000000 --- a/ananke/nall/public-cast.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_PUBLIC_CAST_HPP -#define NALL_PUBLIC_CAST_HPP - -//this is a proof-of-concept-*only* C++ access-privilege elevation exploit. -//this code is 100% legal C++, per C++98 section 14.7.2 paragraph 8: -//"access checking rules do not apply to names in explicit instantiations." -//usage example: - -//struct N { typedef void (Class::*)(); }; -//template class public_cast; -//(class.*public_cast::value); - -//Class::Reference may be public, protected or private -//Class::Reference may be a function, object or variable - -namespace nall { - template struct public_cast; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value = public_cast::value = P; -} - -#endif diff --git a/ananke/nall/random.hpp b/ananke/nall/random.hpp deleted file mode 100644 index 409c4561..00000000 --- a/ananke/nall/random.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_RANDOM_HPP -#define NALL_RANDOM_HPP - -namespace nall { - //pseudo-random number generator - inline unsigned prng() { - static unsigned n = 0; - return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320); - } - - struct random_lfsr { - inline void seed(unsigned seed__) { - seed_ = seed__; - } - - inline unsigned operator()() { - return seed_ = (seed_ >> 1) ^ (((seed_ & 1) - 1) & 0xedb88320); - } - - random_lfsr() : seed_(0) { - } - - private: - unsigned seed_; - }; -} - -#endif diff --git a/ananke/nall/serial.hpp b/ananke/nall/serial.hpp deleted file mode 100644 index da87ae50..00000000 --- a/ananke/nall/serial.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef NALL_SERIAL_HPP -#define NALL_SERIAL_HPP - -#include -#include -#include -#include - -#include - -namespace nall { - struct serial { - bool readable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, &fdset, nullptr, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes read - int read(uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::read(port, (void*)data, length); - } - - bool writable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, nullptr, &fdset, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes written - int write(const uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::write(port, (void*)data, length); - } - - bool open(const char *portname, unsigned rate, bool flowcontrol) { - close(); - - port = ::open(portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); - if(port == -1) return false; - - if(ioctl(port, TIOCEXCL) == -1) { close(); return false; } - if(fcntl(port, F_SETFL, 0) == -1) { close(); return false; } - if(tcgetattr(port, &original_attr) == -1) { close(); return false; } - - termios attr = original_attr; - cfmakeraw(&attr); - cfsetspeed(&attr, rate); - - attr.c_lflag &=~ (ECHO | ECHONL | ISIG | ICANON | IEXTEN); - attr.c_iflag &=~ (BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY); - attr.c_iflag |= (IGNBRK | IGNPAR); - attr.c_oflag &=~ (OPOST); - attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB | CLOCAL); - attr.c_cflag |= (CS8 | CREAD); - if(flowcontrol == false) { - attr.c_cflag &= ~CRTSCTS; - } else { - attr.c_cflag |= CRTSCTS; - } - attr.c_cc[VTIME] = attr.c_cc[VMIN] = 0; - - if(tcsetattr(port, TCSANOW, &attr) == -1) { close(); return false; } - return port_open = true; - } - - void close() { - if(port != -1) { - tcdrain(port); - if(port_open == true) { - tcsetattr(port, TCSANOW, &original_attr); - port_open = false; - } - ::close(port); - port = -1; - } - } - - serial() { - port = -1; - port_open = false; - } - - ~serial() { - close(); - } - - private: - int port; - bool port_open; - termios original_attr; - }; -} - -#endif diff --git a/ananke/nall/serializer.hpp b/ananke/nall/serializer.hpp deleted file mode 100644 index fcb39456..00000000 --- a/ananke/nall/serializer.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef NALL_SERIALIZER_HPP -#define NALL_SERIALIZER_HPP - -#include -#include -#include -#include - -namespace nall { - //serializer: a class designed to save and restore the state of classes. - // - //benefits: - //- data() will be portable in size (it is not necessary to specify type sizes.) - //- data() will be portable in endianness (always stored internally as little-endian.) - //- one serialize function can both save and restore class states. - // - //caveats: - //- only plain-old-data can be stored. complex classes must provide serialize(serializer&); - //- floating-point usage is not portable across platforms - - class serializer { - public: - enum mode_t { Load, Save, Size }; - - mode_t mode() const { - return imode; - } - - const uint8_t* data() const { - return idata; - } - - unsigned size() const { - return isize; - } - - unsigned capacity() const { - return icapacity; - } - - template void floatingpoint(T &value) { - enum { size = sizeof(T) }; - //this is rather dangerous, and not cross-platform safe; - //but there is no standardized way to export FP-values - uint8_t *p = (uint8_t*)&value; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = p[n]; - } else if(imode == Load) { - for(unsigned n = 0; n < size; n++) p[n] = idata[isize++]; - } else { - isize += size; - } - } - - template void integer(T &value) { - enum { size = std::is_same::value ? 1 : sizeof(T) }; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = (uintmax_t)value >> (n << 3); - } else if(imode == Load) { - value = 0; - for(unsigned n = 0; n < size; n++) value |= (uintmax_t)idata[isize++] << (n << 3); - } else if(imode == Size) { - isize += size; - } - } - - template void array(T &array) { - enum { size = sizeof(T) / sizeof(typename std::remove_extent::type) }; - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - template void array(T array, unsigned size) { - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - //copy - serializer& operator=(const serializer &s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = new uint8_t[s.icapacity]; - isize = s.isize; - icapacity = s.icapacity; - - memcpy(idata, s.idata, s.icapacity); - return *this; - } - - serializer(const serializer &s) : idata(0) { - operator=(s); - } - - //move - serializer& operator=(serializer &&s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = s.idata; - isize = s.isize; - icapacity = s.icapacity; - - s.idata = 0; - return *this; - } - - serializer(serializer &&s) { - operator=(std::move(s)); - } - - //construction - serializer() { - imode = Size; - idata = 0; - isize = 0; - icapacity = 0; - } - - serializer(unsigned capacity) { - imode = Save; - idata = new uint8_t[capacity](); - isize = 0; - icapacity = capacity; - } - - serializer(const uint8_t *data, unsigned capacity) { - imode = Load; - idata = new uint8_t[capacity]; - isize = 0; - icapacity = capacity; - memcpy(idata, data, capacity); - } - - ~serializer() { - if(idata) delete[] idata; - } - - private: - mode_t imode; - uint8_t *idata; - unsigned isize; - unsigned icapacity; - }; - -}; - -#endif diff --git a/ananke/nall/set.hpp b/ananke/nall/set.hpp deleted file mode 100644 index c6d3d06e..00000000 --- a/ananke/nall/set.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef NALL_SET_HPP -#define NALL_SET_HPP - -//set -//* unordered -//* intended for unique items -//* dynamic growth -//* reference-based variant - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - -template struct set; - -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - T *pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } -}; - -//reference set -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - typedef typename std::remove_reference::type T; - T **pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - void reset() { - if(pool) free(pool); - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - if(size == poolsize) return; - pool = (T**)realloc(pool, sizeof(T*) * size); - poolsize = size; - objectsize = min(objectsize, size); - } - - void resize(unsigned size) { - if(size > poolsize) reserve(bit::round(size)); //amortize growth - objectsize = size; - } - - bool append(T& data) { - if(find(data)) return false; - unsigned offset = objectsize++; - if(offset >= poolsize) resize(offset + 1); - pool[offset] = &data; - return true; - } - - template - bool append(T& data, Args&&... args) { - bool result = append(data); - append(std::forward(args)...); - return result; - } - - bool remove(T& data) { - if(auto position = find(data)) { - for(signed i = position(); i < objectsize - 1; i++) pool[i] = pool[i + 1]; - resize(objectsize - 1); - return true; - } - return false; - } - - optional find(const T& data) { - for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return {true, n}; - return {false, 0u}; - } - - template set(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) { - construct(std::forward(args)...); - } - - ~set() { - reset(); - } - - set& operator=(const set &source) { - if(&source == this) return *this; - if(pool) free(pool); - objectsize = source.objectsize; - poolsize = source.poolsize; - pool = (T**)malloc(sizeof(T*) * poolsize); - memcpy(pool, source.pool, sizeof(T*) * objectsize); - return *this; - } - - set& operator=(const set &&source) { - if(&source == this) return *this; - if(pool) free(pool); - pool = source.pool; - poolsize = source.poolsize; - objectsize = source.objectsize; - source.pool = nullptr; - source.reset(); - return *this; - } - - T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return *pool[position]; - } - - struct iterator { - bool operator!=(const iterator &source) const { return position != source.position; } - T& operator*() { return source.operator[](position); } - iterator& operator++() { position++; return *this; } - iterator(const set &source, unsigned position) : source(source), position(position) {} - private: - const set &source; - unsigned position; - }; - - iterator begin() { return iterator(*this, 0); } - iterator end() { return iterator(*this, objectsize); } - const iterator begin() const { return iterator(*this, 0); } - const iterator end() const { return iterator(*this, objectsize); } - -private: - void construct() {} - void construct(const set &source) { operator=(source); } - void construct(const set &&source) { operator=(std::move(source)); } - template void construct(T& data, Args&&... args) { - append(data); - construct(std::forward(args)...); - } -}; - -} - -#endif diff --git a/ananke/nall/sha256.hpp b/ananke/nall/sha256.hpp deleted file mode 100644 index c63367a7..00000000 --- a/ananke/nall/sha256.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef NALL_SHA256_HPP -#define NALL_SHA256_HPP - -//author: vladitx - -#include - -namespace nall { - #define PTR(t, a) ((t*)(a)) - - #define SWAP32(x) ((uint32_t)( \ - (((uint32_t)(x) & 0x000000ff) << 24) | \ - (((uint32_t)(x) & 0x0000ff00) << 8) | \ - (((uint32_t)(x) & 0x00ff0000) >> 8) | \ - (((uint32_t)(x) & 0xff000000) >> 24) \ - )) - - #define ST32(a, d) *PTR(uint32_t, a) = (d) - #define ST32BE(a, d) ST32(a, SWAP32(d)) - - #define LD32(a) *PTR(uint32_t, a) - #define LD32BE(a) SWAP32(LD32(a)) - - #define LSL32(x, n) ((uint32_t)(x) << (n)) - #define LSR32(x, n) ((uint32_t)(x) >> (n)) - #define ROR32(x, n) (LSR32(x, n) | LSL32(x, 32 - (n))) - - //first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19 - static const uint32_t T_H[8] = { - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, - }; - - //first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311 - static const uint32_t T_K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, - }; - - struct sha256_ctx { - uint8_t in[64]; - unsigned inlen; - - uint32_t w[64]; - uint32_t h[8]; - uint64_t len; - }; - - inline void sha256_init(sha256_ctx *p) { - memset(p, 0, sizeof(sha256_ctx)); - memcpy(p->h, T_H, sizeof(T_H)); - } - - static void sha256_block(sha256_ctx *p) { - unsigned i; - uint32_t s0, s1; - uint32_t a, b, c, d, e, f, g, h; - uint32_t t1, t2, maj, ch; - - for(i = 0; i < 16; i++) p->w[i] = LD32BE(p->in + i * 4); - - for(i = 16; i < 64; i++) { - s0 = ROR32(p->w[i - 15], 7) ^ ROR32(p->w[i - 15], 18) ^ LSR32(p->w[i - 15], 3); - s1 = ROR32(p->w[i - 2], 17) ^ ROR32(p->w[i - 2], 19) ^ LSR32(p->w[i - 2], 10); - p->w[i] = p->w[i - 16] + s0 + p->w[i - 7] + s1; - } - - a = p->h[0]; b = p->h[1]; c = p->h[2]; d = p->h[3]; - e = p->h[4]; f = p->h[5]; g = p->h[6]; h = p->h[7]; - - for(i = 0; i < 64; i++) { - s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22); - maj = (a & b) ^ (a & c) ^ (b & c); - t2 = s0 + maj; - s1 = ROR32(e, 6) ^ ROR32(e, 11) ^ ROR32(e, 25); - ch = (e & f) ^ (~e & g); - t1 = h + s1 + ch + T_K[i] + p->w[i]; - - h = g; g = f; f = e; e = d + t1; - d = c; c = b; b = a; a = t1 + t2; - } - - p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d; - p->h[4] += e; p->h[5] += f; p->h[6] += g; p->h[7] += h; - - //next block - p->inlen = 0; - } - - inline void sha256_chunk(sha256_ctx *p, const uint8_t *s, unsigned len) { - unsigned l; - p->len += len; - - while(len) { - l = 64 - p->inlen; - l = (len < l) ? len : l; - - memcpy(p->in + p->inlen, s, l); - s += l; - p->inlen += l; - len -= l; - - if(p->inlen == 64) sha256_block(p); - } - } - - inline void sha256_final(sha256_ctx *p) { - uint64_t len; - p->in[p->inlen++] = 0x80; - - if(p->inlen > 56) { - memset(p->in + p->inlen, 0, 64 - p->inlen); - sha256_block(p); - } - - memset(p->in + p->inlen, 0, 56 - p->inlen); - - len = p->len << 3; - ST32BE(p->in + 56, len >> 32); - ST32BE(p->in + 60, len); - sha256_block(p); - } - - inline void sha256_hash(sha256_ctx *p, uint8_t *s) { - uint32_t *t = (uint32_t*)s; - for(unsigned i = 0; i < 8; i++) ST32BE(t++, p->h[i]); - } - - #undef PTR - #undef SWAP32 - #undef ST32 - #undef ST32BE - #undef LD32 - #undef LD32BE - #undef LSL32 - #undef LSR32 - #undef ROR32 -} - -#endif diff --git a/ananke/nall/sort.hpp b/ananke/nall/sort.hpp deleted file mode 100644 index 8326ab1d..00000000 --- a/ananke/nall/sort.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef NALL_SORT_HPP -#define NALL_SORT_HPP - -#include -#include - -//class: merge sort -//average: O(n log n) -//worst: O(n log n) -//memory: O(n) -//stack: O(log n) -//stable?: yes - -//note: merge sort was chosen over quick sort, because: -//* it is a stable sort -//* it lacks O(n^2) worst-case overhead - -#define NALL_SORT_INSERTION -//#define NALL_SORT_SELECTION - -namespace nall { - template - void sort(T list[], unsigned size, const Comparator &lessthan) { - if(size <= 1) return; //nothing to sort - - //use insertion sort to quickly sort smaller blocks - if(size < 64) { - #if defined(NALL_SORT_INSERTION) - for(signed i = 1, j; i < size; i++) { - T copy = std::move(list[i]); - for(j = i - 1; j >= 0; j--) { - if(!lessthan(copy, list[j])) break; - list[j + 1] = std::move(list[j]); - } - list[j + 1] = std::move(copy); - } - #elif defined(NALL_SORT_SELECTION) - for(unsigned i = 0; i < size; i++) { - unsigned min = i; - for(unsigned j = i + 1; j < size; j++) { - if(lessthan(list[j], list[min])) min = j; - } - if(min != i) std::swap(list[i], list[min]); - } - #endif - return; - } - - //split list in half and recursively sort both - unsigned middle = size / 2; - sort(list, middle, lessthan); - sort(list + middle, size - middle, lessthan); - - //left and right are sorted here; perform merge sort - T *buffer = new T[size]; - unsigned offset = 0, left = 0, right = middle; - while(left < middle && right < size) { - if(!lessthan(list[right], list[left])) { - buffer[offset++] = std::move(list[left++]); - } else { - buffer[offset++] = std::move(list[right++]); - } - } - while(left < middle) buffer[offset++] = std::move(list[left++]); - while(right < size) buffer[offset++] = std::move(list[right++]); - - for(unsigned i = 0; i < size; i++) list[i] = std::move(buffer[i]); - delete[] buffer; - } - - template - void sort(T list[], unsigned size) { - return sort(list, size, [](const T &l, const T &r) { return l < r; }); - } -} - -#endif diff --git a/ananke/nall/stdint.hpp b/ananke/nall/stdint.hpp deleted file mode 100644 index c63f5912..00000000 --- a/ananke/nall/stdint.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STDINT_HPP -#define NALL_STDINT_HPP - -#if defined(_MSC_VER) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef signed long long int64_t; - typedef int64_t intmax_t; - #if defined(_WIN64) - typedef int64_t intptr_t; - #else - typedef int32_t intptr_t; - #endif - - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; - typedef unsigned long long uint64_t; - typedef uint64_t uintmax_t; - #if defined(_WIN64) - typedef uint64_t uintptr_t; - #else - typedef uint32_t uintptr_t; - #endif -#else - #include -#endif - -namespace nall { - static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size"); - - static_assert(sizeof(uint8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(uint16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(uint32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(uint64_t) == 8, "int64_t is not of the correct size"); -} - -#endif diff --git a/ananke/nall/stream/auto.hpp b/ananke/nall/stream/auto.hpp deleted file mode 100644 index d1b6e2ba..00000000 --- a/ananke/nall/stream/auto.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NALL_STREAM_AUTO_HPP -#define NALL_STREAM_AUTO_HPP - -namespace nall { - -#define autostream(...) (*makestream(__VA_ARGS__)) - -inline std::unique_ptr makestream(const string &path) { - if(path.ibeginswith("http://")) return std::unique_ptr(new httpstream(path, 80)); - if(path.iendswith(".gz")) return std::unique_ptr(new gzipstream(filestream{path})); - if(path.iendswith(".zip")) return std::unique_ptr(new zipstream(filestream{path})); - return std::unique_ptr(new mmapstream(path)); -} - -inline std::unique_ptr makestream(uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -inline std::unique_ptr makestream(const uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -} - -#endif diff --git a/ananke/nall/stream/file.hpp b/ananke/nall/stream/file.hpp deleted file mode 100644 index 878418cf..00000000 --- a/ananke/nall/stream/file.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_FILE_HPP -#define NALL_STREAM_FILE_HPP - -#include - -namespace nall { - -struct filestream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return false; } - - unsigned size() const { return pfile.size(); } - unsigned offset() const { return pfile.offset(); } - void seek(unsigned offset) const { pfile.seek(offset); } - - uint8_t read() const { return pfile.read(); } - void write(uint8_t data) const { pfile.write(data); } - - filestream(const string &filename) { - pfile.open(filename, file::mode::readwrite); - pwritable = pfile.open(); - if(!pwritable) pfile.open(filename, file::mode::read); - } - - filestream(const string &filename, file::mode mode) { - pfile.open(filename, mode); - pwritable = mode == file::mode::write || mode == file::mode::readwrite; - } - -private: - mutable file pfile; - bool pwritable; -}; - -} - -#endif diff --git a/ananke/nall/stream/gzip.hpp b/ananke/nall/stream/gzip.hpp deleted file mode 100644 index 0c270a72..00000000 --- a/ananke/nall/stream/gzip.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NALL_STREAM_GZIP_HPP -#define NALL_STREAM_GZIP_HPP - -#include - -namespace nall { - -struct gzipstream : memorystream { - using stream::read; - using stream::write; - - gzipstream(const stream &stream) { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - gzip archive; - bool result = archive.decompress(data, size); - delete[] data; - if(result == false) return; - - psize = archive.size; - pdata = new uint8_t[psize]; - memcpy(pdata, archive.data, psize); - } - - ~gzipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/ananke/nall/stream/http.hpp b/ananke/nall/stream/http.hpp deleted file mode 100644 index 2f9e45dd..00000000 --- a/ananke/nall/stream/http.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef NALL_STREAM_HTTP_HPP -#define NALL_STREAM_HTTP_HPP - -#include - -namespace nall { - -struct httpstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return true; } - bool randomaccess() const { return true; } - - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - httpstream(const string &url, unsigned port) : pdata(nullptr), psize(0), poffset(0) { - string uri = url; - uri.ltrim<1>("http://"); - lstring part = uri.split<1>("/"); - part[1] = { "/", part[1] }; - - http connection; - if(connection.connect(part[0], port) == false) return; - connection.download(part[1], pdata, psize); - } - - ~httpstream() { - if(pdata) delete[] pdata; - } - -private: - mutable uint8_t *pdata; - mutable unsigned psize, poffset; -}; - -} - -#endif diff --git a/ananke/nall/stream/memory.hpp b/ananke/nall/stream/memory.hpp deleted file mode 100644 index cf49b3b2..00000000 --- a/ananke/nall/stream/memory.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef NALL_STREAM_MEMORY_HPP -#define NALL_STREAM_MEMORY_HPP - -#include - -namespace nall { - -struct memorystream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t *data() const { return pdata; } - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - memorystream() : pdata(nullptr), psize(0), poffset(0), pwritable(true) {} - - memorystream(uint8_t *data, unsigned size) { - pdata = data, psize = size, poffset = 0; - pwritable = true; - } - - memorystream(const uint8_t *data, unsigned size) { - pdata = (uint8_t*)data, psize = size, poffset = 0; - pwritable = false; - } - -protected: - mutable uint8_t *pdata; - mutable unsigned psize, poffset, pwritable; -}; - -} - -#endif diff --git a/ananke/nall/stream/mmap.hpp b/ananke/nall/stream/mmap.hpp deleted file mode 100644 index ce30f810..00000000 --- a/ananke/nall/stream/mmap.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_MMAP_HPP -#define NALL_STREAM_MMAP_HPP - -#include - -namespace nall { - -struct mmapstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - unsigned size() const { return pmmap.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - mmapstream(const string &filename) { - pmmap.open(filename, filemap::mode::readwrite); - pwritable = pmmap.open(); - if(!pwritable) pmmap.open(filename, filemap::mode::read); - pdata = pmmap.data(), poffset = 0; - } - -private: - mutable filemap pmmap; - mutable uint8_t *pdata; - mutable unsigned pwritable, poffset; -}; - -} - -#endif diff --git a/ananke/nall/stream/stream.hpp b/ananke/nall/stream/stream.hpp deleted file mode 100644 index 043eecba..00000000 --- a/ananke/nall/stream/stream.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef NALL_STREAM_STREAM_HPP -#define NALL_STREAM_STREAM_HPP - -namespace nall { - -struct stream { - virtual bool seekable() const = 0; - virtual bool readable() const = 0; - virtual bool writable() const = 0; - virtual bool randomaccess() const = 0; - - virtual uint8_t* data() const { return nullptr; } - virtual unsigned size() const = 0; - virtual unsigned offset() const = 0; - virtual void seek(unsigned offset) const = 0; - - virtual uint8_t read() const = 0; - virtual void write(uint8_t data) const = 0; - - virtual uint8_t read(unsigned) const { return 0; } - virtual void write(unsigned, uint8_t) const {} - - operator bool() const { - return size(); - } - - bool empty() const { - return size() == 0; - } - - bool end() const { - return offset() >= size(); - } - - uintmax_t readl(unsigned length = 1) const { - uintmax_t data = 0, shift = 0; - while(length--) { data |= read() << shift; shift += 8; } - return data; - } - - uintmax_t readm(unsigned length = 1) const { - uintmax_t data = 0; - while(length--) data = (data << 8) | read(); - return data; - } - - void read(uint8_t *data, unsigned length) const { - while(length--) *data++ = read(); - } - - string text() const { - string buffer; - buffer.resize(size() + 1); - buffer[size()] = 0; - seek(0); - read((uint8_t*)buffer(), size()); - return buffer; - } - - void writel(uintmax_t data, unsigned length = 1) const { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) const { - uintmax_t shift = 8 * length; - while(length--) { - shift -= 8; - write(data >> shift); - } - } - - void write(const uint8_t *data, unsigned length) const { - while(length--) write(*data++); - } - - struct byte { - operator uint8_t() const { return s.read(offset); } - byte& operator=(uint8_t data) { s.write(offset, data); return *this; } - byte(const stream &s, unsigned offset) : s(s), offset(offset) {} - - private: - const stream &s; - const unsigned offset; - }; - - byte operator[](unsigned offset) const { - return byte(*this, offset); - } - - stream() {} - virtual ~stream() {} - stream(const stream&) = delete; - stream& operator=(const stream&) = delete; -}; - -} - -#endif diff --git a/ananke/nall/stream/vector.hpp b/ananke/nall/stream/vector.hpp deleted file mode 100644 index 59f36c02..00000000 --- a/ananke/nall/stream/vector.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef NALL_STREAM_VECTOR_HPP -#define NALL_STREAM_VECTOR_HPP - -#include -#include - -namespace nall { - -struct vectorstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t* data() const { return memory.data(); } - unsigned size() const { return memory.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return memory[poffset++]; } - void write(uint8_t data) const { memory[poffset++] = data; } - - uint8_t read(unsigned offset) const { return memory[offset]; } - void write(unsigned offset, uint8_t data) const { memory[offset] = data; } - - vectorstream(vector &memory) : memory(memory), poffset(0), pwritable(true) {} - vectorstream(const vector &memory) : memory((vector&)memory), poffset(0), pwritable(false) {} - -protected: - vector &memory; - mutable unsigned poffset, pwritable; -}; - -} - -#endif diff --git a/ananke/nall/stream/zip.hpp b/ananke/nall/stream/zip.hpp deleted file mode 100644 index 94aa3992..00000000 --- a/ananke/nall/stream/zip.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef NALL_STREAM_ZIP_HPP -#define NALL_STREAM_ZIP_HPP - -#include - -namespace nall { - -struct zipstream : memorystream { - using stream::read; - using stream::write; - - zipstream(const stream &stream, const string &filter = "*") { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - unzip archive; - if(archive.open(data, size) == false) return; - delete[] data; - - for(auto &file : archive.file) { - if(file.name.wildcard(filter)) { - auto buffer = archive.extract(file); - psize = buffer.size(); - pdata = buffer.move(); - return; - } - } - } - - ~zipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/ananke/nall/string.hpp b/ananke/nall/string.hpp deleted file mode 100644 index 82b7cde4..00000000 --- a/ananke/nall/string.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef NALL_STRING_HPP -#define NALL_STRING_HPP - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define NALL_STRING_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STRING_INTERNAL_HPP - -#endif diff --git a/ananke/nall/string/base.hpp b/ananke/nall/string/base.hpp deleted file mode 100644 index d5f85ca4..00000000 --- a/ananke/nall/string/base.hpp +++ /dev/null @@ -1,229 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - struct cstring; - struct string; - struct lstring; - template inline const char* to_string(T); - - struct cstring { - inline operator const char*() const; - inline unsigned length() const; - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline cstring& operator=(const char *data); - inline cstring(const char *data); - inline cstring(); - - protected: - const char *data; - }; - - struct string { - inline static string read(const string &filename); - - inline static string date(); - inline static string time(); - inline static string datetime(); - - inline void reserve(unsigned); - inline void resize(unsigned); - inline void clear(char); - inline bool empty() const; - - template inline string& assign(Args&&... args); - template inline string& append(Args&&... args); - - inline bool readfile(const string&); - - template inline string& replace(const char*, const char*); - template inline string& ireplace(const char*, const char*); - template inline string& qreplace(const char*, const char*); - template inline string& iqreplace(const char*, const char*); - - inline unsigned length() const; - inline unsigned capacity() const; - - template inline lstring split(const char*) const; - template inline lstring isplit(const char*) const; - template inline lstring qsplit(const char*) const; - template inline lstring iqsplit(const char*) const; - - inline bool equals(const char*) const; - inline bool iequals(const char*) const; - - inline bool wildcard(const char*) const; - inline bool iwildcard(const char*) const; - - inline bool beginswith(const char*) const; - inline bool ibeginswith(const char*) const; - inline bool endswith(const char*) const; - inline bool iendswith(const char*) const; - - inline string& lower(); - inline string& upper(); - inline string& qlower(); - inline string& qupper(); - inline string& transform(const char *before, const char *after); - inline string& reverse(); - - template inline string& ltrim(const char *key = " "); - template inline string& rtrim(const char *key = " "); - template inline string& trim(const char *key = " ", const char *rkey = 0); - inline string& strip(); - - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline optional qposition(const char *key) const; - inline optional iqposition(const char *key) const; - - inline operator const char*() const; - inline char* operator()(); - inline char& operator[](int); - - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline bool operator< (const char*) const; - inline bool operator<=(const char*) const; - inline bool operator> (const char*) const; - inline bool operator>=(const char*) const; - - inline string& operator=(const string&); - inline string& operator=(string&&); - - template inline string(Args&&... args); - inline string(const string&); - inline string(string&&); - inline ~string(); - - inline char* begin() { return &data[0]; } - inline char* end() { return &data[length()]; } - inline const char* begin() const { return &data[0]; } - inline const char* end() const { return &data[length()]; } - - //internal functions - inline string& assign_(const char*); - inline string& append_(const char*); - - protected: - char *data; - unsigned size; - - template inline string& ureplace(const char*, const char*); - - #if defined(QSTRING_H) - public: - inline operator QString() const; - #endif - }; - - struct lstring : vector { - inline optional find(const char*) const; - inline string concatenate(const char*) const; - inline void append() {} - inline void isort(); - template inline void append(const string&, Args&&...); - - template inline lstring& split(const char*, const char*); - template inline lstring& isplit(const char*, const char*); - template inline lstring& qsplit(const char*, const char*); - template inline lstring& iqsplit(const char*, const char*); - - inline bool operator==(const lstring&) const; - inline bool operator!=(const lstring&) const; - - inline lstring& operator=(const lstring&); - inline lstring& operator=(lstring&); - inline lstring& operator=(lstring&&); - - template inline lstring(Args&&... args); - inline lstring(const lstring&); - inline lstring(lstring&); - inline lstring(lstring&&); - - protected: - template inline lstring& usplit(const char*, const char*); - }; - - //compare.hpp - inline char chrlower(char c); - inline char chrupper(char c); - inline int istrcmp(const char *str1, const char *str2); - inline bool strbegin(const char *str, const char *key); - inline bool istrbegin(const char *str, const char *key); - inline bool strend(const char *str, const char *key); - inline bool istrend(const char *str, const char *key); - - //convert.hpp - inline char* strlower(char *str); - inline char* strupper(char *str); - inline char* qstrlower(char *str); - inline char* qstrupper(char *str); - inline char* strtr(char *dest, const char *before, const char *after); - - //format.hpp - template inline string format(const string &value); - template inline string hex(uintmax_t value); - template inline string octal(uintmax_t value); - template inline string binary(uintmax_t value); - - //math.hpp - inline bool strint(const char *str, int &result); - inline bool strmath(const char *str, int &result); - - //platform.hpp - inline string activepath(); - inline string realpath(const string &name); - inline string userpath(); - inline string configpath(); - inline string temppath(); - - //strm.hpp - inline unsigned strmcpy(char *target, const char *source, unsigned length); - inline unsigned strmcat(char *target, const char *source, unsigned length); - inline bool strccpy(char *target, const char *source, unsigned length); - inline bool strccat(char *target, const char *source, unsigned length); - inline void strpcpy(char *&target, const char *source, unsigned &length); - - //strpos.hpp - inline optional strpos(const char *str, const char *key); - inline optional istrpos(const char *str, const char *key); - inline optional qstrpos(const char *str, const char *key); - inline optional iqstrpos(const char *str, const char *key); - template inline optional ustrpos(const char *str, const char *key); - - //trim.hpp - template inline char* ltrim(char *str, const char *key = " "); - template inline char* rtrim(char *str, const char *key = " "); - template inline char* trim(char *str, const char *key = " ", const char *rkey = 0); - inline char* strip(char *s); - - //utility.hpp - template alwaysinline bool chrequal(char x, char y); - template alwaysinline bool quoteskip(T *&p); - template alwaysinline bool quotecopy(char *&t, T *&p); - inline string substr(const char *src, unsigned start = 0, unsigned length = ~0u); - inline string sha256(const uint8_t *data, unsigned size); - - inline char* integer(char *result, intmax_t value); - inline char* decimal(char *result, uintmax_t value); - - //these functions are deprecated, use format() instead: - template inline string integer(intmax_t value); - template inline string linteger(intmax_t value); - template inline string decimal(uintmax_t value); - template inline string ldecimal(uintmax_t value); - inline unsigned fp(char *str, long double value); - inline string fp(long double value); - - //variadic.hpp - template inline void print(Args&&... args); - - //wildcard.hpp - inline bool wildcard(const char *str, const char *pattern); - inline bool iwildcard(const char *str, const char *pattern); -}; - -#endif diff --git a/ananke/nall/string/bsv.hpp b/ananke/nall/string/bsv.hpp deleted file mode 100644 index d9415d53..00000000 --- a/ananke/nall/string/bsv.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BSV v1.0 parser -//revision 0.02 - -namespace nall { - -struct BSV { - static inline string decode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '}' ) return ""; - if(*input == '\r') return ""; - if(*input == '\n') return ""; - - //normal characters - if(*input != '{') { output[offset++] = *input++; continue; } - - //entities - if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; } - if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; } - if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; } - - //illegal entities - return ""; - } - output[offset] = 0; - return output; - } - - static inline string encode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '\r') return ""; - - if(*input == '\n') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'f'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '{') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '}') { - output[offset++] = '{'; - output[offset++] = 'r'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - output[offset++] = *input++; - } - output[offset] = 0; - return output; - } -}; - -} - -#endif diff --git a/ananke/nall/string/cast.hpp b/ananke/nall/string/cast.hpp deleted file mode 100644 index 7c7e276b..00000000 --- a/ananke/nall/string/cast.hpp +++ /dev/null @@ -1,185 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//convert any (supported) type to a const char* without constructing a new nall::string -//this is used inside istring(...) to build nall::string values -template struct stringify; - -// base types - -template<> struct stringify { - bool value; - operator const char*() const { return value ? "true" : "false"; } - stringify(bool value) : value(value) {} -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(char value) { integer(data, value); } -}; - -// signed integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed char value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed short value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed int value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long long value) { integer(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(int_t value) { integer(data, value); } -}; - -// unsigned integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned char value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned short value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned int value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long long value) { decimal(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(uint_t value) { decimal(data, value); } -}; - -// floating-point - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(float value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(double value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(long double value) { fp(data, value); } -}; - -// strings - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(char *value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const char *value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -#if defined(QSTRING_H) - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -string::operator QString() const { - return QString::fromUtf8(*this); -} - -#endif - -// - -template stringify make_string(T value) { - return stringify(std::forward(value)); -} - -} - -#endif diff --git a/ananke/nall/string/compare.hpp b/ananke/nall/string/compare.hpp deleted file mode 100644 index 941c8e67..00000000 --- a/ananke/nall/string/compare.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char chrlower(char c) { - return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; -} - -char chrupper(char c) { - return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; -} - -int istrcmp(const char *str1, const char *str2) { - while(*str1) { - if(chrlower(*str1) != chrlower(*str2)) break; - str1++, str2++; - } - return (int)chrlower(*str1) - (int)chrlower(*str2); -} - -bool strbegin(const char *str, const char *key) { - int i, ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str, key, ksl)); -} - -bool istrbegin(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = 0; i < ksl; i++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[i] && str[i]+0x20 != key[i])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[i] && str[i]-0x20 != key[i])return false; - } else { - if(str[i] != key[i])return false; - } - } - return true; -} - -bool strend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str + ssl - ksl, key, ksl)); -} - -bool istrend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = ssl - ksl, z = 0; i < ssl; i++, z++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[z] && str[i]+0x20 != key[z])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[z] && str[i]-0x20 != key[z])return false; - } else { - if(str[i] != key[z])return false; - } - } - return true; -} - -} - -#endif diff --git a/ananke/nall/string/convert.hpp b/ananke/nall/string/convert.hpp deleted file mode 100644 index f5a2a780..00000000 --- a/ananke/nall/string/convert.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char* strlower(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrlower(str[i]); - i++; - } - return str; -} - -char* strupper(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrupper(str[i]); - i++; - } - return str; -} - -char* qstrlower(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'A' && *s <= 'Z') *s += 0x20; - s++; - } -} - -char* qstrupper(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'a' && *s <= 'z') *s -= 0x20; - s++; - } -} - -char* strtr(char *dest, const char *before, const char *after) { - if(!dest || !before || !after) return dest; - int sl = strlen(dest), bsl = strlen(before), asl = strlen(after); - - if(bsl != asl || bsl == 0) return dest; //patterns must be the same length for 1:1 replace - for(unsigned i = 0; i < sl; i++) { - for(unsigned l = 0; l < bsl; l++) { - if(dest[i] == before[l]) { - dest[i] = after[l]; - break; - } - } - } - - return dest; -} - -} - -#endif diff --git a/ananke/nall/string/core.hpp b/ananke/nall/string/core.hpp deleted file mode 100644 index 64c9250d..00000000 --- a/ananke/nall/string/core.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -static void istring(string &output) { -} - -template -static void istring(string &output, const T &value, Args&&... args) { - output.append_(make_string(value)); - istring(output, std::forward(args)...); -} - -void string::reserve(unsigned size_) { - if(size_ > size) resize(size_); -} - -void string::resize(unsigned size_) { - size = size_; - data = (char*)realloc(data, size + 1); - data[size] = 0; -} - -void string::clear(char c) { - for(unsigned n = 0; n < size; n++) data[n] = c; - data[size] = 0; -} - -bool string::empty() const { - return !*data; -} - -template string& string::assign(Args&&... args) { - *data = 0; - istring(*this, std::forward(args)...); - return *this; -} - -template string& string::append(Args&&... args) { - istring(*this, std::forward(args)...); - return *this; -} - -string& string::assign_(const char *s) { - unsigned length = strlen(s); - reserve(length); - strcpy(data, s); - return *this; -} - -string& string::append_(const char *s) { - unsigned length = strlen(data) + strlen(s); - reserve(length); - strcat(data, s); - return *this; -} - -string::operator const char*() const { - return data; -} - -char* string::operator()() { - return data; -} - -char& string::operator[](int index) { - reserve(index); - return data[index]; -} - -bool string::operator==(const char *str) const { return strcmp(data, str) == 0; } -bool string::operator!=(const char *str) const { return strcmp(data, str) != 0; } -bool string::operator< (const char *str) const { return strcmp(data, str) < 0; } -bool string::operator<=(const char *str) const { return strcmp(data, str) <= 0; } -bool string::operator> (const char *str) const { return strcmp(data, str) > 0; } -bool string::operator>=(const char *str) const { return strcmp(data, str) >= 0; } - -string& string::operator=(const string &value) { - if(&value == this) return *this; - assign(value); - return *this; -} - -string& string::operator=(string &&source) { - if(&source == this) return *this; - if(data) free(data); - size = source.size; - data = source.data; - source.data = nullptr; - source.size = 0; - return *this; -} - -template string::string(Args&&... args) { - size = 64; - data = (char*)malloc(size + 1); - *data = 0; - istring(*this, std::forward(args)...); -} - -string::string(const string &value) { - if(&value == this) return; - size = strlen(value); - data = strdup(value); -} - -string::string(string &&source) { - if(&source == this) return; - size = source.size; - data = source.data; - source.data = nullptr; -} - -string::~string() { - if(data) free(data); -} - -bool string::readfile(const string &filename) { - assign(""); - - #if !defined(_WIN32) - FILE *fp = fopen(filename, "rb"); - #else - FILE *fp = _wfopen(utf16_t(filename), L"rb"); - #endif - if(!fp) return false; - - fseek(fp, 0, SEEK_END); - unsigned size = ftell(fp); - rewind(fp); - char *fdata = new char[size + 1]; - unsigned unused = fread(fdata, 1, size, fp); - fclose(fp); - fdata[size] = 0; - assign(fdata); - delete[] fdata; - - return true; -} - -optional lstring::find(const char *key) const { - for(unsigned i = 0; i < size(); i++) { - if(operator[](i) == key) return { true, i }; - } - return { false, 0 }; -} - -string lstring::concatenate(const char *separator) const { - string output; - for(unsigned i = 0; i < size(); i++) { - output.append(operator[](i), i < size() - 1 ? separator : ""); - } - return output; -} - -template void lstring::append(const string &data, Args&&... args) { - vector::append(data); - append(std::forward(args)...); -} - -void lstring::isort() { - nall::sort(pool, objectsize, [](const string &x, const string &y) { - return istrcmp(x, y) < 0; - }); -} - -bool lstring::operator==(const lstring &source) const { - if(this == &source) return true; - if(size() != source.size()) return false; - for(unsigned n = 0; n < size(); n++) { - if(operator[](n) != source[n]) return false; - } - return true; -} - -bool lstring::operator!=(const lstring &source) const { - return !operator==(source); -} - -lstring& lstring::operator=(const lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &&source) { - vector::operator=(std::move(source)); - return *this; -} - -template lstring::lstring(Args&&... args) { - append(std::forward(args)...); -} - -lstring::lstring(const lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &&source) { - vector::operator=(std::move(source)); -} - -} - -#endif diff --git a/ananke/nall/string/cstring.hpp b/ananke/nall/string/cstring.hpp deleted file mode 100644 index 13b508ff..00000000 --- a/ananke/nall/string/cstring.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//const string: -//bind a const char* pointer to an object that has various testing functionality; -//yet lacks the memory allocation and modification functionality of the string class - -namespace nall { - -cstring::operator const char*() const { return data; } -unsigned cstring::length() const { return strlen(data); } -bool cstring::operator==(const char *s) const { return !strcmp(data, s); } -bool cstring::operator!=(const char *s) const { return strcmp(data, s); } -optional cstring::position (const char *key) const { return strpos(data, key); } -optional cstring::iposition(const char *key) const { return istrpos(data, key); } -cstring& cstring::operator=(const char *data) { this->data = data; return *this; } -cstring::cstring(const char *data) : data(data) {} -cstring::cstring() : data("") {} - -} - -#endif diff --git a/ananke/nall/string/datetime.hpp b/ananke/nall/string/datetime.hpp deleted file mode 100644 index 5382fdfd..00000000 --- a/ananke/nall/string/datetime.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string string::date() { - time_t timestamp = ::time(0); - tm *info = localtime(×tamp); - return { - decimal<4, '0'>(1900 + info->tm_year), "-", - decimal<2, '0'>(1 + info->tm_mon), "-", - decimal<2, '0'>(info->tm_mday) - }; -} - -string string::time() { - time_t timestamp = ::time(0); - tm *info = localtime(×tamp); - return { - decimal<2, '0'>(info->tm_hour), ":", - decimal<2, '0'>(info->tm_min), ":", - decimal<2, '0'>(info->tm_sec) - }; -} - -string string::datetime() { - return {string::date(), " ", string::time()}; -} - -} - -#endif diff --git a/ananke/nall/string/filename.hpp b/ananke/nall/string/filename.hpp deleted file mode 100644 index 19b5f117..00000000 --- a/ananke/nall/string/filename.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// "/foo/bar.c" -> "/foo/" -// "/foo/" -> "/foo/" -// "bar.c" -> "./" -inline string dir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - name[i + 1] = 0; - break; - } - if(i == 0) name = "./"; - } - return name; -} - -// "/foo/bar.c" -> "bar.c" -// "/foo/" -> "" -// "bar.c" -> "bar.c" -inline string notdir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - return (const char*)name + i + 1; - } - } - return name; -} - -// "/foo/bar/baz" -> "/foo/bar/" -// "/foo/bar/" -> "/foo/" -// "/foo/bar" -> "/foo/" -inline string parentdir(string name) { - unsigned length = name.length(), paths = 0, prev, last; - for(unsigned i = 0; i < length; i++) { - if(name[i] == '/' || name[i] == '\\') { - paths++; - prev = last; - last = i; - } - } - if(last + 1 == length) last = prev; //if name ends in slash; use previous slash - if(paths > 1) name[last + 1] = 0; - return name; -} - -// "/foo/bar.c" -> "/foo/bar" -inline string basename(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') break; //file has no extension - if(name[i] == '.') { - name[i] = 0; - break; - } - } - return name; -} - -// "/foo/bar.c" -> "c" -// "/foo/bar" -> "" -inline string extension(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') return ""; //file has no extension - if(name[i] == '.') { - return (const char*)name + i + 1; - } - } - return name; -} - -} - -#endif diff --git a/ananke/nall/string/format.hpp b/ananke/nall/string/format.hpp deleted file mode 100644 index 599021d1..00000000 --- a/ananke/nall/string/format.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template string format(const string &value) { - if(precision == 0) return value; - - bool padright = precision >= 0; - unsigned padding = abs(precision); - - unsigned length = value.length(); - if(padding <= length) { - if(padright) return substr(value, length - padding); - else return substr(value, 0, padding); - } - - string buffer; - buffer.resize(padding); - buffer.clear(padchar); - - memcpy(buffer() + (padright ? padding - length : 0), value, length); - return buffer; -} - -template string hex(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 2); - - unsigned size = 0; - do { - unsigned n = value & 15; - buffer[size++] = n < 10 ? '0' + n : 'a' + n - 10; - value >>= 4; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -template string octal(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 3); - - unsigned size = 0; - do { - buffer[size++] = '0' + (value & 7); - value >>= 3; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -template string binary(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 8); - - unsigned size = 0; - do { - buffer[size++] = '0' + (value & 1); - value >>= 1; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -} - -#endif diff --git a/ananke/nall/string/markup/bml.hpp b/ananke/nall/string/markup/bml.hpp deleted file mode 100644 index 338ca406..00000000 --- a/ananke/nall/string/markup/bml.hpp +++ /dev/null @@ -1,147 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BML v1.0 parser -//revision 0.02 - -namespace nall { -namespace BML { - -struct Node : Markup::Node { -protected: - //test to verify if a valid character for a node name - bool valid(char p) const { //A-Z, a-z, 0-9, -./ - return p - 'A' < 26u || p - 'a' < 26u || p - '0' < 10u || p - '-' < 3u; - } - - //determine indentation level, without incrementing pointer - unsigned readDepth(const char *p) { - unsigned depth = 0; - while(p[depth] == '\t' || p[depth] == ' ') depth++; - return depth; - } - - //determine indentation level - unsigned parseDepth(const char *&p) { - unsigned depth = readDepth(p); - p += depth; - return depth; - } - - //read name - void parseName(const char *&p) { - unsigned length = 0; - while(valid(p[length])) length++; - if(length == 0) throw "Invalid node name"; - name = substr(p, 0, length); - p += length; - } - - void parseData(const char *&p) { - if(*p == '=' && *(p + 1) == '\"') { - unsigned length = 2; - while(p[length] && p[length] != '\n' && p[length] != '\"') length++; - if(p[length] != '\"') throw "Unescaped value"; - data = substr(p, 2, length - 2); - p += length + 1; - } else if(*p == '=') { - unsigned length = 1; - while(p[length] && p[length] != '\n' && p[length] != '\"' && p[length] != ' ') length++; - if(p[length] == '\"') throw "Illegal character in value"; - data = substr(p, 1, length - 1); - p += length; - } else if(*p == ':') { - unsigned length = 1; - while(p[length] && p[length] != '\n') length++; - data = {substr(p, 1, length - 1), "\n"}; - p += length; - } - } - - //read all attributes for a node - void parseAttributes(const char *&p) { - while(*p && *p != '\n') { - if(*p != ' ') throw "Invalid node name"; - while(*p == ' ') p++; //skip excess spaces - - Node node; - node.attribute = true; - unsigned length = 0; - while(valid(p[length])) length++; - if(length == 0) throw "Invalid attribute name"; - node.name = substr(p, 0, length); - node.parseData(p += length); - children.append(node); - } - } - - //read a node and all of its children nodes - void parseNode(const char *&p) { - level = parseDepth(p); - parseName(p); - parseData(p); - parseAttributes(p); - if(*p++ != '\n') throw "Missing line feed"; - - while(*p) { - if(*p == '\n') { p++; continue; } - - unsigned depth = readDepth(p); - if(depth <= level) break; - - if(p[depth] == ':') { - p += depth; - unsigned length = 0; - while(p[length] && p[length] != '\n') length++; - data.append(substr(p, 1, length - 1), "\n"); - p += length; - continue; - } - - Node node; - node.parseNode(p); - children.append(node); - } - - data.rtrim<1>("\n"); - } - - //read top-level nodes - void parse(const char *p) { - while(*p) { - Node node; - node.parseNode(p); - if(node.level > 0) throw "Root nodes cannot be indented"; - children.append(node); - } - } - - friend class Document; -}; - -struct Document : Node { - string error; - - bool load(string document) { - name = "{root}", data = ""; - - try { - document.replace("\r", ""); - while(document.position("\n\n")) document.replace("\n\n", "\n"); - parse(document); - } catch(const char *perror) { - error = perror; - children.reset(); - return false; - } - return true; - } - - Document(const string &document = "") { - load(document); - } -}; - -} -} - -#endif diff --git a/ananke/nall/string/markup/document.hpp b/ananke/nall/string/markup/document.hpp deleted file mode 100644 index 34465a4f..00000000 --- a/ananke/nall/string/markup/document.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { -namespace Markup { - -inline Node Document(const string &markup) { - if(markup.beginswith("<")) return XML::Document(markup); - return BML::Document(markup); -} - -} -} - -#endif diff --git a/ananke/nall/string/markup/node.hpp b/ananke/nall/string/markup/node.hpp deleted file mode 100644 index 77822373..00000000 --- a/ananke/nall/string/markup/node.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//note: specific markups inherit from Markup::Node -//vector will slice any data; so derived nodes must not contain data nor virtual functions -//vector would incur a large performance penalty and greatly increased complexity - -namespace nall { -namespace Markup { - -struct Node { - string name; - string data; - bool attribute; - - bool exists() const { - return !name.empty(); - } - - string text() const { - return string{data}.strip(); - } - - intmax_t integer() const { - return numeral(text()); - } - - uintmax_t decimal() const { - return numeral(text()); - } - - void reset() { - children.reset(); - } - - bool evaluate(const string &query) const { - if(query.empty()) return true; - lstring rules = string{query}.replace(" ", "").split(","); - - for(auto &rule : rules) { - enum class Comparator : unsigned { ID, EQ, NE, LT, LE, GT, GE }; - auto comparator = Comparator::ID; - if(rule.wildcard("*!=*")) comparator = Comparator::NE; - else if(rule.wildcard("*<=*")) comparator = Comparator::LE; - else if(rule.wildcard("*>=*")) comparator = Comparator::GE; - else if(rule.wildcard ("*=*")) comparator = Comparator::EQ; - else if(rule.wildcard ("*<*")) comparator = Comparator::LT; - else if(rule.wildcard ("*>*")) comparator = Comparator::GT; - - if(comparator == Comparator::ID) { - if(find(rule).size()) continue; - return false; - } - - lstring side; - switch(comparator) { - case Comparator::EQ: side = rule.split<1> ("="); break; - case Comparator::NE: side = rule.split<1>("!="); break; - case Comparator::LT: side = rule.split<1> ("<"); break; - case Comparator::LE: side = rule.split<1>("<="); break; - case Comparator::GT: side = rule.split<1> (">"); break; - case Comparator::GE: side = rule.split<1>(">="); break; - } - - string data = text(); - if(side(0).empty() == false) { - auto result = find(side(0)); - if(result.size() == 0) return false; - data = result(0).data; - } - - switch(comparator) { - case Comparator::EQ: if(data.wildcard(side(1)) == true) continue; break; - case Comparator::NE: if(data.wildcard(side(1)) == false) continue; break; - case Comparator::LT: if(numeral(data) < numeral(side(1))) continue; break; - case Comparator::LE: if(numeral(data) <= numeral(side(1))) continue; break; - case Comparator::GT: if(numeral(data) > numeral(side(1))) continue; break; - case Comparator::GE: if(numeral(data) >= numeral(side(1))) continue; break; - } - - return false; - } - - return true; - } - - vector find(const string &query) const { - vector result; - - lstring path = query.split("/"); - string name = path.take(0), rule; - unsigned lo = 0u, hi = ~0u; - - if(name.wildcard("*[*]")) { - lstring side = name.split<1>("["); - name = side(0); - side = side(1).rtrim<1>("]").split<1>("-"); - lo = side(0).empty() ? 0u : numeral(side(0)); - hi = side(1).empty() ? ~0u : numeral(side(1)); - } - - if(name.wildcard("*(*)")) { - lstring side = name.split<1>("("); - name = side(0); - rule = side(1).rtrim<1>(")"); - } - - unsigned position = 0; - for(auto &node : children) { - if(node.name.wildcard(name) == false) continue; - if(node.evaluate(rule) == false) continue; - - bool inrange = position >= lo && position <= hi; - position++; - if(inrange == false) continue; - - if(path.size() == 0) result.append(node); - else { - auto list = node.find(path.concatenate("/")); - for(auto &item : list) result.append(item); - } - } - - return result; - } - - Node operator[](const string &query) const { - auto result = find(query); - return result(0); - } - - Node* begin() { return children.begin(); } - Node* end() { return children.end(); } - const Node* begin() const { return children.begin(); } - const Node* end() const { return children.end(); } - - Node() : attribute(false), level(0) {} - -protected: - unsigned level; - vector children; -}; - -} -} - -#endif diff --git a/ananke/nall/string/markup/xml.hpp b/ananke/nall/string/markup/xml.hpp deleted file mode 100644 index d3a3e15a..00000000 --- a/ananke/nall/string/markup/xml.hpp +++ /dev/null @@ -1,218 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//XML v1.0 subset parser -//revision 0.03 - -namespace nall { -namespace XML { - -struct Node : Markup::Node { -protected: - inline string escape() const { - string result = data; - result.replace("&", "&"); - result.replace("<", "<"); - result.replace(">", ">"); - if(attribute == false) return result; - result.replace("\'", "'"); - result.replace("\"", """); - return result; - } - - inline bool isName(char c) const { - if(c >= 'A' && c <= 'Z') return true; - if(c >= 'a' && c <= 'z') return true; - if(c >= '0' && c <= '9') return true; - if(c == '.' || c == '_') return true; - if(c == '?') return true; - return false; - } - - inline bool isWhitespace(char c) const { - if(c == ' ' || c == '\t') return true; - if(c == '\r' || c == '\n') return true; - return false; - } - - //copy part of string from source document into target string; decode markup while copying - inline void copy(string &target, const char *source, unsigned length) { - target.reserve(length + 1); - - #if defined(NALL_XML_LITERAL) - memcpy(target(), source, length); - target[length] = 0; - return; - #endif - - char *output = target(); - while(length) { - if(*source == '&') { - if(!memcmp(source, "<", 4)) { *output++ = '<'; source += 4; length -= 4; continue; } - if(!memcmp(source, ">", 4)) { *output++ = '>'; source += 4; length -= 4; continue; } - if(!memcmp(source, "&", 5)) { *output++ = '&'; source += 5; length -= 5; continue; } - if(!memcmp(source, "'", 6)) { *output++ = '\''; source += 6; length -= 6; continue; } - if(!memcmp(source, """, 6)) { *output++ = '\"'; source += 6; length -= 6; continue; } - } - - if(attribute == false && source[0] == '<' && source[1] == '!') { - //comment - if(!memcmp(source, "", 3)) source++, length--; - source += 3, length -= 3; - continue; - } - - //CDATA - if(!memcmp(source, "", 3)) *output++ = *source++, length--; - source += 3, length -= 3; - continue; - } - } - - *output++ = *source++, length--; - } - *output = 0; - } - - inline bool parseExpression(const char *&p) { - if(*(p + 1) != '!') return false; - - //comment - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed comment"; - p += 3; - return true; - } - - //CDATA - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed CDATA"; - p += 3; - return true; - } - - //DOCTYPE - if(!memcmp(p, "') counter--; - } while(counter); - return true; - } - - return false; - } - - //returns true if tag closes itself (); false if not () - inline bool parseHead(const char *&p) { - //parse name - const char *nameStart = ++p; //skip '<' - while(isName(*p)) p++; - const char *nameEnd = p; - copy(name, nameStart, nameEnd - nameStart); - if(name.empty()) throw "missing element name"; - - //parse attributes - while(*p) { - while(isWhitespace(*p)) p++; - if(!*p) throw "unclosed attribute"; - if(*p == '?' || *p == '/' || *p == '>') break; - - //parse attribute name - Node attribute; - attribute.attribute = true; - - const char *nameStart = p; - while(isName(*p)) p++; - const char *nameEnd = p; - copy(attribute.name, nameStart, nameEnd - nameStart); - if(attribute.name.empty()) throw "missing attribute name"; - - //parse attribute data - if(*p++ != '=') throw "missing attribute value"; - char terminal = *p++; - if(terminal != '\'' && terminal != '\"') throw "attribute value not quoted"; - const char *dataStart = p; - while(*p && *p != terminal) p++; - if(!*p) throw "missing attribute data terminal"; - const char *dataEnd = p++; //skip closing terminal - - copy(attribute.data, dataStart, dataEnd - dataStart); - children.append(attribute); - } - - //parse closure - if(*p == '?' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '/' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '>') { p += 1; return false; } - throw "invalid element tag"; - } - - //parse element and all of its child elements - inline void parseElement(const char *&p) { - Node node; - if(node.parseHead(p) == false) node.parse(p); - children.append(node); - } - - //return true if matches this node's name - inline bool parseClosureElement(const char *&p) { - if(p[0] != '<' || p[1] != '/') return false; - p += 2; - const char *nameStart = p; - while(*p && *p != '>') p++; - if(*p != '>') throw "unclosed closure element"; - const char *nameEnd = p++; - if(memcmp(name, nameStart, nameEnd - nameStart)) throw "closure element name mismatch"; - return true; - } - - //parse contents of an element - inline void parse(const char *&p) { - const char *dataStart = p, *dataEnd = p; - - while(*p) { - while(*p && *p != '<') p++; - if(!*p) break; - dataEnd = p; - if(parseClosureElement(p) == true) break; - if(parseExpression(p) == true) continue; - parseElement(p); - } - - copy(data, dataStart, dataEnd - dataStart); - } -}; - -struct Document : Node { - string error; - - inline bool load(const char *document) { - if(document == nullptr) return false; - reset(); - try { - parse(document); - } catch(const char *error) { - reset(); - this->error = error; - return false; - } - return true; - } - - inline Document() {} - inline Document(const char *document) { load(document); } -}; - -} -} - -#endif diff --git a/ananke/nall/string/math-fixed-point.hpp b/ananke/nall/string/math-fixed-point.hpp deleted file mode 100644 index a61b23f3..00000000 --- a/ananke/nall/string/math-fixed-point.hpp +++ /dev/null @@ -1,166 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace fixedpoint { - -static nall::function eval_fallback; - -static intmax_t eval_integer(const char *& s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - return value; - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static intmax_t eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - intmax_t value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 13); - else if(x == '~') value = ~eval(++s, 13); - else if(x == '+') value = +eval(++s, 13); - else if(x == '-') value = -eval(++s, 13); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 13) break; - if(x == '*') { value *= eval(++s, 13); continue; } - if(x == '/') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value /= result; continue; } - if(x == '%') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value %= result; continue; } - - if(depth >= 12) break; - if(x == '+') { value += eval(++s, 12); continue; } - if(x == '-') { value -= eval(++s, 12); continue; } - - if(depth >= 11) break; - if(x == '<' && y == '<') { value <<= eval(++++s, 11); continue; } - if(x == '>' && y == '>') { value >>= eval(++++s, 11); continue; } - - if(depth >= 10) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 10); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 10); continue; } - if(x == '<') { value = value < eval(++s, 10); continue; } - if(x == '>') { value = value > eval(++s, 10); continue; } - - if(depth >= 9) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 9); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 9); continue; } - - if(depth >= 8) break; - if(x == '&' && y != '&') { value = value & eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '^' && y != '^') { value = value ^ eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '|' && y != '|') { value = value | eval(++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - intmax_t lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - intmax_t rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, intmax_t &result) { - try { - result = eval(s); - return true; - } catch(const char*) { - result = 0; - return false; - } -} - -static intmax_t parse(const char *s) { - try { - intmax_t result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/ananke/nall/string/math-floating-point.hpp b/ananke/nall/string/math-floating-point.hpp deleted file mode 100644 index 43a2f0f4..00000000 --- a/ananke/nall/string/math-floating-point.hpp +++ /dev/null @@ -1,157 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace floatingpoint { - -static nall::function eval_fallback; - -static double eval_integer(const char *&s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, radix = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0' && y != '.') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - if(*s == '.') { s++; break; } - return value; - } - //floating-point - while(true) { - if(*s >= '0' && *s <= '9') { radix = radix * 10 + (*s++ - '0'); continue; } - return atof(nall::string{ nall::decimal(value), ".", nall::decimal(radix) }); - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static double eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - double value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 9); - else if(x == '+') value = +eval(++s, 9); - else if(x == '-') value = -eval(++s, 9); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 9) break; - if(x == '*') { value *= eval(++s, 9); continue; } - if(x == '/') { double result = eval(++s, 9); if(result == 0.0) throw "division by zero"; value /= result; continue; } - - if(depth >= 8) break; - if(x == '+') { value += eval(++s, 8); continue; } - if(x == '-') { value -= eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 7); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 7); continue; } - if(x == '<') { value = value < eval(++s, 7); continue; } - if(x == '>') { value = value > eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 6); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - double lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - double rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, double &result) { - try { - result = eval(s); - return true; - } catch(const char*e) { - result = 0; - return false; - } -} - -static double parse(const char *s) { - try { - double result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/ananke/nall/string/platform.hpp b/ananke/nall/string/platform.hpp deleted file mode 100644 index 90b6d6b8..00000000 --- a/ananke/nall/string/platform.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string activepath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - auto unused = _wgetcwd(path, PATH_MAX); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - auto unused = getcwd(path, PATH_MAX); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string realpath(const string &name) { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - if(::realpath(name, path)) result = path; - #endif - if(result.empty()) result = {activepath(), name}; - return result; -} - -// /home/username/ -// c:/users/username/ -string userpath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - SHGetFolderPathW(0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, 0, 0, path); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - struct passwd *userinfo = getpwuid(getuid()); - if(userinfo) strcpy(path, userinfo->pw_dir); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -// /home/username/.config/ -// c:/users/username/appdata/roaming/ -string configpath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - result = {userpath(), ".config/"}; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string temppath() { - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - GetTempPathW(PATH_MAX, path); - string result = (const char*)utf8_t(path); - result.transform("\\", "/"); - return result; - #else - return "/tmp/"; - #endif -} - -} - -#endif diff --git a/ananke/nall/string/replace.hpp b/ananke/nall/string/replace.hpp deleted file mode 100644 index 2bd1412f..00000000 --- a/ananke/nall/string/replace.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -string& string::ureplace(const char *key, const char *token) { - if(!key || !*key) return *this; - enum : unsigned { limit = Limit ? Limit : ~0u }; - - const char *p = data; - unsigned counter = 0, keyLength = 0; - - while(*p) { - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter++; p += n; keyLength = n; break; } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - if(counter == 0) return *this; - if(Limit) counter = min(counter, Limit); - - char *t = data, *base; - unsigned tokenLength = strlen(token); - if(tokenLength > keyLength) { - t = base = strdup(data); - reserve((unsigned)(p - data) + ((tokenLength - keyLength) * counter)); - } - char *o = data; - - while(*t && counter) { - if(quotecopy(o, t)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter--; memcpy(o, token, tokenLength); t += keyLength; o += tokenLength; break; } - if(!chrequal(key[n], t[n])) { *o++ = *t++; break; } - } - } - do *o++ = *t; while(*t++); - if(tokenLength > keyLength) free(base); - - return *this; -} - -template string &string::replace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::ireplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::qreplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::iqreplace(const char *key, const char *token) { return ureplace(key, token); } - -}; - -#endif diff --git a/ananke/nall/string/split.hpp b/ananke/nall/string/split.hpp deleted file mode 100644 index bb12a91b..00000000 --- a/ananke/nall/string/split.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template lstring& lstring::usplit(const char *key, const char *base) { - reset(); - if(!key || !*key) return *this; - - const char *p = base; - - while(*p) { - if(Limit) if(size() >= Limit) break; - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { - append(substr(base, 0, p - base)); - p += n; - base = p; - break; - } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - - append(base); - return *this; -} - -template lstring& lstring::split(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::isplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::qsplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::iqsplit(const char *key, const char *src) { return usplit(key, src); } - -}; - -#endif diff --git a/ananke/nall/string/static.hpp b/ananke/nall/string/static.hpp deleted file mode 100644 index ca521cb0..00000000 --- a/ananke/nall/string/static.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string string::read(const string &filename) { - string data; - data.readfile(filename); - return data; -} - -} - -#endif diff --git a/ananke/nall/string/strm.hpp b/ananke/nall/string/strm.hpp deleted file mode 100644 index 21d05652..00000000 --- a/ananke/nall/string/strm.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// -//strmcpy, strmcat created by byuu -// - -//return = strlen(target) -unsigned strmcpy(char *target, const char *source, unsigned length) { - const char *origin = target; - if(length) { - while(*source && --length) *target++ = *source++; - *target = 0; - } - return target - origin; -} - -//return = strlen(target) -unsigned strmcat(char *target, const char *source, unsigned length) { - const char *origin = target; - while(*target && length) target++, length--; - return (target - origin) + strmcpy(target, source, length); -} - -//return = true when all of source was copied -bool strccpy(char *target, const char *source, unsigned length) { - return !source[strmcpy(target, source, length)]; -} - -//return = true when all of source was copied -bool strccat(char *target, const char *source, unsigned length) { - while(*target && length) target++, length--; - return !source[strmcpy(target, source, length)]; -} - -//return = reserved for future use -void strpcpy(char *&target, const char *source, unsigned &length) { - unsigned offset = strmcpy(target, source, length); - target += offset, length -= offset; -} - -} - -#endif diff --git a/ananke/nall/string/strpos.hpp b/ananke/nall/string/strpos.hpp deleted file mode 100644 index fe563a6c..00000000 --- a/ananke/nall/string/strpos.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//usage example: -//if(auto position = strpos(str, key)) print(position(), "\n"); -//prints position of key within str; but only if it is found - -namespace nall { - -template -optional ustrpos(const char *str, const char *key) { - const char *base = str; - - while(*str) { - if(quoteskip(str)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) return { true, (unsigned)(str - base) }; - if(str[n] == 0) return { false, 0 }; - if(!chrequal(str[n], key[n])) break; - } - str++; - } - - return { false, 0 }; -} - -optional strpos(const char *str, const char *key) { return ustrpos(str, key); } -optional istrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional qstrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional iqstrpos(const char *str, const char *key) { return ustrpos(str, key); } - -} - -#endif diff --git a/ananke/nall/string/trim.hpp b/ananke/nall/string/trim.hpp deleted file mode 100644 index 3e0c914f..00000000 --- a/ananke/nall/string/trim.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//limit defaults to zero, which will underflow on first compare; equivalent to no limit -template char* ltrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strbegin(str, key)) { - char *dest = str, *src = str + strlen(key); - while(true) { - *dest = *src++; - if(!*dest) break; - dest++; - } - if(--limit == 0) break; - } - return str; -} - -template char* rtrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strend(str, key)) { - str[strlen(str) - strlen(key)] = 0; - if(--limit == 0) break; - } - return str; -} - -template char* trim(char *str, const char *key, const char *rkey) { - if(rkey) return ltrim(rtrim(str, rkey), key); - return ltrim(rtrim(str, key), key); -} - -//remove whitespace characters from both left and right sides of string -char* strip(char *s) { - signed n = 0, p = 0; - while(s[n]) { - if(s[n] != ' ' && s[n] != '\t' && s[n] != '\r' && s[n] != '\n') break; - n++; - } - while(s[n]) s[p++] = s[n++]; - s[p--] = 0; - while(p >= 0) { - if(s[p] != ' ' && s[p] != '\t' && s[p] != '\r' && s[p] != '\n') break; - p--; - } - s[++p] = 0; - return s; -} - -} - -#endif diff --git a/ananke/nall/string/utf8.hpp b/ananke/nall/string/utf8.hpp deleted file mode 100644 index 77397bf2..00000000 --- a/ananke/nall/string/utf8.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -struct UTF8 { - unsigned size; //size of encoded codepoint - uint64_t data; //encoded codepoint - unsigned codepoint; //decoded codepoint -}; - -inline UTF8 utf8_read(const char *s) { - UTF8 utf8; - - if((*s & 0xfe) == 0xfc) utf8.size = 6; - else if((*s & 0xfc) == 0xf8) utf8.size = 5; - else if((*s & 0xf8) == 0xf0) utf8.size = 4; - else if((*s & 0xf0) == 0xe0) utf8.size = 3; - else if((*s & 0xe0) == 0xc0) utf8.size = 2; - else utf8.size = 1; - - utf8.data = 0; - for(unsigned n = 0; n < utf8.size; n++) { - utf8.data = (utf8.data << 8) | (uint8_t)s[n]; - } - - static uint8_t mask[] = { 0, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; - utf8.codepoint = s[0] & mask[utf8.size]; - for(unsigned n = 1; n < utf8.size; n++) { - utf8.codepoint = (utf8.codepoint << 6) | (s[n] & 0x3f); - } - - return utf8; -} - -inline void utf8_write(char *s, const UTF8 &utf8) { - for(signed n = utf8.size - 1, shift = 0; n >= 0; n--, shift += 8) { - s[n] = utf8.data >> shift; - } -} - -} - -#endif diff --git a/ananke/nall/string/utility.hpp b/ananke/nall/string/utility.hpp deleted file mode 100644 index 657383f8..00000000 --- a/ananke/nall/string/utility.hpp +++ /dev/null @@ -1,242 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -bool chrequal(char x, char y) { - if(Insensitive) return chrlower(x) == chrlower(y); - return x == y; -} - -template -bool quoteskip(T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - while(*p && *p++ != x); - } - return true; -} - -template -bool quotecopy(char *&t, T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - *t++ = x; - while(*p && *p != x) *t++ = *p++; - *t++ = *p++; - } - return true; -} - -string substr(const char *src, unsigned start, unsigned length) { - string dest; - if(length == ~0u) { - //copy entire string - dest.reserve(strlen(src + start) + 1); - strcpy(dest(), src + start); - } else { - //copy partial string - dest.reserve(length + 1); - strmcpy(dest(), src + start, length + 1); - } - return dest; -} - -string sha256(const uint8_t *data, unsigned size) { - sha256_ctx sha; - uint8_t hash[32]; - sha256_init(&sha); - sha256_chunk(&sha, data, size); - sha256_final(&sha); - sha256_hash(&sha, hash); - string result; - for(auto &byte : hash) result.append(hex<2>(byte)); - return result; -} - -/* cast.hpp arithmetic -> string */ - -char* integer(char *result, intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -char* decimal(char *result, uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -/* general-purpose arithmetic -> string */ - -template string integer(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string linteger(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string decimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string ldecimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -//using sprintf is certainly not the most ideal method to convert -//a double to a string ... but attempting to parse a double by -//hand, digit-by-digit, results in subtle rounding errors. -unsigned fp(char *str, long double value) { - char buffer[256]; - #ifdef _WIN32 - //Windows C-runtime does not support long double via sprintf() - sprintf(buffer, "%f", (double)value); - #else - sprintf(buffer, "%Lf", value); - #endif - - //remove excess 0's in fraction (2.500000 -> 2.5) - for(char *p = buffer; *p; p++) { - if(*p == '.') { - char *p = buffer + strlen(buffer) - 1; - while(*p == '0') { - if(*(p - 1) != '.') *p = 0; //... but not for eg 1.0 -> 1. - p--; - } - break; - } - } - - unsigned length = strlen(buffer); - if(str) strcpy(str, buffer); - return length + 1; -} - -string fp(long double value) { - string temp; - temp.reserve(fp(0, value)); - fp(temp(), value); - return temp; -} - -} - -#endif diff --git a/ananke/nall/string/variadic.hpp b/ananke/nall/string/variadic.hpp deleted file mode 100644 index c43bfe86..00000000 --- a/ananke/nall/string/variadic.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template inline void print(Args&&... args) { - printf("%s", (const char*)string(std::forward(args)...)); -} - -} - -#endif diff --git a/ananke/nall/string/wildcard.hpp b/ananke/nall/string/wildcard.hpp deleted file mode 100644 index 9d2359d5..00000000 --- a/ananke/nall/string/wildcard.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -bool wildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && *s != *p) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || *p == *s) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -bool iwildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && chrlower(*s) != chrlower(*p)) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || chrlower(*p) == chrlower(*s)) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(const char *s, const char *p) { - while(*s) { - if(*p == '*') { - while(*s) if(tokenize(s++, p + 1)) return true; - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(lstring &list, const char *s, const char *p) { - while(*s) { - if(*p == '*') { - const char *b = s; - while(*s) { - if(tokenize(list, s++, p + 1)) { - list.prepend(substr(b, 0, --s - b)); - return true; - } - } - list.prepend(b); - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') { list.prepend(s); p++; } - return !*p; -} - -} - -#endif diff --git a/ananke/nall/string/wrapper.hpp b/ananke/nall/string/wrapper.hpp deleted file mode 100644 index 08aa98b3..00000000 --- a/ananke/nall/string/wrapper.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -unsigned string::length() const { return strlen(data); } -unsigned string::capacity() const { return size; } - -template lstring string::split(const char *key) const { lstring result; result.split(key, data); return result; } -template lstring string::isplit(const char *key) const { lstring result; result.isplit(key, data); return result; } -template lstring string::qsplit(const char *key) const { lstring result; result.qsplit(key, data); return result; } -template lstring string::iqsplit(const char *key) const { lstring result; result.iqsplit(key, data); return result; } - -bool string::equals(const char *str) const { return !strcmp(data, str); } -bool string::iequals(const char *str) const { return !istrcmp(data, str); } - -bool string::wildcard(const char *str) const { return nall::wildcard(data, str); } -bool string::iwildcard(const char *str) const { return nall::iwildcard(data, str); } - -bool string::beginswith(const char *str) const { return strbegin(data, str); } -bool string::ibeginswith(const char *str) const { return istrbegin(data, str); } - -bool string::endswith(const char *str) const { return strend(data, str); } -bool string::iendswith(const char *str) const { return istrend(data, str); } - -string& string::lower() { nall::strlower(data); return *this; } -string& string::upper() { nall::strupper(data); return *this; } -string& string::qlower() { nall::qstrlower(data); return *this; } -string& string::qupper() { nall::qstrupper(data); return *this; } -string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } -string& string::reverse() { - unsigned length = strlen(data), pivot = length >> 1; - for(signed x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(data[x], data[y]); - return *this; -} - -template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -template string& string::trim(const char *key, const char *rkey) { nall::trim (data, key, rkey); return *this; } -string& string::strip() { nall::strip(data); return *this; } - -optional string::position(const char *key) const { return strpos(data, key); } -optional string::iposition(const char *key) const { return istrpos(data, key); } -optional string::qposition(const char *key) const { return qstrpos(data, key); } -optional string::iqposition(const char *key) const { return iqstrpos(data, key); } - -} - -#endif diff --git a/ananke/nall/thread.hpp b/ananke/nall/thread.hpp deleted file mode 100644 index de894f2d..00000000 --- a/ananke/nall/thread.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef NALL_THREAD_HPP -#define NALL_THREAD_HPP - -#include -#include -#include - -#if defined(PLATFORM_X) || defined(PLATFORM_OSX) - #include - -namespace nall { - void* thread_entry_point(void*); - - struct thread { - thread(function entryPoint) : entryPoint(entryPoint), completed(false), dead(false) { - initialize(); - pthread_create(&pthread, NULL, thread_entry_point, (void*)this); - } - - ~thread() { - join(); - } - - bool active() const { - return completed == false; - } - - void join() { - if(dead) return; - dead = true; - pthread_join(pthread, NULL); - } - - static bool primary() { - initialize(); - return pthread_equal(primaryThread(), pthread_self()); - } - - private: - pthread_t pthread; - function entryPoint; - volatile bool completed, dead; - friend void* thread_entry_point(void*); - - static void initialize() { - static bool initialized = false; - if(initialized) return; - initialized = true; - primaryThread() = pthread_self(); - } - - static pthread_t& primaryThread() { - static pthread_t thread; - return thread; - } - }; - - void* thread_entry_point(void *parameter) { - thread *context = (thread*)parameter; - context->entryPoint(); - context->completed = true; - pthread_exit(0); - } -} -#elif defined(PLATFORM_WIN) -namespace nall { - inline DWORD WINAPI thread_entry_point(LPVOID); - - struct thread { - thread(function entryPoint) : entryPoint(entryPoint), completed(false), dead(false) { - initialize(); - hthread = CreateThread(NULL, 0, thread_entry_point, (void*)this, 0, NULL); - } - - ~thread() { - join(); - } - - bool active() const { - return completed == false; - } - - void join() { - if(dead) return; - dead = true; - WaitForSingleObject(hthread, INFINITE); - CloseHandle(hthread); - } - - static bool primary() { - initialize(); - return primaryThread() == GetCurrentThreadId(); - } - - private: - HANDLE hthread; - function entryPoint; - volatile bool completed, dead; - friend DWORD WINAPI thread_entry_point(LPVOID); - - static void initialize() { - static bool initialized = false; - if(initialized) return; - initialized = true; - primaryThread() = GetCurrentThreadId(); - } - - static DWORD& primaryThread() { - static DWORD thread; - return thread; - } - }; - - inline DWORD WINAPI thread_entry_point(LPVOID parameter) { - thread *context = (thread*)parameter; - context->entryPoint(); - context->completed = true; - return 0; - } -} -#endif - -#endif diff --git a/ananke/nall/udl.hpp b/ananke/nall/udl.hpp deleted file mode 100644 index 30ceefb3..00000000 --- a/ananke/nall/udl.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_UDL_HPP -#define NALL_UDL_HPP - -//user-defined literals - -#include -#include - -namespace nall { - constexpr inline uintmax_t operator"" _b(const char *n) { return binary(n); } - - //convert to bytes - constexpr inline uintmax_t operator"" _kb(unsigned long long n) { return 1024 * n; } - constexpr inline uintmax_t operator"" _mb(unsigned long long n) { return 1024 * 1024 * n; } - constexpr inline uintmax_t operator"" _gb(unsigned long long n) { return 1024 * 1024 * 1024 * n; } - - //convert to bits - constexpr inline uintmax_t operator"" _kbit(unsigned long long n) { return 1024 * n / 8; } - constexpr inline uintmax_t operator"" _mbit(unsigned long long n) { return 1024 * 1024 * n / 8; } - constexpr inline uintmax_t operator"" _gbit(unsigned long long n) { return 1024 * 1024 * 1024 * n / 8; } - - //convert to hz - constexpr inline uintmax_t operator"" _khz(long double n) { return n * 1000; } - constexpr inline uintmax_t operator"" _mhz(long double n) { return n * 1000000; } - constexpr inline uintmax_t operator"" _ghz(long double n) { return n * 1000000000; } -} - -#endif diff --git a/ananke/nall/unzip.hpp b/ananke/nall/unzip.hpp deleted file mode 100644 index 5a7935f6..00000000 --- a/ananke/nall/unzip.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_UNZIP_HPP -#define NALL_UNZIP_HPP - -#include -#include -#include -#include - -namespace nall { - -struct unzip { - struct File { - string name; - const uint8_t *data; - unsigned size; - unsigned csize; - unsigned cmode; //0 = uncompressed, 8 = deflate - unsigned crc32; - }; - - inline bool open(const string &filename) { - close(); - if(fm.open(filename, filemap::mode::read) == false) return false; - if(open(fm.data(), fm.size()) == false) { - fm.close(); - return false; - } - return true; - } - - inline bool open(const uint8_t *data, unsigned size) { - if(size < 22) return false; - - filedata = data; - filesize = size; - - file.reset(); - - const uint8_t *footer = data + size - 22; - while(true) { - if(footer <= data + 22) return false; - if(read(footer, 4) == 0x06054b50) { - unsigned commentlength = read(footer + 20, 2); - if(footer + 22 + commentlength == data + size) break; - } - footer--; - } - const uint8_t *directory = data + read(footer + 16, 4); - - while(true) { - unsigned signature = read(directory + 0, 4); - if(signature != 0x02014b50) break; - - File file; - file.cmode = read(directory + 10, 2); - file.crc32 = read(directory + 16, 4); - file.csize = read(directory + 20, 4); - file.size = read(directory + 24, 4); - - unsigned namelength = read(directory + 28, 2); - unsigned extralength = read(directory + 30, 2); - unsigned commentlength = read(directory + 32, 2); - - char *filename = new char[namelength + 1]; - memcpy(filename, directory + 46, namelength); - filename[namelength] = 0; - file.name = filename; - delete[] filename; - - unsigned offset = read(directory + 42, 4); - unsigned offsetNL = read(data + offset + 26, 2); - unsigned offsetEL = read(data + offset + 28, 2); - file.data = data + offset + 30 + offsetNL + offsetEL; - - directory += 46 + namelength + extralength + commentlength; - - this->file.append(file); - } - - return true; - } - - inline vector extract(File &file) { - vector buffer; - - if(file.cmode == 0) { - buffer.resize(file.size); - memcpy(buffer.data(), file.data, file.size); - } - - if(file.cmode == 8) { - buffer.resize(file.size); - if(inflate(buffer.data(), buffer.size(), file.data, file.csize) == false) { - buffer.reset(); - } - } - - return buffer; - } - - inline void close() { - if(fm.open()) fm.close(); - } - - ~unzip() { - close(); - } - -protected: - filemap fm; - const uint8_t *filedata; - unsigned filesize; - - unsigned read(const uint8_t *data, unsigned size) { - unsigned result = 0, shift = 0; - while(size--) { result |= *data++ << shift; shift += 8; } - return result; - } - -public: - vector file; -}; - -} - -#endif diff --git a/ananke/nall/ups.hpp b/ananke/nall/ups.hpp deleted file mode 100644 index ffcdb2d7..00000000 --- a/ananke/nall/ups.hpp +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef NALL_UPS_HPP -#define NALL_UPS_HPP - -#include -#include -#include -#include - -namespace nall { - -struct ups { - enum class result : unsigned { - unknown, - success, - patch_unwritable, - patch_invalid, - source_invalid, - target_invalid, - target_too_small, - patch_checksum_invalid, - source_checksum_invalid, - target_checksum_invalid, - }; - - function progress; - - result create( - const uint8_t *sourcedata, unsigned sourcelength, - const uint8_t *targetdata, unsigned targetlength, - const char *patchfilename - ) { - source_data = (uint8_t*)sourcedata, target_data = (uint8_t*)targetdata; - source_length = sourcelength, target_length = targetlength; - source_offset = target_offset = 0; - source_checksum = target_checksum = patch_checksum = ~0; - - if(patch_file.open(patchfilename, file::mode::write) == false) return result::patch_unwritable; - - patch_write('U'); - patch_write('P'); - patch_write('S'); - patch_write('1'); - encode(source_length); - encode(target_length); - - unsigned output_length = source_length > target_length ? source_length : target_length; - unsigned relative = 0; - for(unsigned offset = 0; offset < output_length;) { - uint8_t x = source_read(); - uint8_t y = target_read(); - - if(x == y) { - offset++; - continue; - } - - encode(offset++ - relative); - patch_write(x ^ y); - - while(true) { - if(offset >= output_length) { - patch_write(0x00); - break; - } - - x = source_read(); - y = target_read(); - offset++; - patch_write(x ^ y); - if(x == y) break; - } - - relative = offset; - } - - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(source_checksum >> (i * 8)); - for(unsigned i = 0; i < 4; i++) patch_write(target_checksum >> (i * 8)); - uint32_t patch_result_checksum = ~patch_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(patch_result_checksum >> (i * 8)); - - patch_file.close(); - return result::success; - } - - result apply( - const uint8_t *patchdata, unsigned patchlength, - const uint8_t *sourcedata, unsigned sourcelength, - uint8_t *targetdata, unsigned &targetlength - ) { - patch_data = (uint8_t*)patchdata, source_data = (uint8_t*)sourcedata, target_data = targetdata; - patch_length = patchlength, source_length = sourcelength, target_length = targetlength; - patch_offset = source_offset = target_offset = 0; - patch_checksum = source_checksum = target_checksum = ~0; - - if(patch_length < 18) return result::patch_invalid; - if(patch_read() != 'U') return result::patch_invalid; - if(patch_read() != 'P') return result::patch_invalid; - if(patch_read() != 'S') return result::patch_invalid; - if(patch_read() != '1') return result::patch_invalid; - - unsigned source_read_length = decode(); - unsigned target_read_length = decode(); - - if(source_length != source_read_length && source_length != target_read_length) return result::source_invalid; - targetlength = (source_length == source_read_length ? target_read_length : source_read_length); - if(target_length < targetlength) return result::target_too_small; - target_length = targetlength; - - while(patch_offset < patch_length - 12) { - unsigned length = decode(); - while(length--) target_write(source_read()); - while(true) { - uint8_t patch_xor = patch_read(); - target_write(patch_xor ^ source_read()); - if(patch_xor == 0) break; - } - } - while(source_offset < source_length) target_write(source_read()); - while(target_offset < target_length) target_write(source_read()); - - uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0; - for(unsigned i = 0; i < 4; i++) source_read_checksum |= patch_read() << (i * 8); - for(unsigned i = 0; i < 4; i++) target_read_checksum |= patch_read() << (i * 8); - uint32_t patch_result_checksum = ~patch_checksum; - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_read_checksum |= patch_read() << (i * 8); - - if(patch_result_checksum != patch_read_checksum) return result::patch_invalid; - if(source_checksum == source_read_checksum && source_length == source_read_length) { - if(target_checksum == target_read_checksum && target_length == target_read_length) return result::success; - return result::target_invalid; - } else if(source_checksum == target_read_checksum && source_length == target_read_length) { - if(target_checksum == source_read_checksum && target_length == source_read_length) return result::success; - return result::target_invalid; - } else { - return result::source_invalid; - } - } - -private: - uint8_t *patch_data, *source_data, *target_data; - unsigned patch_length, source_length, target_length; - unsigned patch_offset, source_offset, target_offset; - unsigned patch_checksum, source_checksum, target_checksum; - file patch_file; - - uint8_t patch_read() { - if(patch_offset < patch_length) { - uint8_t n = patch_data[patch_offset++]; - patch_checksum = crc32_adjust(patch_checksum, n); - return n; - } - return 0x00; - } - - uint8_t source_read() { - if(source_offset < source_length) { - uint8_t n = source_data[source_offset++]; - source_checksum = crc32_adjust(source_checksum, n); - return n; - } - return 0x00; - } - - uint8_t target_read() { - uint8_t result = 0x00; - if(target_offset < target_length) { - result = target_data[target_offset]; - target_checksum = crc32_adjust(target_checksum, result); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - return result; - } - - void patch_write(uint8_t n) { - patch_file.write(n); - patch_checksum = crc32_adjust(patch_checksum, n); - } - - void target_write(uint8_t n) { - if(target_offset < target_length) { - target_data[target_offset] = n; - target_checksum = crc32_adjust(target_checksum, n); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - } - - void encode(uint64_t offset) { - while(true) { - uint64_t x = offset & 0x7f; - offset >>= 7; - if(offset == 0) { - patch_write(0x80 | x); - break; - } - patch_write(x); - offset--; - } - } - - uint64_t decode() { - uint64_t offset = 0, shift = 1; - while(true) { - uint8_t x = patch_read(); - offset += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - offset += shift; - } - return offset; - } -}; - -} - -#endif diff --git a/ananke/nall/utility.hpp b/ananke/nall/utility.hpp deleted file mode 100644 index b3c1e5aa..00000000 --- a/ananke/nall/utility.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_UTILITY_HPP -#define NALL_UTILITY_HPP - -#include -#include - -namespace nall { - template struct base_from_member { - T value; - base_from_member(T value_) : value(value_) {} - }; - - template class optional { - public: - bool valid; - T value; - public: - inline operator bool() const { return valid; } - inline const T& operator()() const { if(!valid) throw; return value; } - inline optional& operator=(const optional &source) { valid = source.valid; value = source.value; return *this; } - inline optional() : valid(false) {} - inline optional(bool valid, const T &value) : valid(valid), value(value) {} - }; - - template inline T* allocate(unsigned size, const T &value) { - T *array = new T[size]; - for(unsigned i = 0; i < size; i++) array[i] = value; - return array; - } -} - -#endif diff --git a/ananke/nall/varint.hpp b/ananke/nall/varint.hpp deleted file mode 100644 index 98e189db..00000000 --- a/ananke/nall/varint.hpp +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef NALL_VARINT_HPP -#define NALL_VARINT_HPP - -#include -#include - -namespace nall { - template struct uint_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = uclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = uclip(data - 1); return r; } - inline type_t operator ++() { return data = uclip(data + 1); } - inline type_t operator --() { return data = uclip(data - 1); } - inline type_t operator =(const type_t i) { return data = uclip(i); } - inline type_t operator |=(const type_t i) { return data = uclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = uclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = uclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = uclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = uclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = uclip(data + i); } - inline type_t operator -=(const type_t i) { return data = uclip(data - i); } - inline type_t operator *=(const type_t i) { return data = uclip(data * i); } - inline type_t operator /=(const type_t i) { return data = uclip(data / i); } - inline type_t operator %=(const type_t i) { return data = uclip(data % i); } - - inline uint_t() : data(0) {} - inline uint_t(const type_t i) : data(uclip(i)) {} - - template inline type_t operator=(const uint_t &i) { return data = uclip((type_t)i); } - template inline uint_t(const uint_t &i) : data(uclip(i)) {} - }; - - template struct int_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = sclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = sclip(data - 1); return r; } - inline type_t operator ++() { return data = sclip(data + 1); } - inline type_t operator --() { return data = sclip(data - 1); } - inline type_t operator =(const type_t i) { return data = sclip(i); } - inline type_t operator |=(const type_t i) { return data = sclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = sclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = sclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = sclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = sclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = sclip(data + i); } - inline type_t operator -=(const type_t i) { return data = sclip(data - i); } - inline type_t operator *=(const type_t i) { return data = sclip(data * i); } - inline type_t operator /=(const type_t i) { return data = sclip(data / i); } - inline type_t operator %=(const type_t i) { return data = sclip(data % i); } - - inline int_t() : data(0) {} - inline int_t(const type_t i) : data(sclip(i)) {} - - template inline type_t operator=(const int_t &i) { return data = sclip((type_t)i); } - template inline int_t(const int_t &i) : data(sclip(i)) {} - }; - - template struct varuint_t { - private: - type_t data; - type_t mask; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = (data + 1) & mask; return r; } - inline type_t operator --(int) { type_t r = data; data = (data - 1) & mask; return r; } - inline type_t operator ++() { return data = (data + 1) & mask; } - inline type_t operator --() { return data = (data - 1) & mask; } - inline type_t operator =(const type_t i) { return data = (i) & mask; } - inline type_t operator |=(const type_t i) { return data = (data | i) & mask; } - inline type_t operator ^=(const type_t i) { return data = (data ^ i) & mask; } - inline type_t operator &=(const type_t i) { return data = (data & i) & mask; } - inline type_t operator<<=(const type_t i) { return data = (data << i) & mask; } - inline type_t operator>>=(const type_t i) { return data = (data >> i) & mask; } - inline type_t operator +=(const type_t i) { return data = (data + i) & mask; } - inline type_t operator -=(const type_t i) { return data = (data - i) & mask; } - inline type_t operator *=(const type_t i) { return data = (data * i) & mask; } - inline type_t operator /=(const type_t i) { return data = (data / i) & mask; } - inline type_t operator %=(const type_t i) { return data = (data % i) & mask; } - - inline void bits(type_t bits) { mask = (1ull << (bits - 1)) + ((1ull << (bits - 1)) - 1); data &= mask; } - inline varuint_t() : data(0ull), mask((type_t)~0ull) {} - inline varuint_t(const type_t i) : data(i), mask((type_t)~0ull) {} - }; -} - -//typedefs - typedef nall::uint_t< 1> uint1_t; - typedef nall::uint_t< 2> uint2_t; - typedef nall::uint_t< 3> uint3_t; - typedef nall::uint_t< 4> uint4_t; - typedef nall::uint_t< 5> uint5_t; - typedef nall::uint_t< 6> uint6_t; - typedef nall::uint_t< 7> uint7_t; -//typedef nall::uint_t< 8> uint8_t; - - typedef nall::uint_t< 9> uint9_t; - typedef nall::uint_t<10> uint10_t; - typedef nall::uint_t<11> uint11_t; - typedef nall::uint_t<12> uint12_t; - typedef nall::uint_t<13> uint13_t; - typedef nall::uint_t<14> uint14_t; - typedef nall::uint_t<15> uint15_t; -//typedef nall::uint_t<16> uint16_t; - - typedef nall::uint_t<17> uint17_t; - typedef nall::uint_t<18> uint18_t; - typedef nall::uint_t<19> uint19_t; - typedef nall::uint_t<20> uint20_t; - typedef nall::uint_t<21> uint21_t; - typedef nall::uint_t<22> uint22_t; - typedef nall::uint_t<23> uint23_t; - typedef nall::uint_t<24> uint24_t; - typedef nall::uint_t<25> uint25_t; - typedef nall::uint_t<26> uint26_t; - typedef nall::uint_t<27> uint27_t; - typedef nall::uint_t<28> uint28_t; - typedef nall::uint_t<29> uint29_t; - typedef nall::uint_t<30> uint30_t; - typedef nall::uint_t<31> uint31_t; -//typedef nall::uint_t<32> uint32_t; - - typedef nall::int_t< 1> int1_t; - typedef nall::int_t< 2> int2_t; - typedef nall::int_t< 3> int3_t; - typedef nall::int_t< 4> int4_t; - typedef nall::int_t< 5> int5_t; - typedef nall::int_t< 6> int6_t; - typedef nall::int_t< 7> int7_t; -//typedef nall::int_t< 8> int8_t; - - typedef nall::int_t< 9> int9_t; - typedef nall::int_t<10> int10_t; - typedef nall::int_t<11> int11_t; - typedef nall::int_t<12> int12_t; - typedef nall::int_t<13> int13_t; - typedef nall::int_t<14> int14_t; - typedef nall::int_t<15> int15_t; -//typedef nall::int_t<16> int16_t; - - typedef nall::int_t<17> int17_t; - typedef nall::int_t<18> int18_t; - typedef nall::int_t<19> int19_t; - typedef nall::int_t<20> int20_t; - typedef nall::int_t<21> int21_t; - typedef nall::int_t<22> int22_t; - typedef nall::int_t<23> int23_t; - typedef nall::int_t<24> int24_t; - typedef nall::int_t<25> int25_t; - typedef nall::int_t<26> int26_t; - typedef nall::int_t<27> int27_t; - typedef nall::int_t<28> int28_t; - typedef nall::int_t<29> int29_t; - typedef nall::int_t<30> int30_t; - typedef nall::int_t<31> int31_t; -//typedef nall::int_t<32> int32_t; - -#endif diff --git a/ananke/nall/vector.hpp b/ananke/nall/vector.hpp deleted file mode 100644 index 6818c69d..00000000 --- a/ananke/nall/vector.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef NALL_VECTOR_HPP -#define NALL_VECTOR_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - template struct vector { - struct exception_out_of_bounds{}; - - protected: - T *pool; - unsigned poolsize; - unsigned objectsize; - - public: - operator bool() const { return pool; } - T* data() { return pool; } - const T* data() const { return pool; } - - bool empty() const { return objectsize == 0; } - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - T* move() { - T *result = pool; - pool = nullptr; - poolsize = 0; - objectsize = 0; - return result; - } - - void reset() { - if(pool) { - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - } - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - unsigned outputsize = min(size, objectsize); - size = bit::round(size); //amortize growth - T *copy = (T*)calloc(size, sizeof(T)); - for(unsigned n = 0; n < outputsize; n++) new(copy + n) T(pool[n]); - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - pool = copy; - poolsize = size; - objectsize = outputsize; - } - - //requires trivial constructor - void resize(unsigned size) { - if(size == objectsize) return; - if(size < objectsize) return reserve(size); - while(size > objectsize) append(T()); - } - - template - void append(const T& data, Args&&... args) { - append(data); - append(std::forward(args)...); - } - - void append(const T& data) { - if(objectsize + 1 > poolsize) reserve(objectsize + 1); - new(pool + objectsize++) T(data); - } - - bool appendonce(const T& data) { - if(find(data) == true) return false; - append(data); - return true; - } - - void insert(unsigned position, const T& data) { - append(data); - for(signed n = size() - 1; n > position; n--) pool[n] = pool[n - 1]; - pool[position] = data; - } - - void prepend(const T& data) { - insert(0, data); - } - - void remove(unsigned index = ~0u, unsigned count = 1) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - for(unsigned n = index; count + n < objectsize; n++) pool[n] = pool[count + n]; - objectsize = (count + index >= objectsize) ? index : objectsize - count; - } - - T take(unsigned index = ~0u) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - if(index >= objectsize) throw exception_out_of_bounds(); - T item = pool[index]; - remove(index); - return item; - } - - void reverse() { - unsigned pivot = size() / 2; - for(unsigned l = 0, r = size() - 1; l < pivot; l++, r--) { - std::swap(pool[l], pool[r]); - } - } - - void sort() { - nall::sort(pool, objectsize); - } - - template void sort(const Comparator &lessthan) { - nall::sort(pool, objectsize, lessthan); - } - - optional find(const T& data) { - for(unsigned n = 0; n < size(); n++) if(pool[n] == data) return {true, n}; - return {false, 0u}; - } - - T& first() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[0]; - } - - T& last() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[objectsize - 1]; - } - - //access - inline T& operator[](unsigned position) { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline const T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline T& operator()(unsigned position) { - if(position >= poolsize) reserve(position + 1); - while(position >= objectsize) append(T()); - return pool[position]; - } - - inline const T& operator()(unsigned position, const T& data) const { - if(position >= objectsize) return data; - return pool[position]; - } - - //iteration - T* begin() { return &pool[0]; } - T* end() { return &pool[objectsize]; } - const T* begin() const { return &pool[0]; } - const T* end() const { return &pool[objectsize]; } - - //copy - inline vector& operator=(const vector &source) { - reset(); - reserve(source.capacity()); - for(auto &data : source) append(data); - return *this; - } - - vector(const vector &source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(source); - } - - //move - inline vector& operator=(vector &&source) { - reset(); - pool = source.pool, poolsize = source.poolsize, objectsize = source.objectsize; - source.pool = nullptr, source.poolsize = 0, source.objectsize = 0; - return *this; - } - - vector(vector &&source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(std::move(source)); - } - - //construction - vector() : pool(nullptr), poolsize(0), objectsize(0) { - } - - vector(std::initializer_list list) : pool(nullptr), poolsize(0), objectsize(0) { - for(auto &data : list) append(data); - } - - ~vector() { - reset(); - } - }; -} - -#endif diff --git a/ananke/nall/windows/detour.hpp b/ananke/nall/windows/detour.hpp deleted file mode 100644 index e270f318..00000000 --- a/ananke/nall/windows/detour.hpp +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef NALL_WINDOWS_DETOUR_HPP -#define NALL_WINDOWS_DETOUR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -#define Copy 0 -#define RelNear 1 - -struct detour { - static bool insert(const string &moduleName, const string &functionName, void *&source, void *target); - static bool remove(const string &moduleName, const string &functionName, void *&source); - -protected: - static unsigned length(const uint8_t *function); - static unsigned mirror(uint8_t *target, const uint8_t *source); - - struct opcode { - uint16_t prefix; - unsigned length; - unsigned mode; - uint16_t modify; - }; - static opcode opcodes[]; -}; - -//TODO: -//* fs:, gs: should force another opcode copy -//* conditional branches within +5-byte range should fail -detour::opcode detour::opcodes[] = { - { 0x50, 1 }, //push eax - { 0x51, 1 }, //push ecx - { 0x52, 1 }, //push edx - { 0x53, 1 }, //push ebx - { 0x54, 1 }, //push esp - { 0x55, 1 }, //push ebp - { 0x56, 1 }, //push esi - { 0x57, 1 }, //push edi - { 0x58, 1 }, //pop eax - { 0x59, 1 }, //pop ecx - { 0x5a, 1 }, //pop edx - { 0x5b, 1 }, //pop ebx - { 0x5c, 1 }, //pop esp - { 0x5d, 1 }, //pop ebp - { 0x5e, 1 }, //pop esi - { 0x5f, 1 }, //pop edi - { 0x64, 1 }, //fs: - { 0x65, 1 }, //gs: - { 0x68, 5 }, //push dword - { 0x6a, 2 }, //push byte - { 0x74, 2, RelNear, 0x0f84 }, //je near -> je far - { 0x75, 2, RelNear, 0x0f85 }, //jne near -> jne far - { 0x89, 2 }, //mov reg,reg - { 0x8b, 2 }, //mov reg,reg - { 0x90, 1 }, //nop - { 0xa1, 5 }, //mov eax,[dword] - { 0xeb, 2, RelNear, 0xe9 }, //jmp near -> jmp far -}; - -bool detour::insert(const string &moduleName, const string &functionName, void *&source, void *target) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - unsigned sourceLength = detour::length(sourceData); - if(sourceLength < 5) { - //unable to clone enough bytes to insert hook - #if 1 - string output = { "detour::insert(", moduleName, "::", functionName, ") failed: " }; - for(unsigned n = 0; n < 16; n++) output.append(hex<2>(sourceData[n]), " "); - output.rtrim<1>(" "); - MessageBoxA(0, output, "nall::detour", MB_OK); - #endif - return false; - } - - uint8_t *mirrorData = new uint8_t[512](); - detour::mirror(mirrorData, sourceData); - - DWORD privileges; - VirtualProtect((void*)mirrorData, 512, PAGE_EXECUTE_READWRITE, &privileges); - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - uintmax_t address = (uintmax_t)target - ((uintmax_t)sourceData + 5); - sourceData[0] = 0xe9; //jmp target - sourceData[1] = address >> 0; - sourceData[2] = address >> 8; - sourceData[3] = address >> 16; - sourceData[4] = address >> 24; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)mirrorData; - return true; -} - -bool detour::remove(const string &moduleName, const string &functionName, void *&source) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - uint8_t *mirrorData = (uint8_t*)source; - if(mirrorData == sourceData) return false; //hook was never installed - - unsigned length = detour::length(256 + mirrorData); - if(length < 5) return false; - - DWORD privileges; - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - for(unsigned n = 0; n < length; n++) sourceData[n] = mirrorData[256 + n]; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)sourceData; - delete[] mirrorData; - return true; -} - -unsigned detour::length(const uint8_t *function) { - unsigned length = 0; - while(length < 5) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(function[length] == op.prefix) { - opcode = &op; - break; - } - } - if(opcode == 0) break; - length += opcode->length; - } - return length; -} - -unsigned detour::mirror(uint8_t *target, const uint8_t *source) { - const uint8_t *entryPoint = source; - for(unsigned n = 0; n < 256; n++) target[256 + n] = source[n]; - - unsigned size = detour::length(source); - while(size) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(*source == op.prefix) { - opcode = &op; - break; - } - } - - switch(opcode->mode) { - case Copy: - for(unsigned n = 0; n < opcode->length; n++) *target++ = *source++; - break; - case RelNear: { - source++; - uintmax_t sourceAddress = (uintmax_t)source + 1 + (int8_t)*source; - *target++ = opcode->modify; - if(opcode->modify >> 8) *target++ = opcode->modify >> 8; - uintmax_t targetAddress = (uintmax_t)target + 4; - uintmax_t address = sourceAddress - targetAddress; - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - source += 2; - } break; - } - - size -= opcode->length; - } - - uintmax_t address = (entryPoint + detour::length(entryPoint)) - (target + 5); - *target++ = 0xe9; //jmp entryPoint - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - - return source - entryPoint; -} - -#undef Implied -#undef RelNear - -} - -#endif diff --git a/ananke/nall/windows/guid.hpp b/ananke/nall/windows/guid.hpp deleted file mode 100644 index 386cfc75..00000000 --- a/ananke/nall/windows/guid.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NALL_WINDOWS_GUID_HPP -#define NALL_WINDOWS_GUID_HPP - -#include -#include - -namespace nall { - -//generate unique GUID -inline string guid() { - random_lfsr lfsr; - lfsr.seed(time(0)); - for(unsigned n = 0; n < 256; n++) lfsr(); - - string output; - for(unsigned n = 0; n < 4; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 6; n++) output.append(hex<2>(lfsr())); - return {"{", output, "}"}; -} - -} - -#endif diff --git a/ananke/nall/windows/launcher.hpp b/ananke/nall/windows/launcher.hpp deleted file mode 100644 index 914683ec..00000000 --- a/ananke/nall/windows/launcher.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef NALL_WINDOWS_LAUNCHER_HPP -#define NALL_WINDOWS_LAUNCHER_HPP - -namespace nall { - -//launch a new process and inject specified DLL into it - -bool launch(const char *applicationName, const char *libraryName, uint32_t entryPoint) { - //if a launcher does not send at least one message, a wait cursor will appear - PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0); - MSG msg; - GetMessage(&msg, 0, 0, 0); - - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - memset(&si, 0, sizeof(STARTUPINFOW)); - BOOL result = CreateProcessW( - utf16_t(applicationName), GetCommandLineW(), NULL, NULL, TRUE, - DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, //do not break if application creates its own processes - NULL, NULL, &si, &pi - ); - if(result == false) return false; - - uint8_t entryData[1024], entryHook[1024] = { - 0x68, 0x00, 0x00, 0x00, 0x00, //push libraryName - 0xb8, 0x00, 0x00, 0x00, 0x00, //mov eax,LoadLibraryW - 0xff, 0xd0, //call eax - 0xcd, 0x03, //int 3 - }; - - entryHook[1] = (uint8_t)((entryPoint + 14) >> 0); - entryHook[2] = (uint8_t)((entryPoint + 14) >> 8); - entryHook[3] = (uint8_t)((entryPoint + 14) >> 16); - entryHook[4] = (uint8_t)((entryPoint + 14) >> 24); - - uint32_t pLoadLibraryW = (uint32_t)GetProcAddress(GetModuleHandleW(L"kernel32"), "LoadLibraryW"); - entryHook[6] = pLoadLibraryW >> 0; - entryHook[7] = pLoadLibraryW >> 8; - entryHook[8] = pLoadLibraryW >> 16; - entryHook[9] = pLoadLibraryW >> 24; - - utf16_t buffer = utf16_t(libraryName); - memcpy(entryHook + 14, buffer, 2 * wcslen(buffer) + 2); - - while(true) { - DEBUG_EVENT event; - WaitForDebugEvent(&event, INFINITE); - - if(event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break; - - if(event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) { - if(event.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) { - if(event.u.Exception.ExceptionRecord.ExceptionAddress == (void*)(entryPoint + 14 - 1)) { - HANDLE hProcess = OpenProcess(0, FALSE, event.dwProcessId); - HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, event.dwThreadId); - - CONTEXT context; - context.ContextFlags = CONTEXT_FULL; - GetThreadContext(hThread, &context); - - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - context.Eip = entryPoint; - SetThreadContext(hThread, &context); - - CloseHandle(hThread); - CloseHandle(hProcess); - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); - continue; - } - - if(event.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) { - ReadProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryHook, sizeof entryHook, NULL); - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - } - - return true; -} - -} - -#endif diff --git a/ananke/nall/windows/registry.hpp b/ananke/nall/windows/registry.hpp deleted file mode 100644 index 0774e04a..00000000 --- a/ananke/nall/windows/registry.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef NALL_WINDOWS_REGISTRY_HPP -#define NALL_WINDOWS_REGISTRY_HPP - -#include -#include - -#include -#ifndef KEY_WOW64_64KEY - #define KEY_WOW64_64KEY 0x0100 -#endif -#ifndef KEY_WOW64_32KEY - #define KEY_WOW64_32KEY 0x0200 -#endif - -#ifndef NWR_FLAGS - #define NWR_FLAGS KEY_WOW64_64KEY -#endif - -#ifndef NWR_SIZE - #define NWR_SIZE 4096 -#endif - -namespace nall { - -struct registry { - static bool exists(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return true; - } - return false; - } - - static string read(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return (const char*)utf8_t(data); - } - return ""; - } - - static void write(const string &name, const string &data = "") { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(), path; - DWORD disposition; - for(unsigned n = 0; n < part.size(); n++) { - path.append(part[n]); - if(RegCreateKeyExW(rootKey, utf16_t(path), 0, NULL, 0, NWR_FLAGS | KEY_ALL_ACCESS, NULL, &handle, &disposition) == ERROR_SUCCESS) { - if(n == part.size() - 1) { - RegSetValueExW(handle, utf16_t(node), 0, REG_SZ, (BYTE*)(wchar_t*)utf16_t(data), (data.length() + 1) * sizeof(wchar_t)); - } - RegCloseKey(handle); - } - path.append("\\"); - } - } - - static bool remove(const string &name) { - lstring part = name.split("/"); - HKEY rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(node.empty()) return SHDeleteKeyW(rootKey, utf16_t(path)) == ERROR_SUCCESS; - return SHDeleteValueW(rootKey, utf16_t(path), utf16_t(node)) == ERROR_SUCCESS; - } - - static lstring contents(const string &name) { - lstring part = name.split("/"), result; - HKEY handle, rootKey = root(part.take(0)); - part.remove(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD folders, nodes; - RegQueryInfoKey(handle, NULL, NULL, NULL, &folders, NULL, NULL, &nodes, NULL, NULL, NULL, NULL); - for(unsigned n = 0; n < folders; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumKeyEx(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append({(const char*)utf8_t(name), "/"}); - } - for(unsigned n = 0; n < nodes; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumValueW(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append((const char*)utf8_t(name)); - } - RegCloseKey(handle); - } - return result; - } - -private: - static HKEY root(const string &name) { - if(name == "HKCR") return HKEY_CLASSES_ROOT; - if(name == "HKCC") return HKEY_CURRENT_CONFIG; - if(name == "HKCU") return HKEY_CURRENT_USER; - if(name == "HKLM") return HKEY_LOCAL_MACHINE; - if(name == "HKU" ) return HKEY_USERS; - return NULL; - } -}; - -} - -#endif diff --git a/ananke/nall/windows/utf8.hpp b/ananke/nall/windows/utf8.hpp deleted file mode 100644 index b1374943..00000000 --- a/ananke/nall/windows/utf8.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef NALL_UTF8_HPP -#define NALL_UTF8_HPP - -//UTF-8 <> UTF-16 conversion -//used only for Win32; Linux, etc use UTF-8 internally - -#if defined(_WIN32) - -#undef UNICODE -#undef _WIN32_WINNT -#undef NOMINMAX -#define UNICODE -#define _WIN32_WINNT 0x0501 -#define NOMINMAX -#include -#include -#undef interface - -namespace nall { - //UTF-8 to UTF-16 - class utf16_t { - public: - operator wchar_t*() { - return buffer; - } - - operator const wchar_t*() const { - return buffer; - } - - utf16_t(const char *s = "") { - if(!s) s = ""; - unsigned length = MultiByteToWideChar(CP_UTF8, 0, s, -1, 0, 0); - buffer = new wchar_t[length + 1](); - MultiByteToWideChar(CP_UTF8, 0, s, -1, buffer, length); - } - - ~utf16_t() { - delete[] buffer; - } - - private: - wchar_t *buffer; - }; - - //UTF-16 to UTF-8 - class utf8_t { - public: - operator char*() { - return buffer; - } - - operator const char*() const { - return buffer; - } - - utf8_t(const wchar_t *s = L"") { - if(!s) s = L""; - unsigned length = WideCharToMultiByte(CP_UTF8, 0, s, -1, 0, 0, (const char*)0, (BOOL*)0); - buffer = new char[length + 1](); - WideCharToMultiByte(CP_UTF8, 0, s, -1, buffer, length, (const char*)0, (BOOL*)0); - } - - ~utf8_t() { - delete[] buffer; - } - - utf8_t(const utf8_t&) = delete; - utf8_t& operator=(const utf8_t&) = delete; - - private: - char *buffer; - }; - - inline void utf8_args(int &argc, char **&argv) { - wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = new char*[argc]; - for(unsigned i = 0; i < argc; i++) { - argv[i] = new char[_MAX_PATH]; - strcpy(argv[i], nall::utf8_t(wargv[i])); - } - } -} - -#endif //if defined(_WIN32) - -#endif diff --git a/ananke/nall/xorg/guard.hpp b/ananke/nall/xorg/guard.hpp deleted file mode 100644 index a1282683..00000000 --- a/ananke/nall/xorg/guard.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NALL_XORG_GUARD_HPP -#define NALL_XORG_GUARD_HPP - -#define None -#undef XlibNone -#define XlibNone 0L -#define Button1 XlibButton1 -#define Button2 XlibButton2 -#define Button3 XlibButton3 -#define Button4 XlibButton4 -#define Button5 XlibButton5 -#define Display XlibDisplay -#define Screen XlibScreen -#define Window XlibWindow - -#else -#undef NALL_XORG_GUARD_HPP - -#undef None -#undef Button1 -#undef Button2 -#undef Button3 -#undef Button4 -#undef Button5 -#undef Display -#undef Screen -#undef Window - -#endif diff --git a/ananke/nall/zip.hpp b/ananke/nall/zip.hpp deleted file mode 100644 index 0a73ccdd..00000000 --- a/ananke/nall/zip.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef NALL_ZIP_HPP -#define NALL_ZIP_HPP - -//creates uncompressed ZIP archives - -#include -#include - -namespace nall { - -struct zip { - zip(const string &filename) { - fp.open(filename, file::mode::write); - time_t currentTime = time(0); - tm *info = localtime(¤tTime); - dosTime = (info->tm_hour << 11) | (info->tm_min << 5) | (info->tm_sec >> 1); - dosDate = ((info->tm_year - 80) << 9) | ((1 + info->tm_mon) << 5) + (info->tm_mday); - } - - //append path: append("path/"); - //append file: append("path/file", data, size); - void append(string filename, const uint8_t *data = nullptr, unsigned size = 0u) { - filename.transform("\\", "/"); - uint32_t checksum = crc32_calculate(data, size); - directory.append({filename, checksum, size, fp.offset()}); - - fp.writel(0x04034b50, 4); //signature - fp.writel(0x0014, 2); //minimum version (2.0) - fp.writel(0x0000, 2); //general purpose bit flags - fp.writel(0x0000, 2); //compression method (0 = uncompressed) - fp.writel(dosTime, 2); - fp.writel(dosDate, 2); - fp.writel(checksum, 4); - fp.writel(size, 4); //compressed size - fp.writel(size, 4); //uncompressed size - fp.writel(filename.length(), 2); //file name length - fp.writel(0x0000, 2); //extra field length - fp.print(filename); //file name - - fp.write(data, size); //file data - } - - ~zip() { - //central directory - unsigned baseOffset = fp.offset(); - for(auto &entry : directory) { - fp.writel(0x02014b50, 4); //signature - fp.writel(0x0014, 2); //version made by (2.0) - fp.writel(0x0014, 2); //version needed to extract (2.0) - fp.writel(0x0000, 2); //general purpose bit flags - fp.writel(0x0000, 2); //compression method (0 = uncompressed) - fp.writel(dosTime, 2); - fp.writel(dosDate, 2); - fp.writel(entry.checksum, 4); - fp.writel(entry.size, 4); //compressed size - fp.writel(entry.size, 4); //uncompressed size - fp.writel(entry.filename.length(), 2); //file name length - fp.writel(0x0000, 2); //extra field length - fp.writel(0x0000, 2); //file comment length - fp.writel(0x0000, 2); //disk number start - fp.writel(0x0000, 2); //internal file attributes - fp.writel(0x00000000, 4); //external file attributes - fp.writel(entry.offset, 4); //relative offset of file header - fp.print(entry.filename); - } - unsigned finishOffset = fp.offset(); - - //end of central directory - fp.writel(0x06054b50, 4); //signature - fp.writel(0x0000, 2); //number of this disk - fp.writel(0x0000, 2); //disk where central directory starts - fp.writel(directory.size(), 2); //number of central directory records on this disk - fp.writel(directory.size(), 2); //total number of central directory records - fp.writel(finishOffset - baseOffset, 4); //size of central directory - fp.writel(baseOffset, 4); //offset of central directory - fp.writel(0x0000, 2); //comment length - - fp.close(); - } - -protected: - file fp; - uint16_t dosTime, dosDate; - struct entry_t { - string filename; - uint32_t checksum; - uint32_t size; - uint32_t offset; - }; - vector directory; -}; - -} - -#endif diff --git a/ananke/patch.cpp b/ananke/patch.cpp index a2dc1f9c..66928006 100644 --- a/ananke/patch.cpp +++ b/ananke/patch.cpp @@ -1,5 +1,5 @@ void Ananke::applyBeatPatch(vector &buffer) { - string name = {nall::basename(information.name), ".bps"}; + string name = {information.path, nall::basename(information.name), ".bps"}; if(!file::exists(name)) return; bpspatch patch; diff --git a/ananke/phoenix/Makefile b/ananke/phoenix/Makefile deleted file mode 100644 index d1c9d981..00000000 --- a/ananke/phoenix/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -ifeq ($(platform),x) - ifeq ($(phoenix),) - phoenix := gtk - endif - - ifeq ($(phoenix),gtk) - phoenixflags := -DPHOENIX_GTK `pkg-config --cflags gtk+-2.0` - phoenixlink := `pkg-config --libs gtk+-2.0` - endif - - ifeq ($(phoenix),qt) - phoenixflags := -DPHOENIX_QT `pkg-config --cflags QtCore QtGui` - phoenixlink := `pkg-config --libs QtCore QtGui` - endif -else ifeq ($(platform),win) - phoenixflags := -DPHOENIX_WINDOWS - phoenixlink := -lkernel32 -luser32 -lgdi32 -ladvapi32 -lole32 -lcomctl32 -lcomdlg32 -lshlwapi -else - phoenixflags := -DPHOENIX_REFERENCE - phoenixlink := -endif diff --git a/ananke/phoenix/core/core.cpp b/ananke/phoenix/core/core.cpp deleted file mode 100644 index a2588770..00000000 --- a/ananke/phoenix/core/core.cpp +++ /dev/null @@ -1,1342 +0,0 @@ -#include "state.hpp" -#include "layout/fixed-layout.cpp" -#include "layout/horizontal-layout.cpp" -#include "layout/vertical-layout.cpp" - -#if defined(PHOENIX_WINDOWS) - #include "../windows/platform.cpp" -#elif defined(PHOENIX_QT) - #include "../qt/platform.cpp" -#elif defined(PHOENIX_GTK) - #include "../gtk/platform.cpp" -#elif defined(PHOENIX_REFERENCE) - #include "../reference/platform.cpp" -#endif - -static bool OS_quit = false; - -//Color -//===== - -uint32_t Color::rgb() const { - return (255 << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -uint32_t Color::rgba() const { - return (alpha << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -//Geometry -//======== - -Position Geometry::position() const { - return { x, y }; -} - -Size Geometry::size() const { - return { width, height }; -} - -string Geometry::text() const { - return { x, ",", y, ",", width, ",", height }; -} - -Geometry::Geometry(const string &text) { - lstring part = text.split(","); - x = integer(part(0, "256")); - y = integer(part(1, "256")); - width = decimal(part(2, "256")); - height = decimal(part(3, "256")); -} - -//Font -//==== - -Geometry Font::geometry(const string &text) { - return pFont::geometry(description, text); -} - -Font::Font(const string &description): -description(description) { -} - -//Desktop -//======= - -Size Desktop::size() { - return pDesktop::size(); -} - -Geometry Desktop::workspace() { - return pDesktop::workspace(); -} - -//Keyboard -//======== - -bool Keyboard::pressed(Keyboard::Scancode scancode) { - return pKeyboard::pressed(scancode); -} - -bool Keyboard::released(Keyboard::Scancode scancode) { - return !pressed(scancode); -} - -vector Keyboard::state() { - return pKeyboard::state(); -} - -//Mouse -//===== - -Position Mouse::position() { - return pMouse::position(); -} - -bool Mouse::pressed(Mouse::Button button) { - return pMouse::pressed(button); -} - -bool Mouse::released(Mouse::Button button) { - return !pressed(button); -} - -//DialogWindow -//============ - -string DialogWindow::fileOpen_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileOpen(parent, path, filter); -} - -string DialogWindow::fileSave_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileSave(parent, path, filter); -} - -string DialogWindow::folderSelect(Window &parent, const string &path) { - return pDialogWindow::folderSelect(parent, path); -} - -//MessageWindow -//============= - -MessageWindow::Response MessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::information(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::question(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::warning(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::critical(parent, text, buttons); -} - -//Object -//====== - -Object::Object(pObject &p): -p(p) { - OS::initialize(); - p.constructor(); -} - -Object::~Object() { - p.destructor(); - delete &p; -} - -//OS -//== - -void OS::main() { - return pOS::main(); -} - -bool OS::pendingEvents() { - return pOS::pendingEvents(); -} - -void OS::processEvents() { - return pOS::processEvents(); -} - -void OS::quit() { - OS_quit = true; - return pOS::quit(); -} - -void OS::setName(const string &name) { - osState.name = name; -} - -void OS::initialize() { - static bool initialized = false; - if(initialized == false) { - initialized = true; - return pOS::initialize(); - } -} - -//Timer -//===== - -void Timer::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Timer::setInterval(unsigned milliseconds) { - state.milliseconds = milliseconds; - return p.setInterval(milliseconds); -} - -Timer::Timer(): -state(*new State), -base_from_member(*new pTimer(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Timer::~Timer() { - p.destructor(); - delete &state; -} - -//Window -//====== - -Window& Window::none() { - return pWindow::none(); -} - -void Window::append_(Layout &layout) { - if(state.layout.append(layout)) { - ((Sizable&)layout).state.window = this; - ((Sizable&)layout).state.layout = 0; - p.append(layout); - layout.synchronizeLayout(); - } -} - -void Window::append_(Menu &menu) { - if(state.menu.append(menu)) { - ((Action&)menu).state.window = this; - p.append(menu); - } -} - -void Window::append_(Widget &widget) { - if(state.widget.append(widget)) { - ((Sizable&)widget).state.window = this; - p.append(widget); - } -} - -Color Window::backgroundColor() { - return p.backgroundColor(); -} - -Geometry Window::frameGeometry() { - Geometry geometry = p.geometry(); - Geometry margin = p.frameMargin(); - return { - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height - }; -} - -Geometry Window::frameMargin() { - return p.frameMargin(); -} - -bool Window::focused() { - return p.focused(); -} - -bool Window::fullScreen() { - return state.fullScreen; -} - -Geometry Window::geometry() { - return p.geometry(); -} - -void Window::ignore() { - state.ignore = true; -} - -void Window::remove_(Layout &layout) { - if(state.layout.remove(layout)) { - p.remove(layout); - ((Sizable&)layout).state.window = 0; - } -} - -void Window::remove_(Menu &menu) { - if(state.menu.remove(menu)) { - p.remove(menu); - ((Action&)menu).state.window = 0; - } -} - -void Window::remove_(Widget &widget) { - if(state.widget.remove(widget)) { - p.remove(widget); - ((Sizable&)widget).state.window = 0; - } -} - -void Window::setBackgroundColor(const Color &color) { - state.backgroundColorOverride = true; - state.backgroundColor = color; - return p.setBackgroundColor(color); -} - -void Window::setFrameGeometry(const Geometry &geometry) { - Geometry margin = p.frameMargin(); - return setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width - margin.width, geometry.height - margin.height - }); -} - -void Window::setFocused() { - return p.setFocused(); -} - -void Window::setFullScreen(bool fullScreen) { - state.fullScreen = fullScreen; - return p.setFullScreen(fullScreen); -} - -void Window::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Window::setMenuFont(const string &font) { - state.menuFont = font; - return p.setMenuFont(font); -} - -void Window::setMenuVisible(bool visible) { - state.menuVisible = visible; - return p.setMenuVisible(visible); -} - -void Window::setModal(bool modal) { - state.modal = modal; - return p.setModal(modal); -} - -void Window::setResizable(bool resizable) { - state.resizable = resizable; - return p.setResizable(resizable); -} - -void Window::setSmartGeometry(const Geometry &geometry) { - Geometry margin = p.frameMargin(); - return setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width, geometry.height - }); -} - -void Window::setStatusFont(const string &font) { - state.statusFont = font; - return p.setStatusFont(font); -} - -void Window::setStatusText(const string &text) { - state.statusText = text; - return p.setStatusText(text); -} - -void Window::setStatusVisible(bool visible) { - state.statusVisible = visible; - return p.setStatusVisible(visible); -} - -void Window::setTitle(const string &text) { - state.title = text; - return p.setTitle(text); -} - -void Window::setVisible(bool visible) { - state.visible = visible; - synchronizeLayout(); - return p.setVisible(visible); -} - -void Window::setWidgetFont(const string &font) { - state.widgetFont = font; - return p.setWidgetFont(font); -} - -string Window::statusText() { - return state.statusText; -} - -void Window::synchronizeLayout() { - if(visible() && OS_quit == false) setGeometry(geometry()); -} - -bool Window::visible() { - return state.visible; -} - -Window::Window(): -state(*new State), -base_from_member(*new pWindow(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Window::~Window() { - p.destructor(); - delete &state; -} - -//Action -//====== - -bool Action::enabled() { - return state.enabled; -} - -void Action::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Action::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Action::visible() { - return state.visible; -} - -Action::Action(pAction &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Action::~Action() { - p.destructor(); - delete &state; -} - -//Menu -//==== - -void Menu::append(const set &list) { - for(auto &action : list) { - if(state.action.append(action)) { - action.state.menu = this; - p.append(action); - } - } -} - -void Menu::remove(const set &list) { - for(auto &action : list) { - if(state.action.remove(action)) { - action.state.menu = 0; - return p.remove(action); - } - } -} - -void Menu::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Menu::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Menu::Menu(): -state(*new State), -base_from_member(*new pMenu(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Menu::~Menu() { - p.destructor(); - delete &state; -} - -//Separator -//========= - -Separator::Separator(): -base_from_member(*new pSeparator(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Separator::~Separator() { - p.destructor(); -} - -//Item -//==== - -void Item::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Item::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Item::Item(): -state(*new State), -base_from_member(*new pItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Item::~Item() { - p.destructor(); - delete &state; -} - -//CheckItem -//========= - -bool CheckItem::checked() { - return p.checked(); -} - -void CheckItem::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckItem::CheckItem(): -state(*new State), -base_from_member(*new pCheckItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckItem::~CheckItem() { - p.destructor(); - delete &state; -} - -//RadioItem -//========= - -void RadioItem::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioItem::checked() { - return p.checked(); -} - -void RadioItem::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string RadioItem::text() { - return state.text; -} - -RadioItem::RadioItem(): -state(*new State), -base_from_member(*new pRadioItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioItem::~RadioItem() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//Sizable -//======= - -Layout* Sizable::layout() { - return state.layout; -} - -Window* Sizable::window() { - if(state.layout) return state.layout->window(); - return state.window; -} - -Sizable::Sizable(pSizable &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Sizable::~Sizable() { - if(layout()) layout()->remove(*this); - p.destructor(); - delete &state; -} - -//Layout -//====== - -void Layout::append(Sizable &sizable) { - sizable.state.layout = this; - sizable.state.window = 0; - - if(dynamic_cast(&sizable)) { - Layout &layout = (Layout&)sizable; - layout.synchronizeLayout(); - } - - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->append(widget); - } -} - -void Layout::remove(Sizable &sizable) { - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->remove(widget); - } - - sizable.state.layout = 0; - sizable.state.window = 0; -} - -Layout::Layout(): -state(*new State), -base_from_member(*new pLayout(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { -} - -Layout::Layout(pLayout &p): -state(*new State), -base_from_member(p), -Sizable(p), -p(p) { -} - -Layout::~Layout() { - if(layout()) layout()->remove(*this); - else if(window()) window()->remove(*this); - p.destructor(); - delete &state; -} - -//Widget -//====== - -bool Widget::enabled() { - return state.enabled; -} - -bool Widget::focused() { - return p.focused(); -} - -string Widget::font() { - return state.font; -} - -Geometry Widget::geometry() { - return state.geometry; -} - -Geometry Widget::minimumGeometry() { - return p.minimumGeometry(); -} - -void Widget::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Widget::setFocused() { - return p.setFocused(); -} - -void Widget::setFont(const string &font) { - state.font = font; - return p.setFont(font); -} - -void Widget::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Widget::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Widget::visible() { - return state.visible; -} - -Widget::Widget(): -state(*new State), -base_from_member(*new pWidget(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { - state.abstract = true; - p.constructor(); -} - -Widget::Widget(pWidget &p): -state(*new State), -base_from_member(p), -Sizable(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Widget::~Widget() { - p.destructor(); - delete &state; -} - -//Button -//====== - -void Button::setImage(const image &image, Orientation orientation) { - state.image = image; - state.orientation = orientation; - return p.setImage(image, orientation); -} - -void Button::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Button::Button(): -state(*new State), -base_from_member(*new pButton(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Button::~Button() { - p.destructor(); - delete &state; -} - -//Canvas -//====== - -uint32_t* Canvas::data() { - return state.data; -} - -bool Canvas::setImage(const nall::image &image) { - if(image.data == nullptr || image.width == 0 || image.height == 0) return false; - state.width = image.width; - state.height = image.height; - setSize({ state.width, state.height }); - memcpy(state.data, image.data, state.width * state.height * sizeof(uint32_t)); - return true; -} - -void Canvas::setSize(const Size &size) { - state.width = size.width; - state.height = size.height; - delete[] state.data; - state.data = new uint32_t[size.width * size.height]; - return p.setSize(size); -} - -Size Canvas::size() { - return { state.width, state.height }; -} - -void Canvas::update() { - return p.update(); -} - -Canvas::Canvas(): -state(*new State), -base_from_member(*new pCanvas(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - state.data = new uint32_t[state.width * state.height]; - p.constructor(); -} - -Canvas::~Canvas() { - p.destructor(); - delete[] state.data; - delete &state; -} - -//CheckBox -//======== - -bool CheckBox::checked() { - return p.checked(); -} - -void CheckBox::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckBox::CheckBox(): -state(*new State), -base_from_member(*new pCheckBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckBox::~CheckBox() { - p.destructor(); - delete &state; -} - -//ComboBox -//======== - -void ComboBox::append_(const lstring &list) { - for(auto &text : list) { - state.text.append(text); - p.append(text); - } -} - -void ComboBox::modify(unsigned row, const string &text) { - state.text(row) = text; - p.modify(row, text); -} - -void ComboBox::remove(unsigned row) { - state.text.remove(row); - p.remove(row); -} - -void ComboBox::reset() { - state.selection = 0; - state.text.reset(); - return p.reset(); -} - -unsigned ComboBox::selection() { - return p.selection(); -} - -void ComboBox::setSelection(unsigned row) { - state.selection = row; - return p.setSelection(row); -} - -string ComboBox::text() { - return state.text(selection()); -} - -string ComboBox::text(unsigned row) { - return state.text(row); -} - -ComboBox::ComboBox(): -state(*new State), -base_from_member(*new pComboBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ComboBox::~ComboBox() { - p.destructor(); - delete &state; -} - -//HexEdit -//======= - -void HexEdit::setColumns(unsigned columns) { - state.columns = columns; - return p.setColumns(columns); -} - -void HexEdit::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HexEdit::setOffset(unsigned offset) { - state.offset = offset; - return p.setOffset(offset); -} - -void HexEdit::setRows(unsigned rows) { - state.rows = rows; - return p.setRows(rows); -} - -void HexEdit::update() { - return p.update(); -} - -HexEdit::HexEdit(): -state(*new State), -base_from_member(*new pHexEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HexEdit::~HexEdit() { - p.destructor(); - delete &state; -} - -//HorizontalScrollBar -//=================== - -unsigned HorizontalScrollBar::length() { - return state.length; -} - -unsigned HorizontalScrollBar::position() { - return p.position(); -} - -void HorizontalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalScrollBar::HorizontalScrollBar(): -state(*new State), -base_from_member(*new pHorizontalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalScrollBar::~HorizontalScrollBar() { - p.destructor(); - delete &state; -} - -//HorizontalSlider -//================ - -unsigned HorizontalSlider::length() { - return state.length; -} - -unsigned HorizontalSlider::position() { - return p.position(); -} - -void HorizontalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalSlider::HorizontalSlider(): -state(*new State), -base_from_member(*new pHorizontalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalSlider::~HorizontalSlider() { - p.destructor(); - delete &state; -} - -//Label -//===== - -void Label::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Label::Label(): -state(*new State), -base_from_member(*new pLabel(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Label::~Label() { - p.destructor(); - delete &state; -} - -//LineEdit -//======== - -void LineEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void LineEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string LineEdit::text() { - return p.text(); -} - -LineEdit::LineEdit(): -state(*new State), -base_from_member(*new pLineEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -LineEdit::~LineEdit() { - p.destructor(); - delete &state; -} - -//ListView -//======== - -void ListView::append_(const lstring &text) { - state.checked.append(false); - state.text.append(text); - return p.append(text); -} - -void ListView::autoSizeColumns() { - return p.autoSizeColumns(); -} - -bool ListView::checked(unsigned row) { - return p.checked(row); -} - -void ListView::modify_(unsigned row, const lstring &text) { - state.text[row] = text; - return p.modify(row, text); -} - -void ListView::remove(unsigned row) { - state.text.remove(row); - state.image.remove(row); - return p.remove(row); -} - -void ListView::reset() { - state.checked.reset(); - state.image.reset(); - state.text.reset(); - return p.reset(); -} - -bool ListView::selected() { - return p.selected(); -} - -unsigned ListView::selection() { - return p.selection(); -} - -void ListView::setCheckable(bool checkable) { - state.checkable = checkable; - return p.setCheckable(checkable); -} - -void ListView::setChecked(unsigned row, bool checked) { - state.checked[row] = checked; - return p.setChecked(row, checked); -} - -void ListView::setHeaderText_(const lstring &text) { - state.headerText = text; - return p.setHeaderText(text); -} - -void ListView::setHeaderVisible(bool visible) { - state.headerVisible = visible; - return p.setHeaderVisible(visible); -} - -void ListView::setImage(unsigned row, unsigned column, const nall::image &image) { - state.image(row)(column) = image; - return p.setImage(row, column, image); -} - -void ListView::setSelected(bool selected) { - state.selected = selected; - return p.setSelected(selected); -} - -void ListView::setSelection(unsigned row) { - state.selected = true; - state.selection = row; - return p.setSelection(row); -} - -ListView::ListView(): -state(*new State), -base_from_member(*new pListView(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ListView::~ListView() { - p.destructor(); - delete &state; -} - -//ProgressBar -//=========== - -void ProgressBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -ProgressBar::ProgressBar(): -state(*new State), -base_from_member(*new pProgressBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ProgressBar::~ProgressBar() { - p.destructor(); - delete &state; -} - -//RadioBox -//======== - -void RadioBox::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioBox::checked() { - return p.checked(); -} - -void RadioBox::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -RadioBox::RadioBox(): -state(*new State), -base_from_member(*new pRadioBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioBox::~RadioBox() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//TextEdit -//======== - -void TextEdit::setCursorPosition(unsigned position) { - state.cursorPosition = position; - return p.setCursorPosition(position); -} - -void TextEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void TextEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -void TextEdit::setWordWrap(bool wordWrap) { - state.wordWrap = wordWrap; - return p.setWordWrap(wordWrap); -} - -string TextEdit::text() { - return p.text(); -} - -TextEdit::TextEdit(): -state(*new State), -base_from_member(*new pTextEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -TextEdit::~TextEdit() { - p.destructor(); - delete &state; -} - -//VerticalScrollBar -//================= - -unsigned VerticalScrollBar::length() { - return state.length; -} - -unsigned VerticalScrollBar::position() { - return p.position(); -} - -void VerticalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalScrollBar::VerticalScrollBar(): -state(*new State), -base_from_member(*new pVerticalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalScrollBar::~VerticalScrollBar() { - p.destructor(); - delete &state; -} - -//VerticalSlider -//============== - -unsigned VerticalSlider::length() { - return state.length; -} - -unsigned VerticalSlider::position() { - return p.position(); -} - -void VerticalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalSlider::VerticalSlider(): -state(*new State), -base_from_member(*new pVerticalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalSlider::~VerticalSlider() { - p.destructor(); - delete &state; -} - -//Viewport -//======== - -uintptr_t Viewport::handle() { - return p.handle(); -} - -Viewport::Viewport(): -base_from_member(*new pViewport(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Viewport::~Viewport() { - p.destructor(); -} diff --git a/ananke/phoenix/core/core.hpp b/ananke/phoenix/core/core.hpp deleted file mode 100644 index 1b329f85..00000000 --- a/ananke/phoenix/core/core.hpp +++ /dev/null @@ -1,615 +0,0 @@ -struct Font; -struct Window; -struct Menu; -struct Sizable; -struct Layout; -struct Widget; - -struct pFont; -struct pObject; -struct pOS; -struct pTimer; -struct pWindow; -struct pAction; -struct pMenu; -struct pSeparator; -struct pItem; -struct pCheckItem; -struct pRadioItem; -struct pSizable; -struct pLayout; -struct pWidget; -struct pButton; -struct pCanvas; -struct pCheckBox; -struct pComboBox; -struct pHexEdit; -struct pHorizontalScrollBar; -struct pHorizontalSlider; -struct pLabel; -struct pLineEdit; -struct pListView; -struct pProgressBar; -struct pRadioBox; -struct pTextEdit; -struct pVerticalScrollBar; -struct pVerticalSlider; -struct pViewport; - -enum : unsigned { - MaximumSize = ~0u, - MinimumSize = 0u, -}; - -struct Color { - uint8_t red, green, blue, alpha; - uint32_t rgb() const; - uint32_t rgba() const; - inline Color() : red(0), green(0), blue(0), alpha(255) {} - inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) : red(red), green(green), blue(blue), alpha(alpha) {} -}; - -struct Position { - signed x, y; - inline Position() : x(0), y(0) {} - template inline Position(X x, Y y) : x(x), y(y) {} -}; - -struct Size { - unsigned width, height; - inline Size() : width(0), height(0) {} - template inline Size(W width, H height) : width(width), height(height) {} -}; - -struct Geometry { - signed x, y; - unsigned width, height; - Position position() const; - Size size() const; - nall::string text() const; - inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(const Position& position, const Size& size) : x(position.x), y(position.y), width(size.width), height(size.height) {} - template inline Geometry(X x, Y y, W width, H height) : x(x), y(y), width(width), height(height) {} - Geometry(const nall::string &text); -}; - -enum class Orientation : unsigned { Horizontal, Vertical }; - -struct Font { - nall::string description; - Geometry geometry(const nall::string &text); - Font(const nall::string &description = ""); -}; - -struct Desktop { - static Size size(); - static Geometry workspace(); - Desktop() = delete; -}; - -struct Keyboard { - #include "keyboard.hpp" - static bool pressed(Scancode scancode); - static bool released(Scancode scancode); - static nall::vector state(); - Keyboard() = delete; -}; - -struct Mouse { - enum class Button : unsigned { Left, Middle, Right }; - static Position position(); - static bool pressed(Button); - static bool released(Button); - Mouse() = delete; -}; - -struct DialogWindow { - template static nall::string fileOpen(Window &parent, const nall::string &path, const Args&... args) { return fileOpen_(parent, path, { args... }); } - template static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); } - static nall::string folderSelect(Window &parent, const nall::string &path); - DialogWindow() = delete; - -private: - static nall::string fileOpen_(Window &parent, const nall::string &path, const nall::lstring& filter); - static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter); -}; - -struct MessageWindow { - enum class Buttons : unsigned { - Ok, - OkCancel, - YesNo, - }; - - enum class Response : unsigned { - Ok, - Cancel, - Yes, - No, - }; - - static Response information(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response question(Window &parent, const nall::string &text, Buttons = Buttons::YesNo); - static Response warning(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - MessageWindow() = delete; -}; - -struct Object { - Object(pObject &p); - Object& operator=(const Object&) = delete; - Object(const Object&) = delete; - virtual ~Object(); - pObject &p; -}; - -struct OS { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - static void setName(const nall::string &name); - - struct State; - static void initialize(); -}; - -struct Timer : private nall::base_from_member, Object { - nall::function onTimeout; - - void setEnabled(bool enabled = true); - void setInterval(unsigned milliseconds); - - Timer(); - ~Timer(); - struct State; - State &state; - pTimer &p; -}; - -struct Window : private nall::base_from_member, Object { - nall::function onClose; - nall::function onKeyPress; - nall::function onKeyRelease; - nall::function onMove; - nall::function onSize; - - static Window& none(); - - inline void append() {} - inline void remove() {} - template void append(T &arg, Args&... args) { append_(arg); append(args...); } - template void remove(T &arg, Args&... args) { remove_(arg); remove(args...); } - - void append_(Layout &layout); - void append_(Menu &menu); - void append_(Widget &widget); - Color backgroundColor(); - Geometry frameGeometry(); - Geometry frameMargin(); - bool focused(); - bool fullScreen(); - Geometry geometry(); - void ignore(); - void remove_(Layout &layout); - void remove_(Menu &menu); - void remove_(Widget &widget); - void setBackgroundColor(const Color &color); - void setFrameGeometry(const Geometry &geometry); - void setFocused(); - void setFullScreen(bool fullScreen = true); - void setGeometry(const Geometry &geometry); - void setMenuFont(const nall::string &font); - void setMenuVisible(bool visible = true); - void setModal(bool modal = true); - void setResizable(bool resizable = true); - void setSmartGeometry(const Geometry &geometry); - void setStatusFont(const nall::string &font); - void setStatusText(const nall::string &text); - void setStatusVisible(bool visible = true); - void setTitle(const nall::string &text); - void setVisible(bool visible = true); - void setWidgetFont(const nall::string &font); - nall::string statusText(); - void synchronizeLayout(); - bool visible(); - - Window(); - ~Window(); - struct State; - State &state; - pWindow &p; -}; - -struct Action : Object { - bool enabled(); - void setEnabled(bool enabled = true); - void setVisible(bool visible = true); - bool visible(); - - Action(pAction &p); - ~Action(); - struct State; - State &state; - pAction &p; -}; - -struct Menu : private nall::base_from_member, Action { - template void append(Args&... args) { append({args...}); } - template void remove(Args&... args) { remove({args...}); } - - void append(const nall::set &list); - void remove(const nall::set &list); - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Menu(); - ~Menu(); - struct State; - State &state; - pMenu &p; -}; - -struct Separator : private nall::base_from_member, Action { - Separator(); - ~Separator(); - pSeparator &p; -}; - -struct Item : private nall::base_from_member, Action { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Item(); - ~Item(); - struct State; - State &state; - pItem &p; -}; - -struct CheckItem : private nall::base_from_member, Action { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckItem(); - ~CheckItem(); - struct State; - State &state; - pCheckItem &p; -}; - -struct RadioItem : private nall::base_from_member, Action { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - nall::string text(); - - RadioItem(); - ~RadioItem(); - struct State; - State &state; - pRadioItem &p; -}; - -struct Sizable : Object { - virtual bool enabled() = 0; - Layout* layout(); - virtual Geometry minimumGeometry() = 0; - virtual void setEnabled(bool enabled = true) = 0; - virtual void setGeometry(const Geometry &geometry) = 0; - virtual void setVisible(bool visible = true) = 0; - virtual bool visible() = 0; - Window* window(); - - Sizable(pSizable &p); - ~Sizable(); - struct State; - State &state; - pSizable &p; -}; - -struct Layout : private nall::base_from_member, Sizable { - virtual void append(Sizable &sizable); - virtual void remove(Sizable &sizable); - virtual void reset() {} - virtual void synchronizeLayout() = 0; - - Layout(); - Layout(pLayout &p); - ~Layout(); - struct State; - State &state; - pLayout &p; -}; - -struct Widget : private nall::base_from_member, Sizable { - bool enabled(); - bool focused(); - nall::string font(); - Geometry geometry(); - Geometry minimumGeometry(); - void setEnabled(bool enabled = true); - void setFocused(); - void setFont(const nall::string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - bool visible(); - - Widget(); - Widget(pWidget &p); - ~Widget(); - struct State; - State &state; - pWidget &p; -}; - -struct Button : private nall::base_from_member, Widget { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}, Orientation = Orientation::Horizontal); - void setText(const nall::string &text); - - Button(); - ~Button(); - struct State; - State &state; - pButton &p; -}; - -struct Canvas : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uint32_t* data(); - bool setImage(const nall::image &image); - void setSize(const Size &size); - Size size(); - void update(); - - Canvas(); - ~Canvas(); - struct State; - State &state; - pCanvas &p; -}; - -struct CheckBox : private nall::base_from_member, Widget { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckBox(); - ~CheckBox(); - struct State; - State &state; - pCheckBox &p; -}; - -struct ComboBox : private nall::base_from_member, Widget { - nall::function onChange; - - template void append(const Args&... args) { append_({args...}); } - - void append_(const nall::lstring &list); - void modify(unsigned row, const nall::string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - nall::string text(); - nall::string text(unsigned row); - - ComboBox(); - ~ComboBox(); - struct State; - State &state; - pComboBox &p; -}; - -struct HexEdit : private nall::base_from_member, Widget { - nall::function onRead; - nall::function onWrite; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - HexEdit(); - ~HexEdit(); - struct State; - State &state; - pHexEdit &p; -}; - -struct HorizontalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalScrollBar(); - ~HorizontalScrollBar(); - struct State; - State &state; - pHorizontalScrollBar &p; -}; - -struct HorizontalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalSlider(); - ~HorizontalSlider(); - struct State; - State &state; - pHorizontalSlider &p; -}; - -struct Label : private nall::base_from_member, Widget { - void setText(const nall::string &text); - - Label(); - ~Label(); - struct State; - State &state; - pLabel &p; -}; - -struct LineEdit : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - - void setEditable(bool editable = true); - void setText(const nall::string &text); - nall::string text(); - - LineEdit(); - ~LineEdit(); - struct State; - State &state; - pLineEdit &p; -}; - -struct ListView : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - nall::function onToggle; - - template void append(const Args&... args) { append_({args...}); } - template void modify(unsigned row, const Args&... args) { modify_(row, {args...}); } - template void setHeaderText(const Args&... args) { setHeaderText_({args...}); } - - void append_(const nall::lstring &list); - void autoSizeColumns(); - bool checked(unsigned row); - void modify_(unsigned row, const nall::lstring &list); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable = true); - void setChecked(unsigned row, bool checked = true); - void setHeaderText_(const nall::lstring &list); - void setHeaderVisible(bool visible = true); - void setImage(unsigned row, unsigned column, const nall::image &image = nall::image{}); - void setSelected(bool selected = true); - void setSelection(unsigned row); - - ListView(); - ~ListView(); - struct State; - State &state; - pListView &p; -}; - -struct ProgressBar : private nall::base_from_member, Widget { - void setPosition(unsigned position); - - ProgressBar(); - ~ProgressBar(); - struct State; - State &state; - pProgressBar &p; -}; - -struct RadioBox : private nall::base_from_member, Widget { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - - RadioBox(); - ~RadioBox(); - struct State; - State &state; - pRadioBox &p; -}; - -struct TextEdit : private nall::base_from_member, Widget { - nall::function onChange; - - void setCursorPosition(unsigned position); - void setEditable(bool editable = true); - void setText(const nall::string &text); - void setWordWrap(bool wordWrap = true); - nall::string text(); - - TextEdit(); - ~TextEdit(); - struct State; - State &state; - pTextEdit &p; -}; - -struct VerticalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalScrollBar(); - ~VerticalScrollBar(); - struct State; - State &state; - pVerticalScrollBar &p; -}; - -struct VerticalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalSlider(); - ~VerticalSlider(); - struct State; - State &state; - pVerticalSlider &p; -}; - -struct Viewport : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uintptr_t handle(); - - Viewport(); - ~Viewport(); - pViewport &p; -}; - -#include "layout/fixed-layout.hpp" -#include "layout/horizontal-layout.hpp" -#include "layout/vertical-layout.hpp" diff --git a/ananke/phoenix/core/layout/fixed-layout.cpp b/ananke/phoenix/core/layout/fixed-layout.cpp deleted file mode 100644 index 71ff3dac..00000000 --- a/ananke/phoenix/core/layout/fixed-layout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -void FixedLayout::append(Sizable &sizable, const Geometry &geometry) { - children.append({ &sizable, geometry }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void FixedLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool FixedLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry FixedLayout::minimumGeometry() { - unsigned width = MinimumSize, height = MinimumSize; - for(auto &child : children) { - width = max(width, child.sizable->minimumGeometry().width); - height = max(height, child.sizable->minimumGeometry().height); - } - return { 0, 0, width, height }; -} - -void FixedLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void FixedLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void FixedLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void FixedLayout::setGeometry(const Geometry &geometry) { -} - -void FixedLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void FixedLayout::synchronizeLayout() { - for(auto &child : children) { - Layout::append(*child.sizable); - child.sizable->setGeometry(child.geometry); - } -} - -bool FixedLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -FixedLayout::FixedLayout() { - state.enabled = true; - state.visible = true; -} - -FixedLayout::~FixedLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/ananke/phoenix/core/layout/fixed-layout.hpp b/ananke/phoenix/core/layout/fixed-layout.hpp deleted file mode 100644 index a67f2185..00000000 --- a/ananke/phoenix/core/layout/fixed-layout.hpp +++ /dev/null @@ -1,27 +0,0 @@ -struct FixedLayout : Layout { - void append(Sizable &sizable, const Geometry &geometry); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - FixedLayout(); - ~FixedLayout(); - -//private: - struct State { - bool enabled; - bool visible; - } state; - - struct Children { - Sizable *sizable; - Geometry geometry; - }; - nall::vector children; -}; diff --git a/ananke/phoenix/core/layout/horizontal-layout.cpp b/ananke/phoenix/core/layout/horizontal-layout.cpp deleted file mode 100644 index a1146038..00000000 --- a/ananke/phoenix/core/layout/horizontal-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void HorizontalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void HorizontalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool HorizontalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry HorizontalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - width += child.spacing; - if(child.width == MinimumSize || child.width == MaximumSize) { - width += child.sizable->minimumGeometry().width; - continue; - } - width += child.width; - } - - for(auto &child : children) { - if(child.height == MinimumSize || child.height == MaximumSize) { - height = max(height, child.sizable->minimumGeometry().height); - continue; - } - height = max(height, child.height); - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void HorizontalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void HorizontalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void HorizontalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void HorizontalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void HorizontalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumWidth = 0, maximumWidthCounter = 0; - for(auto &child : children) { - if(child.width == MaximumSize) maximumWidthCounter++; - if(child.width != MaximumSize) minimumWidth += child.width; - minimumWidth += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = (geometry.width - minimumWidth) / maximumWidthCounter; - if(child.height == MaximumSize) child.height = geometry.height; - } - - unsigned maximumHeight = 0; - for(auto &child : children) maximumHeight = max(maximumHeight, child.height); - - for(auto &child : children) { - unsigned pivot = (maximumHeight - child.height) * state.alignment; - Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.x += child.width + child.spacing; - geometry.width -= child.width + child.spacing; - } -} - -void HorizontalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void HorizontalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void HorizontalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool HorizontalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -HorizontalLayout::HorizontalLayout() { - state.alignment = 0.5; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -HorizontalLayout::~HorizontalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/ananke/phoenix/core/layout/horizontal-layout.hpp b/ananke/phoenix/core/layout/horizontal-layout.hpp deleted file mode 100644 index 96d4f101..00000000 --- a/ananke/phoenix/core/layout/horizontal-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct HorizontalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - HorizontalLayout(); - ~HorizontalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/ananke/phoenix/core/layout/vertical-layout.cpp b/ananke/phoenix/core/layout/vertical-layout.cpp deleted file mode 100644 index 4fd6315b..00000000 --- a/ananke/phoenix/core/layout/vertical-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void VerticalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void VerticalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool VerticalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry VerticalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - if(child.width == MinimumSize || child.width == MaximumSize) { - width = max(width, child.sizable->minimumGeometry().width); - continue; - } - width = max(width, child.width); - } - - for(auto &child : children) { - height += child.spacing; - if(child.height == MinimumSize || child.height == MaximumSize) { - height += child.sizable->minimumGeometry().height; - continue; - } - height += child.height; - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void VerticalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void VerticalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void VerticalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void VerticalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void VerticalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumHeight = 0, maximumHeightCounter = 0; - for(auto &child : children) { - if(child.height == MaximumSize) maximumHeightCounter++; - if(child.height != MaximumSize) minimumHeight += child.height; - minimumHeight += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = geometry.width; - if(child.height == MaximumSize) child.height = (geometry.height - minimumHeight) / maximumHeightCounter; - } - - unsigned maximumWidth = 0; - for(auto &child : children) maximumWidth = max(maximumWidth, child.width); - - for(auto &child : children) { - unsigned pivot = (maximumWidth - child.width) * state.alignment; - Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.y += child.height + child.spacing; - geometry.height -= child.height + child.spacing; - } -} - -void VerticalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void VerticalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void VerticalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool VerticalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -VerticalLayout::VerticalLayout() { - state.alignment = 0.0; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -VerticalLayout::~VerticalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/ananke/phoenix/core/layout/vertical-layout.hpp b/ananke/phoenix/core/layout/vertical-layout.hpp deleted file mode 100644 index 8273dbe2..00000000 --- a/ananke/phoenix/core/layout/vertical-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct VerticalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - VerticalLayout(); - ~VerticalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/ananke/phoenix/core/state.hpp b/ananke/phoenix/core/state.hpp deleted file mode 100644 index a4bff751..00000000 --- a/ananke/phoenix/core/state.hpp +++ /dev/null @@ -1,285 +0,0 @@ -struct OS::State { - string name; - - State() { - } -} osState; - -struct Timer::State { - bool enabled; - unsigned milliseconds; - - State() { - enabled = false; - milliseconds = 0; - } -}; - -struct Window::State { - bool backgroundColorOverride; - Color backgroundColor; - bool fullScreen; - Geometry geometry; - bool ignore; - set layout; - set menu; - string menuFont; - bool menuVisible; - bool modal; - bool resizable; - string statusFont; - string statusText; - bool statusVisible; - string title; - bool visible; - set widget; - string widgetFont; - - State() { - backgroundColorOverride = false; - backgroundColor = {0, 0, 0, 255}; - fullScreen = false; - geometry = {128, 128, 256, 256}; - ignore = false; - menuVisible = false; - modal = false; - resizable = true; - statusVisible = false; - visible = false; - } -}; - -struct Action::State { - bool enabled; - Menu *menu; - bool visible; - Window *window; - - State() { - enabled = true; - menu = 0; - visible = true; - window = 0; - } -}; - -struct Menu::State { - set action; - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Item::State { - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct CheckItem::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct RadioItem::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct Sizable::State { - Layout *layout; - Window *window; - - State() { - layout = 0; - window = 0; - } -}; - -struct Layout::State { - State() { - } -}; - -struct Widget::State { - bool abstract; - bool enabled; - string font; - Geometry geometry; - bool visible; - - State() { - abstract = false; - enabled = true; - geometry = {0, 0, 0, 0}; - visible = true; - } -}; - -struct Button::State { - nall::image image; - Orientation orientation; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Canvas::State { - uint32_t *data; - unsigned width; - unsigned height; - - State() { - data = nullptr; - width = 256; - height = 256; - } -}; - -struct CheckBox::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct ComboBox::State { - unsigned selection; - vector text; - - State() { - selection = 0; - } -}; - -struct HexEdit::State { - unsigned columns; - unsigned length; - unsigned offset; - unsigned rows; - - State() { - columns = 16; - length = 0; - offset = 0; - rows = 16; - } -}; - -struct HorizontalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct HorizontalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct Label::State { - string text; -}; - -struct LineEdit::State { - bool editable; - string text; - - State() { - editable = true; - } -}; - -struct ListView::State { - bool checkable; - vector checked; - lstring headerText; - bool headerVisible; - vector> image; - bool selected; - unsigned selection; - vector text; - - State() { - checkable = false; - headerVisible = false; - selected = false; - selection = 0; - } -}; - -struct ProgressBar::State { - unsigned position; - - State() { - position = 0; - } -}; - -struct RadioBox::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct TextEdit::State { - unsigned cursorPosition; - bool editable; - string text; - bool wordWrap; - - State() { - cursorPosition = 0; - editable = true; - wordWrap = true; - } -}; - -struct VerticalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct VerticalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; diff --git a/ananke/phoenix/gtk/action/action.cpp b/ananke/phoenix/gtk/action/action.cpp deleted file mode 100644 index 950259de..00000000 --- a/ananke/phoenix/gtk/action/action.cpp +++ /dev/null @@ -1,27 +0,0 @@ -void pAction::setEnabled(bool enabled) { - gtk_widget_set_sensitive(widget, enabled); -} - -void pAction::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); -} - -void pAction::constructor() { -} - -void pAction::orphan() { -} - -//GTK+ uses _ for mnemonics, __ for _ -//transform so that & is used for mnemonics, && for & -string pAction::mnemonic(string text) { - text.transform("&_", "\x01\x02"); - text.replace("\x01\x01", "&"); - text.transform("\x01", "_"); - text.replace("\x02", "__"); - return text; -} - -void pAction::setFont(const string &font) { - pFont::setFont(widget, font); -} diff --git a/ananke/phoenix/gtk/action/check-item.cpp b/ananke/phoenix/gtk/action/check-item.cpp deleted file mode 100644 index 2cc182a6..00000000 --- a/ananke/phoenix/gtk/action/check-item.cpp +++ /dev/null @@ -1,33 +0,0 @@ -static void CheckItem_toggle(CheckItem *self) { - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pCheckItem::setChecked(bool checked) { - locked = true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked); - locked = false; -} - -void pCheckItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pCheckItem::constructor() { - widget = gtk_check_menu_item_new_with_mnemonic(""); - setChecked(checkItem.state.checked); - setText(checkItem.state.text); - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_toggle), (gpointer)&checkItem); -} - -void pCheckItem::destructor() { - gtk_widget_destroy(widget); -} - -void pCheckItem::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/action/item.cpp b/ananke/phoenix/gtk/action/item.cpp deleted file mode 100644 index afab955e..00000000 --- a/ananke/phoenix/gtk/action/item.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static void Item_activate(Item *self) { - if(self->onActivate) self->onActivate(); -} - -void pItem::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pItem::constructor() { - widget = gtk_image_menu_item_new_with_mnemonic(""); - g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_activate), (gpointer)&item); - setText(item.state.text); -} - -void pItem::destructor() { - gtk_widget_destroy(widget); -} - -void pItem::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/action/menu.cpp b/ananke/phoenix/gtk/action/menu.cpp deleted file mode 100644 index 92252085..00000000 --- a/ananke/phoenix/gtk/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - action.state.window = this->action.state.window; - - gtk_menu_shell_append(GTK_MENU_SHELL(gtkMenu), action.p.widget); - if(action.state.window && action.state.window->state.menuFont != "") { - action.p.setFont(action.state.window->state.menuFont); - } - gtk_widget_show(action.p.widget); -} - -void pMenu::remove(Action &action) { - action.p.orphan(); - action.state.window = 0; -} - -void pMenu::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pMenu::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pMenu::constructor() { - gtkMenu = gtk_menu_new(); - widget = gtk_image_menu_item_new_with_mnemonic(""); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), gtkMenu); - setText(menu.state.text); -} - -void pMenu::destructor() { - gtk_widget_destroy(gtkMenu); - gtk_widget_destroy(widget); -} - -void pMenu::orphan() { - for(auto &action : menu.state.action) action.p.orphan(); - destructor(); - constructor(); - for(auto &action : menu.state.action) append(action); -} - -void pMenu::setFont(const string &font) { - pAction::setFont(font); - for(auto &item : menu.state.action) item.p.setFont(font); -} diff --git a/ananke/phoenix/gtk/action/radio-item.cpp b/ananke/phoenix/gtk/action/radio-item.cpp deleted file mode 100644 index a599d70b..00000000 --- a/ananke/phoenix/gtk/action/radio-item.cpp +++ /dev/null @@ -1,48 +0,0 @@ -static void RadioItem_activate(RadioItem *self) { - for(auto &item : self->state.group) item.state.checked = (&item == self); - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true); - locked = false; -} - -void pRadioItem::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget)); - if(currentGroup != gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[n].p.widget))) { - gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(group[n].p.widget), currentGroup); - } - } -} - -void pRadioItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pRadioItem::constructor() { - widget = gtk_radio_menu_item_new_with_mnemonic(0, ""); - setGroup(radioItem.state.group); - setText(radioItem.state.text); - for(auto &item : radioItem.state.group) { - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), item.state.checked); - } - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_activate), (gpointer)&radioItem); -} - -void pRadioItem::destructor() { - gtk_widget_destroy(widget); -} - -void pRadioItem::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/action/separator.cpp b/ananke/phoenix/gtk/action/separator.cpp deleted file mode 100644 index 8b7a1a6b..00000000 --- a/ananke/phoenix/gtk/action/separator.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pSeparator::constructor() { - widget = gtk_separator_menu_item_new(); -} - -void pSeparator::destructor() { - gtk_widget_destroy(widget); -} - -void pSeparator::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/desktop.cpp b/ananke/phoenix/gtk/desktop.cpp deleted file mode 100644 index 2b1801ad..00000000 --- a/ananke/phoenix/gtk/desktop.cpp +++ /dev/null @@ -1,36 +0,0 @@ -Size pDesktop::size() { - return { - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} - -Geometry pDesktop::workspace() { - XlibDisplay *display = XOpenDisplay(0); - int screen = DefaultScreen(display); - - static Atom atom = XlibNone; - if(atom == XlibNone) atom = XInternAtom(display, "_NET_WORKAREA", True); - - int format; - unsigned char *data = 0; - unsigned long items, after; - Atom returnAtom; - - int result = XGetWindowProperty( - display, RootWindow(display, screen), atom, 0, 4, False, XA_CARDINAL, &returnAtom, &format, &items, &after, &data - ); - - XCloseDisplay(display); - - if(result == Success && returnAtom == XA_CARDINAL && format == 32 && items == 4) { - unsigned long *workarea = (unsigned long*)data; - return { (signed)workarea[0], (signed)workarea[1], (unsigned)workarea[2], (unsigned)workarea[3] }; - } - - return { - 0, 0, - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} diff --git a/ananke/phoenix/gtk/dialog-window.cpp b/ananke/phoenix/gtk/dialog-window.cpp deleted file mode 100644 index eb04bd64..00000000 --- a/ananke/phoenix/gtk/dialog-window.cpp +++ /dev/null @@ -1,69 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - save == 0 ? "Load File" : "Save File", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - save == 0 ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - for(auto &filterItem : filter) { - GtkFileFilter *gtkFilter = gtk_file_filter_new(); - gtk_file_filter_set_name(gtkFilter, filterItem); - lstring part; - part.split("(", filterItem); - part[1].rtrim<1>(")"); - lstring list; - list.split(",", part[1]); - for(auto &pattern : list) gtk_file_filter_add_pattern(gtkFilter, pattern); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), gtkFilter); - } - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(0, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(1, parent, path, filter); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - "Select Folder", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - if(name == "") return ""; - if(name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/ananke/phoenix/gtk/font.cpp b/ananke/phoenix/gtk/font.cpp deleted file mode 100644 index cb6889d1..00000000 --- a/ananke/phoenix/gtk/font.cpp +++ /dev/null @@ -1,58 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - PangoFontDescription *font = create(description); - Geometry geometry = pFont::geometry(font, text); - free(font); - return geometry; -} - -PangoFontDescription* pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - PangoFontDescription *font = pango_font_description_new(); - pango_font_description_set_family(font, family); - pango_font_description_set_size(font, size * PANGO_SCALE); - pango_font_description_set_weight(font, !bold ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD); - pango_font_description_set_style(font, !italic ? PANGO_STYLE_NORMAL : PANGO_STYLE_OBLIQUE); - return font; -} - -void pFont::free(PangoFontDescription *font) { - pango_font_description_free(font); -} - -Geometry pFont::geometry(PangoFontDescription *font, const string &text) { - PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); - PangoLayout *layout = pango_layout_new(context); - pango_layout_set_font_description(layout, font); - pango_layout_set_text(layout, text, -1); - int width = 0, height = 0; - pango_layout_get_pixel_size(layout, &width, &height); - g_object_unref((gpointer)layout); - return { 0, 0, width, height }; -} - -void pFont::setFont(GtkWidget *widget, const string &font) { - auto gtkFont = pFont::create(font); - pFont::setFont(widget, (gpointer)gtkFont); - pFont::free(gtkFont); -} - -void pFont::setFont(GtkWidget *widget, gpointer font) { - if(font == 0) return; - gtk_widget_modify_font(widget, (PangoFontDescription*)font); - if(GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)pFont::setFont, font); - } -} diff --git a/ananke/phoenix/gtk/keyboard.cpp b/ananke/phoenix/gtk/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/ananke/phoenix/gtk/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/ananke/phoenix/gtk/message-window.cpp b/ananke/phoenix/gtk/message-window.cpp deleted file mode 100644 index 7cd2172a..00000000 --- a/ananke/phoenix/gtk/message-window.cpp +++ /dev/null @@ -1,61 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, gint response) { - if(response == GTK_RESPONSE_OK) return MessageWindow::Response::Ok; - if(response == GTK_RESPONSE_CANCEL) return MessageWindow::Response::Cancel; - if(response == GTK_RESPONSE_YES) return MessageWindow::Response::Yes; - if(response == GTK_RESPONSE_NO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} diff --git a/ananke/phoenix/gtk/mouse.cpp b/ananke/phoenix/gtk/mouse.cpp deleted file mode 100644 index e00f7ff7..00000000 --- a/ananke/phoenix/gtk/mouse.cpp +++ /dev/null @@ -1,20 +0,0 @@ -Position pMouse::position() { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - return { rootx, rooty }; -} - -bool pMouse::pressed(Mouse::Button button) { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - switch(button) { - case Mouse::Button::Left: return mask & Button1Mask; - case Mouse::Button::Middle: return mask & Button2Mask; - case Mouse::Button::Right: return mask & Button3Mask; - } - return false; -} diff --git a/ananke/phoenix/gtk/platform.cpp b/ananke/phoenix/gtk/platform.cpp deleted file mode 100644 index c6650dbb..00000000 --- a/ananke/phoenix/gtk/platform.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; -Font pOS::defaultFont; - -void pOS::main() { - gtk_main(); -} - -bool pOS::pendingEvents() { - return gtk_events_pending(); -} - -void pOS::processEvents() { - while(pendingEvents()) gtk_main_iteration_do(false); -} - -void pOS::quit() { - gtk_main_quit(); -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - int argc = 1; - char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - gtk_init(&argc, &argvp); - - gtk_rc_parse_string(R"( - style "phoenix-gtk" - { - GtkWindow::resize-grip-width = 0 - GtkWindow::resize-grip-height = 0 - GtkTreeView::vertical-separator = 0 - GtkComboBox::appears-as-list = 1 - } - class "GtkWindow" style "phoenix-gtk" - class "GtkTreeView" style "phoenix-gtk" - # class "GtkComboBox" style "phoenix-gtk" - )"); - - pKeyboard::initialize(); -} diff --git a/ananke/phoenix/gtk/platform.hpp b/ananke/phoenix/gtk/platform.hpp deleted file mode 100644 index 01c4a223..00000000 --- a/ananke/phoenix/gtk/platform.hpp +++ /dev/null @@ -1,505 +0,0 @@ -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - unsigned windowBackgroundColor; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static PangoFontDescription* create(const string &description); - static void free(PangoFontDescription *font); - static Geometry geometry(PangoFontDescription *font, const string &text); - static void setFont(GtkWidget *widget, const string &font); - static void setFont(GtkWidget *widget, gpointer font); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - static Font defaultFont; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - GtkWidget *widget; - GtkWidget *menuContainer; - GtkWidget *formContainer; - GtkWidget *statusContainer; - GtkWidget *menu; - GtkWidget *status; - GtkAllocation lastAllocation; - bool onSizePending; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - unsigned menuHeight(); - unsigned statusHeight(); -}; - -struct pAction : public pObject { - Action &action; - GtkWidget *widget; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - virtual void orphan(); - string mnemonic(string text); - virtual void setFont(const string &font); -}; - -struct pMenu : public pAction { - Menu &menu; - GtkWidget *gtkMenu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); - void orphan(); - void setFont(const string &font); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - GtkWidget *gtkWidget; - - bool enabled(); - virtual bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - virtual void setFocused(); - virtual void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public pWidget { - Button &button; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - cairo_surface_t *surface; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - unsigned itemCounter; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - GtkWidget *container; - GtkWidget *subWidget; - GtkWidget *scrollBar; - GtkTextBuffer *textBuffer; - GtkTextMark *textCursor; - - bool focused(); - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - unsigned cursorPosition(); - bool keyPress(unsigned scancode); - void scroll(unsigned position); - void setCursorPosition(unsigned position); - void setScroll(); - void updateScroll(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - GtkWidget *subWidget; - GtkListStore *store; - struct GtkColumn { - GtkTreeViewColumn *column; - GtkCellRenderer *checkbox, *icon, *text; - GtkWidget *label; - }; - vector column; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - bool focused(); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - void setFocused(); - void setFont(const string &font); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - GtkWidget *subWidget; - GtkTextBuffer *textBuffer; - - bool focused(); - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/ananke/phoenix/gtk/settings.cpp b/ananke/phoenix/gtk/settings.cpp deleted file mode 100644 index aeb28bba..00000000 --- a/ananke/phoenix/gtk/settings.cpp +++ /dev/null @@ -1,25 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/gtk.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("gtk.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); - append(windowBackgroundColor = 0xedeceb, "windowBackgroundColor"); -} diff --git a/ananke/phoenix/gtk/timer.cpp b/ananke/phoenix/gtk/timer.cpp deleted file mode 100644 index d04183f8..00000000 --- a/ananke/phoenix/gtk/timer.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static guint Timer_trigger(pTimer *self) { - //timer may have been disabled prior to triggering, so check state - if(self->timer.state.enabled) { - if(self->timer.onTimeout) self->timer.onTimeout(); - } - //callback may have disabled timer, so check state again - if(self->timer.state.enabled) { - g_timeout_add(self->timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)self); - } - //kill this timer instance (it is spawned above if needed again) - return false; -} - -void pTimer::setEnabled(bool enabled) { - if(enabled) { - g_timeout_add(timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)this); - } -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/ananke/phoenix/gtk/utility.cpp b/ananke/phoenix/gtk/utility.cpp deleted file mode 100644 index 29e87bb8..00000000 --- a/ananke/phoenix/gtk/utility.cpp +++ /dev/null @@ -1,200 +0,0 @@ -static GdkPixbuf* CreatePixbuf(const nall::image &image, bool scale = false) { - nall::image gdkImage = image; - gdkImage.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); - if(scale) gdkImage.scale(15, 15, Interpolation::Linear); - - GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, gdkImage.width, gdkImage.height); - memcpy(gdk_pixbuf_get_pixels(pixbuf), gdkImage.data, gdkImage.width * gdkImage.height * 4); - - return pixbuf; -} - -static GtkImage* CreateImage(const nall::image &image, bool scale = false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, scale); - GtkImage *gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); - return gtkImage; -} - -static Keyboard::Keycode Keysym(unsigned keysym) { - switch(keysym) { - case GDK_Escape: return Keyboard::Keycode::Escape; - case GDK_F1: return Keyboard::Keycode::F1; - case GDK_F2: return Keyboard::Keycode::F2; - case GDK_F3: return Keyboard::Keycode::F3; - case GDK_F4: return Keyboard::Keycode::F4; - case GDK_F5: return Keyboard::Keycode::F5; - case GDK_F6: return Keyboard::Keycode::F6; - case GDK_F7: return Keyboard::Keycode::F7; - case GDK_F8: return Keyboard::Keycode::F8; - case GDK_F9: return Keyboard::Keycode::F9; - case GDK_F10: return Keyboard::Keycode::F10; - case GDK_F11: return Keyboard::Keycode::F11; - case GDK_F12: return Keyboard::Keycode::F12; - - case GDK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case GDK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case GDK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case GDK_Insert: return Keyboard::Keycode::Insert; - case GDK_Delete: return Keyboard::Keycode::Delete; - case GDK_Home: return Keyboard::Keycode::Home; - case GDK_End: return Keyboard::Keycode::End; - case GDK_Prior: return Keyboard::Keycode::PageUp; - case GDK_Next: return Keyboard::Keycode::PageDown; - - case GDK_Up: return Keyboard::Keycode::Up; - case GDK_Down: return Keyboard::Keycode::Down; - case GDK_Left: return Keyboard::Keycode::Left; - case GDK_Right: return Keyboard::Keycode::Right; - - case GDK_grave: return Keyboard::Keycode::Grave; - case GDK_1: return Keyboard::Keycode::Number1; - case GDK_2: return Keyboard::Keycode::Number2; - case GDK_3: return Keyboard::Keycode::Number3; - case GDK_4: return Keyboard::Keycode::Number4; - case GDK_5: return Keyboard::Keycode::Number5; - case GDK_6: return Keyboard::Keycode::Number6; - case GDK_7: return Keyboard::Keycode::Number7; - case GDK_8: return Keyboard::Keycode::Number8; - case GDK_9: return Keyboard::Keycode::Number9; - case GDK_0: return Keyboard::Keycode::Number0; - case GDK_minus: return Keyboard::Keycode::Minus; - case GDK_equal: return Keyboard::Keycode::Equal; - case GDK_BackSpace: return Keyboard::Keycode::Backspace; - - case GDK_asciitilde: return Keyboard::Keycode::Tilde; - case GDK_exclam: return Keyboard::Keycode::Exclamation; - case GDK_at: return Keyboard::Keycode::At; - case GDK_numbersign: return Keyboard::Keycode::Pound; - case GDK_dollar: return Keyboard::Keycode::Dollar; - case GDK_percent: return Keyboard::Keycode::Percent; - case GDK_asciicircum: return Keyboard::Keycode::Power; - case GDK_ampersand: return Keyboard::Keycode::Ampersand; - case GDK_asterisk: return Keyboard::Keycode::Asterisk; - case GDK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case GDK_parenright: return Keyboard::Keycode::ParenthesisRight; - case GDK_underscore: return Keyboard::Keycode::Underscore; - case GDK_plus: return Keyboard::Keycode::Plus; - - case GDK_bracketleft: return Keyboard::Keycode::BracketLeft; - case GDK_bracketright: return Keyboard::Keycode::BracketRight; - case GDK_backslash: return Keyboard::Keycode::Backslash; - case GDK_semicolon: return Keyboard::Keycode::Semicolon; - case GDK_apostrophe: return Keyboard::Keycode::Apostrophe; - case GDK_comma: return Keyboard::Keycode::Comma; - case GDK_period: return Keyboard::Keycode::Period; - case GDK_slash: return Keyboard::Keycode::Slash; - - case GDK_braceleft: return Keyboard::Keycode::BraceLeft; - case GDK_braceright: return Keyboard::Keycode::BraceRight; - case GDK_bar: return Keyboard::Keycode::Pipe; - case GDK_colon: return Keyboard::Keycode::Colon; - case GDK_quotedbl: return Keyboard::Keycode::Quote; - case GDK_less: return Keyboard::Keycode::CaretLeft; - case GDK_greater: return Keyboard::Keycode::CaretRight; - case GDK_question: return Keyboard::Keycode::Question; - - case GDK_Tab: return Keyboard::Keycode::Tab; - case GDK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case GDK_Return: return Keyboard::Keycode::Return; - case GDK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case GDK_Shift_R: return Keyboard::Keycode::ShiftRight; - case GDK_Control_L: return Keyboard::Keycode::ControlLeft; - case GDK_Control_R: return Keyboard::Keycode::ControlRight; - case GDK_Super_L: return Keyboard::Keycode::SuperLeft; - case GDK_Super_R: return Keyboard::Keycode::SuperRight; - case GDK_Alt_L: return Keyboard::Keycode::AltLeft; - case GDK_Alt_R: return Keyboard::Keycode::AltRight; - case GDK_space: return Keyboard::Keycode::Space; - case GDK_Menu: return Keyboard::Keycode::Menu; - - case GDK_A: return Keyboard::Keycode::A; - case GDK_B: return Keyboard::Keycode::B; - case GDK_C: return Keyboard::Keycode::C; - case GDK_D: return Keyboard::Keycode::D; - case GDK_E: return Keyboard::Keycode::E; - case GDK_F: return Keyboard::Keycode::F; - case GDK_G: return Keyboard::Keycode::G; - case GDK_H: return Keyboard::Keycode::H; - case GDK_I: return Keyboard::Keycode::I; - case GDK_J: return Keyboard::Keycode::J; - case GDK_K: return Keyboard::Keycode::K; - case GDK_L: return Keyboard::Keycode::L; - case GDK_M: return Keyboard::Keycode::M; - case GDK_N: return Keyboard::Keycode::N; - case GDK_O: return Keyboard::Keycode::O; - case GDK_P: return Keyboard::Keycode::P; - case GDK_Q: return Keyboard::Keycode::Q; - case GDK_R: return Keyboard::Keycode::R; - case GDK_S: return Keyboard::Keycode::S; - case GDK_T: return Keyboard::Keycode::T; - case GDK_U: return Keyboard::Keycode::U; - case GDK_V: return Keyboard::Keycode::V; - case GDK_W: return Keyboard::Keycode::W; - case GDK_X: return Keyboard::Keycode::X; - case GDK_Y: return Keyboard::Keycode::Y; - case GDK_Z: return Keyboard::Keycode::Z; - - case GDK_a: return Keyboard::Keycode::a; - case GDK_b: return Keyboard::Keycode::b; - case GDK_c: return Keyboard::Keycode::c; - case GDK_d: return Keyboard::Keycode::d; - case GDK_e: return Keyboard::Keycode::e; - case GDK_f: return Keyboard::Keycode::f; - case GDK_g: return Keyboard::Keycode::g; - case GDK_h: return Keyboard::Keycode::h; - case GDK_i: return Keyboard::Keycode::i; - case GDK_j: return Keyboard::Keycode::j; - case GDK_k: return Keyboard::Keycode::k; - case GDK_l: return Keyboard::Keycode::l; - case GDK_m: return Keyboard::Keycode::m; - case GDK_n: return Keyboard::Keycode::n; - case GDK_o: return Keyboard::Keycode::o; - case GDK_p: return Keyboard::Keycode::p; - case GDK_q: return Keyboard::Keycode::q; - case GDK_r: return Keyboard::Keycode::r; - case GDK_s: return Keyboard::Keycode::s; - case GDK_t: return Keyboard::Keycode::t; - case GDK_u: return Keyboard::Keycode::u; - case GDK_v: return Keyboard::Keycode::v; - case GDK_w: return Keyboard::Keycode::w; - case GDK_x: return Keyboard::Keycode::x; - case GDK_y: return Keyboard::Keycode::y; - case GDK_z: return Keyboard::Keycode::z; - - case GDK_Num_Lock: return Keyboard::Keycode::NumLock; - case GDK_KP_Divide: return Keyboard::Keycode::Divide; - case GDK_KP_Multiply: return Keyboard::Keycode::Multiply; - case GDK_KP_Subtract: return Keyboard::Keycode::Subtract; - case GDK_KP_Add: return Keyboard::Keycode::Add; - case GDK_KP_Enter: return Keyboard::Keycode::Enter; - case GDK_KP_Decimal: return Keyboard::Keycode::Point; - - case GDK_KP_1: return Keyboard::Keycode::Keypad1; - case GDK_KP_2: return Keyboard::Keycode::Keypad2; - case GDK_KP_3: return Keyboard::Keycode::Keypad3; - case GDK_KP_4: return Keyboard::Keycode::Keypad4; - case GDK_KP_5: return Keyboard::Keycode::Keypad5; - case GDK_KP_6: return Keyboard::Keycode::Keypad6; - case GDK_KP_7: return Keyboard::Keycode::Keypad7; - case GDK_KP_8: return Keyboard::Keycode::Keypad8; - case GDK_KP_9: return Keyboard::Keycode::Keypad9; - case GDK_KP_0: return Keyboard::Keycode::Keypad0; - - case GDK_KP_Home: return Keyboard::Keycode::KeypadHome; - case GDK_KP_End: return Keyboard::Keycode::KeypadEnd; - case GDK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case GDK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case GDK_KP_Up: return Keyboard::Keycode::KeypadUp; - case GDK_KP_Down: return Keyboard::Keycode::KeypadDown; - case GDK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case GDK_KP_Right: return Keyboard::Keycode::KeypadRight; - case GDK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case GDK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case GDK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/ananke/phoenix/gtk/widget/button.cpp b/ananke/phoenix/gtk/widget/button.cpp deleted file mode 100644 index 6f646a25..00000000 --- a/ananke/phoenix/gtk/widget/button.cpp +++ /dev/null @@ -1,53 +0,0 @@ -static void Button_activate(Button *self) { - if(self->onActivate) self->onActivate(); -} - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 24, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image); - gtk_button_set_image(GTK_BUTTON(gtkWidget), (GtkWidget*)gtkImage); - } else { - gtk_button_set_image(GTK_BUTTON(gtkWidget), nullptr); - } - switch(orientation) { - case Orientation::Horizontal: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_LEFT); break; - case Orientation::Vertical: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_TOP); break; - } -} - -void pButton::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); - setFont(widget.state.font); -} - -void pButton::constructor() { - gtkWidget = gtk_button_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_activate), (gpointer)&button); - - setText(button.state.text); -} - -void pButton::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/canvas.cpp b/ananke/phoenix/gtk/widget/canvas.cpp deleted file mode 100644 index 9d17dc82..00000000 --- a/ananke/phoenix/gtk/widget/canvas.cpp +++ /dev/null @@ -1,70 +0,0 @@ -static gboolean Canvas_expose(GtkWidget *widget, GdkEvent *event, pCanvas *self) { - cairo_t *context = gdk_cairo_create(gtk_widget_get_window(widget)); - cairo_set_source_surface(context, self->surface, 0, 0); - cairo_paint(context); - cairo_destroy(context); - return true; -} - -static gboolean Canvas_mouseLeave(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseLeave) self->canvas.onMouseLeave(); - return true; -} - -static gboolean Canvas_mouseMove(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseMove) self->canvas.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Canvas_mousePress(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMousePress) switch(event->button) { - case 1: self->canvas.onMousePress(Mouse::Button::Left); break; - case 2: self->canvas.onMousePress(Mouse::Button::Middle); break; - case 3: self->canvas.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Canvas_mouseRelease(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseRelease) switch(event->button) { - case 1: self->canvas.onMouseRelease(Mouse::Button::Left); break; - case 2: self->canvas.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->canvas.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -void pCanvas::setSize(const Size &size) { - cairo_surface_destroy(surface); - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); -} - -void pCanvas::update() { - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - if(gtk_widget_get_realized(gtkWidget) == false) return; - gdk_window_invalidate_rect(gtk_widget_get_window(gtkWidget), 0, true); -} - -void pCanvas::constructor() { - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - gtkWidget = gtk_drawing_area_new(); - gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Canvas_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Canvas_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Canvas_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Canvas_mouseMove), (gpointer)this); -} - -void pCanvas::destructor() { - gtk_widget_destroy(gtkWidget); - cairo_surface_destroy(surface); -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/check-box.cpp b/ananke/phoenix/gtk/widget/check-box.cpp deleted file mode 100644 index b6493f32..00000000 --- a/ananke/phoenix/gtk/widget/check-box.cpp +++ /dev/null @@ -1,40 +0,0 @@ -static void CheckBox_toggle(CheckBox *self) { - self->state.checked = self->checked(); - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, checkBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pCheckBox::constructor() { - gtkWidget = gtk_check_button_new_with_label(""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_toggle), (gpointer)&checkBox); - - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/combo-box.cpp b/ananke/phoenix/gtk/widget/combo-box.cpp deleted file mode 100644 index 648d587f..00000000 --- a/ananke/phoenix/gtk/widget/combo-box.cpp +++ /dev/null @@ -1,73 +0,0 @@ -static void ComboBox_change(ComboBox *self) { - if(self->p.locked == false) { - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -void pComboBox::append(const string &text) { - gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text); - if(itemCounter++ == 0) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &item : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(widget.state.font, item).width); - - Geometry geometry = pFont::geometry(widget.state.font, " "); - return { 0, 0, maximumWidth + 44, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkWidget), row, text); - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - if(position == row) gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), 0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(gtkWidget)))); - itemCounter = 0; - locked = false; -} - -unsigned pComboBox::selection() { - return gtk_combo_box_get_active(GTK_COMBO_BOX(gtkWidget)); -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), row); - locked = false; -} - -void pComboBox::constructor() { - itemCounter = 0; - gtkWidget = gtk_combo_box_new_text(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox); - - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(comboBox.state.selection); -} - -void pComboBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/hex-edit.cpp b/ananke/phoenix/gtk/widget/hex-edit.cpp deleted file mode 100644 index ec10cd7c..00000000 --- a/ananke/phoenix/gtk/widget/hex-edit.cpp +++ /dev/null @@ -1,268 +0,0 @@ -static bool HexEdit_keyPress(GtkWidget *widget, GdkEventKey *event, HexEdit *self) { - return self->p.keyPress(event->keyval); -} - -static bool HexEdit_scroll(GtkRange *range, GtkScrollType scroll, gdouble value, HexEdit *self) { - self->p.scroll((unsigned)value); - return false; -} - -bool pHexEdit::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pHexEdit::setColumns(unsigned columns) { - setScroll(); - update(); -} - -void pHexEdit::setLength(unsigned length) { - setScroll(); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - setScroll(); - updateScroll(); - update(); -} - -void pHexEdit::setRows(unsigned rows) { - setScroll(); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - gtk_text_buffer_set_text(textBuffer, "", -1); - return; - } - - unsigned position = cursorPosition(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - gtk_text_buffer_set_text(textBuffer, output, -1); - if(position == 0) position = 10; //start at first position where hex values can be entered - setCursorPosition(position); -} - -void pHexEdit::constructor() { - gtkWidget = gtk_hbox_new(false, 0); - - container = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(container), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(container), GTK_SHADOW_ETCHED_IN); - - subWidget = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), false); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_NONE); - gtk_container_add(GTK_CONTAINER(container), subWidget); - g_signal_connect(G_OBJECT(subWidget), "key-press-event", G_CALLBACK(HexEdit_keyPress), (gpointer)&hexEdit); - - scrollBar = gtk_vscrollbar_new((GtkAdjustment*)0); - gtk_range_set_range(GTK_RANGE(scrollBar), 0, 255); - gtk_range_set_increments(GTK_RANGE(scrollBar), 1, 16); - gtk_widget_set_sensitive(scrollBar, false); - g_signal_connect(G_OBJECT(scrollBar), "change-value", G_CALLBACK(HexEdit_scroll), (gpointer)&hexEdit); - - gtk_box_pack_start(GTK_BOX(gtkWidget), container, true, true, 0); - gtk_box_pack_start(GTK_BOX(gtkWidget), scrollBar, false, false, 1); - - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - textCursor = gtk_text_buffer_get_mark(textBuffer, "insert"); - - gtk_widget_show(scrollBar); - gtk_widget_show(subWidget); - gtk_widget_show(container); - - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - gtk_widget_destroy(scrollBar); - gtk_widget_destroy(subWidget); - gtk_widget_destroy(container); - gtk_widget_destroy(gtkWidget); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -unsigned pHexEdit::cursorPosition() { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - return gtk_text_iter_get_offset(&iter); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = cursorPosition(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - if(scancode == GDK_Home) { - setCursorPosition(cursorY * lineWidth + 10); - return true; - } - - if(scancode == GDK_End) { - setCursorPosition(cursorY * lineWidth + 10 + (hexEdit.state.columns * 3 - 1)); - return true; - } - - if(scancode == GDK_Up) { - if(cursorY != 0) return false; - - signed newOffset = hexEdit.state.offset - hexEdit.state.columns; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Down) { - if(cursorY != hexEdit.state.rows - 1) return false; - - signed newOffset = hexEdit.state.offset + hexEdit.state.columns; - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Page_Up) { - signed newOffset = hexEdit.state.offset - hexEdit.state.columns * hexEdit.state.rows; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - } else { - hexEdit.setOffset(0); - } - update(); - return true; - } - - if(scancode == GDK_Page_Down) { - signed newOffset = hexEdit.state.offset + hexEdit.state.columns * hexEdit.state.rows; - for(unsigned n = 0; n < hexEdit.state.rows; n++) { - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - break; - } - newOffset -= hexEdit.state.columns; - } - return true; - } - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; //not a valid hex value - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - setCursorPosition(position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} - -void pHexEdit::scroll(unsigned position) { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(position >= rows) position = rows - 1; - hexEdit.setOffset(position * hexEdit.state.columns); -} - -void pHexEdit::setCursorPosition(unsigned position) { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - - //GTK+ will throw many errors to the terminal if you set iterator past end of buffer - GtkTextIter endIter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - unsigned endPosition = gtk_text_iter_get_offset(&iter); - - gtk_text_iter_set_offset(&iter, min(position, endPosition)); - gtk_text_buffer_place_cursor(textBuffer, &iter); -} - -void pHexEdit::setScroll() { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(rows) rows--; - if(rows) { - gtk_range_set_range(GTK_RANGE(scrollBar), 0, rows); - gtk_widget_set_sensitive(scrollBar, true); - } else { - gtk_widget_set_sensitive(scrollBar, false); - } -} - -void pHexEdit::updateScroll() { - unsigned row = hexEdit.state.offset / hexEdit.state.columns; - gtk_range_set_value(GTK_RANGE(scrollBar), row); -} diff --git a/ananke/phoenix/gtk/widget/horizontal-scroll-bar.cpp b/ananke/phoenix/gtk/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 0d765e92..00000000 --- a/ananke/phoenix/gtk/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void HorizontalScrollBar_change(HorizontalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalScrollBar::constructor() { - gtkWidget = gtk_hscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar); - - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/horizontal-slider.cpp b/ananke/phoenix/gtk/widget/horizontal-slider.cpp deleted file mode 100644 index 2d19bae6..00000000 --- a/ananke/phoenix/gtk/widget/horizontal-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void HorizontalSlider_change(HorizontalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalSlider::constructor() { - gtkWidget = gtk_hscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider); - - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/label.cpp b/ananke/phoenix/gtk/widget/label.cpp deleted file mode 100644 index 8b5cec4f..00000000 --- a/ananke/phoenix/gtk/widget/label.cpp +++ /dev/null @@ -1,24 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - gtk_label_set_text(GTK_LABEL(gtkWidget), text); -} - -void pLabel::constructor() { - gtkWidget = gtk_label_new(""); - gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5); - - setText(label.state.text); -} - -void pLabel::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/line-edit.cpp b/ananke/phoenix/gtk/widget/line-edit.cpp deleted file mode 100644 index 8dbe9ef4..00000000 --- a/ananke/phoenix/gtk/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -static void LineEdit_activate(LineEdit *self) { - if(self->onActivate) self->onActivate(); -} - -static void LineEdit_change(LineEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, lineEdit.state.text); - return { 0, 0, geometry.width + 10, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - gtk_editable_set_editable(GTK_EDITABLE(gtkWidget), editable); -} - -void pLineEdit::setText(const string &text) { - locked = true; - gtk_entry_set_text(GTK_ENTRY(gtkWidget), text); - locked = false; -} - -string pLineEdit::text() { - return gtk_entry_get_text(GTK_ENTRY(gtkWidget)); -} - -void pLineEdit::constructor() { - gtkWidget = gtk_entry_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit); - - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/list-view.cpp b/ananke/phoenix/gtk/widget/list-view.cpp deleted file mode 100644 index 10e1d439..00000000 --- a/ananke/phoenix/gtk/widget/list-view.cpp +++ /dev/null @@ -1,221 +0,0 @@ -static void ListView_activate(ListView *self) { - if(self->onActivate) self->onActivate(); -} - -static void ListView_change(ListView *self) { - if(self->state.selected == false || self->state.selection != self->selection()) { - self->state.selected = true; - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -static void ListView_toggle(GtkCellRendererToggle *cell, gchar *path, ListView *self) { - unsigned row = decimal(path); - self->setChecked(row, !self->checked(row)); - if(self->onToggle) self->onToggle(row); -} - -void pListView::append(const lstring &text) { - GtkTreeIter iter; - gtk_list_store_append(store, &iter); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::autoSizeColumns() { - gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget)); -} - -bool pListView::checked(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - bool state; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return false; - gtk_tree_model_get(model, &iter, 0, &state, -1); - return state; -} - -bool pListView::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pListView::modify(unsigned row, const lstring &text) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::remove(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_remove(store, &iter); -} - -void pListView::reset() { - listView.state.selected = false; - listView.state.selection = 0; - gtk_list_store_clear(GTK_LIST_STORE(store)); - gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store)); - //reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty - gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); - gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); -} - -bool pListView::selected() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - return gtk_tree_selection_get_selected(selection, 0, 0); -} - -unsigned pListView::selection() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - if(gtk_tree_selection_get_selected(selection, 0, &iter) == false) return listView.state.selection; - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - unsigned row = decimal(path); - g_free(path); - return row; -} - -void pListView::setCheckable(bool checkable) { - gtk_cell_renderer_set_visible(column(0).checkbox, checkable); -} - -void pListView::setChecked(unsigned row, bool checked) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, checked, -1); -} - -void pListView::setHeaderText(const lstring &text) { - destructor(); - constructor(); -} - -void pListView::setHeaderVisible(bool visible) { - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - if(image.empty() == false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, true); - gtk_list_store_set(store, &iter, 1 + column * 2, pixbuf, -1); - } else { - gtk_list_store_set(store, &iter, 1 + column * 2, nullptr, -1); - } -} - -void pListView::setSelected(bool selected) { - if(selected == false) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - } else { - setSelection(listView.state.selection); - } -} - -void pListView::setSelection(unsigned row) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - GtkTreeIter iter; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return; - gtk_tree_selection_select_iter(selection, &iter); - - //scroll window to selected item - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - GtkTreePath *treePath = gtk_tree_path_new_from_string(path); - gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(subWidget), treePath, nullptr, true, 0.5, 0.0); - gtk_tree_path_free(treePath); - g_free(path); -} - -void pListView::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - - lstring headerText = listView.state.headerText; - if(headerText.size() == 0) headerText.append(""); //ListView must have at least one column - - column.reset(); - vector gtype; - for(auto &text : headerText) { - GtkColumn cell; - cell.label = gtk_label_new(text); - cell.column = gtk_tree_view_column_new(); - gtk_tree_view_column_set_resizable(cell.column, true); - gtk_tree_view_column_set_title(cell.column, ""); - - if(column.size() == 0) { //first column checkbox - cell.checkbox = gtk_cell_renderer_toggle_new(); - gtk_tree_view_column_pack_start(cell.column, cell.checkbox, false); - gtk_tree_view_column_set_attributes(cell.column, cell.checkbox, "active", gtype.size(), nullptr); - gtype.append(G_TYPE_BOOLEAN); - g_signal_connect(cell.checkbox, "toggled", G_CALLBACK(ListView_toggle), (gpointer)&listView); - } - - cell.icon = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(cell.column, cell.icon, false); - gtk_tree_view_column_set_attributes(cell.column, cell.icon, "pixbuf", gtype.size(), nullptr); - gtype.append(GDK_TYPE_PIXBUF); - - cell.text = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(cell.column, cell.text, false); - gtk_tree_view_column_set_attributes(cell.column, cell.text, "text", gtype.size(), nullptr); - gtype.append(G_TYPE_STRING); - - column.append(cell); - } - - store = gtk_list_store_newv(gtype.size(), gtype.data()); - subWidget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - g_object_unref(G_OBJECT(store)); - - for(auto &cell : column) { - gtk_tree_view_column_set_widget(GTK_TREE_VIEW_COLUMN(cell.column), cell.label); - gtk_tree_view_append_column(GTK_TREE_VIEW(subWidget), cell.column); - gtk_widget_show(cell.label); - } - - gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(subWidget), headerText.size() >= 2); //two or more columns + checkbox column - gtk_tree_view_set_search_column(GTK_TREE_VIEW(subWidget), 2); - - g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView); - g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView); - - gtk_widget_show(subWidget); - - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setFocused() { - gtk_widget_grab_focus(subWidget); -} - -void pListView::setFont(const string &font) { - pFont::setFont(gtkWidget, font); - for(auto &cell : column) pFont::setFont(cell.label, font); -} diff --git a/ananke/phoenix/gtk/widget/progress-bar.cpp b/ananke/phoenix/gtk/widget/progress-bar.cpp deleted file mode 100644 index 972170b8..00000000 --- a/ananke/phoenix/gtk/widget/progress-bar.cpp +++ /dev/null @@ -1,23 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - position = position <= 100 ? position : 0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (double)position / 100.0); -} - -void pProgressBar::constructor() { - gtkWidget = gtk_progress_bar_new(); - - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/radio-box.cpp b/ananke/phoenix/gtk/widget/radio-box.cpp deleted file mode 100644 index 36aff3fa..00000000 --- a/ananke/phoenix/gtk/widget/radio-box.cpp +++ /dev/null @@ -1,50 +0,0 @@ -static void RadioBox_activate(RadioBox *self) { - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, radioBox.state.text); -//Font &font = pWidget::font(); -//Geometry geometry = font.geometry(radioBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), true); - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(group[0].p.gtkWidget)); - if(currentGroup != gtk_radio_button_get_group(GTK_RADIO_BUTTON(gtkWidget))) { - gtk_radio_button_set_group(GTK_RADIO_BUTTON(gtkWidget), currentGroup); - } - } -} - -void pRadioBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pRadioBox::constructor() { - gtkWidget = gtk_radio_button_new_with_label(0, ""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_activate), (gpointer)&radioBox); - - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/text-edit.cpp b/ananke/phoenix/gtk/widget/text-edit.cpp deleted file mode 100644 index 2d2b740b..00000000 --- a/ananke/phoenix/gtk/widget/text-edit.cpp +++ /dev/null @@ -1,70 +0,0 @@ -static void TextEdit_change(TextEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -bool pTextEdit::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pTextEdit::setCursorPosition(unsigned position) { - GtkTextMark *mark = gtk_text_buffer_get_mark(textBuffer, "insert"); - GtkTextIter iter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter))); - gtk_text_buffer_place_cursor(textBuffer, &iter); - gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(subWidget), mark); -} - -void pTextEdit::setEditable(bool editable) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable); -} - -void pTextEdit::setText(const string &text) { - locked = true; - gtk_text_buffer_set_text(textBuffer, text, -1); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), - wordWrap ? GTK_POLICY_NEVER : GTK_POLICY_ALWAYS, - GTK_POLICY_ALWAYS); -} - -string pTextEdit::text() { - GtkTextIter start, end; - gtk_text_buffer_get_start_iter(textBuffer, &start); - gtk_text_buffer_get_end_iter(textBuffer, &end); - char *temp = gtk_text_buffer_get_text(textBuffer, &start, &end, true); - string text = temp; - g_free(temp); - return text; -} - -void pTextEdit::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - subWidget = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_WORD_CHAR); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit); - gtk_widget_show(subWidget); - - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/vertical-scroll-bar.cpp b/ananke/phoenix/gtk/widget/vertical-scroll-bar.cpp deleted file mode 100644 index e3bde589..00000000 --- a/ananke/phoenix/gtk/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void VerticalScrollBar_change(VerticalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pVerticalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalScrollBar::constructor() { - gtkWidget = gtk_vscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalScrollBar_change), (gpointer)&verticalScrollBar); - - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/vertical-slider.cpp b/ananke/phoenix/gtk/widget/vertical-slider.cpp deleted file mode 100644 index 3c68489e..00000000 --- a/ananke/phoenix/gtk/widget/vertical-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void VerticalSlider_change(VerticalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalSlider::constructor() { - gtkWidget = gtk_vscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider); - - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/viewport.cpp b/ananke/phoenix/gtk/widget/viewport.cpp deleted file mode 100644 index e842a2e5..00000000 --- a/ananke/phoenix/gtk/widget/viewport.cpp +++ /dev/null @@ -1,58 +0,0 @@ -static gboolean Viewport_mouseLeave(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseLeave) self->viewport.onMouseLeave(); - return true; -} - -static gboolean Viewport_mouseMove(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseMove) self->viewport.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Viewport_mousePress(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMousePress) switch(event->button) { - case 1: self->viewport.onMousePress(Mouse::Button::Left); break; - case 2: self->viewport.onMousePress(Mouse::Button::Middle); break; - case 3: self->viewport.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Viewport_mouseRelease(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseRelease) switch(event->button) { - case 1: self->viewport.onMouseRelease(Mouse::Button::Left); break; - case 2: self->viewport.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->viewport.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -uintptr_t pViewport::handle() { - return GDK_WINDOW_XID(gtk_widget_get_window(gtkWidget)); -} - -void pViewport::constructor() { - gtkWidget = gtk_drawing_area_new(); -//gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Viewport_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Viewport_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Viewport_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Viewport_mouseMove), (gpointer)this); - - GdkColor color; - color.pixel = 0; - color.red = 0; - color.green = 0; - color.blue = 0; - gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color); -} - -void pViewport::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/widget/widget.cpp b/ananke/phoenix/gtk/widget/widget.cpp deleted file mode 100644 index aa4eacfa..00000000 --- a/ananke/phoenix/gtk/widget/widget.cpp +++ /dev/null @@ -1,51 +0,0 @@ -bool pWidget::enabled() { - return gtk_widget_get_sensitive(gtkWidget); -} - -bool pWidget::focused() { - return GTK_WIDGET_HAS_FOCUS(gtkWidget); -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - gtk_widget_set_sensitive(gtkWidget, enabled); -} - -void pWidget::setFocused() { - gtk_widget_grab_focus(gtkWidget); -} - -void pWidget::setFont(const string &font) { - pFont::setFont(gtkWidget, font); -} - -void pWidget::setGeometry(const Geometry &geometry) { - if(sizable.window() && sizable.window()->visible()) gtk_fixed_move(GTK_FIXED(sizable.window()->p.formContainer), gtkWidget, geometry.x, geometry.y); - unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width; - unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height; - gtk_widget_set_size_request(gtkWidget, width, height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - gtk_widget_set_visible(gtkWidget, visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) gtkWidget = gtk_label_new(""); -} - -void pWidget::destructor() { - if(widget.state.abstract) gtk_widget_destroy(gtkWidget); -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/gtk/window.cpp b/ananke/phoenix/gtk/window.cpp deleted file mode 100644 index 4518c38a..00000000 --- a/ananke/phoenix/gtk/window.cpp +++ /dev/null @@ -1,362 +0,0 @@ -static gint Window_close(GtkWidget *widget, GdkEvent *event, Window *window) { - window->state.ignore = false; - if(window->onClose) window->onClose(); - if(window->state.ignore == false) window->setVisible(false); - return true; -} - -static gboolean Window_expose(GtkWidget *widget, GdkEvent *event, Window *window) { - if(window->state.backgroundColorOverride == false) return false; - cairo_t *context = gdk_cairo_create(widget->window); - - Color color = window->backgroundColor(); - double red = (double)color.red / 255.0; - double green = (double)color.green / 255.0; - double blue = (double)color.blue / 255.0; - double alpha = (double)color.alpha / 255.0; - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - cairo_set_source_rgba(context, red, green, blue, alpha); - } else { - cairo_set_source_rgb(context, red, green, blue); - } - - cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); - cairo_paint(context); - cairo_destroy(context); - - return false; -} - -static gboolean Window_configure(GtkWidget *widget, GdkEvent *event, Window *window) { - if(gtk_widget_get_realized(window->p.widget) == false) return false; - if(window->visible() == false) return false; - GdkWindow *gdkWindow = gtk_widget_get_window(widget); - - GdkRectangle border, client; - gdk_window_get_frame_extents(gdkWindow, &border); - gdk_window_get_geometry(gdkWindow, 0, 0, &client.width, &client.height, 0); - gdk_window_get_origin(gdkWindow, &client.x, &client.y); - - if(window->state.fullScreen == false) { - //update geometry settings - settings->frameGeometryX = client.x - border.x; - settings->frameGeometryY = client.y - border.y; - settings->frameGeometryWidth = border.width - client.width; - settings->frameGeometryHeight = border.height - client.height; - if(window->state.backgroundColorOverride == false) { - GdkColor color = widget->style->bg[GTK_STATE_NORMAL]; - settings->windowBackgroundColor - = ((uint8_t)(color.red >> 8) << 16) - + ((uint8_t)(color.green >> 8) << 8) - + ((uint8_t)(color.blue >> 8) << 0); - } - settings->save(); - } - - Geometry geometry = { - client.x, - client.y + window->p.menuHeight(), - client.width, - client.height - window->p.menuHeight() - window->p.statusHeight() - }; - - //move - if(geometry.x != window->state.geometry.x || geometry.y != window->state.geometry.y) { - if(window->state.fullScreen == false) { - window->state.geometry.x = geometry.x; - window->state.geometry.y = geometry.y; - } - if(window->p.locked == false && window->onMove) window->onMove(); - } - - //size - if(geometry.width != window->state.geometry.width || geometry.height != window->state.geometry.height) { - window->p.onSizePending = true; - } - - return false; -} - -static gboolean Window_keyPressEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyPress) window->onKeyPress(key); - return false; -} - -static gboolean Window_keyReleaseEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyRelease) window->onKeyRelease(key); - return false; -} - -static void Window_sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, Window *window) { - //size-allocate sent from gtk_fixed_move(); detect if layout unchanged and return - if(allocation->width == window->p.lastAllocation.width - && allocation->height == window->p.lastAllocation.height) return; - - window->state.geometry.width = allocation->width; - window->state.geometry.height = allocation->height; - - for(auto &layout : window->state.layout) { - Geometry geometry = window->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(window->p.onSizePending && window->p.locked == false && window->onSize) { - window->p.onSizePending = false; - window->onSize(); - } - - window->p.lastAllocation = *allocation; -} - -static void Window_sizeRequest(GtkWidget *widget, GtkRequisition *requisition, Window *window) { - requisition->width = window->state.geometry.width; - requisition->height = window->state.geometry.height; -} - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = this->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), menu.p.widget); - gtk_widget_show(menu.p.widget); -} - -void pWindow::append(Widget &widget) { - ((Sizable&)widget).state.window = &window; - gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - return { - (uint8_t)(settings->windowBackgroundColor >> 16), - (uint8_t)(settings->windowBackgroundColor >> 8), - (uint8_t)(settings->windowBackgroundColor >> 0), - 255 - }; -} - -Geometry pWindow::frameMargin() { - if(window.state.fullScreen) return { - 0, - menuHeight(), - 0, - menuHeight() + statusHeight() - }; - - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight(), - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight() + statusHeight() - }; -} - -bool pWindow::focused() { - return gtk_window_is_active(GTK_WINDOW(widget)); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen == true) return { - 0, - menuHeight(), - Desktop::size().width, - Desktop::size().height - menuHeight() - statusHeight() - }; - - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - menu.p.orphan(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - GdkColor gdkColor; - gdkColor.pixel = (color.red << 16) | (color.green << 8) | (color.blue << 0); - gdkColor.red = (color.red << 8) | (color.red << 0); - gdkColor.green = (color.green << 8) | (color.green << 0); - gdkColor.blue = (color.blue << 8) | (color.blue << 0); - gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &gdkColor); -} - -void pWindow::setFocused() { - gtk_window_present(GTK_WINDOW(widget)); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - gtk_window_unfullscreen(GTK_WINDOW(widget)); - } else { - gtk_window_fullscreen(GTK_WINDOW(widget)); - } -} - -void pWindow::setGeometry(const Geometry &geometry) { - Geometry margin = frameMargin(); - gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y); - - GdkGeometry geom; - geom.min_width = window.state.resizable ? 1 : window.state.geometry.width; - geom.min_height = window.state.resizable ? 1 : window.state.geometry.height; - gtk_window_set_geometry_hints(GTK_WINDOW(widget), GTK_WIDGET(widget), &geom, GDK_HINT_MIN_SIZE); - -//gtk_window_set_policy(GTK_WINDOW(widget), true, true, false); - gtk_widget_set_size_request(formContainer, geometry.width, geometry.height); - gtk_window_resize(GTK_WINDOW(widget), geometry.width, geometry.height + menuHeight() + statusHeight()); -} - -void pWindow::setMenuFont(const string &font) { - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - gtk_widget_set_visible(menu, visible); -} - -void pWindow::setModal(bool modal) { - gtk_window_set_modal(GTK_WINDOW(widget), modal); -} - -void pWindow::setResizable(bool resizable) { - gtk_window_set_resizable(GTK_WINDOW(widget), resizable); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable); -} - -void pWindow::setStatusFont(const string &font) { - pFont::setFont(status, font); -} - -void pWindow::setStatusText(const string &text) { - gtk_statusbar_pop(GTK_STATUSBAR(status), 1); - gtk_statusbar_push(GTK_STATUSBAR(status), 1, text); -} - -void pWindow::setStatusVisible(bool visible) { - gtk_widget_set_visible(status, visible); -} - -void pWindow::setTitle(const string &text) { - gtk_window_set_title(GTK_WINDOW(widget), text); -} - -void pWindow::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); - if(visible) { - if(gtk_widget_get_visible(menu)) { - GtkAllocation allocation; - gtk_widget_get_allocation(menu, &allocation); - settings->menuGeometryHeight = allocation.height; - } - - if(gtk_widget_get_visible(status)) { - GtkAllocation allocation; - gtk_widget_get_allocation(status, &allocation); - settings->statusGeometryHeight = allocation.height; - } - } -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(item.state.font == "") item.setFont(font); - } -} - -void pWindow::constructor() { - lastAllocation.width = 0; - lastAllocation.height = 0; - onSizePending = false; - - widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - //if program was given a name, try and set the window taskbar icon from one of the pixmaps folders - if(osState.name.empty() == false) { - if(file::exists({"/usr/share/pixmaps/", osState.name, ".png"})) { - gtk_window_set_icon_from_file(GTK_WINDOW(widget), string{"/usr/share/pixmaps/", osState.name, ".png"}, nullptr); - } else if(file::exists({"/usr/local/share/pixmaps/", osState.name, ".png"})) { - gtk_window_set_icon_from_file(GTK_WINDOW(widget), string{"/usr/local/share/pixmaps/", osState.name, ".png"}, nullptr); - } - } - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - gtk_widget_set_colormap(widget, gdk_screen_get_rgba_colormap(gdk_screen_get_default())); - } else { - gtk_widget_set_colormap(widget, gdk_screen_get_rgb_colormap(gdk_screen_get_default())); - } - - gtk_window_set_resizable(GTK_WINDOW(widget), true); - #if GTK_MAJOR_VERSION >= 3 - gtk_window_set_has_resize_grip(GTK_WINDOW(widget), false); - #endif - - gtk_widget_set_app_paintable(widget, true); - gtk_widget_add_events(widget, GDK_CONFIGURE); - - menuContainer = gtk_vbox_new(false, 0); - gtk_container_add(GTK_CONTAINER(widget), menuContainer); - gtk_widget_show(menuContainer); - - menu = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), menu, false, false, 0); - - formContainer = gtk_fixed_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), formContainer, true, true, 0); - gtk_widget_show(formContainer); - - statusContainer = gtk_event_box_new(); - status = gtk_statusbar_new(); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), true); - gtk_container_add(GTK_CONTAINER(statusContainer), status); - gtk_box_pack_start(GTK_BOX(menuContainer), statusContainer, false, false, 0); - gtk_widget_show(statusContainer); - - setTitle(""); - setResizable(window.state.resizable); - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); - - g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "expose-event", G_CALLBACK(Window_expose), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - - g_signal_connect(G_OBJECT(formContainer), "size-allocate", G_CALLBACK(Window_sizeAllocate), (gpointer)&window); - g_signal_connect(G_OBJECT(formContainer), "size-request", G_CALLBACK(Window_sizeRequest), (gpointer)&window); -} - -unsigned pWindow::menuHeight() { - return window.state.menuVisible ? settings->menuGeometryHeight : 0; -} - -unsigned pWindow::statusHeight() { - return window.state.statusVisible ? settings->statusGeometryHeight : 0; -} diff --git a/ananke/phoenix/phoenix.cpp b/ananke/phoenix/phoenix.cpp deleted file mode 100644 index eaa66b97..00000000 --- a/ananke/phoenix/phoenix.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef PHOENIX_CPP -#define PHOENIX_CPP - -#if defined(PHOENIX_WINDOWS) - #define UNICODE - #define WINVER 0x0501 - #define _WIN32_WINNT 0x0501 - #define _WIN32_IE 0x0600 - #define __MSVCRT_VERSION__ 0x0601 - #define NOMINMAX - - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_QT) - #include - #include - #include - #define XK_MISCELLANY - #define XK_LATIN1 - #include - #include - #undef XK_MISCELLANY - #undef XK_LATIN1 - #include -#elif defined(PHOENIX_GTK) - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_REFERENCE) -#else - #error "phoenix: unrecognized target" -#endif - -#include "phoenix.hpp" -using namespace nall; - -namespace phoenix { - #include "core/core.cpp" -} - -#endif diff --git a/ananke/phoenix/phoenix.hpp b/ananke/phoenix/phoenix.hpp deleted file mode 100644 index 8a6129c4..00000000 --- a/ananke/phoenix/phoenix.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PHOENIX_HPP -#define PHOENIX_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace phoenix { - #include "core/core.hpp" -} - -#endif diff --git a/ananke/phoenix/qt/action/action.cpp b/ananke/phoenix/qt/action/action.cpp deleted file mode 100644 index 62efaa2a..00000000 --- a/ananke/phoenix/qt/action/action.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setEnabled(enabled); - } -} - -void pAction::setFont(const string &font) { - QFont qtFont = pFont::create(font); - - if(dynamic_cast(&action)) { - ((Menu&)action).p.setFont(font); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setFont(qtFont); - } -} - -void pAction::setVisible(bool visible) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->menuAction()->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setVisible(visible); - } -} - -void pAction::constructor() { -} - -void pAction::destructor() { -} diff --git a/ananke/phoenix/qt/action/check-item.cpp b/ananke/phoenix/qt/action/check-item.cpp deleted file mode 100644 index ef451e73..00000000 --- a/ananke/phoenix/qt/action/check-item.cpp +++ /dev/null @@ -1,27 +0,0 @@ -bool pCheckItem::checked() { - return qtAction->isChecked(); -} - -void pCheckItem::setChecked(bool checked) { - qtAction->setChecked(checked); -} - -void pCheckItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pCheckItem::constructor() { - qtAction = new QAction(0); - qtAction->setCheckable(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onToggle())); -} - -void pCheckItem::destructor() { - if(action.state.menu) action.state.menu->remove(checkItem); - delete qtAction; -} - -void pCheckItem::onToggle() { - checkItem.state.checked = checked(); - if(checkItem.onToggle) checkItem.onToggle(); -} diff --git a/ananke/phoenix/qt/action/item.cpp b/ananke/phoenix/qt/action/item.cpp deleted file mode 100644 index 7f142289..00000000 --- a/ananke/phoenix/qt/action/item.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pItem::setImage(const image &image) { - qtAction->setIcon(CreateIcon(image)); -} - -void pItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pItem::constructor() { - qtAction = new QAction(0); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pItem::destructor() { - if(action.state.menu) action.state.menu->remove(item); - delete qtAction; -} - -void pItem::onActivate() { - if(item.onActivate) item.onActivate(); -} diff --git a/ananke/phoenix/qt/action/menu.cpp b/ananke/phoenix/qt/action/menu.cpp deleted file mode 100644 index 43d89a1e..00000000 --- a/ananke/phoenix/qt/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - if(dynamic_cast(&action)) { - qtMenu->addMenu(((Menu&)action).p.qtMenu); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((RadioItem&)action).p.qtAction); - } -} - -void pMenu::remove(Action &action) { - if(dynamic_cast(&action)) { - //QMenu::removeMenu() does not exist - qtMenu->clear(); - for(auto &action : menu.state.action) append(action); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } -} - -void pMenu::setFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : menu.state.action) item.p.setFont(font); -} - -void pMenu::setImage(const image &image) { - qtMenu->setIcon(CreateIcon(image)); -} - -void pMenu::setText(const string &text) { - qtMenu->setTitle(QString::fromUtf8(text)); -} - -void pMenu::constructor() { - qtMenu = new QMenu; -} - -void pMenu::destructor() { - if(action.state.menu) action.state.menu->remove(menu); - delete qtMenu; -} diff --git a/ananke/phoenix/qt/action/radio-item.cpp b/ananke/phoenix/qt/action/radio-item.cpp deleted file mode 100644 index 66cf6c6a..00000000 --- a/ananke/phoenix/qt/action/radio-item.cpp +++ /dev/null @@ -1,41 +0,0 @@ -bool pRadioItem::checked() { - return qtAction->isChecked(); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) { - bool checkState = item.p.qtAction == qtAction; - item.state.checked = checkState; - item.p.qtAction->setChecked(checkState); - } - locked = false; -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pRadioItem::constructor() { - qtAction = new QAction(0); - qtGroup = new QActionGroup(0); - qtAction->setCheckable(true); - qtAction->setActionGroup(qtGroup); - qtAction->setChecked(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pRadioItem::destructor() { - if(action.state.menu) action.state.menu->remove(radioItem); - delete qtAction; -} - -void pRadioItem::onActivate() { - if(radioItem.state.checked == false) { - setChecked(); - if(locked == false && radioItem.onActivate) radioItem.onActivate(); - } -} diff --git a/ananke/phoenix/qt/action/separator.cpp b/ananke/phoenix/qt/action/separator.cpp deleted file mode 100644 index 95e66b6c..00000000 --- a/ananke/phoenix/qt/action/separator.cpp +++ /dev/null @@ -1,9 +0,0 @@ -void pSeparator::constructor() { - qtAction = new QAction(0); - qtAction->setSeparator(true); -} - -void pSeparator::destructor() { - if(action.state.menu) action.state.menu->remove(separator); - delete qtAction; -} diff --git a/ananke/phoenix/qt/desktop.cpp b/ananke/phoenix/qt/desktop.cpp deleted file mode 100644 index 554106b5..00000000 --- a/ananke/phoenix/qt/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - QRect rect = QApplication::desktop()->screenGeometry(); - return { rect.width(), rect.height() }; -} - -Geometry pDesktop::workspace() { - QRect rect = QApplication::desktop()->availableGeometry(); - return { rect.x(), rect.y(), rect.width(), rect.height() }; -} diff --git a/ananke/phoenix/qt/dialog-window.cpp b/ananke/phoenix/qt/dialog-window.cpp deleted file mode 100644 index 680a6e2e..00000000 --- a/ananke/phoenix/qt/dialog-window.cpp +++ /dev/null @@ -1,57 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getOpenFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Open File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getSaveFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Save File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - QString directory = QFileDialog::getExistingDirectory( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Select Directory", - QString::fromUtf8(path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks - ); - string name = directory.toUtf8().constData(); - if(name != "" && name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/ananke/phoenix/qt/font.cpp b/ananke/phoenix/qt/font.cpp deleted file mode 100644 index bb3261cd..00000000 --- a/ananke/phoenix/qt/font.cpp +++ /dev/null @@ -1,40 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return pFont::geometry(pFont::create(description), text); -} - -QFont pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - QFont qtFont; - qtFont.setFamily(family); - qtFont.setPointSize(size); - if(bold) qtFont.setBold(true); - if(italic) qtFont.setItalic(true); - return qtFont; -} - -Geometry pFont::geometry(const QFont &qtFont, const string &text) { - QFontMetrics metrics(qtFont); - - lstring lines; - lines.split("\n", text); - - unsigned maxWidth = 0; - for(auto &line : lines) { - maxWidth = max(maxWidth, metrics.width(line)); - } - - return { 0, 0, maxWidth, metrics.height() * lines.size() }; -} diff --git a/ananke/phoenix/qt/keyboard.cpp b/ananke/phoenix/qt/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/ananke/phoenix/qt/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/ananke/phoenix/qt/message-window.cpp b/ananke/phoenix/qt/message-window.cpp deleted file mode 100644 index 7bceba0f..00000000 --- a/ananke/phoenix/qt/message-window.cpp +++ /dev/null @@ -1,47 +0,0 @@ -static QMessageBox::StandardButtons MessageWindow_buttons(MessageWindow::Buttons buttons) { - QMessageBox::StandardButtons standardButtons = QMessageBox::NoButton; - if(buttons == MessageWindow::Buttons::Ok) standardButtons = QMessageBox::Ok; - if(buttons == MessageWindow::Buttons::OkCancel) standardButtons = QMessageBox::Ok | QMessageBox::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) standardButtons = QMessageBox::Yes | QMessageBox::No; - return standardButtons; -} - -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, QMessageBox::StandardButton response) { - if(response == QMessageBox::Ok) return MessageWindow::Response::Ok; - if(response == QMessageBox::Cancel) return MessageWindow::Response::Cancel; - if(response == QMessageBox::Yes) return MessageWindow::Response::Yes; - if(response == QMessageBox::No) return MessageWindow::Response::No; - - //MessageWindow was closed via window manager, rather than by a button; assume a cancel/no response - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::information(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::question(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::warning(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::critical(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} diff --git a/ananke/phoenix/qt/mouse.cpp b/ananke/phoenix/qt/mouse.cpp deleted file mode 100644 index 4ea06cc9..00000000 --- a/ananke/phoenix/qt/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - QPoint point = QCursor::pos(); - return { point.x(), point.y() }; -} - -bool pMouse::pressed(Mouse::Button button) { - Qt::MouseButtons buttons = QApplication::mouseButtons(); - switch(button) { - case Mouse::Button::Left: return buttons & Qt::LeftButton; - case Mouse::Button::Middle: return buttons & Qt::MidButton; - case Mouse::Button::Right: return buttons & Qt::RightButton; - } - return false; -} diff --git a/ananke/phoenix/qt/platform.cpp b/ananke/phoenix/qt/platform.cpp deleted file mode 100644 index 86f659c8..00000000 --- a/ananke/phoenix/qt/platform.cpp +++ /dev/null @@ -1,91 +0,0 @@ -//Qt 4.8.0 and earlier improperly define the QLOCATION macro -//in C++11, it is detected as a malformed user-defined literal -//below is a workaround to fix compilation errors caused by this -#undef QLOCATION -#define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__) - -#include "platform.moc.hpp" -#include "platform.moc" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; - -void pOS::main() { - QApplication::exec(); -} - -bool pOS::pendingEvents() { - return QApplication::hasPendingEvents(); -} - -void pOS::processEvents() { - while(pendingEvents()) QApplication::processEvents(); -} - -void pOS::quit() { - QApplication::quit(); - //note: QApplication cannot be deleted; or libQtGui will crash - qtApplication = 0; -} - -void pOS::syncX() { - for(unsigned n = 0; n < 8; n++) { - QApplication::syncX(); - OS::processEvents(); - usleep(2000); - } -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - static int argc = 1; - static char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - - qtApplication = new QApplication(argc, argvp); - - pKeyboard::initialize(); -} diff --git a/ananke/phoenix/qt/platform.moc b/ananke/phoenix/qt/platform.moc deleted file mode 100644 index 2a53a326..00000000 --- a/ananke/phoenix/qt/platform.moc +++ /dev/null @@ -1,1105 +0,0 @@ -/**************************************************************************** -** Meta object code from reading C++ file 'platform.moc.hpp' -** -** Created: Wed Dec 26 00:12:14 2012 -** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - -#if !defined(Q_MOC_OUTPUT_REVISION) -#error "The header file 'platform.moc.hpp' doesn't include ." -#elif Q_MOC_OUTPUT_REVISION != 62 -#error "This file was generated using the moc from 4.6.3. It" -#error "cannot be used with the include files from this version of Qt." -#error "(The moc has changed too much.)" -#endif - -QT_BEGIN_MOC_NAMESPACE -static const uint qt_meta_data_pTimer[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 8, 7, 7, 7, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTimer[] = { - "pTimer\0\0onTimeout()\0" -}; - -const QMetaObject pTimer::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTimer, - qt_meta_data_pTimer, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTimer::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTimer::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTimer::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTimer)) - return static_cast(const_cast< pTimer*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pTimer*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTimer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onTimeout(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pWindow[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pWindow[] = { - "pWindow\0" -}; - -const QMetaObject pWindow::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pWindow, - qt_meta_data_pWindow, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pWindow::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pWindow::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pWindow::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pWindow)) - return static_cast(const_cast< pWindow*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pWindow*>(this)); - return QObject::qt_metacast(_clname); -} - -int pWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 7, 6, 6, 6, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pItem[] = { - "pItem\0\0onActivate()\0" -}; - -const QMetaObject pItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pItem, - qt_meta_data_pItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pItem)) - return static_cast(const_cast< pItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCheckItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckItem[] = { - "pCheckItem\0\0onToggle()\0" -}; - -const QMetaObject pCheckItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckItem, - qt_meta_data_pCheckItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckItem)) - return static_cast(const_cast< pCheckItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pCheckItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pRadioItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioItem[] = { - "pRadioItem\0\0onActivate()\0" -}; - -const QMetaObject pRadioItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioItem, - qt_meta_data_pRadioItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioItem)) - return static_cast(const_cast< pRadioItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pRadioItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pButton[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 9, 8, 8, 8, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pButton[] = { - "pButton\0\0onActivate()\0" -}; - -const QMetaObject pButton::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pButton, - qt_meta_data_pButton, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pButton::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pButton::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pButton::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pButton)) - return static_cast(const_cast< pButton*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pButton*>(this)); - return QObject::qt_metacast(_clname); -} - -int pButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCanvas[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pCanvas[] = { - "pCanvas\0" -}; - -const QMetaObject pCanvas::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCanvas, - qt_meta_data_pCanvas, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCanvas::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCanvas::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCanvas::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCanvas)) - return static_cast(const_cast< pCanvas*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCanvas*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCanvas::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pCheckBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckBox[] = { - "pCheckBox\0\0onToggle()\0" -}; - -const QMetaObject pCheckBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckBox, - qt_meta_data_pCheckBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckBox)) - return static_cast(const_cast< pCheckBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCheckBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pComboBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pComboBox[] = { - "pComboBox\0\0onChange()\0" -}; - -const QMetaObject pComboBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pComboBox, - qt_meta_data_pComboBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pComboBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pComboBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pComboBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pComboBox)) - return static_cast(const_cast< pComboBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pComboBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHexEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 10, 9, 9, 9, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHexEdit[] = { - "pHexEdit\0\0onScroll()\0" -}; - -const QMetaObject pHexEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHexEdit, - qt_meta_data_pHexEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHexEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHexEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHexEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHexEdit)) - return static_cast(const_cast< pHexEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHexEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHexEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onScroll(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 22, 21, 21, 21, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalScrollBar[] = { - "pHorizontalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pHorizontalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalScrollBar, - qt_meta_data_pHorizontalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalScrollBar)) - return static_cast(const_cast< pHorizontalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 19, 18, 18, 18, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalSlider[] = { - "pHorizontalSlider\0\0onChange()\0" -}; - -const QMetaObject pHorizontalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalSlider, - qt_meta_data_pHorizontalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalSlider)) - return static_cast(const_cast< pHorizontalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pLineEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 2, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 24, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pLineEdit[] = { - "pLineEdit\0\0onActivate()\0onChange()\0" -}; - -const QMetaObject pLineEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pLineEdit, - qt_meta_data_pLineEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pLineEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pLineEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pLineEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pLineEdit)) - return static_cast(const_cast< pLineEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pLineEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange(); break; - default: ; - } - _id -= 2; - } - return _id; -} -static const uint qt_meta_data_pListView[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 3, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 29, 24, 10, 10, 0x0a, - 56, 24, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pListView[] = { - "pListView\0\0onActivate()\0item\0" - "onChange(QTreeWidgetItem*)\0" - "onToggle(QTreeWidgetItem*)\0" -}; - -const QMetaObject pListView::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pListView, - qt_meta_data_pListView, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pListView::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pListView::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pListView::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pListView)) - return static_cast(const_cast< pListView*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pListView*>(this)); - return QObject::qt_metacast(_clname); -} - -int pListView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - case 2: onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - default: ; - } - _id -= 3; - } - return _id; -} -static const uint qt_meta_data_pRadioBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioBox[] = { - "pRadioBox\0\0onActivate()\0" -}; - -const QMetaObject pRadioBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioBox, - qt_meta_data_pRadioBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioBox)) - return static_cast(const_cast< pRadioBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pRadioBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pTextEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTextEdit[] = { - "pTextEdit\0\0onChange()\0" -}; - -const QMetaObject pTextEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTextEdit, - qt_meta_data_pTextEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTextEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTextEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTextEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTextEdit)) - return static_cast(const_cast< pTextEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pTextEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTextEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 20, 19, 19, 19, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalScrollBar[] = { - "pVerticalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pVerticalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalScrollBar, - qt_meta_data_pVerticalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalScrollBar)) - return static_cast(const_cast< pVerticalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 17, 16, 16, 16, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalSlider[] = { - "pVerticalSlider\0\0onChange()\0" -}; - -const QMetaObject pVerticalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalSlider, - qt_meta_data_pVerticalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalSlider)) - return static_cast(const_cast< pVerticalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -QT_END_MOC_NAMESPACE diff --git a/ananke/phoenix/qt/platform.moc.hpp b/ananke/phoenix/qt/platform.moc.hpp deleted file mode 100644 index 6a3909bf..00000000 --- a/ananke/phoenix/qt/platform.moc.hpp +++ /dev/null @@ -1,634 +0,0 @@ -static QApplication *qtApplication = nullptr; - -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static QFont create(const string &description); - static Geometry geometry(const QFont &qtFont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); - static void syncX(); -}; - -struct pTimer : public QObject, public pObject { - Q_OBJECT - -public: - Timer &timer; - QTimer *qtTimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); - void destructor(); - -public slots: - void onTimeout(); -}; - -struct pWindow : public QObject, public pObject { - Q_OBJECT - -public: - Window &window; - struct QtWindow : public QWidget { - pWindow &self; - void closeEvent(QCloseEvent*); - void keyPressEvent(QKeyEvent*); - void keyReleaseEvent(QKeyEvent*); - void moveEvent(QMoveEvent*); - void resizeEvent(QResizeEvent*); - QSize sizeHint() const; - QtWindow(pWindow &self) : self(self) {} - } *qtWindow; - QVBoxLayout *qtLayout; - QMenuBar *qtMenu; - QStatusBar *qtStatus; - QWidget *qtContainer; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - Geometry frameMargin(); - bool focused(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateFrameGeometry(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setFont(const string &font); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - void destructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - QMenu *qtMenu; - - void append(Action &action); - void remove(Action &action); - void setFont(const string &font); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - QAction *qtAction; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public QObject, public pAction { - Q_OBJECT - -public: - Item &item; - QAction *qtAction; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pCheckItem : public QObject, public pAction { - Q_OBJECT - -public: - CheckItem &checkItem; - QAction *qtAction; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - -public slots: - void onToggle(); -}; - -struct pRadioItem : public QObject, public pAction { - Q_OBJECT - -public: - RadioItem &radioItem; - QAction *qtAction; - QActionGroup *qtGroup; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} - - void constructor() {} - void destructor() {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} - - void constructor() {} - void destructor() {} -}; - -struct pWidget : public pSizable { - Widget &widget; - QWidget *qtWidget; - - bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void synchronizeState(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public QObject, public pWidget { - Q_OBJECT - -public: - Button &button; - QToolButton *qtButton; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pCanvas : public QObject, public pWidget { - Q_OBJECT - -public: - Canvas &canvas; - QImage *qtImage; - struct QtCanvas : public QWidget { - pCanvas &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - void paintEvent(QPaintEvent*); - QtCanvas(pCanvas &self); - } *qtCanvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: -}; - -struct pCheckBox : public QObject, public pWidget { - Q_OBJECT - -public: - CheckBox &checkBox; - QCheckBox *qtCheckBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onToggle(); -}; - -struct pComboBox : public QObject, public pWidget { - Q_OBJECT - -public: - ComboBox &comboBox; - QComboBox *qtComboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHexEdit : public QObject, public pWidget { - Q_OBJECT - -public: - HexEdit &hexEdit; - struct QtHexEdit : public QTextEdit { - pHexEdit &self; - void keyPressEvent(QKeyEvent*); - void keyPressEventAcknowledge(QKeyEvent*); - QtHexEdit(pHexEdit &self) : self(self) {} - } *qtHexEdit; - QHBoxLayout *qtLayout; - QScrollBar *qtScroll; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - void keyPressEvent(QKeyEvent*); - -public slots: - void onScroll(); -}; - -struct pHorizontalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalScrollBar &horizontalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHorizontalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalSlider &horizontalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pLabel : public pWidget { - Label &label; - QLabel *qtLabel; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public QObject, public pWidget { - Q_OBJECT - -public: - LineEdit &lineEdit; - QLineEdit *qtLineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(); -}; - -struct pListView : public QObject, public pWidget { - Q_OBJECT - -public: - ListView &listView; - QTreeWidget *qtListView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(QTreeWidgetItem *item); - void onToggle(QTreeWidgetItem *item); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - QProgressBar *qtProgressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public QObject, public pWidget { - Q_OBJECT - -public: - RadioBox &radioBox; - QRadioButton *qtRadioBox; - QButtonGroup *qtGroup; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pTextEdit : public QObject, public pWidget { - Q_OBJECT - -public: - TextEdit &textEdit; - QTextEdit *qtTextEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalScrollBar &verticalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalSlider &verticalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - struct QtViewport : public QWidget { - pViewport &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - QtViewport(pViewport &self); - } *qtViewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/ananke/phoenix/qt/settings.cpp b/ananke/phoenix/qt/settings.cpp deleted file mode 100644 index 90d3a76e..00000000 --- a/ananke/phoenix/qt/settings.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/qt.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("qt.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); -} diff --git a/ananke/phoenix/qt/timer.cpp b/ananke/phoenix/qt/timer.cpp deleted file mode 100644 index 61f00ba8..00000000 --- a/ananke/phoenix/qt/timer.cpp +++ /dev/null @@ -1,25 +0,0 @@ -void pTimer::setEnabled(bool enabled) { - if(enabled) { - qtTimer->start(); - } else { - qtTimer->stop(); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - qtTimer->setInterval(milliseconds); -} - -void pTimer::constructor() { - qtTimer = new QTimer; - qtTimer->setInterval(0); - connect(qtTimer, SIGNAL(timeout()), SLOT(onTimeout())); -} - -void pTimer::destructor() { - delete qtTimer; -} - -void pTimer::onTimeout() { - if(timer.onTimeout) timer.onTimeout(); -} diff --git a/ananke/phoenix/qt/utility.cpp b/ananke/phoenix/qt/utility.cpp deleted file mode 100644 index 400df0a2..00000000 --- a/ananke/phoenix/qt/utility.cpp +++ /dev/null @@ -1,190 +0,0 @@ -static QIcon CreateIcon(const nall::image &image, bool scale = false) { - nall::image qtBuffer = image; - qtBuffer.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - if(scale) qtBuffer.scale(16, 16, Interpolation::Linear); - QImage qtImage(qtBuffer.data, qtBuffer.width, qtBuffer.height, QImage::Format_ARGB32); - return QIcon(QPixmap::fromImage(qtImage)); -} - -static Keyboard::Keycode Keysym(int keysym) { - switch(keysym) { - case XK_Escape: return Keyboard::Keycode::Escape; - case XK_F1: return Keyboard::Keycode::F1; - case XK_F2: return Keyboard::Keycode::F2; - case XK_F3: return Keyboard::Keycode::F3; - case XK_F4: return Keyboard::Keycode::F4; - case XK_F5: return Keyboard::Keycode::F5; - case XK_F6: return Keyboard::Keycode::F6; - case XK_F7: return Keyboard::Keycode::F7; - case XK_F8: return Keyboard::Keycode::F8; - case XK_F9: return Keyboard::Keycode::F9; - case XK_F10: return Keyboard::Keycode::F10; - case XK_F11: return Keyboard::Keycode::F11; - case XK_F12: return Keyboard::Keycode::F12; - - case XK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case XK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case XK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case XK_Insert: return Keyboard::Keycode::Insert; - case XK_Delete: return Keyboard::Keycode::Delete; - case XK_Home: return Keyboard::Keycode::Home; - case XK_End: return Keyboard::Keycode::End; - case XK_Prior: return Keyboard::Keycode::PageUp; - case XK_Next: return Keyboard::Keycode::PageDown; - - case XK_Up: return Keyboard::Keycode::Up; - case XK_Down: return Keyboard::Keycode::Down; - case XK_Left: return Keyboard::Keycode::Left; - case XK_Right: return Keyboard::Keycode::Right; - - case XK_grave: return Keyboard::Keycode::Grave; - case XK_1: return Keyboard::Keycode::Number1; - case XK_2: return Keyboard::Keycode::Number2; - case XK_3: return Keyboard::Keycode::Number3; - case XK_4: return Keyboard::Keycode::Number4; - case XK_5: return Keyboard::Keycode::Number5; - case XK_6: return Keyboard::Keycode::Number6; - case XK_7: return Keyboard::Keycode::Number7; - case XK_8: return Keyboard::Keycode::Number8; - case XK_9: return Keyboard::Keycode::Number9; - case XK_0: return Keyboard::Keycode::Number0; - case XK_minus: return Keyboard::Keycode::Minus; - case XK_equal: return Keyboard::Keycode::Equal; - case XK_BackSpace: return Keyboard::Keycode::Backspace; - - case XK_asciitilde: return Keyboard::Keycode::Tilde; - case XK_exclam: return Keyboard::Keycode::Exclamation; - case XK_at: return Keyboard::Keycode::At; - case XK_numbersign: return Keyboard::Keycode::Pound; - case XK_dollar: return Keyboard::Keycode::Dollar; - case XK_percent: return Keyboard::Keycode::Percent; - case XK_asciicircum: return Keyboard::Keycode::Power; - case XK_ampersand: return Keyboard::Keycode::Ampersand; - case XK_asterisk: return Keyboard::Keycode::Asterisk; - case XK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case XK_parenright: return Keyboard::Keycode::ParenthesisRight; - case XK_underscore: return Keyboard::Keycode::Underscore; - case XK_plus: return Keyboard::Keycode::Plus; - - case XK_bracketleft: return Keyboard::Keycode::BracketLeft; - case XK_bracketright: return Keyboard::Keycode::BracketRight; - case XK_backslash: return Keyboard::Keycode::Backslash; - case XK_semicolon: return Keyboard::Keycode::Semicolon; - case XK_apostrophe: return Keyboard::Keycode::Apostrophe; - case XK_comma: return Keyboard::Keycode::Comma; - case XK_period: return Keyboard::Keycode::Period; - case XK_slash: return Keyboard::Keycode::Slash; - - case XK_braceleft: return Keyboard::Keycode::BraceLeft; - case XK_braceright: return Keyboard::Keycode::BraceRight; - case XK_bar: return Keyboard::Keycode::Pipe; - case XK_colon: return Keyboard::Keycode::Colon; - case XK_quotedbl: return Keyboard::Keycode::Quote; - case XK_less: return Keyboard::Keycode::CaretLeft; - case XK_greater: return Keyboard::Keycode::CaretRight; - case XK_question: return Keyboard::Keycode::Question; - - case XK_Tab: return Keyboard::Keycode::Tab; - case XK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case XK_Return: return Keyboard::Keycode::Return; - case XK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case XK_Shift_R: return Keyboard::Keycode::ShiftRight; - case XK_Control_L: return Keyboard::Keycode::ControlLeft; - case XK_Control_R: return Keyboard::Keycode::ControlRight; - case XK_Super_L: return Keyboard::Keycode::SuperLeft; - case XK_Super_R: return Keyboard::Keycode::SuperRight; - case XK_Alt_L: return Keyboard::Keycode::AltLeft; - case XK_Alt_R: return Keyboard::Keycode::AltRight; - case XK_space: return Keyboard::Keycode::Space; - case XK_Menu: return Keyboard::Keycode::Menu; - - case XK_A: return Keyboard::Keycode::A; - case XK_B: return Keyboard::Keycode::B; - case XK_C: return Keyboard::Keycode::C; - case XK_D: return Keyboard::Keycode::D; - case XK_E: return Keyboard::Keycode::E; - case XK_F: return Keyboard::Keycode::F; - case XK_G: return Keyboard::Keycode::G; - case XK_H: return Keyboard::Keycode::H; - case XK_I: return Keyboard::Keycode::I; - case XK_J: return Keyboard::Keycode::J; - case XK_K: return Keyboard::Keycode::K; - case XK_L: return Keyboard::Keycode::L; - case XK_M: return Keyboard::Keycode::M; - case XK_N: return Keyboard::Keycode::N; - case XK_O: return Keyboard::Keycode::O; - case XK_P: return Keyboard::Keycode::P; - case XK_Q: return Keyboard::Keycode::Q; - case XK_R: return Keyboard::Keycode::R; - case XK_S: return Keyboard::Keycode::S; - case XK_T: return Keyboard::Keycode::T; - case XK_U: return Keyboard::Keycode::U; - case XK_V: return Keyboard::Keycode::V; - case XK_W: return Keyboard::Keycode::W; - case XK_X: return Keyboard::Keycode::X; - case XK_Y: return Keyboard::Keycode::Y; - case XK_Z: return Keyboard::Keycode::Z; - - case XK_a: return Keyboard::Keycode::a; - case XK_b: return Keyboard::Keycode::b; - case XK_c: return Keyboard::Keycode::c; - case XK_d: return Keyboard::Keycode::d; - case XK_e: return Keyboard::Keycode::e; - case XK_f: return Keyboard::Keycode::f; - case XK_g: return Keyboard::Keycode::g; - case XK_h: return Keyboard::Keycode::h; - case XK_i: return Keyboard::Keycode::i; - case XK_j: return Keyboard::Keycode::j; - case XK_k: return Keyboard::Keycode::k; - case XK_l: return Keyboard::Keycode::l; - case XK_m: return Keyboard::Keycode::m; - case XK_n: return Keyboard::Keycode::n; - case XK_o: return Keyboard::Keycode::o; - case XK_p: return Keyboard::Keycode::p; - case XK_q: return Keyboard::Keycode::q; - case XK_r: return Keyboard::Keycode::r; - case XK_s: return Keyboard::Keycode::s; - case XK_t: return Keyboard::Keycode::t; - case XK_u: return Keyboard::Keycode::u; - case XK_v: return Keyboard::Keycode::v; - case XK_w: return Keyboard::Keycode::w; - case XK_x: return Keyboard::Keycode::x; - case XK_y: return Keyboard::Keycode::y; - case XK_z: return Keyboard::Keycode::z; - - case XK_Num_Lock: return Keyboard::Keycode::NumLock; - case XK_KP_Divide: return Keyboard::Keycode::Divide; - case XK_KP_Multiply: return Keyboard::Keycode::Multiply; - case XK_KP_Subtract: return Keyboard::Keycode::Subtract; - case XK_KP_Add: return Keyboard::Keycode::Add; - case XK_KP_Enter: return Keyboard::Keycode::Enter; - case XK_KP_Decimal: return Keyboard::Keycode::Point; - - case XK_KP_1: return Keyboard::Keycode::Keypad1; - case XK_KP_2: return Keyboard::Keycode::Keypad2; - case XK_KP_3: return Keyboard::Keycode::Keypad3; - case XK_KP_4: return Keyboard::Keycode::Keypad4; - case XK_KP_5: return Keyboard::Keycode::Keypad5; - case XK_KP_6: return Keyboard::Keycode::Keypad6; - case XK_KP_7: return Keyboard::Keycode::Keypad7; - case XK_KP_8: return Keyboard::Keycode::Keypad8; - case XK_KP_9: return Keyboard::Keycode::Keypad9; - case XK_KP_0: return Keyboard::Keycode::Keypad0; - - case XK_KP_Home: return Keyboard::Keycode::KeypadHome; - case XK_KP_End: return Keyboard::Keycode::KeypadEnd; - case XK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case XK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case XK_KP_Up: return Keyboard::Keycode::KeypadUp; - case XK_KP_Down: return Keyboard::Keycode::KeypadDown; - case XK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case XK_KP_Right: return Keyboard::Keycode::KeypadRight; - case XK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case XK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case XK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/ananke/phoenix/qt/widget/button.cpp b/ananke/phoenix/qt/widget/button.cpp deleted file mode 100644 index 0e1522b3..00000000 --- a/ananke/phoenix/qt/widget/button.cpp +++ /dev/null @@ -1,52 +0,0 @@ -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - qtButton->setIconSize(QSize(image.width, image.height)); - qtButton->setIcon(CreateIcon(image)); - qtButton->setStyleSheet("text-align: top;"); - switch(orientation) { - case Orientation::Horizontal: qtButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; - case Orientation::Vertical: qtButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; - } -} - -void pButton::setText(const string &text) { - qtButton->setText(QString::fromUtf8(text)); -} - -void pButton::constructor() { - qtWidget = qtButton = new QToolButton; - qtButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - connect(qtButton, SIGNAL(released()), SLOT(onActivate())); - - pWidget::synchronizeState(); - setText(button.state.text); -} - -void pButton::destructor() { - delete qtButton; - qtWidget = qtButton = 0; -} - -void pButton::orphan() { - destructor(); - constructor(); -} - -void pButton::onActivate() { - if(button.onActivate) button.onActivate(); -} diff --git a/ananke/phoenix/qt/widget/canvas.cpp b/ananke/phoenix/qt/widget/canvas.cpp deleted file mode 100644 index 245c1e9f..00000000 --- a/ananke/phoenix/qt/widget/canvas.cpp +++ /dev/null @@ -1,73 +0,0 @@ -void pCanvas::setSize(const Size &size) { - delete qtImage; - qtImage = new QImage(size.width, size.height, QImage::Format_ARGB32); -} - -void pCanvas::update() { - uint32_t *dp = (uint32_t*)qtImage->bits(), *sp = (uint32_t*)canvas.state.data; - for(unsigned n = 0; n < canvas.state.width * canvas.state.height; n++) *dp++ = 0xff000000 | *sp++; - qtCanvas->update(); -} - -void pCanvas::constructor() { - qtWidget = qtCanvas = new QtCanvas(*this); - qtCanvas->setMouseTracking(true); - qtImage = new QImage(canvas.state.width, canvas.state.height, QImage::Format_ARGB32); - memcpy(qtImage->bits(), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - - pWidget::synchronizeState(); - update(); -} - -void pCanvas::destructor() { - delete qtCanvas; - delete qtImage; - qtWidget = qtCanvas = 0; - qtImage = 0; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::QtCanvas::leaveEvent(QEvent *event) { - if(self.canvas.onMouseLeave) self.canvas.onMouseLeave(); -} - -void pCanvas::QtCanvas::mouseMoveEvent(QMouseEvent *event) { - if(self.canvas.onMouseMove) self.canvas.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pCanvas::QtCanvas::mousePressEvent(QMouseEvent *event) { - if(self.canvas.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMousePress(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::mouseReleaseEvent(QMouseEvent *event) { - if(self.canvas.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMouseRelease(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::paintEvent(QPaintEvent *event) { - QPainter painter(self.qtCanvas); - painter.drawImage(0, 0, *self.qtImage); - -//this will scale the source image to fit the target widget size (nearest-neighbor): -//painter.drawImage( -// QRect(0, 0, geometry().width(), geometry().height()), -// *self.qtImage, -// QRect(0, 0, self.canvas.state.width, self.canvas.state.height) -//); -} - -pCanvas::QtCanvas::QtCanvas(pCanvas &self) : self(self) { -} diff --git a/ananke/phoenix/qt/widget/check-box.cpp b/ananke/phoenix/qt/widget/check-box.cpp deleted file mode 100644 index c45bb326..00000000 --- a/ananke/phoenix/qt/widget/check-box.cpp +++ /dev/null @@ -1,42 +0,0 @@ -bool pCheckBox::checked() { - return qtCheckBox->isChecked(); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), checkBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - qtCheckBox->setChecked(checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - qtCheckBox->setText(QString::fromUtf8(text)); -} - -void pCheckBox::constructor() { - qtWidget = qtCheckBox = new QCheckBox; - connect(qtCheckBox, SIGNAL(stateChanged(int)), SLOT(onToggle())); - - pWidget::synchronizeState(); - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - delete qtCheckBox; - qtWidget = qtCheckBox = 0; -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} - -void pCheckBox::onToggle() { - checkBox.state.checked = checked(); - if(locked == false && checkBox.onToggle) checkBox.onToggle(); -} diff --git a/ananke/phoenix/qt/widget/combo-box.cpp b/ananke/phoenix/qt/widget/combo-box.cpp deleted file mode 100644 index 1dfa609d..00000000 --- a/ananke/phoenix/qt/widget/combo-box.cpp +++ /dev/null @@ -1,68 +0,0 @@ -void pComboBox::append(const string &text) { - locked = true; - qtComboBox->addItem(QString::fromUtf8(text)); - locked = false; -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(qtWidget->font(), text).width); - Geometry geometry = pFont::geometry(qtWidget->font(), " "); - return { 0, 0, maximumWidth + 32, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - qtComboBox->setItemText(row, text); -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - qtComboBox->removeItem(row); - if(position == row) qtComboBox->setCurrentIndex(0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - while(qtComboBox->count()) qtComboBox->removeItem(0); - locked = false; -} - -unsigned pComboBox::selection() { - signed index = qtComboBox->currentIndex(); - return index >= 0 ? index : 0; -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - qtComboBox->setCurrentIndex(row); - locked = false; -} - -void pComboBox::constructor() { - qtWidget = qtComboBox = new QComboBox; - connect(qtComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - unsigned selection = comboBox.state.selection; - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(selection); -} - -void pComboBox::destructor() { - delete qtComboBox; - qtWidget = qtComboBox = 0; -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::onChange() { - comboBox.state.selection = selection(); - if(locked == false && comboBox.onChange) comboBox.onChange(); -} diff --git a/ananke/phoenix/qt/widget/hex-edit.cpp b/ananke/phoenix/qt/widget/hex-edit.cpp deleted file mode 100644 index fdeebe4a..00000000 --- a/ananke/phoenix/qt/widget/hex-edit.cpp +++ /dev/null @@ -1,191 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - //add one if last row is not equal to column length (eg only part of the row is present) - bool indivisible = hexEdit.state.columns == 0 || (hexEdit.state.length % hexEdit.state.columns) != 0; - qtScroll->setRange(0, hexEdit.state.length / hexEdit.state.columns + indivisible - hexEdit.state.rows); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - locked = true; - qtScroll->setSliderPosition(hexEdit.state.offset / hexEdit.state.columns); - locked = false; - update(); -} - -void pHexEdit::setRows(unsigned rows) { - qtScroll->setPageStep(hexEdit.state.rows); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - qtHexEdit->setPlainText(""); - return; - } - - unsigned cursorPosition = qtHexEdit->textCursor().position(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - qtHexEdit->setPlainText(QString::fromUtf8(output)); - QTextCursor cursor = qtHexEdit->textCursor(); - cursor.setPosition(cursorPosition); - qtHexEdit->setTextCursor(cursor); -} - -void pHexEdit::constructor() { - qtWidget = qtHexEdit = new QtHexEdit(*this); - - qtHexEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - qtHexEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - qtLayout = new QHBoxLayout; - qtLayout->setAlignment(Qt::AlignRight); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtHexEdit->setLayout(qtLayout); - - qtScroll = new QScrollBar(Qt::Vertical); - qtScroll->setSingleStep(1); - qtLayout->addWidget(qtScroll); - - connect(qtScroll, SIGNAL(actionTriggered(int)), SLOT(onScroll())); - - pWidget::synchronizeState(); - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - delete qtScroll; - delete qtLayout; - delete qtHexEdit; - qtWidget = qtHexEdit = 0; - qtLayout = 0; - qtScroll = 0; -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -void pHexEdit::keyPressEvent(QKeyEvent *event) { - if(!hexEdit.onRead) return; - - QTextCursor cursor = qtHexEdit->textCursor(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = cursor.position() / lineWidth; - unsigned cursorX = cursor.position() % lineWidth; - - unsigned nibble; - switch(event->key()) { - case Qt::Key_0: nibble = 0; break; - case Qt::Key_1: nibble = 1; break; - case Qt::Key_2: nibble = 2; break; - case Qt::Key_3: nibble = 3; break; - case Qt::Key_4: nibble = 4; break; - case Qt::Key_5: nibble = 5; break; - case Qt::Key_6: nibble = 6; break; - case Qt::Key_7: nibble = 7; break; - case Qt::Key_8: nibble = 8; break; - case Qt::Key_9: nibble = 9; break; - case Qt::Key_A: nibble = 10; break; - case Qt::Key_B: nibble = 11; break; - case Qt::Key_C: nibble = 12; break; - case Qt::Key_D: nibble = 13; break; - case Qt::Key_E: nibble = 14; break; - case Qt::Key_F: nibble = 15; break; - default: { - //allow navigation keys to move cursor, but block text input - qtHexEdit->setTextInteractionFlags(Qt::TextInteractionFlags( - Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse - )); - qtHexEdit->keyPressEventAcknowledge(event); - qtHexEdit->setTextInteractionFlags(Qt::TextEditorInteraction); - return; - } - } - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return; //do not edit past end of file - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (nibble << 0); - } else { - data = (data & 0x0f) | (nibble << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - unsigned step = 1; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) step = 2; - cursor.setPosition(cursor.position() + step); - qtHexEdit->setTextCursor(cursor); - - //refresh output to reflect modified data - update(); - } - } - } -} - -void pHexEdit::onScroll() { - if(locked) return; - unsigned offset = qtScroll->sliderPosition(); - hexEdit.state.offset = offset * hexEdit.state.columns; - update(); -} - -void pHexEdit::QtHexEdit::keyPressEvent(QKeyEvent *event) { - self.keyPressEvent(event); -} - -void pHexEdit::QtHexEdit::keyPressEventAcknowledge(QKeyEvent *event) { - QTextEdit::keyPressEvent(event); -} diff --git a/ananke/phoenix/qt/widget/horizontal-scroll-bar.cpp b/ananke/phoenix/qt/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 6127c301..00000000 --- a/ananke/phoenix/qt/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 15 }; -} - -unsigned pHorizontalScrollBar::position() { - return qtScrollBar->value(); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pHorizontalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Horizontal); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pHorizontalScrollBar::onChange() { - horizontalScrollBar.state.position = position(); - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); -} diff --git a/ananke/phoenix/qt/widget/horizontal-slider.cpp b/ananke/phoenix/qt/widget/horizontal-slider.cpp deleted file mode 100644 index 5401aae1..00000000 --- a/ananke/phoenix/qt/widget/horizontal-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return qtSlider->value(); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pHorizontalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Horizontal); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} - -void pHorizontalSlider::onChange() { - horizontalSlider.state.position = position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); -} diff --git a/ananke/phoenix/qt/widget/label.cpp b/ananke/phoenix/qt/widget/label.cpp deleted file mode 100644 index 8dd86eb6..00000000 --- a/ananke/phoenix/qt/widget/label.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - qtLabel->setText(QString::fromUtf8(text)); -} - -void pLabel::constructor() { - qtWidget = qtLabel = new QLabel; - - pWidget::synchronizeState(); - setText(label.state.text); -} - -void pLabel::destructor() { - delete qtLabel; - qtWidget = qtLabel = 0; -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/qt/widget/line-edit.cpp b/ananke/phoenix/qt/widget/line-edit.cpp deleted file mode 100644 index a13f3b81..00000000 --- a/ananke/phoenix/qt/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 12 }; -} - -void pLineEdit::setEditable(bool editable) { - qtLineEdit->setReadOnly(!editable); -} - -void pLineEdit::setText(const string &text) { - qtLineEdit->setText(QString::fromUtf8(text)); -} - -string pLineEdit::text() { - return qtLineEdit->text().toUtf8().constData(); -} - -void pLineEdit::constructor() { - qtWidget = qtLineEdit = new QLineEdit; - connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate())); - connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - delete qtLineEdit; - qtWidget = qtLineEdit = 0; -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} - -void pLineEdit::onActivate() { - if(lineEdit.onActivate) lineEdit.onActivate(); -} - -void pLineEdit::onChange() { - lineEdit.state.text = text(); - if(lineEdit.onChange) lineEdit.onChange(); -} diff --git a/ananke/phoenix/qt/widget/list-view.cpp b/ananke/phoenix/qt/widget/list-view.cpp deleted file mode 100644 index a81c092d..00000000 --- a/ananke/phoenix/qt/widget/list-view.cpp +++ /dev/null @@ -1,164 +0,0 @@ -void pListView::append(const lstring &text) { - locked = true; - auto items = qtListView->findItems("", Qt::MatchContains); - QTreeWidgetItem *item = new QTreeWidgetItem(qtListView); - - item->setData(0, Qt::UserRole, (unsigned)items.size()); - if(listView.state.checkable) item->setCheckState(0, Qt::Unchecked); - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::autoSizeColumns() { - for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n); -} - -bool pListView::checked(unsigned row) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - return item ? item->checkState(0) == Qt::Checked : false; -} - -void pListView::modify(unsigned row, const lstring &text) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::remove(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - delete item; - locked = false; -} - -void pListView::reset() { - qtListView->clear(); -} - -bool pListView::selected() { - QTreeWidgetItem *item = qtListView->currentItem(); - return (item && item->isSelected() == true); -} - -unsigned pListView::selection() { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item == 0) return 0; - return item->data(0, Qt::UserRole).toUInt(); -} - -void pListView::setCheckable(bool checkable) { - if(checkable) { - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) items[n]->setCheckState(0, Qt::Unchecked); - } -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) item->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); - locked = false; -} - -void pListView::setHeaderText(const lstring &text) { - QStringList labels; - for(auto &column : text) labels << QString::fromUtf8(column); - - qtListView->setColumnCount(text.size()); - qtListView->setAlternatingRowColors(text.size() >= 2); - qtListView->setHeaderLabels(labels); - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - qtListView->setHeaderHidden(!visible); - autoSizeColumns(); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) { - if(image.empty() == 0) item->setIcon(column, CreateIcon(image)); - if(image.empty() == 1) item->setIcon(column, QIcon()); - } -} - -void pListView::setSelected(bool selected) { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(selected); -} - -void pListView::setSelection(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(false); - qtListView->setCurrentItem(0); - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) { - if(items[n]->data(0, Qt::UserRole).toUInt() == row) { - qtListView->setCurrentItem(items[n]); - break; - } - } - locked = false; -} - -void pListView::constructor() { - qtWidget = qtListView = new QTreeWidget; - qtListView->setAllColumnsShowFocus(true); - qtListView->setRootIsDecorated(false); - - connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate())); - connect(qtListView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(onChange(QTreeWidgetItem*))); - connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*))); - - pWidget::synchronizeState(); - setCheckable(listView.state.checkable); - setHeaderText(listView.state.headerText.size() ? listView.state.headerText : lstring{ " " }); - setHeaderVisible(listView.state.headerVisible); - for(auto &row : listView.state.text) append(row); - if(listView.state.checkable) { - for(unsigned n = 0; n < listView.state.checked.size(); n++) { - setChecked(n, listView.state.checked[n]); - } - } - setSelected(listView.state.selected); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - delete qtListView; - qtWidget = qtListView = 0; -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::onActivate() { - if(locked == false && listView.onActivate) listView.onActivate(); -} - -void pListView::onChange(QTreeWidgetItem *item) { - //Qt bug workaround: clicking items with mouse does not mark items as selected - if(item) item->setSelected(true); - listView.state.selected = selected(); - if(listView.state.selected) listView.state.selection = selection(); - if(locked == false && listView.onChange) listView.onChange(); -} - -void pListView::onToggle(QTreeWidgetItem *item) { - unsigned row = item->data(0, Qt::UserRole).toUInt(); - bool checkState = checked(row); - listView.state.checked[row] = checkState; - if(locked == false && listView.onToggle) listView.onToggle(row); -} diff --git a/ananke/phoenix/qt/widget/progress-bar.cpp b/ananke/phoenix/qt/widget/progress-bar.cpp deleted file mode 100644 index 8178bb66..00000000 --- a/ananke/phoenix/qt/widget/progress-bar.cpp +++ /dev/null @@ -1,26 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - qtProgressBar->setValue(position); -} - -void pProgressBar::constructor() { - qtWidget = qtProgressBar = new QProgressBar; - qtProgressBar->setRange(0, 100); - qtProgressBar->setTextVisible(false); - - pWidget::synchronizeState(); - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - delete qtProgressBar; - qtWidget = qtProgressBar = 0; -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/qt/widget/radio-box.cpp b/ananke/phoenix/qt/widget/radio-box.cpp deleted file mode 100644 index bf640fd2..00000000 --- a/ananke/phoenix/qt/widget/radio-box.cpp +++ /dev/null @@ -1,64 +0,0 @@ -bool pRadioBox::checked() { - return qtRadioBox->isChecked(); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), radioBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pRadioBox::setChecked() { - locked = true; - for(auto &item : radioBox.state.group) { - bool checkState = item.p.qtRadioBox == qtRadioBox; - item.state.checked = checkState; - item.p.qtRadioBox->setChecked(checkState); - } - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - locked = true; - if(qtGroup) { - delete qtGroup; - qtGroup = 0; - } - if(group.size() > 0 && qtRadioBox == group[0].p.qtRadioBox) { - qtGroup = new QButtonGroup; - for(auto &item : group) qtGroup->addButton(item.p.qtRadioBox); - setChecked(); - } - locked = false; -} - -void pRadioBox::setText(const string &text) { - qtRadioBox->setText(QString::fromUtf8(text)); -} - -void pRadioBox::constructor() { - qtWidget = qtRadioBox = new QRadioButton; - qtGroup = new QButtonGroup; - qtGroup->addButton(qtRadioBox); - qtRadioBox->setChecked(true); - connect(qtRadioBox, SIGNAL(toggled(bool)), SLOT(onActivate())); - - pWidget::synchronizeState(); - setGroup(radioBox.state.group); - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - delete qtGroup; - delete qtRadioBox; - qtWidget = qtRadioBox = 0; - qtGroup = 0; -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} - -void pRadioBox::onActivate() { - if(locked == false && checked() && radioBox.onActivate) radioBox.onActivate(); -} diff --git a/ananke/phoenix/qt/widget/text-edit.cpp b/ananke/phoenix/qt/widget/text-edit.cpp deleted file mode 100644 index 8cdbe573..00000000 --- a/ananke/phoenix/qt/widget/text-edit.cpp +++ /dev/null @@ -1,50 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - QTextCursor cursor = qtTextEdit->textCursor(); - unsigned lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData()); - cursor.setPosition(min(position, lastCharacter)); - qtTextEdit->setTextCursor(cursor); -} - -void pTextEdit::setEditable(bool editable) { - qtTextEdit->setReadOnly(!editable); -} - -void pTextEdit::setText(const string &text) { - qtTextEdit->setPlainText(QString::fromUtf8(text)); -} - -void pTextEdit::setWordWrap(bool wordWrap) { - qtTextEdit->setWordWrapMode(wordWrap ? QTextOption::WordWrap : QTextOption::NoWrap); - qtTextEdit->setHorizontalScrollBarPolicy(wordWrap ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn); - qtTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); -} - -string pTextEdit::text() { - return qtTextEdit->toPlainText().toUtf8().constData(); -} - -void pTextEdit::constructor() { - qtWidget = qtTextEdit = new QTextEdit; - connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - if(sizable.state.layout) sizable.state.layout->remove(textEdit); - delete qtTextEdit; - qtWidget = qtTextEdit = 0; -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} - -void pTextEdit::onChange() { - textEdit.state.text = text(); - if(textEdit.onChange) textEdit.onChange(); -} diff --git a/ananke/phoenix/qt/widget/vertical-scroll-bar.cpp b/ananke/phoenix/qt/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 74d68ca6..00000000 --- a/ananke/phoenix/qt/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 15, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return qtScrollBar->value(); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pVerticalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Vertical); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pVerticalScrollBar::onChange() { - verticalScrollBar.state.position = position(); - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); -} diff --git a/ananke/phoenix/qt/widget/vertical-slider.cpp b/ananke/phoenix/qt/widget/vertical-slider.cpp deleted file mode 100644 index 500adb07..00000000 --- a/ananke/phoenix/qt/widget/vertical-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return qtSlider->value(); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pVerticalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Vertical); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} - -void pVerticalSlider::onChange() { - verticalSlider.state.position = position(); - if(verticalSlider.onChange) verticalSlider.onChange(); -} diff --git a/ananke/phoenix/qt/widget/viewport.cpp b/ananke/phoenix/qt/widget/viewport.cpp deleted file mode 100644 index 1b67d776..00000000 --- a/ananke/phoenix/qt/widget/viewport.cpp +++ /dev/null @@ -1,51 +0,0 @@ -uintptr_t pViewport::handle() { - return (uintptr_t)qtViewport->winId(); -} - -void pViewport::constructor() { - qtWidget = qtViewport = new QtViewport(*this); - qtViewport->setMouseTracking(true); - qtViewport->setAttribute(Qt::WA_PaintOnScreen, true); - qtViewport->setStyleSheet("background: #000000"); - - pWidget::synchronizeState(); -} - -void pViewport::destructor() { - delete qtViewport; - qtWidget = qtViewport = nullptr; -} - -void pViewport::orphan() { - destructor(); - constructor(); -} - -void pViewport::QtViewport::leaveEvent(QEvent *event) { - if(self.viewport.onMouseLeave) self.viewport.onMouseLeave(); -} - -void pViewport::QtViewport::mouseMoveEvent(QMouseEvent *event) { - if(self.viewport.onMouseMove) self.viewport.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pViewport::QtViewport::mousePressEvent(QMouseEvent *event) { - if(self.viewport.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMousePress(Mouse::Button::Right); break; - } -} - -void pViewport::QtViewport::mouseReleaseEvent(QMouseEvent *event) { - if(self.viewport.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMouseRelease(Mouse::Button::Right); break; - } -} - -pViewport::QtViewport::QtViewport(pViewport &self) : self(self) { -} diff --git a/ananke/phoenix/qt/widget/widget.cpp b/ananke/phoenix/qt/widget/widget.cpp deleted file mode 100644 index 27d23354..00000000 --- a/ananke/phoenix/qt/widget/widget.cpp +++ /dev/null @@ -1,56 +0,0 @@ -bool pWidget::focused() { - return qtWidget->hasFocus(); -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - qtWidget->setEnabled(enabled); -} - -void pWidget::setFocused() { - qtWidget->setFocus(Qt::OtherFocusReason); -} - -void pWidget::setFont(const string &font) { - qtWidget->setFont(pFont::create(font)); -} - -void pWidget::setGeometry(const Geometry &geometry) { - qtWidget->setGeometry(geometry.x, geometry.y, geometry.width, geometry.height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout == 0) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - qtWidget->setVisible(visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) qtWidget = new QWidget; -} - -//pWidget::constructor() called before p{Derived}::constructor(); ergo qtWidget is not yet valid -//pWidget::synchronizeState() is called to finish construction of p{Derived}::constructor() -void pWidget::synchronizeState() { - setEnabled(widget.state.enabled); - setFont(widget.state.font); -//setVisible(widget.state.visible); -} - -void pWidget::destructor() { - if(widget.state.abstract) { - delete qtWidget; - qtWidget = 0; - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/qt/window.cpp b/ananke/phoenix/qt/window.cpp deleted file mode 100644 index dac311ee..00000000 --- a/ananke/phoenix/qt/window.cpp +++ /dev/null @@ -1,297 +0,0 @@ -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = window.state.geometry; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - qtMenu->addMenu(menu.p.qtMenu); -} - -void pWindow::append(Widget &widget) { - if(widget.state.font == "") { - if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - } - widget.p.qtWidget->setParent(qtContainer); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - QColor color = qtWindow->palette().color(QPalette::ColorRole::Window); - return { (uint8_t)color.red(), (uint8_t)color.green(), (uint8_t)color.blue(), (uint8_t)color.alpha() }; -} - -Geometry pWindow::frameMargin() { - unsigned menuHeight = window.state.menuVisible ? settings->menuGeometryHeight : 0; - unsigned statusHeight = window.state.statusVisible ? settings->statusGeometryHeight : 0; - if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight }; - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight, - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight + statusHeight - }; -} - -bool pWindow::focused() { - return qtWindow->isActiveWindow() && !qtWindow->isMinimized(); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen) { - unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; - unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; - return { 0, menuHeight, Desktop::size().width, Desktop::size().height - menuHeight - statusHeight }; - } - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - //QMenuBar::removeMenu() does not exist - qtMenu->clear(); - for(auto &menu : window.state.menu) append(menu); -} - -void pWindow::remove(Widget &widget) { - //bugfix: orphan() destroys and recreates widgets (to disassociate them from their parent); - //attempting to create widget again after QApplication::quit() crashes libQtGui - if(qtApplication) widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - QPalette palette; - palette.setColor(QPalette::Window, QColor(color.red, color.green, color.blue, color.alpha)); - qtContainer->setPalette(palette); - qtContainer->setAutoFillBackground(true); - qtWindow->setAttribute(Qt::WA_TranslucentBackground, color.alpha != 255); -} - -void pWindow::setFocused() { - qtWindow->raise(); - qtWindow->activateWindow(); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - setResizable(window.state.resizable); - qtWindow->showNormal(); - qtWindow->adjustSize(); - } else { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setFixedSize(Desktop::size().width - frameMargin().width, Desktop::size().height - frameMargin().height); - qtWindow->showFullScreen(); - } -} - -void pWindow::setGeometry(const Geometry &geometry_) { - locked = true; - OS::processEvents(); - QApplication::syncX(); - Geometry geometry = geometry_, margin = frameMargin(); - - setResizable(window.state.resizable); - qtWindow->move(geometry.x - frameMargin().x, geometry.y - frameMargin().y); - //qtWindow->adjustSize() fails if larger than 2/3rds screen size - qtWindow->resize(qtWindow->sizeHint()); - qtWindow->setMinimumSize(1, 1); - qtContainer->setMinimumSize(1, 1); - - for(auto &layout : window.state.layout) { - geometry = geometry_; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - qtMenu->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setModal(bool modal) { - qtWindow->setWindowModality(modal ? Qt::ApplicationModal : Qt::NonModal); -} - -void pWindow::setResizable(bool resizable) { - if(resizable) { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setMinimumSize(window.state.geometry.width, window.state.geometry.height); - } else { - qtLayout->setSizeConstraint(QLayout::SetFixedSize); - qtContainer->setFixedSize(window.state.geometry.width, window.state.geometry.height); - } - qtStatus->setSizeGripEnabled(resizable); -} - -void pWindow::setStatusFont(const string &font) { - qtStatus->setFont(pFont::create(font)); -} - -void pWindow::setStatusText(const string &text) { - qtStatus->showMessage(QString::fromUtf8(text), 0); -} - -void pWindow::setStatusVisible(bool visible) { - qtStatus->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setTitle(const string &text) { - qtWindow->setWindowTitle(QString::fromUtf8(text)); -} - -void pWindow::setVisible(bool visible) { - locked = true; - qtWindow->setVisible(visible); - if(visible) { - updateFrameGeometry(); - setGeometry(window.state.geometry); - } - locked = false; -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(!item.state.font) item.setFont(font); - } -} - -void pWindow::constructor() { - qtWindow = new QtWindow(*this); - qtWindow->setWindowTitle(" "); - - //if program was given a name, try and set the window taskbar icon to a matching pixmap image - if(osState.name.empty() == false) { - if(file::exists({"/usr/share/pixmaps/", osState.name, ".png"})) { - qtWindow->setWindowIcon(QIcon(string{"/usr/share/pixmaps/", osState.name, ".png"})); - } else if(file::exists({"/usr/local/share/pixmaps/", osState.name, ".png"})) { - qtWindow->setWindowIcon(QIcon(string{"/usr/local/share/pixmaps/", osState.name, ".png"})); - } - } - - qtLayout = new QVBoxLayout(qtWindow); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtWindow->setLayout(qtLayout); - - qtMenu = new QMenuBar(qtWindow); - qtMenu->setVisible(false); - qtLayout->addWidget(qtMenu); - - qtContainer = new QWidget(qtWindow); - qtContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - qtContainer->setVisible(true); - qtLayout->addWidget(qtContainer); - - qtStatus = new QStatusBar(qtWindow); - qtStatus->setSizeGripEnabled(true); - qtStatus->setVisible(false); - qtLayout->addWidget(qtStatus); - - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); -} - -void pWindow::destructor() { - delete qtStatus; - delete qtContainer; - delete qtMenu; - delete qtLayout; - delete qtWindow; -} - -void pWindow::updateFrameGeometry() { - pOS::syncX(); - QRect border = qtWindow->frameGeometry(); - QRect client = qtWindow->geometry(); - - settings->frameGeometryX = client.x() - border.x(); - settings->frameGeometryY = client.y() - border.y(); - settings->frameGeometryWidth = border.width() - client.width(); - settings->frameGeometryHeight = border.height() - client.height(); - - if(window.state.menuVisible) { - pOS::syncX(); - settings->menuGeometryHeight = qtMenu->height(); - } - - if(window.state.statusVisible) { - pOS::syncX(); - settings->statusGeometryHeight = qtStatus->height(); - } - - settings->save(); -} - -void pWindow::QtWindow::closeEvent(QCloseEvent *event) { - self.window.state.ignore = false; - event->ignore(); - if(self.window.onClose) self.window.onClose(); - if(self.window.state.ignore == false) hide(); -} - -void pWindow::QtWindow::moveEvent(QMoveEvent *event) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.x += event->pos().x() - event->oldPos().x(); - self.window.state.geometry.y += event->pos().y() - event->oldPos().y(); - } - - if(self.locked == false) { - if(self.window.onMove) self.window.onMove(); - } -} - -void pWindow::QtWindow::keyPressEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym); -} - -void pWindow::QtWindow::keyReleaseEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym); -} - -void pWindow::QtWindow::resizeEvent(QResizeEvent*) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.width = self.qtContainer->geometry().width(); - self.window.state.geometry.height = self.qtContainer->geometry().height(); - } - - for(auto &layout : self.window.state.layout) { - Geometry geometry = self.geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(self.locked == false) { - if(self.window.onSize) self.window.onSize(); - } -} - -QSize pWindow::QtWindow::sizeHint() const { - unsigned width = self.window.state.geometry.width; - unsigned height = self.window.state.geometry.height; - if(self.window.state.menuVisible) height += settings->menuGeometryHeight; - if(self.window.state.statusVisible) height += settings->statusGeometryHeight; - return QSize(width, height); -} diff --git a/ananke/phoenix/reference/action/action.cpp b/ananke/phoenix/reference/action/action.cpp deleted file mode 100644 index 0bc6bc3f..00000000 --- a/ananke/phoenix/reference/action/action.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pAction::setEnabled(bool enabled) { -} - -void pAction::setVisible(bool visible) { -} - -void pAction::constructor() { -} diff --git a/ananke/phoenix/reference/action/check-item.cpp b/ananke/phoenix/reference/action/check-item.cpp deleted file mode 100644 index 26970fc8..00000000 --- a/ananke/phoenix/reference/action/check-item.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pCheckItem::checked() { - return false; -} - -void pCheckItem::setChecked(bool checked) { -} - -void pCheckItem::setText(const string &text) { -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { -} diff --git a/ananke/phoenix/reference/action/item.cpp b/ananke/phoenix/reference/action/item.cpp deleted file mode 100644 index 438ed32f..00000000 --- a/ananke/phoenix/reference/action/item.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pItem::setImage(const image &image) { -} - -void pItem::setText(const string &text) { -} - -void pItem::constructor() { -} - -void pItem::destructor() { -} diff --git a/ananke/phoenix/reference/action/menu.cpp b/ananke/phoenix/reference/action/menu.cpp deleted file mode 100644 index 4f0a65a8..00000000 --- a/ananke/phoenix/reference/action/menu.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pMenu::append(Action &action) { -} - -void pMenu::remove(Action &action) { -} - -void pMenu::setImage(const image &image) { -} - -void pMenu::setText(const string &text) { -} - -void pMenu::constructor() { -} - -void pMenu::destructor() { -} diff --git a/ananke/phoenix/reference/action/radio-item.cpp b/ananke/phoenix/reference/action/radio-item.cpp deleted file mode 100644 index e87a4deb..00000000 --- a/ananke/phoenix/reference/action/radio-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pRadioItem::checked() { - return false; -} - -void pRadioItem::setChecked() { -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { -} diff --git a/ananke/phoenix/reference/action/separator.cpp b/ananke/phoenix/reference/action/separator.cpp deleted file mode 100644 index 24a45c04..00000000 --- a/ananke/phoenix/reference/action/separator.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { -} diff --git a/ananke/phoenix/reference/desktop.cpp b/ananke/phoenix/reference/desktop.cpp deleted file mode 100644 index a96eb1f0..00000000 --- a/ananke/phoenix/reference/desktop.cpp +++ /dev/null @@ -1,8 +0,0 @@ -Size pDesktop::size() { - return { 0, 0 }; -} - -Geometry pDesktop::workspace() { - return { 0, 0, 0, 0 }; -} - diff --git a/ananke/phoenix/reference/dialog-window.cpp b/ananke/phoenix/reference/dialog-window.cpp deleted file mode 100644 index c7d089ae..00000000 --- a/ananke/phoenix/reference/dialog-window.cpp +++ /dev/null @@ -1,11 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - return ""; -} diff --git a/ananke/phoenix/reference/font.cpp b/ananke/phoenix/reference/font.cpp deleted file mode 100644 index bfda5c06..00000000 --- a/ananke/phoenix/reference/font.cpp +++ /dev/null @@ -1,3 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return { 0, 0, 0, 0 }; -} diff --git a/ananke/phoenix/reference/keyboard.cpp b/ananke/phoenix/reference/keyboard.cpp deleted file mode 100644 index 40b3a1a7..00000000 --- a/ananke/phoenix/reference/keyboard.cpp +++ /dev/null @@ -1,10 +0,0 @@ -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return false; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - return output; -} diff --git a/ananke/phoenix/reference/message-window.cpp b/ananke/phoenix/reference/message-window.cpp deleted file mode 100644 index 84a287f5..00000000 --- a/ananke/phoenix/reference/message-window.cpp +++ /dev/null @@ -1,15 +0,0 @@ -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} diff --git a/ananke/phoenix/reference/mouse.cpp b/ananke/phoenix/reference/mouse.cpp deleted file mode 100644 index f103a15a..00000000 --- a/ananke/phoenix/reference/mouse.cpp +++ /dev/null @@ -1,7 +0,0 @@ -Position pMouse::position() { - return { 0, 0 }; -} - -bool pMouse::pressed(Mouse::Button button) { - return false; -} diff --git a/ananke/phoenix/reference/platform.cpp b/ananke/phoenix/reference/platform.cpp deleted file mode 100644 index e64f7eab..00000000 --- a/ananke/phoenix/reference/platform.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "platform.hpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -void pOS::main() { -} - -bool pOS::pendingEvents() { - return false; -} - -void pOS::processEvents() { -} - -void pOS::quit() { -} - -void pOS::initialize() { -} diff --git a/ananke/phoenix/reference/platform.hpp b/ananke/phoenix/reference/platform.hpp deleted file mode 100644 index cd9e4152..00000000 --- a/ananke/phoenix/reference/platform.hpp +++ /dev/null @@ -1,384 +0,0 @@ -struct pFont; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(locked) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - - bool enabled(); - bool focused(); - Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); -}; - -struct pButton : public pWidget { - Button &button; - - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); -}; - -struct pLabel : public pWidget { - Label &label; - - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); -}; - -struct pListView : public pWidget { - ListView &listView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); -}; diff --git a/ananke/phoenix/reference/timer.cpp b/ananke/phoenix/reference/timer.cpp deleted file mode 100644 index 6cbe571a..00000000 --- a/ananke/phoenix/reference/timer.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pTimer::setEnabled(bool enabled) { -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/ananke/phoenix/reference/widget/button.cpp b/ananke/phoenix/reference/widget/button.cpp deleted file mode 100644 index fc06c371..00000000 --- a/ananke/phoenix/reference/widget/button.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pButton::setImage(const image &image, Orientation orientation) { -} - -void pButton::setText(const string &text) { -} - -void pButton::constructor() { -} diff --git a/ananke/phoenix/reference/widget/canvas.cpp b/ananke/phoenix/reference/widget/canvas.cpp deleted file mode 100644 index 953cfa77..00000000 --- a/ananke/phoenix/reference/widget/canvas.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pCanvas::setSize(const Size &size) { -} - -void pCanvas::update() { -} - -void pCanvas::constructor() { -} diff --git a/ananke/phoenix/reference/widget/check-box.cpp b/ananke/phoenix/reference/widget/check-box.cpp deleted file mode 100644 index c5aec216..00000000 --- a/ananke/phoenix/reference/widget/check-box.cpp +++ /dev/null @@ -1,12 +0,0 @@ -bool pCheckBox::checked() { - return false; -} - -void pCheckBox::setChecked(bool checked) { -} - -void pCheckBox::setText(const string &text) { -} - -void pCheckBox::constructor() { -} diff --git a/ananke/phoenix/reference/widget/combo-box.cpp b/ananke/phoenix/reference/widget/combo-box.cpp deleted file mode 100644 index 297d7369..00000000 --- a/ananke/phoenix/reference/widget/combo-box.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pComboBox::append(const string &text) { -} - -void pComboBox::modify(unsigned row, const string &text) { -} - -void pComboBox::remove(unsigned row) { -} - -void pComboBox::reset() { -} - -unsigned pComboBox::selection() { - return 0; -} - -void pComboBox::setSelection(unsigned row) { -} - -void pComboBox::constructor() { -} diff --git a/ananke/phoenix/reference/widget/hex-edit.cpp b/ananke/phoenix/reference/widget/hex-edit.cpp deleted file mode 100644 index 40bf9f5d..00000000 --- a/ananke/phoenix/reference/widget/hex-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { -} - -void pHexEdit::setLength(unsigned length) { -} - -void pHexEdit::setOffset(unsigned offset) { -} - -void pHexEdit::setRows(unsigned rows) { -} - -void pHexEdit::update() { -} - -void pHexEdit::constructor() { -} diff --git a/ananke/phoenix/reference/widget/horizontal-scroll-bar.cpp b/ananke/phoenix/reference/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 352b3393..00000000 --- a/ananke/phoenix/reference/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalScrollBar::position() { - return 0; -} - -void pHorizontalScrollBar::setLength(unsigned length) { -} - -void pHorizontalScrollBar::setPosition(unsigned position) { -} - -void pHorizontalScrollBar::constructor() { -} diff --git a/ananke/phoenix/reference/widget/horizontal-slider.cpp b/ananke/phoenix/reference/widget/horizontal-slider.cpp deleted file mode 100644 index 0a4a8392..00000000 --- a/ananke/phoenix/reference/widget/horizontal-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalSlider::position() { - return 0; -} - -void pHorizontalSlider::setLength(unsigned length) { -} - -void pHorizontalSlider::setPosition(unsigned position) { -} - -void pHorizontalSlider::constructor() { -} diff --git a/ananke/phoenix/reference/widget/label.cpp b/ananke/phoenix/reference/widget/label.cpp deleted file mode 100644 index 25600d2a..00000000 --- a/ananke/phoenix/reference/widget/label.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pLabel::setText(const string &text) { -} - -void pLabel::constructor() { -} diff --git a/ananke/phoenix/reference/widget/line-edit.cpp b/ananke/phoenix/reference/widget/line-edit.cpp deleted file mode 100644 index 96b9ac6c..00000000 --- a/ananke/phoenix/reference/widget/line-edit.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pLineEdit::setEditable(bool editable) { -} - -void pLineEdit::setText(const string &text) { -} - -string pLineEdit::text() { -} - -void pLineEdit::constructor() { -} diff --git a/ananke/phoenix/reference/widget/list-view.cpp b/ananke/phoenix/reference/widget/list-view.cpp deleted file mode 100644 index 6e90e0a3..00000000 --- a/ananke/phoenix/reference/widget/list-view.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pListView::append(const lstring &text) { -} - -void pListView::autoSizeColumns() { -} - -bool pListView::checked(unsigned row) { -} - -void pListView::modify(unsigned row, const lstring &text) { -} - -void pListView::remove(unsigned row) { -} - -void pListView::reset() { -} - -bool pListView::selected() { - return false; -} - -unsigned pListView::selection() { - return 0; -} - -void pListView::setCheckable(bool checkable) { -} - -void pListView::setChecked(unsigned row, bool checked) { -} - -void pListView::setHeaderText(const lstring &text) { -} - -void pListView::setHeaderVisible(bool visible) { -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { -} - -void pListView::setSelected(bool selected) { -} - -void pListView::setSelection(unsigned row) { -} - -void pListView::constructor() { -} diff --git a/ananke/phoenix/reference/widget/progress-bar.cpp b/ananke/phoenix/reference/widget/progress-bar.cpp deleted file mode 100644 index b4905a85..00000000 --- a/ananke/phoenix/reference/widget/progress-bar.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pProgressBar::setPosition(unsigned position) { -} - -void pProgressBar::constructor() { -} diff --git a/ananke/phoenix/reference/widget/radio-box.cpp b/ananke/phoenix/reference/widget/radio-box.cpp deleted file mode 100644 index f6aebcbe..00000000 --- a/ananke/phoenix/reference/widget/radio-box.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pRadioBox::checked() { - return false; -} - -void pRadioBox::setChecked() { -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { -} - -void pRadioBox::constructor() { -} diff --git a/ananke/phoenix/reference/widget/text-edit.cpp b/ananke/phoenix/reference/widget/text-edit.cpp deleted file mode 100644 index 74121b2d..00000000 --- a/ananke/phoenix/reference/widget/text-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { -} - -void pTextEdit::setEditable(bool editable) { -} - -void pTextEdit::setText(const string &text) { -} - -void pTextEdit::setWordWrap(bool wordWrap) { -} - -string pTextEdit::text() { -} - -void pTextEdit::constructor() { -} diff --git a/ananke/phoenix/reference/widget/vertical-scroll-bar.cpp b/ananke/phoenix/reference/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 26795248..00000000 --- a/ananke/phoenix/reference/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalScrollBar::position() { - return 0; -} - -void pVerticalScrollBar::setLength(unsigned length) { -} - -void pVerticalScrollBar::setPosition(unsigned position) { -} - -void pVerticalScrollBar::constructor() { -} diff --git a/ananke/phoenix/reference/widget/vertical-slider.cpp b/ananke/phoenix/reference/widget/vertical-slider.cpp deleted file mode 100644 index a6d8ae00..00000000 --- a/ananke/phoenix/reference/widget/vertical-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalSlider::position() { - return 0; -} - -void pVerticalSlider::setLength(unsigned length) { -} - -void pVerticalSlider::setPosition(unsigned position) { -} - -void pVerticalSlider::constructor() { -} diff --git a/ananke/phoenix/reference/widget/viewport.cpp b/ananke/phoenix/reference/widget/viewport.cpp deleted file mode 100644 index 9d398438..00000000 --- a/ananke/phoenix/reference/widget/viewport.cpp +++ /dev/null @@ -1,6 +0,0 @@ -uintptr_t pViewport::handle() { - return 0; -} - -void pViewport::constructor() { -} diff --git a/ananke/phoenix/reference/widget/widget.cpp b/ananke/phoenix/reference/widget/widget.cpp deleted file mode 100644 index d9c86478..00000000 --- a/ananke/phoenix/reference/widget/widget.cpp +++ /dev/null @@ -1,29 +0,0 @@ -bool pWidget::enabled() { - return false; -} - -bool pWidget::focused() { - return false; -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { -} - -void pWidget::setFocused() { -} - -void pWidget::setFont(const string &font) { -} - -void pWidget::setGeometry(const Geometry &geometry) { -} - -void pWidget::setVisible(bool visible) { -} - -void pWidget::constructor() { -} diff --git a/ananke/phoenix/reference/window.cpp b/ananke/phoenix/reference/window.cpp deleted file mode 100644 index aca2cc2d..00000000 --- a/ananke/phoenix/reference/window.cpp +++ /dev/null @@ -1,84 +0,0 @@ -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { -} - -void pWindow::append(Menu &menu) { -} - -void pWindow::append(Widget &widget) { -} - -Color pWindow::backgroundColor() { - return {0, 0, 0, 255}; -} - -bool pWindow::focused() { - return false; -} - -Geometry pWindow::frameMargin() { - return {0, 0, 0, 0}; -} - -Geometry pWindow::geometry() { - return {0, 0, 0, 0}; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { -} - -void pWindow::remove(Widget &widget) { -} - -void pWindow::setBackgroundColor(const Color &color) { -} - -void pWindow::setFocused() { -} - -void pWindow::setFullScreen(bool fullScreen) { -} - -void pWindow::setGeometry(const Geometry &geometry) { -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { -} - -void pWindow::setModal(bool modal) { -} - -void pWindow::setResizable(bool resizable) { -} - -void pWindow::setStatusFont(const string &font) { -} - -void pWindow::setStatusText(const string &text) { -} - -void pWindow::setStatusVisible(bool visible) { -} - -void pWindow::setTitle(const string &text) { -} - -void pWindow::setVisible(bool visible) { -} - -void pWindow::setWidgetFont(const string &font) { -} - -void pWindow::constructor() { -} diff --git a/ananke/phoenix/sync.sh b/ananke/phoenix/sync.sh deleted file mode 100644 index 40ee3d98..00000000 --- a/ananke/phoenix/sync.sh +++ /dev/null @@ -1,9 +0,0 @@ -synchronize() { - if [ -d ../"$1" ]; then - test -d "$1" && rm -r "$1" - cp -r ../"$1" ./"$1" - fi -} - -synchronize "nall" -rm -r nall/test diff --git a/ananke/phoenix/windows/action/action.cpp b/ananke/phoenix/windows/action/action.cpp deleted file mode 100644 index b80208d1..00000000 --- a/ananke/phoenix/windows/action/action.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::setVisible(bool visible) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::constructor() { - parentMenu = 0; - parentWindow = 0; -} diff --git a/ananke/phoenix/windows/action/check-item.cpp b/ananke/phoenix/windows/action/check-item.cpp deleted file mode 100644 index 195deabd..00000000 --- a/ananke/phoenix/windows/action/check-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pCheckItem::checked() { - return checkItem.state.checked; -} - -void pCheckItem::setChecked(bool checked) { - if(parentMenu) CheckMenuItem(parentMenu->p.hmenu, id, checked ? MF_CHECKED : MF_UNCHECKED); -} - -void pCheckItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { - if(parentMenu) parentMenu->remove(checkItem); -} diff --git a/ananke/phoenix/windows/action/item.cpp b/ananke/phoenix/windows/action/item.cpp deleted file mode 100644 index 2804bfcb..00000000 --- a/ananke/phoenix/windows/action/item.cpp +++ /dev/null @@ -1,29 +0,0 @@ -void pItem::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::constructor() { - createBitmap(); -} - -void pItem::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) parentMenu->remove(item); -} - -void pItem::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(item.state.image.width && item.state.image.height) { - nall::image nallImage = item.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} diff --git a/ananke/phoenix/windows/action/menu.cpp b/ananke/phoenix/windows/action/menu.cpp deleted file mode 100644 index 5d9da04e..00000000 --- a/ananke/phoenix/windows/action/menu.cpp +++ /dev/null @@ -1,109 +0,0 @@ -void pMenu::append(Action &action) { - action.p.parentMenu = &menu; - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::remove(Action &action) { - if(parentWindow) parentWindow->p.updateMenu(); - action.p.parentMenu = 0; -} - -void pMenu::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::constructor() { - hmenu = 0; - createBitmap(); -} - -void pMenu::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) { - parentMenu->remove(menu); - } else if(parentWindow) { - //belongs to window's main menubar - parentWindow->remove(menu); - } -} - -void pMenu::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(menu.state.image.width && menu.state.image.height) { - nall::image nallImage = menu.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} - -//Windows actions lack the ability to toggle visibility. -//To support this, menus must be destroyed and recreated when toggling any action's visibility. -void pMenu::update(Window &parentWindow, Menu *parentMenu) { - this->parentMenu = parentMenu; - this->parentWindow = &parentWindow; - - if(hmenu) DestroyMenu(hmenu); - hmenu = CreatePopupMenu(); - - for(auto &action : menu.state.action) { - action.p.parentMenu = &menu; - action.p.parentWindow = &parentWindow; - - unsigned enabled = action.state.enabled ? 0 : MF_GRAYED; - if(dynamic_cast(&action)) { - Menu &item = (Menu&)action; - if(action.state.visible) { - item.p.update(parentWindow, &menu); - AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, (UINT_PTR)item.p.hmenu, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - Separator &item = (Separator&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L""); - } - } else if(dynamic_cast(&action)) { - Item &item = (Item&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, item.p.id, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - CheckItem &item = (CheckItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } else if(dynamic_cast(&action)) { - RadioItem &item = (RadioItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } - } -} diff --git a/ananke/phoenix/windows/action/radio-item.cpp b/ananke/phoenix/windows/action/radio-item.cpp deleted file mode 100644 index 6b4f3a31..00000000 --- a/ananke/phoenix/windows/action/radio-item.cpp +++ /dev/null @@ -1,26 +0,0 @@ -bool pRadioItem::checked() { - return radioItem.state.checked; -} - -void pRadioItem::setChecked() { - for(auto &item : radioItem.state.group) { - //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi - //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) - //to check id, we use: lo == hi == id (only ID, but in range) - if(item.p.parentMenu) CheckMenuRadioItem(item.p.parentMenu->p.hmenu, item.p.id, item.p.id, item.p.id + (id != item.p.id), MF_BYCOMMAND); - } -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { - if(parentMenu) parentMenu->remove(radioItem); -} diff --git a/ananke/phoenix/windows/action/separator.cpp b/ananke/phoenix/windows/action/separator.cpp deleted file mode 100644 index fac38eca..00000000 --- a/ananke/phoenix/windows/action/separator.cpp +++ /dev/null @@ -1,6 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { - if(parentMenu) parentMenu->remove(separator); -} diff --git a/ananke/phoenix/windows/desktop.cpp b/ananke/phoenix/windows/desktop.cpp deleted file mode 100644 index 956ba521..00000000 --- a/ananke/phoenix/windows/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - return { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) }; -} - -Geometry pDesktop::workspace() { - RECT rc; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top }; -} diff --git a/ananke/phoenix/windows/dialog-window.cpp b/ananke/phoenix/windows/dialog-window.cpp deleted file mode 100644 index 5ef21153..00000000 --- a/ananke/phoenix/windows/dialog-window.cpp +++ /dev/null @@ -1,98 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string dir = path; - dir.replace("/", "\\"); - - string filterList; - for(auto &filterItem : filter) { - lstring part; - part.split("(", filterItem); - if(part.size() != 2) continue; - part[1].rtrim<1>(")"); - part[1].replace(" ", ""); - part[1].transform(",", ";"); - filterList.append(string(filterItem, "\t", part[1], "\t")); - } - - utf16_t wfilter(filterList); - utf16_t wdir(dir); - wchar_t wfilename[PATH_MAX + 1] = L""; - - wchar_t *p = wfilter; - while(*p != L'\0') { - if(*p == L'\t') *p = L'\0'; - p++; - } - - if(path.empty() == false) { - //clear COMDLG32 MRU (most recently used) file list - //this is required in order for lpstrInitialDir to be honored in Windows 7 and above - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/LastVisitedPidlMRU/"); - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/OpenSavePidlMRU/"); - } - - OPENFILENAME ofn; - memset(&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - ofn.lpstrFilter = wfilter; - ofn.lpstrInitialDir = wdir; - ofn.lpstrFile = wfilename; - ofn.nMaxFile = PATH_MAX; - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - ofn.lpstrDefExt = L""; - - bool result = (save == false ? GetOpenFileName(&ofn) : GetSaveFileName(&ofn)); - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - name.transform("\\", "/"); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(false, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(true, parent, path, filter); -} - -static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpdata) { - if(msg == BFFM_INITIALIZED) { - if(lpdata) SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpdata); - } - - return 0; -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - wchar_t wfilename[PATH_MAX + 1] = L""; - utf16_t wpath(string{path}.transform("/", "\\")); - - BROWSEINFO bi; - bi.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - bi.pidlRoot = NULL; - bi.pszDisplayName = wfilename; - bi.lpszTitle = L""; - bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS; - bi.lpfn = BrowseCallbackProc; - bi.lParam = (LPARAM)(wchar_t*)wpath; - bi.iImage = 0; - bool result = false; - LPITEMIDLIST pidl = SHBrowseForFolder(&bi); - if(pidl) { - if(SHGetPathFromIDList(pidl, wfilename)) { - result = true; - IMalloc *imalloc = 0; - if(SUCCEEDED(SHGetMalloc(&imalloc))) { - imalloc->Free(pidl); - imalloc->Release(); - } - } - } - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - if(name == "") return ""; - name.transform("\\", "/"); - if(name.endswith("/") == false) name.append("/"); - return name; -} \ No newline at end of file diff --git a/ananke/phoenix/windows/font.cpp b/ananke/phoenix/windows/font.cpp deleted file mode 100644 index de42f24d..00000000 --- a/ananke/phoenix/windows/font.cpp +++ /dev/null @@ -1,44 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - HFONT hfont = pFont::create(description); - Geometry geometry = pFont::geometry(hfont, text); - pFont::free(hfont); - return geometry; -} - -HFONT pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - return CreateFont( - -(size * 96.0 / 72.0 + 0.5), - 0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, 0, 0, 0, 0, 0, 0, 0, - utf16_t(family) - ); -} - -void pFont::free(HFONT hfont) { - DeleteObject(hfont); -} - -Geometry pFont::geometry(HFONT hfont, const string &text_) { - //temporary fix: empty text string returns height of zero; bad for eg Button height - string text = (text_ == "" ? " " : text_); - - HDC hdc = GetDC(0); - SelectObject(hdc, hfont); - RECT rc = { 0, 0, 0, 0 }; - DrawText(hdc, utf16_t(text), -1, &rc, DT_CALCRECT); - ReleaseDC(0, hdc); - return { 0, 0, rc.right, rc.bottom }; -} diff --git a/ananke/phoenix/windows/keyboard.cpp b/ananke/phoenix/windows/keyboard.cpp deleted file mode 100644 index 1edffcb3..00000000 --- a/ananke/phoenix/windows/keyboard.cpp +++ /dev/null @@ -1,137 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, keysym); - }; - - append(Keyboard::Scancode::Escape, VK_ESCAPE); - append(Keyboard::Scancode::F1, VK_F1); - append(Keyboard::Scancode::F2, VK_F2); - append(Keyboard::Scancode::F3, VK_F3); - append(Keyboard::Scancode::F4, VK_F4); - append(Keyboard::Scancode::F5, VK_F5); - append(Keyboard::Scancode::F6, VK_F6); - append(Keyboard::Scancode::F7, VK_F7); - append(Keyboard::Scancode::F8, VK_F8); - append(Keyboard::Scancode::F9, VK_F9); - append(Keyboard::Scancode::F10, VK_F10); - append(Keyboard::Scancode::F11, VK_F11); - append(Keyboard::Scancode::F12, VK_F12); - - append(Keyboard::Scancode::PrintScreen, VK_SNAPSHOT); - append(Keyboard::Scancode::ScrollLock, VK_SCROLL); - append(Keyboard::Scancode::Pause, VK_PAUSE); - - append(Keyboard::Scancode::Insert, VK_INSERT); - append(Keyboard::Scancode::Delete, VK_DELETE); - append(Keyboard::Scancode::Home, VK_HOME); - append(Keyboard::Scancode::End, VK_END); - append(Keyboard::Scancode::PageUp, VK_PRIOR); - append(Keyboard::Scancode::PageDown, VK_NEXT); - - append(Keyboard::Scancode::Up, VK_UP); - append(Keyboard::Scancode::Down, VK_DOWN); - append(Keyboard::Scancode::Left, VK_LEFT); - append(Keyboard::Scancode::Right, VK_RIGHT); - - append(Keyboard::Scancode::Grave, VK_OEM_3); - append(Keyboard::Scancode::Number1, '1'); - append(Keyboard::Scancode::Number2, '2'); - append(Keyboard::Scancode::Number3, '3'); - append(Keyboard::Scancode::Number4, '4'); - append(Keyboard::Scancode::Number5, '5'); - append(Keyboard::Scancode::Number6, '6'); - append(Keyboard::Scancode::Number7, '7'); - append(Keyboard::Scancode::Number8, '8'); - append(Keyboard::Scancode::Number9, '9'); - append(Keyboard::Scancode::Number0, '0'); - append(Keyboard::Scancode::Minus, VK_OEM_MINUS); - append(Keyboard::Scancode::Equal, VK_OEM_PLUS); - append(Keyboard::Scancode::Backspace, VK_BACK); - - append(Keyboard::Scancode::BracketLeft, VK_OEM_4); - append(Keyboard::Scancode::BracketRight, VK_OEM_6); - append(Keyboard::Scancode::Backslash, VK_OEM_5); - append(Keyboard::Scancode::Semicolon, VK_OEM_1); - append(Keyboard::Scancode::Apostrophe, VK_OEM_7); - append(Keyboard::Scancode::Comma, VK_OEM_COMMA); - append(Keyboard::Scancode::Period, VK_OEM_PERIOD); - append(Keyboard::Scancode::Slash, VK_OEM_2); - - append(Keyboard::Scancode::Tab, VK_TAB); - append(Keyboard::Scancode::CapsLock, VK_CAPITAL); - append(Keyboard::Scancode::Return, VK_RETURN); - append(Keyboard::Scancode::ShiftLeft, VK_LSHIFT); - append(Keyboard::Scancode::ShiftRight, VK_RSHIFT); - append(Keyboard::Scancode::ControlLeft, VK_LCONTROL); - append(Keyboard::Scancode::ControlRight, VK_RCONTROL); - append(Keyboard::Scancode::SuperLeft, VK_LWIN); - append(Keyboard::Scancode::SuperRight, VK_RWIN); - append(Keyboard::Scancode::AltLeft, VK_LMENU); - append(Keyboard::Scancode::AltRight, VK_RMENU); - append(Keyboard::Scancode::Space, VK_SPACE); - append(Keyboard::Scancode::Menu, VK_APPS); - - append(Keyboard::Scancode::A, 'A'); - append(Keyboard::Scancode::B, 'B'); - append(Keyboard::Scancode::C, 'C'); - append(Keyboard::Scancode::D, 'D'); - append(Keyboard::Scancode::E, 'E'); - append(Keyboard::Scancode::F, 'F'); - append(Keyboard::Scancode::G, 'G'); - append(Keyboard::Scancode::H, 'H'); - append(Keyboard::Scancode::I, 'I'); - append(Keyboard::Scancode::J, 'J'); - append(Keyboard::Scancode::K, 'K'); - append(Keyboard::Scancode::L, 'L'); - append(Keyboard::Scancode::M, 'M'); - append(Keyboard::Scancode::N, 'N'); - append(Keyboard::Scancode::O, 'O'); - append(Keyboard::Scancode::P, 'P'); - append(Keyboard::Scancode::Q, 'Q'); - append(Keyboard::Scancode::R, 'R'); - append(Keyboard::Scancode::S, 'S'); - append(Keyboard::Scancode::T, 'T'); - append(Keyboard::Scancode::U, 'U'); - append(Keyboard::Scancode::V, 'V'); - append(Keyboard::Scancode::W, 'W'); - append(Keyboard::Scancode::X, 'X'); - append(Keyboard::Scancode::Y, 'Y'); - append(Keyboard::Scancode::Z, 'Z'); - - append(Keyboard::Scancode::NumLock, VK_NUMLOCK); - append(Keyboard::Scancode::Divide, VK_DIVIDE); - append(Keyboard::Scancode::Multiply, VK_MULTIPLY); - append(Keyboard::Scancode::Subtract, VK_SUBTRACT); - append(Keyboard::Scancode::Add, VK_ADD); -//append(Keyboard::Scancode::Enter, ...); - append(Keyboard::Scancode::Point, VK_DECIMAL); - - append(Keyboard::Scancode::Keypad1, VK_NUMPAD1); - append(Keyboard::Scancode::Keypad2, VK_NUMPAD2); - append(Keyboard::Scancode::Keypad3, VK_NUMPAD3); - append(Keyboard::Scancode::Keypad4, VK_NUMPAD4); - append(Keyboard::Scancode::Keypad5, VK_NUMPAD5); - append(Keyboard::Scancode::Keypad6, VK_NUMPAD6); - append(Keyboard::Scancode::Keypad7, VK_NUMPAD7); - append(Keyboard::Scancode::Keypad8, VK_NUMPAD8); - append(Keyboard::Scancode::Keypad9, VK_NUMPAD9); - append(Keyboard::Scancode::Keypad0, VK_NUMPAD0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return GetAsyncKeyState(settings->keymap.lhs[scancode]) & 0x8000; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - for(auto &n : settings->keymap.rhs) { - if(GetAsyncKeyState(n.name) & 0x8000) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/ananke/phoenix/windows/message-window.cpp b/ananke/phoenix/windows/message-window.cpp deleted file mode 100644 index fca126f4..00000000 --- a/ananke/phoenix/windows/message-window.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, UINT response) { - if(response == IDOK) return MessageWindow::Response::Ok; - if(response == IDCANCEL) return MessageWindow::Response::Cancel; - if(response == IDYES) return MessageWindow::Response::Yes; - if(response == IDNO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONINFORMATION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONQUESTION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONWARNING; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONERROR; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} diff --git a/ananke/phoenix/windows/mouse.cpp b/ananke/phoenix/windows/mouse.cpp deleted file mode 100644 index e5004645..00000000 --- a/ananke/phoenix/windows/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - POINT point = { 0 }; - GetCursorPos(&point); - return { point.x, point.y }; -} - -bool pMouse::pressed(Mouse::Button button) { - switch(button) { - case Mouse::Button::Left: return GetAsyncKeyState(VK_LBUTTON) & 0x8000; - case Mouse::Button::Middle: return GetAsyncKeyState(VK_MBUTTON) & 0x8000; - case Mouse::Button::Right: return GetAsyncKeyState(VK_RBUTTON) & 0x8000; - } - return false; -} \ No newline at end of file diff --git a/ananke/phoenix/windows/object.cpp b/ananke/phoenix/windows/object.cpp deleted file mode 100644 index 78811d79..00000000 --- a/ananke/phoenix/windows/object.cpp +++ /dev/null @@ -1,13 +0,0 @@ -vector pObject::objects; - -pObject::pObject(Object &object) : object(object) { - static unsigned uniqueId = 100; - objects.append(this); - id = uniqueId++; - locked = false; -} - -pObject* pObject::find(unsigned id) { - for(auto &item : objects) if(item->id == id) return item; - return 0; -} diff --git a/ananke/phoenix/windows/platform.cpp b/ananke/phoenix/windows/platform.cpp deleted file mode 100644 index 1214f2c2..00000000 --- a/ananke/phoenix/windows/platform.cpp +++ /dev/null @@ -1,479 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "object.cpp" -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -static bool OS_keyboardProc(HWND, UINT, WPARAM, LPARAM); -static void OS_processDialogMessage(MSG&); -static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM); - -void pOS::main() { - MSG msg; - while(GetMessage(&msg, 0, 0, 0)) { - OS_processDialogMessage(msg); - } -} - -bool pOS::pendingEvents() { - MSG msg; - return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); -} - -void pOS::processEvents() { - while(pendingEvents()) { - MSG msg; - if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { - OS_processDialogMessage(msg); - } - } -} - -void OS_processDialogMessage(MSG &msg) { - if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP - || msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) { - if(OS_keyboardProc(msg.hwnd, msg.message, msg.wParam, msg.lParam)) { - DispatchMessage(&msg); - return; - } - } - - if(!IsDialogMessage(GetForegroundWindow(), &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -void pOS::quit() { - osQuit = true; - PostQuitMessage(0); -} - -void pOS::initialize() { - CoInitialize(0); - InitCommonControls(); - - WNDCLASS wc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(2)); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = OS_windowProc; - wc.lpszClassName = L"phoenix_window"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Canvas_windowProc; - wc.lpszClassName = L"phoenix_canvas"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Label_windowProc; - wc.lpszClassName = L"phoenix_label"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Viewport_windowProc; - wc.lpszClassName = L"phoenix_viewport"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - settings = new Settings; - pKeyboard::initialize(); -} - -static bool OS_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - if(msg != WM_KEYDOWN && msg != WM_SYSKEYDOWN && msg != WM_KEYUP && msg != WM_SYSKEYUP) return false; - - GUITHREADINFO info; - memset(&info, 0, sizeof(GUITHREADINFO)); - info.cbSize = sizeof(GUITHREADINFO); - GetGUIThreadInfo(GetCurrentThreadId(), &info); - Object *object = (Object*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA); - if(object == nullptr) return false; - - if(dynamic_cast(object)) { - Window &window = (Window&)*object; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) return false; - Keyboard::Keycode keysym = Keysym(wparam, lparam); - if(keysym != Keyboard::Keycode::None) { - if((msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) && window.onKeyPress) window.onKeyPress(keysym); - if((msg == WM_KEYUP || msg == WM_SYSKEYUP) && window.onKeyRelease) window.onKeyRelease(keysym); - } - return false; - } - - if(msg == WM_KEYDOWN) { - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - if(wparam == VK_RETURN) { - if(listView.onActivate) listView.onActivate(); - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(wparam == VK_RETURN) { - if(lineEdit.onActivate) lineEdit.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(wparam == 'A' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+A = select all text - //note: this is not a standard accelerator on Windows - Edit_SetSel(textEdit.p.hwnd, 0, ~0); - return true; - } else if(wparam == 'V' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+V = paste text - //note: this formats Unix (LF) and OS9 (CR) line-endings to Windows (CR+LF) line-endings - //this is necessary as the EDIT control only supports Windows line-endings - OpenClipboard(hwnd); - HANDLE handle = GetClipboardData(CF_UNICODETEXT); - if(handle) { - wchar_t *text = (wchar_t*)GlobalLock(handle); - if(text) { - string data = (const char*)utf8_t(text); - data.replace("\r\n", "\n"); - data.replace("\r", "\n"); - data.replace("\n", "\r\n"); - GlobalUnlock(handle); - utf16_t output(data); - HGLOBAL resource = GlobalAlloc(GMEM_MOVEABLE, (wcslen(output) + 1) * sizeof(wchar_t)); - if(resource) { - wchar_t *write = (wchar_t*)GlobalLock(resource); - if(write) { - wcscpy(write, output); - GlobalUnlock(write); - if(SetClipboardData(CF_UNICODETEXT, resource) == FALSE) { - GlobalFree(resource); - } - } - } - } - } - CloseClipboard(); - return false; - } - } - } - - return false; -} - -static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!object || !dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Window &window = (Window&)*object; - - bool process = true; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) process = false; - if(osQuit) process = false; - - if(process) switch(msg) { - case WM_CLOSE: { - window.state.ignore = false; - if(window.onClose) window.onClose(); - if(window.state.ignore == false) { - window.setVisible(false); - window.setModal(false); - } - return TRUE; - } - - case WM_MOVE: { - if(window.p.locked) break; - - Geometry geometry = window.geometry(); - window.state.geometry.x = geometry.x; - window.state.geometry.y = geometry.y; - - if(window.onMove) window.onMove(); - break; - } - - case WM_SIZE: { - if(window.p.locked) break; - SetWindowPos(window.p.hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - - Geometry geometry = window.geometry(); - window.state.geometry.width = geometry.width; - window.state.geometry.height = geometry.height; - - for(auto &layout : window.state.layout) { - Geometry geom = window.geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - - if(window.onSize) window.onSize(); - break; - } - - case WM_GETMINMAXINFO: { - MINMAXINFO *mmi = (MINMAXINFO*)lparam; - //mmi->ptMinTrackSize.x = 256 + window.p.frameMargin().width; - //mmi->ptMinTrackSize.y = 256 + window.p.frameMargin().height; - //return TRUE; - break; - } - - case WM_ERASEBKGND: { - if(window.p.brush == 0) break; - RECT rc; - GetClientRect(window.p.hwnd, &rc); - PAINTSTRUCT ps; - BeginPaint(window.p.hwnd, &ps); - FillRect(ps.hdc, &rc, window.p.brush); - EndPaint(window.p.hwnd, &ps); - return TRUE; - } - - case WM_CTLCOLORBTN: - case WM_CTLCOLORSTATIC: { - Object *object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - if(object && window.p.brush) { - HDC hdc = (HDC)wparam; - SetBkColor((HDC)wparam, window.p.brushColor); - return (INT_PTR)window.p.brush; - } - break; - } - - case WM_COMMAND: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) { - pObject *object = (pObject*)pObject::find(id); - if(!object) break; - if(dynamic_cast(object)) { - Item &item = ((pItem*)object)->item; - if(item.onActivate) item.onActivate(); - } else if(dynamic_cast(object)) { - CheckItem &checkItem = ((pCheckItem*)object)->checkItem; - checkItem.setChecked(!checkItem.state.checked); - if(checkItem.onToggle) checkItem.onToggle(); - } else if(dynamic_cast(object)) { - RadioItem &radioItem = ((pRadioItem*)object)->radioItem; - if(radioItem.state.checked == false) { - radioItem.setChecked(); - if(radioItem.onActivate) radioItem.onActivate(); - } - } - } else { - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(!object) break; - if(dynamic_cast(object)) { - Button &button = (Button&)*object; - if(button.onActivate) button.onActivate(); - } else if(dynamic_cast(object)) { - CheckBox &checkBox = (CheckBox&)*object; - checkBox.setChecked(!checkBox.state.checked); - if(checkBox.onToggle) checkBox.onToggle(); - } else if(dynamic_cast(object)) { - ComboBox &comboBox = (ComboBox&)*object; - if(HIWORD(wparam) == CBN_SELCHANGE) { - if(comboBox.state.selection != comboBox.selection()) { - comboBox.state.selection = comboBox.selection(); - if(comboBox.onChange) comboBox.onChange(); - } - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(lineEdit.p.locked == false && lineEdit.onChange) lineEdit.onChange(); - } - } else if(dynamic_cast(object)) { - RadioBox &radioBox = (RadioBox&)*object; - if(radioBox.state.checked == false) { - radioBox.setChecked(); - if(radioBox.onActivate) radioBox.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(textEdit.p.locked == false && textEdit.onChange) textEdit.onChange(); - } - } - } - break; - } - - case WM_NOTIFY: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(object == 0) break; - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - LPNMHDR nmhdr = (LPNMHDR)lparam; - LPNMLISTVIEW nmlistview = (LPNMLISTVIEW)lparam; - - if(nmhdr->code == LVN_ITEMCHANGED && (nmlistview->uChanged & LVIF_STATE)) { - unsigned imagemask = ((nmlistview->uNewState & LVIS_STATEIMAGEMASK) >> 12) - 1; - if(imagemask == 0 || imagemask == 1) { - if(listView.p.locked == false && listView.onToggle) listView.onToggle(nmlistview->iItem); - } else if((nmlistview->uOldState & LVIS_FOCUSED) && !(nmlistview->uNewState & LVIS_FOCUSED)) { - listView.p.lostFocus = true; - } else if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) { - listView.p.lostFocus = false; - listView.state.selected = true; - listView.state.selection = listView.selection(); - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } else if(listView.p.lostFocus == false && listView.selected() == false) { - listView.p.lostFocus = false; - listView.state.selected = false; - listView.state.selection = 0; - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } - } else if(nmhdr->code == LVN_ITEMACTIVATE) { - if(listView.onActivate) listView.onActivate(); - } else if(nmhdr->code == NM_CUSTOMDRAW) { - LPNMLVCUSTOMDRAW lvcd = (LPNMLVCUSTOMDRAW)nmhdr; - switch(lvcd->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - return CDRF_NOTIFYITEMDRAW; - case CDDS_ITEMPREPAINT: - if(listView.state.headerText.size() >= 2) { - //draw alternating row colors of there are two or more columns - if(lvcd->nmcd.dwItemSpec % 2) lvcd->clrTextBk = GetSysColor(COLOR_WINDOW) ^ 0x070707; - } - return CDRF_DODEFAULT; - default: - return CDRF_DODEFAULT; - } - } - } - break; - } - - case WM_HSCROLL: - case WM_VSCROLL: { - Object *object = 0; - if(lparam) { - object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - } else { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - } - if(object == 0) break; - - if(dynamic_cast(object) - || dynamic_cast(object)) { - SCROLLINFO info; - memset(&info, 0, sizeof(SCROLLINFO)); - info.cbSize = sizeof(SCROLLINFO); - info.fMask = SIF_ALL; - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - switch(LOWORD(wparam)) { - case SB_LEFT: info.nPos = info.nMin; break; - case SB_RIGHT: info.nPos = info.nMax; break; - case SB_LINELEFT: info.nPos--; break; - case SB_LINERIGHT: info.nPos++; break; - case SB_PAGELEFT: info.nPos -= info.nMax >> 3; break; - case SB_PAGERIGHT: info.nPos += info.nMax >> 3; break; - case SB_THUMBTRACK: info.nPos = info.nTrackPos; break; - } - - info.fMask = SIF_POS; - SetScrollInfo((HWND)lparam, SB_CTL, &info, TRUE); - - //Windows may clamp position to scrollbar range - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - if(dynamic_cast(object)) { - HorizontalScrollBar &horizontalScrollBar = (HorizontalScrollBar&)*object; - if(horizontalScrollBar.state.position != info.nPos) { - horizontalScrollBar.state.position = info.nPos; - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); - } - } else { - VerticalScrollBar &verticalScrollBar = (VerticalScrollBar&)*object; - if(verticalScrollBar.state.position != info.nPos) { - verticalScrollBar.state.position = info.nPos; - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); - } - } - - return TRUE; - } - - if(dynamic_cast(object)) { - HorizontalSlider &horizontalSlider = (HorizontalSlider&)*object; - if(horizontalSlider.state.position != horizontalSlider.position()) { - horizontalSlider.state.position = horizontalSlider.position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); - } - } else if(dynamic_cast(object)) { - VerticalSlider &verticalSlider = (VerticalSlider&)*object; - if(verticalSlider.state.position != verticalSlider.position()) { - verticalSlider.state.position = verticalSlider.position(); - if(verticalSlider.onChange) verticalSlider.onChange(); - } - } - - break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/ananke/phoenix/windows/platform.hpp b/ananke/phoenix/windows/platform.hpp deleted file mode 100644 index d14685b2..00000000 --- a/ananke/phoenix/windows/platform.hpp +++ /dev/null @@ -1,484 +0,0 @@ -struct Settings { - bidirectional_map keymap; -}; - -struct pFont; -struct pObject; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -static bool osQuit = false; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static HFONT create(const string &description); - static void free(HFONT hfont); - static Geometry geometry(HFONT hfont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - static vector objects; - - Object &object; - uintptr_t id; - bool locked; - - pObject(Object &object); - static pObject* find(unsigned id); - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - UINT_PTR htimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - static vector modal; - static void updateModality(); - - Window &window; - HWND hwnd; - HMENU hmenu; - HWND hstatus; - HFONT hstatusfont; - HBRUSH brush; - COLORREF brushColor; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateMenu(); -}; - -struct pAction : public pObject { - Action &action; - Menu *parentMenu; - Window *parentWindow; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - HMENU hmenu; - HBITMAP hbitmap; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); - void update(Window &parentWindow, Menu *parentMenu = 0); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - HBITMAP hbitmap; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - Window *parentWindow; - HWND hwnd; - HFONT hfont; - - bool enabled(); - bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) { parentWindow = &Window::none(); } - void constructor(); - void destructor(); - virtual void orphan(); - void setDefaultFont(); - void synchronize(); -}; - -struct pButton : public pWidget { - Button &button; - HBITMAP hbitmap; - HIMAGELIST himagelist; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button), hbitmap(0), himagelist(0) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - uint32_t *data; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - void paint(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - LRESULT CALLBACK (*windowProc)(HWND, UINT, LPARAM, WPARAM); - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - bool keyPress(unsigned key); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - HIMAGELIST imageList; - vector> imageMap; - vector images; - bool lostFocus; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView), imageList(nullptr) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); - void buildImageList(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/ananke/phoenix/windows/settings.cpp b/ananke/phoenix/windows/settings.cpp deleted file mode 100644 index 343fc9fb..00000000 --- a/ananke/phoenix/windows/settings.cpp +++ /dev/null @@ -1 +0,0 @@ -static Settings *settings = nullptr; \ No newline at end of file diff --git a/ananke/phoenix/windows/timer.cpp b/ananke/phoenix/windows/timer.cpp deleted file mode 100644 index 99fb5c00..00000000 --- a/ananke/phoenix/windows/timer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static vector timers; - -static void CALLBACK Timer_timeoutProc(HWND hwnd, UINT msg, UINT_PTR timerID, DWORD time) { - for(auto &timer : timers) { - if(timer->htimer == timerID) { - if(timer->timer.onTimeout) timer->timer.onTimeout(); - return; - } - } -} - -void pTimer::setEnabled(bool enabled) { - if(htimer) { - KillTimer(NULL, htimer); - htimer = 0; - } - - if(enabled == true) { - htimer = SetTimer(NULL, 0U, timer.state.milliseconds, Timer_timeoutProc); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - //destroy and recreate timer if interval changed - setEnabled(timer.state.enabled); -} - -void pTimer::constructor() { - timers.append(this); - htimer = 0; -} diff --git a/ananke/phoenix/windows/utility.cpp b/ananke/phoenix/windows/utility.cpp deleted file mode 100644 index c247d5cc..00000000 --- a/ananke/phoenix/windows/utility.cpp +++ /dev/null @@ -1,150 +0,0 @@ -static const unsigned Windows2000 = 0x0500; -static const unsigned WindowsXP = 0x0501; -static const unsigned WindowsVista = 0x0600; -static const unsigned Windows7 = 0x0601; - -static unsigned OsVersion() { - OSVERSIONINFO versionInfo = { 0 }; - versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&versionInfo); - return (versionInfo.dwMajorVersion << 8) + (versionInfo.dwMajorVersion << 0); -} - -static HBITMAP CreateBitmap(const image &image) { - HDC hdc = GetDC(0); - BITMAPINFO bitmapInfo; - memset(&bitmapInfo, 0, sizeof(BITMAPINFO)); - bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bitmapInfo.bmiHeader.biWidth = image.width; - bitmapInfo.bmiHeader.biHeight = -image.height; //bitmaps are stored upside down unless we negate height - bitmapInfo.bmiHeader.biPlanes = 1; - bitmapInfo.bmiHeader.biBitCount = 32; - bitmapInfo.bmiHeader.biCompression = BI_RGB; - bitmapInfo.bmiHeader.biSizeImage = image.width * image.height * 4; - void *bits = nullptr; - HBITMAP hbitmap = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0); - if(bits) memcpy(bits, image.data, image.width * image.height * 4); - ReleaseDC(0, hdc); - return hbitmap; -} - -static Keyboard::Keycode Keysym(unsigned keysym, unsigned keyflags) { - #define pressed(keysym) (GetAsyncKeyState(keysym) & 0x8000) - #define enabled(keysym) (GetKeyState(keysym)) - #define shifted() (pressed(VK_LSHIFT) || pressed(VK_RSHIFT)) - #define extended() (keyflags & (1 << 24)) - - switch(keysym) { - case VK_ESCAPE: return Keyboard::Keycode::Escape; - case VK_F1: return Keyboard::Keycode::F1; - case VK_F2: return Keyboard::Keycode::F2; - case VK_F3: return Keyboard::Keycode::F3; - case VK_F4: return Keyboard::Keycode::F4; - case VK_F5: return Keyboard::Keycode::F5; - case VK_F6: return Keyboard::Keycode::F6; - case VK_F7: return Keyboard::Keycode::F7; - case VK_F8: return Keyboard::Keycode::F8; - case VK_F9: return Keyboard::Keycode::F9; - //Keyboard::Keycode::F10 (should be captured under VK_MENU from WM_SYSKEY(UP,DOWN); but this is not working...) - case VK_F11: return Keyboard::Keycode::F11; - case VK_F12: return Keyboard::Keycode::F12; - - //Keyboard::Keycode::PrintScreen - //Keyboard::Keycode::SysRq - case VK_SCROLL: return Keyboard::Keycode::ScrollLock; - case VK_PAUSE: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case VK_INSERT: return extended() ? Keyboard::Keycode::Insert : Keyboard::Keycode::KeypadInsert; - case VK_DELETE: return extended() ? Keyboard::Keycode::Delete : Keyboard::Keycode::KeypadDelete; - case VK_HOME: return extended() ? Keyboard::Keycode::Home : Keyboard::Keycode::KeypadHome; - case VK_END: return extended() ? Keyboard::Keycode::End : Keyboard::Keycode::KeypadEnd; - case VK_PRIOR: return extended() ? Keyboard::Keycode::PageUp : Keyboard::Keycode::KeypadPageUp; - case VK_NEXT: return extended() ? Keyboard::Keycode::PageDown : Keyboard::Keycode::KeypadPageDown; - - case VK_UP: return extended() ? Keyboard::Keycode::Up : Keyboard::Keycode::KeypadUp; - case VK_DOWN: return extended() ? Keyboard::Keycode::Down : Keyboard::Keycode::KeypadDown; - case VK_LEFT: return extended() ? Keyboard::Keycode::Left : Keyboard::Keycode::KeypadLeft; - case VK_RIGHT: return extended() ? Keyboard::Keycode::Right : Keyboard::Keycode::KeypadRight; - - case VK_OEM_3: return !shifted() ? Keyboard::Keycode::Grave : Keyboard::Keycode::Tilde; - case '1': return !shifted() ? Keyboard::Keycode::Number1 : Keyboard::Keycode::Exclamation; - case '2': return !shifted() ? Keyboard::Keycode::Number2 : Keyboard::Keycode::At; - case '3': return !shifted() ? Keyboard::Keycode::Number3 : Keyboard::Keycode::Pound; - case '4': return !shifted() ? Keyboard::Keycode::Number4 : Keyboard::Keycode::Dollar; - case '5': return !shifted() ? Keyboard::Keycode::Number5 : Keyboard::Keycode::Percent; - case '6': return !shifted() ? Keyboard::Keycode::Number6 : Keyboard::Keycode::Power; - case '7': return !shifted() ? Keyboard::Keycode::Number7 : Keyboard::Keycode::Ampersand; - case '8': return !shifted() ? Keyboard::Keycode::Number8 : Keyboard::Keycode::Asterisk; - case '9': return !shifted() ? Keyboard::Keycode::Number9 : Keyboard::Keycode::ParenthesisLeft; - case '0': return !shifted() ? Keyboard::Keycode::Number0 : Keyboard::Keycode::ParenthesisRight; - case VK_OEM_MINUS: return !shifted() ? Keyboard::Keycode::Minus : Keyboard::Keycode::Underscore; - case VK_OEM_PLUS: return !shifted() ? Keyboard::Keycode::Equal : Keyboard::Keycode::Plus; - case VK_BACK: return Keyboard::Keycode::Backspace; - - case VK_OEM_4: return !shifted() ? Keyboard::Keycode::BracketLeft : Keyboard::Keycode::BraceLeft; - case VK_OEM_6: return !shifted() ? Keyboard::Keycode::BracketRight : Keyboard::Keycode::BraceRight; - case VK_OEM_5: return !shifted() ? Keyboard::Keycode::Backslash : Keyboard::Keycode::Pipe; - case VK_OEM_1: return !shifted() ? Keyboard::Keycode::Semicolon : Keyboard::Keycode::Colon; - case VK_OEM_7: return !shifted() ? Keyboard::Keycode::Apostrophe : Keyboard::Keycode::Quote; - case VK_OEM_COMMA: return !shifted() ? Keyboard::Keycode::Comma : Keyboard::Keycode::CaretLeft; - case VK_OEM_PERIOD: return !shifted() ? Keyboard::Keycode::Period : Keyboard::Keycode::CaretRight; - case VK_OEM_2: return !shifted() ? Keyboard::Keycode::Slash : Keyboard::Keycode::Question; - - case VK_TAB: return Keyboard::Keycode::Tab; - case VK_CAPITAL: return Keyboard::Keycode::CapsLock; - case VK_RETURN: return !extended() ? Keyboard::Keycode::Return : Keyboard::Keycode::Enter; - case VK_SHIFT: return !pressed(VK_RSHIFT) ? Keyboard::Keycode::ShiftLeft : Keyboard::Keycode::ShiftRight; - case VK_CONTROL: return !pressed(VK_RCONTROL) ? Keyboard::Keycode::ControlLeft : Keyboard::Keycode::ControlRight; - case VK_LWIN: return Keyboard::Keycode::SuperLeft; - case VK_RWIN: return Keyboard::Keycode::SuperRight; - case VK_MENU: - if(keyflags & (1 << 24)) return Keyboard::Keycode::AltRight; - return Keyboard::Keycode::AltLeft; - case VK_SPACE: return Keyboard::Keycode::Space; - case VK_APPS: return Keyboard::Keycode::Menu; - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': - case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': - if(enabled(VK_CAPITAL)) { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } - } else { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } - } - break; - - case VK_NUMLOCK: return Keyboard::Keycode::NumLock; - case VK_DIVIDE: return Keyboard::Keycode::Divide; - case VK_MULTIPLY: return Keyboard::Keycode::Multiply; - case VK_SUBTRACT: return Keyboard::Keycode::Subtract; - case VK_ADD: return Keyboard::Keycode::Add; - case VK_DECIMAL: return Keyboard::Keycode::Point; - case VK_NUMPAD1: return Keyboard::Keycode::Keypad1; - case VK_NUMPAD2: return Keyboard::Keycode::Keypad2; - case VK_NUMPAD3: return Keyboard::Keycode::Keypad3; - case VK_NUMPAD4: return Keyboard::Keycode::Keypad4; - case VK_NUMPAD5: return Keyboard::Keycode::Keypad5; - case VK_NUMPAD6: return Keyboard::Keycode::Keypad6; - case VK_NUMPAD7: return Keyboard::Keycode::Keypad7; - case VK_NUMPAD8: return Keyboard::Keycode::Keypad8; - case VK_NUMPAD9: return Keyboard::Keycode::Keypad9; - case VK_NUMPAD0: return Keyboard::Keycode::Keypad0; - - case VK_CLEAR: return Keyboard::Keycode::KeypadCenter; - } - - return Keyboard::Keycode::None; - - #undef pressed - #undef enabled - #undef shifted - #undef extended -} diff --git a/ananke/phoenix/windows/widget/button.cpp b/ananke/phoenix/windows/widget/button.cpp deleted file mode 100644 index 12cacbe5..00000000 --- a/ananke/phoenix/windows/widget/button.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef Button_SetImageList - //MinGW/32-bit has painfully outdated platform headers ... - typedef struct { - HIMAGELIST himl; - RECT margin; - UINT uAlign; - } BUTTON_IMAGELIST, *PBUTTON_IMAGELIST; - - #define BUTTON_IMAGELIST_ALIGN_LEFT 0 - #define BUTTON_IMAGELIST_ALIGN_RIGHT 1 - #define BUTTON_IMAGELIST_ALIGN_TOP 2 - #define BUTTON_IMAGELIST_ALIGN_BOTTOM 3 - #define BUTTON_IMAGELIST_ALIGN_CENTER 4 - - #define BCM_FIRST 0x1600 - #define BCM_SETIMAGELIST (BCM_FIRST+2) - #define Button_SetImageList(hwnd, pbuttonImagelist) (WINBOOL)SNDMSG((hwnd),BCM_SETIMAGELIST,0,(LPARAM)(pbuttonImagelist)) -#endif - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 10 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - nall::image nallImage = image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - - if(OsVersion() >= WindowsVista) { - hbitmap = CreateBitmap(nallImage); - SendMessage(hwnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmap); - switch(orientation) { - case Orientation::Horizontal: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_TOP); break; - case Orientation::Vertical: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_TOP); break; - } - } else { - //Windows XP and earlier cannot display bitmaps and text at the same time with BM_SETIMAGE - //Use BCM_SETIMAGELIST instead. It does not support alpha blending, so blend with button color - //The XP theme and above use a gradient fade background, so it won't be a perfect match there - nallImage.alphaBlend(GetSysColor(COLOR_BTNFACE)); - hbitmap = CreateBitmap(nallImage); - himagelist = ImageList_Create(nallImage.width, nallImage.height, ILC_COLOR32, 1, 0); - ImageList_Add(himagelist, hbitmap, NULL); - BUTTON_IMAGELIST list; - list.himl = himagelist; - switch(orientation) { - case Orientation::Horizontal: SetRect(&list.margin, 5, 0, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; break; - case Orientation::Vertical: SetRect(&list.margin, 0, 5, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_TOP; break; - } - Button_SetImageList(hwnd, &list); - } - - setText(button.state.text); //update text to display nicely with image (or lack thereof) -} - -void pButton::setText(const string &text) { - if(text.empty()) { - //bitmaps will not show up if text is empty - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_BITMAP); - } else { - //text will not show up if BS_BITMAP is set - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_BITMAP); - } - - if(OsVersion() >= WindowsVista && button.state.image.empty() == false && text.empty() == false) { - //Vista+ does not add spacing between the icon and text; causing them to run into each other - SetWindowText(hwnd, utf16_t(string{" ", text})); - } else { - SetWindowText(hwnd, utf16_t(text)); - } -} - -void pButton::constructor() { - hwnd = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&button); - setDefaultFont(); - setImage(button.state.image, button.state.orientation); -//setText(button.state.text); //called by setImage(); - synchronize(); -} - -void pButton::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - DestroyWindow(hwnd); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/canvas.cpp b/ananke/phoenix/windows/widget/canvas.cpp deleted file mode 100644 index f2be9e38..00000000 --- a/ananke/phoenix/windows/widget/canvas.cpp +++ /dev/null @@ -1,92 +0,0 @@ -static LRESULT CALLBACK Canvas_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Canvas &canvas = (Canvas&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_PAINT) { - canvas.p.paint(); - return TRUE; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(canvas.onMouseMove) canvas.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(canvas.onMouseLeave) canvas.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(canvas.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: canvas.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: canvas.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: canvas.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(canvas.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: canvas.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: canvas.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: canvas.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -void pCanvas::setSize(const Size &size) { - delete[] data; - data = new uint32_t[size.width * size.height]; -} - -void pCanvas::update() { - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - InvalidateRect(hwnd, 0, false); -} - -void pCanvas::constructor() { - data = new uint32_t[canvas.state.width * canvas.state.height]; - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas); - synchronize(); -} - -void pCanvas::destructor() { - DestroyWindow(hwnd); - delete[] data; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::paint() { - RECT rc; - GetClientRect(hwnd, &rc); - unsigned width = canvas.state.width, height = canvas.state.height; - - BITMAPINFO bmi; - memset(&bmi, 0, sizeof(BITMAPINFO)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = 32; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biWidth = width; - bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap - bmi.bmiHeader.biSizeImage = sizeof(uint32_t) * width * height; - - PAINTSTRUCT ps; - BeginPaint(hwnd, &ps); - SetDIBitsToDevice(ps.hdc, 0, 0, width, height, 0, 0, 0, height, (void*)data, &bmi, DIB_RGB_COLORS); - EndPaint(hwnd, &ps); -} diff --git a/ananke/phoenix/windows/widget/check-box.cpp b/ananke/phoenix/windows/widget/check-box.cpp deleted file mode 100644 index 8f0d2eb8..00000000 --- a/ananke/phoenix/windows/widget/check-box.cpp +++ /dev/null @@ -1,39 +0,0 @@ -bool pCheckBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, checkBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - SendMessage(hwnd, BM_SETCHECK, (WPARAM)checked, 0); -} - -void pCheckBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pCheckBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_CHECKBOX, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&checkBox); - setDefaultFont(); - if(checkBox.state.checked) setChecked(true); - setText(checkBox.state.text); - synchronize(); - -} - -void pCheckBox::destructor() { - DestroyWindow(hwnd); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/combo-box.cpp b/ananke/phoenix/windows/widget/combo-box.cpp deleted file mode 100644 index bff1170d..00000000 --- a/ananke/phoenix/windows/widget/combo-box.cpp +++ /dev/null @@ -1,70 +0,0 @@ -void pComboBox::append(const string &text) { - SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(text)); - if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) == 1) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(hfont, text).width); - return { 0, 0, maximumWidth + 24, pFont::geometry(hfont, " ").height + 10 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - SendMessage(hwnd, CB_INSERTSTRING, row, (LPARAM)(wchar_t*)utf16_t(text)); - setSelection(position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - if(position == row) setSelection(0); - locked = false; -} - -void pComboBox::reset() { - SendMessage(hwnd, CB_RESETCONTENT, 0, 0); -} - -unsigned pComboBox::selection() { - return SendMessage(hwnd, CB_GETCURSEL, 0, 0); -} - -void pComboBox::setSelection(unsigned row) { - SendMessage(hwnd, CB_SETCURSEL, row, 0); -} - -void pComboBox::constructor() { - hwnd = CreateWindow( - L"COMBOBOX", L"", - WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, - 0, 0, 0, 0, - parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&comboBox); - setDefaultFont(); - for(auto &text : comboBox.state.text) append(text); - setSelection(comboBox.state.selection); - synchronize(); -} - -void pComboBox::destructor() { - DestroyWindow(hwnd); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER); - RECT rc; - GetWindowRect(hwnd, &rc); - unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); - SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); -} diff --git a/ananke/phoenix/windows/widget/hex-edit.cpp b/ananke/phoenix/windows/widget/hex-edit.cpp deleted file mode 100644 index 789f4faf..00000000 --- a/ananke/phoenix/windows/widget/hex-edit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -static LRESULT CALLBACK HexEdit_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - HexEdit &hexEdit = *(HexEdit*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(msg == WM_CHAR) { - if(hexEdit.p.keyPress(wparam)) return 0; - } - return hexEdit.p.windowProc(hwnd, msg, wparam, lparam); -} - -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - update(); -} - -void pHexEdit::setRows(unsigned rows) { - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - SetWindowText(hwnd, L""); - return; - } - - unsigned cursorPosition = Edit_GetSel(hwnd); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\r\n"); - } - - SetWindowText(hwnd, utf16_t(output)); - Edit_SetSel(hwnd, LOWORD(cursorPosition), HIWORD(cursorPosition)); -} - -void pHexEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_READONLY | ES_MULTILINE | ES_WANTRETURN, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&hexEdit); - setDefaultFont(); - update(); - - windowProc = (LRESULT CALLBACK (*)(HWND, UINT, LPARAM, WPARAM))GetWindowLongPtr(hwnd, GWLP_WNDPROC); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)HexEdit_windowProc); - synchronize(); -} - -void pHexEdit::destructor() { - DestroyWindow(hwnd); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = LOWORD(Edit_GetSel(hwnd)); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 2; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble or byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - Edit_SetSel(hwnd, position, position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} diff --git a/ananke/phoenix/windows/widget/horizontal-scroll-bar.cpp b/ananke/phoenix/windows/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 250ac247..00000000 --- a/ananke/phoenix/windows/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 18 }; -} - -unsigned pHorizontalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - horizontalScrollBar.setPosition(0); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pHorizontalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | WS_TABSTOP | SBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalScrollBar); - unsigned position = horizontalScrollBar.state.position; - setLength(horizontalScrollBar.state.length); - horizontalScrollBar.setPosition(position); - synchronize(); -} - -void pHorizontalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/horizontal-slider.cpp b/ananke/phoenix/windows/widget/horizontal-slider.cpp deleted file mode 100644 index 807086ae..00000000 --- a/ananke/phoenix/windows/widget/horizontal-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pHorizontalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - horizontalSlider.setPosition(0); -} - -void pHorizontalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pHorizontalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalSlider); - unsigned position = horizontalSlider.state.position; - setLength(horizontalSlider.state.length); - horizontalSlider.setPosition(position); - synchronize(); -} - -void pHorizontalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/label.cpp b/ananke/phoenix/windows/widget/label.cpp deleted file mode 100644 index 56f0d433..00000000 --- a/ananke/phoenix/windows/widget/label.cpp +++ /dev/null @@ -1,64 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); - InvalidateRect(hwnd, 0, false); -} - -void pLabel::constructor() { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label); - setDefaultFont(); - setText(label.state.text); - synchronize(); -} - -void pLabel::destructor() { - DestroyWindow(hwnd); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} - -static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Window *window = (Window*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam); - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_ERASEBKGND) { - //background is erased during WM_PAINT to prevent flickering - return TRUE; - } - - if(msg == WM_PAINT) { - PAINTSTRUCT ps; - RECT rc; - BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - FillRect(ps.hdc, &rc, window->p.brush ? window->p.brush : GetSysColorBrush(COLOR_3DFACE)); - SetBkColor(ps.hdc, window->p.brush ? window->p.brushColor : GetSysColor(COLOR_3DFACE)); - SelectObject(ps.hdc, ((Widget*)label)->p.hfont); - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); - unsigned height = rc.bottom; - GetClientRect(hwnd, &rc); - rc.top = (rc.bottom - height) / 2; - rc.bottom = rc.top + height; - DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); - EndPaint(hwnd, &ps); - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/ananke/phoenix/windows/widget/line-edit.cpp b/ananke/phoenix/windows/widget/line-edit.cpp deleted file mode 100644 index eb6a8fb7..00000000 --- a/ananke/phoenix/windows/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, 0); -} - -void pLineEdit::setText(const string &text) { - locked = true; - SetWindowText(hwnd, utf16_t(text)); - locked = false; -} - -string pLineEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - return (const char*)utf8_t(text); -} - -void pLineEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&lineEdit); - setDefaultFont(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); - synchronize(); -} - -void pLineEdit::destructor() { - lineEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/list-view.cpp b/ananke/phoenix/windows/widget/list-view.cpp deleted file mode 100644 index 675691e6..00000000 --- a/ananke/phoenix/windows/widget/list-view.cpp +++ /dev/null @@ -1,243 +0,0 @@ -unsigned ListView_GetColumnCount(HWND hwnd) { - unsigned count = 0; - LVCOLUMN column; - column.mask = LVCF_WIDTH; - while(ListView_GetColumn(hwnd, count++, &column)); - return --count; -} - -void ListView_SetImage(HWND hwnd, HIMAGELIST imageList, unsigned row, unsigned column, unsigned imageID) { - //if this is the first image assigned, set image list now - //do not set sooner, or image blocks will appear in a list with no images - if(ListView_GetImageList(hwnd, LVSIL_SMALL) != imageList) { - ListView_SetImageList(hwnd, imageList, LVSIL_SMALL); - } - - LVITEM item; - item.mask = LVIF_IMAGE; - item.iItem = row; - item.iSubItem = column; - item.iImage = imageID; - ListView_SetItem(hwnd, &item); -} - -void ImageList_Append(HIMAGELIST imageList, const nall::image &source) { - auto image = source; - if(image.empty()) { - image.allocate(15, 15); - image.clear(GetSysColor(COLOR_WINDOW)); - } - image.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - image.scale(15, 15, Interpolation::Linear); - HBITMAP bitmap = CreateBitmap(image); - ImageList_Add(imageList, bitmap, NULL); - DeleteObject(bitmap); -} - -void pListView::append(const lstring &list) { - wchar_t empty[] = L""; - unsigned row = ListView_GetItemCount(hwnd); - LVITEM item; - item.mask = LVIF_TEXT; - item.iItem = row; - item.iSubItem = 0; - item.pszText = empty; - locked = true; - ListView_InsertItem(hwnd, &item); - locked = false; - for(unsigned column = 0; column < list.size(); column++) { - utf16_t wtext(list(column, "")); - ListView_SetItemText(hwnd, row, column, wtext); - } -} - -void pListView::autoSizeColumns() { - unsigned columns = ListView_GetColumnCount(hwnd); - for(unsigned n = 0; n < columns; n++) { - ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER); - } -} - -bool pListView::checked(unsigned row) { - return ListView_GetCheckState(hwnd, row); -} - -void pListView::modify(unsigned row, const lstring &list) { - for(unsigned n = 0; n < list.size(); n++) { - utf16_t wtext(list(n, "")); - ListView_SetItemText(hwnd, row, n, wtext); - } -} - -void pListView::remove(unsigned row) { - ListView_DeleteItem(hwnd, row); -} - -void pListView::reset() { - ListView_DeleteAllItems(hwnd); - buildImageList(); //free previously allocated images -} - -bool pListView::selected() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return true; - } - return false; -} - -unsigned pListView::selection() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return n; - } - return listView.state.selection; -} - -void pListView::setCheckable(bool checkable) { - ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES | (checkable ? LVS_EX_CHECKBOXES : 0)); -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - ListView_SetCheckState(hwnd, row, checked); - locked = false; -} - -void pListView::setHeaderText(const lstring &list) { - while(ListView_DeleteColumn(hwnd, 0)); - - lstring headers = list; - if(headers.size() == 0) headers.append(""); //must have at least one column - - for(unsigned n = 0; n < headers.size(); n++) { - LVCOLUMN column; - column.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM; - column.fmt = LVCFMT_LEFT; - column.iSubItem = n; - utf16_t headerText(headers[n]); - column.pszText = headerText; - ListView_InsertColumn(hwnd, n, &column); - } - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - SetWindowLong( - hwnd, GWL_STYLE, - (GetWindowLong(hwnd, GWL_STYLE) & ~LVS_NOCOLUMNHEADER) | - (visible ? 0 : LVS_NOCOLUMNHEADER) - ); -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { - //assign existing image - for(unsigned n = 0; n < images.size(); n++) { - if(images[n] == image) { - imageMap(row)(column) = n; - return ListView_SetImage(hwnd, imageList, row, column, n); - } - } - - //append and assign new image - imageMap(row)(column) = images.size(); - images.append(image); - ImageList_Append(imageList, image); - ListView_SetImage(hwnd, imageList, row, column, imageMap(row)(column)); -} - -void pListView::setSelected(bool selected) { - locked = true; - lostFocus = false; - if(selected == false) { - ListView_SetItemState(hwnd, -1, 0, LVIS_FOCUSED | LVIS_SELECTED); - } else { - setSelection(listView.state.selection); - } - locked = false; -} - -void pListView::setSelection(unsigned row) { - locked = true; - lostFocus = false; - ListView_SetItemState(hwnd, row, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); - locked = false; -} - -void pListView::constructor() { - lostFocus = false; - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", - WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&listView); - setDefaultFont(); - setHeaderText(listView.state.headerText); - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - buildImageList(); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); - synchronize(); -} - -void pListView::destructor() { - DestroyWindow(hwnd); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setGeometry(const Geometry &geometry) { - pWidget::setGeometry(geometry); - autoSizeColumns(); -} - -void pListView::buildImageList() { - auto &list = listView.state.image; - unsigned columns = listView.state.text.size(); - unsigned rows = max(1u, listView.state.headerText.size()); - - ListView_SetImageList(hwnd, NULL, LVSIL_SMALL); - if(imageList) ImageList_Destroy(imageList); - imageList = ImageList_Create(15, 15, ILC_COLOR32, 1, 0); - - imageMap.reset(); - images.reset(); - images.append(nall::image()); //empty icon for cells without an image assigned (I_IMAGENONE does not work) - - //create a vector of unique images from all images used (many cells may use the same image) - for(unsigned y = 0; y < list.size(); y++) { - for(unsigned x = 0; x < list[y].size(); x++) { - bool found = false; - for(unsigned z = 0; z < images.size(); z++) { - if(list[y][x] == images[z]) { - found = true; - imageMap(y)(x) = z; - break; - } - } - - if(found == false) { - imageMap(y)(x) = images.size(); - images.append(list[y][x]); - } - } - } - - //build image list - for(auto &imageItem : images) ImageList_Append(imageList, imageItem); - if(images.size() <= 1) return; - - //set images for all cells - for(unsigned y = 0; y < columns; y++) { - for(unsigned x = 0; x < rows; x++) { - ListView_SetImage(hwnd, imageList, y, x, imageMap(y)(x)); - } - } -} diff --git a/ananke/phoenix/windows/widget/progress-bar.cpp b/ananke/phoenix/windows/widget/progress-bar.cpp deleted file mode 100644 index f4703f1e..00000000 --- a/ananke/phoenix/windows/widget/progress-bar.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 23 }; -} - -void pProgressBar::setPosition(unsigned position) { - SendMessage(hwnd, PBM_SETPOS, (WPARAM)position, 0); -} - -void pProgressBar::constructor() { - hwnd = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | PBS_SMOOTH, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&progressBar); - SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); - SendMessage(hwnd, PBM_SETSTEP, MAKEWPARAM(1, 0), 0); - setPosition(progressBar.state.position); - synchronize(); -} - -void pProgressBar::destructor() { - DestroyWindow(hwnd); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/radio-box.cpp b/ananke/phoenix/windows/widget/radio-box.cpp deleted file mode 100644 index ebcb1edc..00000000 --- a/ananke/phoenix/windows/widget/radio-box.cpp +++ /dev/null @@ -1,43 +0,0 @@ -bool pRadioBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, radioBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - for(auto &item : radioBox.state.group) { - SendMessage(item.p.hwnd, BM_SETCHECK, (WPARAM)(&item == &radioBox), 0); - } -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pRadioBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_RADIOBUTTON, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&radioBox); - setDefaultFont(); - if(radioBox.state.checked) setChecked(); - setText(radioBox.state.text); - synchronize(); -} - -void pRadioBox::destructor() { - DestroyWindow(hwnd); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/text-edit.cpp b/ananke/phoenix/windows/widget/text-edit.cpp deleted file mode 100644 index 8e1df517..00000000 --- a/ananke/phoenix/windows/widget/text-edit.cpp +++ /dev/null @@ -1,58 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - if(position == ~0) position >>= 1; //Edit_SetSel takes signed type - Edit_SetSel(hwnd, position, position); - Edit_ScrollCaret(hwnd); -} - -void pTextEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, (LPARAM)0); -} - -void pTextEdit::setText(const string &text) { - locked = true; - string output = text; - output.replace("\r", ""); - output.replace("\n", "\r\n"); - SetWindowText(hwnd, utf16_t(output)); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - //ES_AUTOHSCROLL cannot be changed after widget creation. - //As a result, we must destroy and re-create widget to change this setting. - orphan(); -} - -string pTextEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t buffer[length + 1]; - GetWindowText(hwnd, buffer, length + 1); - buffer[length] = 0; - string text = (const char*)utf8_t(buffer); - text.replace("\r", ""); - return text; -} - -void pTextEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | (textEdit.state.wordWrap == false ? WS_HSCROLL | ES_AUTOHSCROLL : 0), - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&textEdit); - setDefaultFont(); - setCursorPosition(textEdit.state.cursorPosition); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - synchronize(); -} - -void pTextEdit::destructor() { - textEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/vertical-scroll-bar.cpp b/ananke/phoenix/windows/widget/vertical-scroll-bar.cpp deleted file mode 100644 index dcc281f2..00000000 --- a/ananke/phoenix/windows/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 18, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - verticalScrollBar.setPosition(0); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pVerticalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | SBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalScrollBar); - unsigned position = verticalScrollBar.state.position; - setLength(verticalScrollBar.state.length); - verticalScrollBar.setPosition(position); - synchronize(); -} - -void pVerticalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/vertical-slider.cpp b/ananke/phoenix/windows/widget/vertical-slider.cpp deleted file mode 100644 index ac5cb1ce..00000000 --- a/ananke/phoenix/windows/widget/vertical-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pVerticalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pVerticalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - verticalSlider.setPosition(0); -} - -void pVerticalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pVerticalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalSlider); - unsigned position = verticalSlider.state.position; - setLength(verticalSlider.state.length); - verticalSlider.setPosition(position); - synchronize(); -} - -void pVerticalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/ananke/phoenix/windows/widget/viewport.cpp b/ananke/phoenix/windows/widget/viewport.cpp deleted file mode 100644 index c0b13b69..00000000 --- a/ananke/phoenix/windows/widget/viewport.cpp +++ /dev/null @@ -1,57 +0,0 @@ -static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Viewport &viewport = (Viewport&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(viewport.onMouseMove) viewport.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(viewport.onMouseLeave) viewport.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(viewport.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: viewport.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: viewport.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: viewport.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(viewport.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: viewport.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: viewport.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: viewport.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -uintptr_t pViewport::handle() { - return (uintptr_t)hwnd; -} - -void pViewport::constructor() { - hwnd = CreateWindow(L"phoenix_viewport", L"", WS_CHILD | WS_DISABLED, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&viewport); - synchronize(); -} - -void pViewport::destructor() { - DestroyWindow(hwnd); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} \ No newline at end of file diff --git a/ananke/phoenix/windows/widget/widget.cpp b/ananke/phoenix/windows/widget/widget.cpp deleted file mode 100644 index d8c25c9b..00000000 --- a/ananke/phoenix/windows/widget/widget.cpp +++ /dev/null @@ -1,70 +0,0 @@ -bool pWidget::enabled() { - return IsWindowEnabled(hwnd); -} - -bool pWidget::focused() { - return GetFocus() == hwnd; -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - EnableWindow(hwnd, enabled); -} - -void pWidget::setFocused() { - SetFocus(hwnd); -} - -void pWidget::setFont(const string &font) { - if(hfont) DeleteObject(hfont); - hfont = pFont::create(font); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -void pWidget::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, geometry.height, SWP_NOZORDER); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); -} - -void pWidget::constructor() { - hfont = pFont::create("Tahoma, 8"); - if(widget.state.abstract) { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&widget); - } -} - -void pWidget::destructor() { - if(widget.state.abstract) { - DestroyWindow(hwnd); - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} - -void pWidget::setDefaultFont() { - string description = widget.state.font; - if(description == "") description = "Tahoma, 8"; - hfont = pFont::create(description); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -//calling Widget::setParent destroys widget and re-creates it: -//need to re-apply visiblity and enabled status; called by each subclassed setParent() function -void pWidget::synchronize() { - widget.setEnabled(widget.enabled()); - widget.setVisible(widget.visible()); -} diff --git a/ananke/phoenix/windows/window.cpp b/ananke/phoenix/windows/window.cpp deleted file mode 100644 index dc8aea28..00000000 --- a/ananke/phoenix/windows/window.cpp +++ /dev/null @@ -1,229 +0,0 @@ -vector pWindow::modal; - -void pWindow::updateModality() { - for(auto &object : pObject::objects) { - if(dynamic_cast(object) == nullptr) continue; - pWindow *p = (pWindow*)object; - if(modal.size() == 0) EnableWindow(p->hwnd, true); - else EnableWindow(p->hwnd, modal.find(p)); - } -} - -static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; -static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geom = window.state.geometry; - geom.x = geom.y = 0; - layout.setGeometry(geom); -} - -void pWindow::append(Menu &menu) { - menu.p.parentWindow = &window; - updateMenu(); -} - -void pWindow::append(Widget &widget) { - widget.p.parentWindow = &window; - widget.p.orphan(); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Tahoma, 8"); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - DWORD color = GetSysColor(COLOR_3DFACE); - return { (uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color >> 0), 255 }; -} - -bool pWindow::focused() { - return (GetForegroundWindow() == hwnd); -} - -Geometry pWindow::frameMargin() { - unsigned style = window.state.resizable ? ResizableStyle : FixedStyle; - if(window.state.fullScreen) style = 0; - RECT rc = { 0, 0, 640, 480 }; - AdjustWindowRect(&rc, style, window.state.menuVisible); - unsigned statusHeight = 0; - if(window.state.statusVisible) { - RECT src; - GetClientRect(hstatus, &src); - statusHeight = src.bottom - src.top; - } - return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 }; -} - -Geometry pWindow::geometry() { - Geometry margin = frameMargin(); - - RECT rc; - if(IsIconic(hwnd)) { - //GetWindowRect returns -32000(x),-32000(y) when window is minimized - WINDOWPLACEMENT wp; - GetWindowPlacement(hwnd, &wp); - rc = wp.rcNormalPosition; - } else { - GetWindowRect(hwnd, &rc); - } - - signed x = rc.left + margin.x; - signed y = rc.top + margin.y; - unsigned width = (rc.right - rc.left) - margin.width; - unsigned height = (rc.bottom - rc.top) - margin.height; - - return { x, y, width, height }; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - updateMenu(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - if(brush) DeleteObject(brush); - brushColor = RGB(color.red, color.green, color.blue); - brush = CreateSolidBrush(brushColor); -} - -void pWindow::setFocused() { - if(window.state.visible == false) setVisible(true); - SetFocus(hwnd); -} - -void pWindow::setFullScreen(bool fullScreen) { - locked = true; - if(fullScreen == false) { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | (window.state.resizable ? ResizableStyle : FixedStyle)); - setGeometry(window.state.geometry); - } else { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); - Geometry margin = frameMargin(); - setGeometry({ margin.x, margin.y, GetSystemMetrics(SM_CXSCREEN) - margin.width, GetSystemMetrics(SM_CYSCREEN) - margin.height }); - } - locked = false; -} - -void pWindow::setGeometry(const Geometry &geometry) { - locked = true; - Geometry margin = frameMargin(); - SetWindowPos( - hwnd, NULL, - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height, - SWP_NOZORDER | SWP_FRAMECHANGED - ); - SetWindowPos(hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - for(auto &layout : window.state.layout) { - Geometry geom = this->geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { - locked = true; - SetMenu(hwnd, visible ? hmenu : 0); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setModal(bool modality) { - if(modality == false) { - if(auto position = modal.find(this)) modal.remove(position()); - } else { - modal.appendonce(this); - } - updateModality(); -} - -void pWindow::setResizable(bool resizable) { - SetWindowLongPtr(hwnd, GWL_STYLE, window.state.resizable ? ResizableStyle : FixedStyle); - setGeometry(window.state.geometry); -} - -void pWindow::setStatusFont(const string &font) { - if(hstatusfont) DeleteObject(hstatusfont); - hstatusfont = pFont::create(font); - SendMessage(hstatus, WM_SETFONT, (WPARAM)hstatusfont, 0); -} - -void pWindow::setStatusText(const string &text) { - SendMessage(hstatus, SB_SETTEXT, 0, (LPARAM)(wchar_t*)utf16_t(text)); -} - -void pWindow::setStatusVisible(bool visible) { - locked = true; - ShowWindow(hstatus, visible ? SW_SHOWNORMAL : SW_HIDE); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setTitle(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pWindow::setVisible(bool visible) { - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); - if(visible == false) setModal(false); -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &widget : window.state.widget) { - if(widget.state.font == "") widget.setFont(font); - } -} - -void pWindow::constructor() { - brush = 0; - - hwnd = CreateWindow(L"phoenix_window", L"", ResizableStyle, 128, 128, 256, 256, 0, 0, GetModuleHandle(0), 0); - hmenu = CreateMenu(); - hstatus = CreateWindow(STATUSCLASSNAME, L"", WS_CHILD, 0, 0, 0, 0, hwnd, 0, GetModuleHandle(0), 0); - hstatusfont = 0; - setStatusFont("Tahoma, 8"); - - //status bar will be capable of receiving tab focus if it is not disabled - SetWindowLongPtr(hstatus, GWL_STYLE, GetWindowLong(hstatus, GWL_STYLE) | WS_DISABLED); - - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&window); - setGeometry({ 128, 128, 256, 256 }); -} - -void pWindow::destructor() { - DeleteObject(hstatusfont); - DestroyWindow(hstatus); - DestroyMenu(hmenu); - DestroyWindow(hwnd); -} - -void pWindow::updateMenu() { - if(hmenu) DestroyMenu(hmenu); - hmenu = CreateMenu(); - - for(auto &menu : window.state.menu) { - menu.p.update(window); - if(menu.visible()) { - AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR)menu.p.hmenu, utf16_t(menu.state.text)); - } - } - - SetMenu(hwnd, window.state.menuVisible ? hmenu : 0); -} diff --git a/ananke/sufami-turbo.cpp b/ananke/sufami-turbo.cpp index 6440bf7c..ea2dc184 100644 --- a/ananke/sufami-turbo.cpp +++ b/ananke/sufami-turbo.cpp @@ -36,9 +36,10 @@ string Ananke::createSufamiTurboHeuristic(vector &buffer) { ".st/" }; directory::create(pathname); - file::create({pathname, "unverified"}); file::write({pathname, "manifest.bml"}, { + "unverified\n", + "\n", "cartridge\n", " rom name=program.rom size=0x", hex(buffer.size()), "\n", " ram name=save.ram size=0x2000\n", diff --git a/ananke/super-famicom.cpp b/ananke/super-famicom.cpp index 4b8937aa..c6f3c103 100644 --- a/ananke/super-famicom.cpp +++ b/ananke/super-famicom.cpp @@ -50,19 +50,18 @@ string Ananke::createSuperFamicomHeuristic(vector &buffer) { ".sfc/" }; directory::create(pathname); - file::create({pathname, "unverified"}); if((buffer.size() & 0x7fff) == 512) buffer.remove(0, 512); //strip copier header, if present SuperFamicomCartridge info(buffer.data(), buffer.size()); - string markup = info.markup; + string markup = {"unverified\n\n", info.markup}; markup.append("\ninformation\n title: ", nall::basename(information.name), "\n"); if(!information.manifest.empty()) markup = information.manifest; //override with embedded beat manifest, if one exists information.manifest = markup; //save for use with firmware routine below file::write({pathname, "manifest.bml"}, markup); - if(!markup.position("spc7110")) { + if(!markup.find("spc7110")) { file::write({pathname, "program.rom"}, buffer.data(), info.rom_size); } else { file::write({pathname, "program.rom"}, buffer.data(), 0x100000); @@ -89,11 +88,11 @@ void Ananke::createSuperFamicomHeuristicFirmware(vector &buffer, const auto buffer = file::read({information.path, name}); //try and read from the containing directory if(buffer.size() == 0) buffer = extractFile(name); //try and read from the containing archive, if one exists if(buffer.size() == 0) { - if(thread::primary()) MessageWindow::critical(Window::none(), { + if(thread::primary()) MessageWindow().setText({ "Error: ", information.name, "\n\n", "Required firmware ", name, " not found. Game will not be playable!\n\n", "You must obtain this file, and place it in the same folder as this game." - }); + }).error(); return; } @@ -109,16 +108,16 @@ void Ananke::createSuperFamicomHeuristicFirmware(vector &buffer, const }; string markup = information.manifest; - if(markup.position("dsp1.program.rom" )) copyFirmware("dsp1.rom", 0x001800, 0x000800); - if(markup.position("dsp1b.program.rom")) copyFirmware("dsp1b.rom", 0x001800, 0x000800); - if(markup.position("dsp2.program.rom" )) copyFirmware("dsp2.rom", 0x001800, 0x000800); - if(markup.position("dsp3.program.rom" )) copyFirmware("dsp3.rom", 0x001800, 0x000800); - if(markup.position("dsp4.program.rom" )) copyFirmware("dsp4.rom", 0x001800, 0x000800); - if(markup.position("st010.program.rom")) copyFirmware("st010.rom", 0x00c000, 0x001000); - if(markup.position("st011.program.rom")) copyFirmware("st011.rom", 0x00c000, 0x001000); - if(markup.position("st018.program.rom")) copyFirmware("st018.rom", 0x020000, 0x008000); - if(markup.position("cx4.data.rom" )) copyFirmware("cx4.rom", 0x000000, 0x000c00); - if(markup.position("sgb.boot.rom" )) copyFirmware("sgb.rom", 0x000000, 0x000000, 0x000100); + if(markup.find("dsp1.program.rom" )) copyFirmware("dsp1.rom", 0x001800, 0x000800); + if(markup.find("dsp1b.program.rom")) copyFirmware("dsp1b.rom", 0x001800, 0x000800); + if(markup.find("dsp2.program.rom" )) copyFirmware("dsp2.rom", 0x001800, 0x000800); + if(markup.find("dsp3.program.rom" )) copyFirmware("dsp3.rom", 0x001800, 0x000800); + if(markup.find("dsp4.program.rom" )) copyFirmware("dsp4.rom", 0x001800, 0x000800); + if(markup.find("st010.program.rom")) copyFirmware("st010.rom", 0x00c000, 0x001000); + if(markup.find("st011.program.rom")) copyFirmware("st011.rom", 0x00c000, 0x001000); + if(markup.find("st018.program.rom")) copyFirmware("st018.rom", 0x020000, 0x008000); + if(markup.find("cx4.data.rom" )) copyFirmware("cx4.rom", 0x000000, 0x000c00); + if(markup.find("sgb.boot.rom" )) copyFirmware("sgb.rom", 0x000000, 0x000000, 0x000100); } string Ananke::openSuperFamicom(vector &buffer) { diff --git a/higan/data/Info.plist b/data/Info.plist similarity index 100% rename from higan/data/Info.plist rename to data/Info.plist diff --git a/higan/data/cheats.bml b/data/cheats.bml similarity index 95% rename from higan/data/cheats.bml rename to data/cheats.bml index 89e3425d..ce6a6667 100644 --- a/higan/data/cheats.bml +++ b/data/cheats.bml @@ -1,4 +1,10 @@ -database revision=2012-11-21 +database revision=2013-06-09 + +cartridge sha256:8e844d77da01f86ace52823f1f974c9230f09e6a6cbf33a07abfe9beeff00292 + name:10-Yard Fight (USA, Europe) + cheat + description:Your team runs faster + code:ZEEXIPIE cartridge sha256:e868400409c70876b98dad2cca87b8e9ee31877b0cccbbd8405be5c54922722a name:1942 (Japan, USA) @@ -827,6 +833,9 @@ cartridge sha256:58d0f0e504b8450e7d2dfbe11948a244143bfe3065f7e78524633cce8ac7310 cheat description:Don't fall into the pits (you'll still lose any special ability you currently have) code:AEKAOPZA + cheat + description:Hit anywhere + code:GKNONOSU+XPEPOZLE+YGEPEZGV cheat description:Once Macho, stay Macho code:IEVASPIG @@ -1016,6 +1025,9 @@ cartridge sha256:03db3d003eaa91e1434093ea259a82b9f2d5ed5b02404f9feba05819f69f81c cheat description:Infinite Bombs code:SKKAPVVK + cheat + description:Get bombs from anywhere + code:AAKAOUEP+AAVAEUUP cheat description:Rocky loses no health when flying when you have full health code:TAVEYGYA @@ -1282,7 +1294,7 @@ cartridge sha256:c70f0f5d4054ce7c4850259879c9823add73ccc234ddcf96d95681bb78bd2c5 code:SZNEKPSE cheat description:Multi-jump - code:OZVPEAES+SASOSESX+SAVPXESX+SZUOEASA+SZSOEAGA+ZASOXEAE+AVSANLAP+ASSOGYTS+ASSOGLTS+AZSOOEOK+EIVPUAIV+EPSOUAEL+IAVOEEAA+IAVPOEGA+IAVPVATZ + code:AVSANLAP+ASSOGYTS+ASSOGLTS+AZSOOEOK+EIVPUAIV+EPSOUAEL+IAVOEEAA+IAVPOEGA+IAVPVATZ+OZVPEAES+SASOSESX+SAVPXESX+SZUOEASA+SZSOEAGA+ZASOXEAE cartridge sha256:ff5b96853cf67171918aad5157661dc223e0002e0373e2580cee2e207bb0a682 name:Akumajou Special - Boku Dracula-kun (Japan) @@ -1296,6 +1308,12 @@ cartridge sha256:ff5b96853cf67171918aad5157661dc223e0002e0373e2580cee2e207bb0a68 description:Infinite lives code:SXXSVGVG +cartridge sha256:4c95afeda9a92842933c174983fee954cf40d1301d32f6169f6653f1e5cdc10f + name:Al Unser Jr. Turbo Racing (USA) + cheat + description:Can't be slowed down by signs and grass, prevents suspension from being shot + code:AENSANPZ+SZSIOASA+SZEIOAVG + cartridge sha256:722096b8929442310bc268f9cfea10b26cff8a7e900197b54c73b4a8603b5d96 name:Aladdin (Europe) cheat @@ -1373,15 +1391,9 @@ cartridge sha256:d73a9a1fae7396754c19eecd6aa9e44d02c230df8efed0bafd86aa1cb0dd2a2 cheat description:Infinite gun heat code:SXOSNKVT - cheat - description:Super-jump - code:IPUZTALA+IPUXPALA cheat description:Invincible against long falls code:AASGKNYA - cheat - description:Always have Radar - code:NNKVNPAE cheat description:Infinite Radar code:SZVXVXVK @@ -1397,9 +1409,18 @@ cartridge sha256:d73a9a1fae7396754c19eecd6aa9e44d02c230df8efed0bafd86aa1cb0dd2a2 cheat description:Infinite ammo for Flame Thrower code:SZEIUOVK + cheat + description:Hit anywhere + code:AEOLYVIA+ATKYZIST + cheat + description:Super-jump + code:IPUZTALA+IPUXPALA cheat description:Level skip (pause and press any key (except left) code:TUVUYLZG + cheat + description:Always have Radar + code:NNKVNPAE cheat description:Invincibility (alt) code:03C8:4A @@ -1697,6 +1718,9 @@ cartridge sha256:427876021e6c077479a1a1171e013f84ae951197005a317b099df3b6c286260 cartridge sha256:bb834eb82f0ac53114035e6f353434a934d4aa47742644740de5fa8b2b033b5b name:Arch Rivals - A Basketbrawl! (USA) + cheat + description:Never miss a shot - both players + code:GZVPOZEI cheat description:More time for a quarter code:ALXLNZGU+ALNLPPGU @@ -1736,6 +1760,9 @@ cartridge sha256:a3763e702f8ae0818480cf0a8b2395d3f928c539f75e230ed43fa6b904fe636 cheat description:Infinite lives code:SZNEATVG + cheat + description:Paddle hits ball anywhere + code:AESXNALL+ASVZNAEP cheat description:No lasers code:SXVATAAX @@ -1883,6 +1910,12 @@ cartridge sha256:381fcbe2b714c38fdeb4045d93f0867fe80f4a219077c3dc5a683a05a8b8e78 cheat description:Infinite lives code:SZULXKVK + cheat + description:Hit anywhere + code:AAXXXTEG + cheat + description:Walk through walls + code:AAKPZNAP+AAOPYNYA+AEEOZNKP+AESOGTTP cheat description:Start with fewer hearts code:ZAKATIIA @@ -2048,6 +2081,9 @@ cartridge sha256:a08e6b53f1fa593e001719d87e2f203deb24ee1d389a8f3f339d75e9fb7c02f cheat description:Hit anywhere code:GXKSKPEL+GXUISPAL + cheat + description:Multi-jump + code:EEEEIZYY+EEEEYZAP+ZUOAPZIL cheat description:Double health and SP code:AZKAVZGO @@ -2270,6 +2306,9 @@ cartridge sha256:56382fac9104b26797de262a7c70ddd5850451d81a5008f3943d7bc492cbeb4 cartridge sha256:467a2e53c7af4c60809db9c2670850a6e21a98ea37c1d920dc4fcb6afcb5a104 name:Bad News Baseball (USA) + cheat + description:Balls are considered strikes + code:XTOPAKEV cheat description:Play as girls team code:PYEGZPLP+PAEGAPEP @@ -2433,8 +2472,17 @@ cartridge sha256:bb30e4f4b1f6d8ccfdbd538b6f20347ed732cd37e8ac0a8305a277cf298b3dc description:Start with 1 Z (1st credit only) code:PEEZEZIA +cartridge sha256:f22944452be3259aac853258759f469e7d2e2447c6178f26cc7bd0e89945bc04 + name:Baseball (USA, Europe) + cheat + description:Balls are considered strikes + code:OZSIZYSX + cartridge sha256:8bb20791eb3f4fd2455c33f0eead4538af3372205fba70fd4c3e0867b2c34c9a name:Baseball Simulator 1.000 (USA) + cheat + description:Balls are considered strikes + code:PAKPKTZA cheat description:Strike outs aren't allowed code:OXVZITVV @@ -2466,8 +2514,17 @@ cartridge sha256:8bb20791eb3f4fd2455c33f0eead4538af3372205fba70fd4c3e0867b2c34c9 description:9 balls and you walk code:PESALTGE +cartridge sha256:b035ec9e2a7fc408c19bb2ffd22dceb0483a73e5f5bf232132628c9d8657b1e8 + name:Baseball Stars (USA) + cheat + description:Balls are considered strikes + code:AEVSPGLA + cartridge sha256:5f8807999205f3800e445d6265b66fa6edff0070fc38905f7284f0ad437f9f53 name:Baseball Stars II (USA) + cheat + description:Balls are considered strikes + code:OXKILGEN cheat description:Strikes do not count code:SZSSZSVV @@ -2546,6 +2603,9 @@ cartridge sha256:5f8807999205f3800e445d6265b66fa6edff0070fc38905f7284f0ad437f9f5 cartridge sha256:b9af9efdf490e14895e7980097a86d2f69d6396383773c221e77c6183a4ab9c8 name:Bases Loaded II - Second Season (USA) + cheat + description:Balls are considered strikes + code:SXKKIVGK cheat description:1 strike and you're out - most of the time code:PEOGOALA @@ -2573,6 +2633,9 @@ cartridge sha256:5d84d61e7e4c2b7d72a2b4599bd8cc415b71c90d1e332a83f95d96c75bc48ef cheat description:Computer can't score code:SZSYGNVV+SZSNTNVN + cheat + description:Balls are counted as strikes + code:NYVPOETE+TAVPUEON cheat description:Some strikes aren't counted code:SXOPSEVV @@ -2603,6 +2666,9 @@ cartridge sha256:5d84d61e7e4c2b7d72a2b4599bd8cc415b71c90d1e332a83f95d96c75bc48ef cartridge sha256:e4aa19e0fd2800b58655eac814e1d9a9aa16d83eabd641789f8a6625591063a3 name:Bases Loaded 4 (USA) + cheat + description:Balls are considered strikes + code:NYKXZUGE+TAKXGUON cheat description:Balls do not count code:SZNXGUVV @@ -2809,7 +2875,7 @@ cartridge sha256:8b7363e037883aaa36d2c643c36a6f09ce49bd515f166154bd2a48e0a6468b9 code:0147:00 cartridge sha256:64832bef6533d98f49e807c000537c8cb26ef94e6c3f871b8b6b35c5a11e427b - name:Battle City (Japan) + name:BattleCity (Japan) cheat description:Infinite freeze time once you obtain a clock code:SZEIEKVK @@ -2825,6 +2891,18 @@ cartridge sha256:a50c0b6d93f7e20ecfd8a95abd5b7bccd4cf290901376fcf9e4053b3f964fca cartridge sha256:d095eab5376c2b7c4f1c09018c9591598831c557e0b691c01ca2480e49e60c0a name:Battle of Olympus, The (USA) + cheat + description:Invincibility + code:ENOAPGEI + cheat + description:Infinite health + code:SXSSNASA + cheat + description:Hit anywhere + code:APVEIGES+ATVETKVT + cheat + description:Get items from anywhere (press down) + code:AEVESSOT+GXVANIEL cheat description:Start with less stamina code:AAUGPAAO @@ -2880,54 +2958,6 @@ cartridge sha256:c49a5d7f565646d76bdc307ccb0202197f579b77c5bf5ea409b5cb29f72edf3 description:Start on level 8 code:YASAKGAA+VASEOGSA+VASASGSA -cartridge sha256:a2039efb5b5b8d4941c31ae0977dacccec5aaa72fe307ae36af2a454d30d9e26 - name:Battletank (USA) - cheat - description:Infinite energy - code:SKOPAAVT - cheat - description:Infinite hits - code:SXOPAAVT+SXSLNPSA - cheat - description:Infinite fuel - code:SKUAANSE - cheat - description:Infinite weapons - code:SIXTEEVS+SGKVINVK - cheat - description:Infinite ammo - code:SLXTEEVS - cheat - description:Start with half 150mm ammo - code:TOVZIAZL - cheat - description:Start with double 150mm ammo - code:LVVZIAZL - cheat - description:Start with more wire guided shells - code:ZUVXTAPA - cheat - description:Start with max wire guided shells - code:LVVXTAPA - cheat - description:Start with more smoke shells - code:ZUNXAAPA - cheat - description:Start with max smoke shells - code:LVNXAAPA - cheat - description:Start with less 50mm shells - code:LGEZPPVO - cheat - description:Start with max 50mm shells - code:NYEZPPVO - cheat - description:Start with less 50mm ammo after mission 5 - code:GTEZIOEG - cheat - description:Start with max 50mm ammo after mission 5 - code:NYEZIOEK - cartridge sha256:56d25e05dde2048c3a9b4e36ab5325091310ce2b65171615b5596fc542db66fa name:Battletoads (USA) cheat @@ -3370,7 +3400,7 @@ cartridge sha256:4f59f3ef6045be753ed5f7988e4b302b7f71216354a644f760f4a0aa43af7d2 code:ZAXAYGAA cartridge sha256:92c481350b63c57385834dfa0ab02aeb527df7e80cec14a3e1a1a77118cd38d1 - name:Bio Miracle Bokutte Upa (Japan).nes + name:Bio Miracle Bokutte Upa (Japan) cheat description:Hit anywhere - normal enemies code:AAKTZTIG+AEOLVGTZ @@ -3630,6 +3660,12 @@ cartridge sha256:46fb05f80167bd185bd6eef40e1f86a0dcdd36e250ef8e2b29a575550d75473 description:Infinite lives (alt) code:0428:02 +cartridge sha256:7e59dcd2576d2e83f6f628a7bb8d5f1e54fa300f7ecb9aa5e1e0f6d967be8371 + name:Bo Jackson Baseball (USA) + cheat + description:Balls are considered strikes + code:AEEGYKAP + cartridge sha256:2967746c2a434c97a074b14d894ea132fab8e443899f6ca870718eeee1669039 name:Bomberman (USA) cheat @@ -3887,12 +3923,18 @@ cartridge sha256:b3d82e2818aea6caa69dcfe7d56197a7a51afe87819527880cf08876d1a988d cartridge sha256:0e58f270e7b116782e0822f52058eff66465df49527c6f8c6f0eca994d8cae7a name:Boulder Dash (USA) + cheat + description:Invincibility + code:AAEGLTPA+AVKKPLSZ+IKEKYOYX cheat description:Infinite lives code:SLEZXTVI cheat description:Infinite time code:SXSGSYAX + cheat + description:One Diamond needed to open exit + code:AEUGVGIZ cheat description:Speed up timer code:YOSGXNYU @@ -3918,75 +3960,6 @@ cartridge sha256:0e58f270e7b116782e0822f52058eff66465df49527c6f8c6f0eca994d8cae7 description:Start with 9 lives code:PAKIELLE -cartridge sha256:911fb75ec1f900a5c258635fae79e56520eeb4aec35b40737c44b735eeccdc56 - name:Boy and His Blob, A - Trouble on Blobolonia (USA) - cheat - description:Invincible (restart if you die underwater and get stuck by being unable to call your Blob) - code:AVOGAEOZ - cheat - description:Never take damage from enemies - code:AVOPVGEI - cheat - description:Infinite lives - code:GXXEOPVG - cheat - description:Infinite Jellybeans - code:AAVKIPPA - cheat - description:1 life only - code:AAULNGIA - cheat - description:Double lives - code:ZAULNGIE - cheat - description:Fast play - code:SXEEZAAX - cheat - description:Gives 10 Orange Jellybeans - code:APEUUIAA - cheat - description:10 Lime Jellybeans - code:AONUSGAA - cheat - description:99 Licorice Jellybeans - code:OONLOGZN - cheat - description:Double Strawberry Jellybeans - code:AUNLUGIP - cheat - description:Double Cola Jellybeans - code:TUNLNKAP - cheat - description:Double Cinnamon Jellybeans - code:AKNUOGGX - cheat - description:Double Apple Jellybeans - code:GXNUUGZP - cheat - description:Double Vanilla Jellybeans - code:AVNUNGAL - cheat - description:Double Ketchup Jellybeans - code:ZPELNITA - cheat - description:Triple Coconut Jellybeans - code:AONLSGTE - cheat - description:Triple Rootbeer Jellybeans - code:APELUITE - cheat - description:10 Vitamin A for Vita-Blaster - code:APEUSIAA - cheat - description:10 Vitamin B for Vita-Blaster - code:APEUNIAA - cheat - description:10 Vitamin C for Vita-Blaster - code:APOLOIAA - cheat - description:Start with 101 of all starting Jellybeans - code:SZXLXKSU+YYXLUGEY - cartridge sha256:a8b6829d8d1e17cc23c8815e0b0add09e26fc5a2a27ad6bba260cef926535af2 name:Bram Stoker's Dracula (USA) cheat @@ -4957,7 +4930,7 @@ cartridge sha256:7eba1637cd2fdbc4f0732eb5249e32d827dbdadbd7e165f961440af4310880d code:EVPPEL cheat description:Multi-jump - code:AVOPZYEP+VEEOGGSV+KOEOIGOZ+OZOOIKSE+PAOOTGLG+SAOOYGPE+GTXPAKVV+GAXPPKGT+ZGXPZGGE+AXKOZKSZ+PEKOLGGP+KOKOGGIA + code:OZOOIKSE+PAOOTGLG+SAOOYGPE+GTXPAKVV+GAXPPKGT+ZGXPZGGE+AXKOZKSZ+PEKOLGGP+KOKOGGIA+AVOPZYEP+VEEOGGSV+KOEOIGOZ cheat description:Start with 40 hearts code:AXOGOPIE @@ -5023,7 +4996,7 @@ cartridge sha256:a35e846379ff252594ace83da2a1a1cb0692717b931055d1f6603812f18ad5c code:EVPPEL cheat description:Multi-jump - code:AVOPZYEP+VEEOGGSV+KOEOIGOZ+OZOOIKSE+PAOOTGLG+SAOOYGPE+GTXPAKVV+GAXPPKGT+ZGXPZGGE+AXKOZKSZ+PEKOLGGP+KOKOGGIA + code:OZOOIKSE+PAOOTGLG+SAOOYGPE+GTXPAKVV+GAXPPKGT+ZGXPZGGE+AXKOZKSZ+PEKOLGGP+KOKOGGIA+AVOPZYEP+VEEOGGSV+KOEOIGOZ cheat description:Start on last level code:VXOLEOVE+PEEUEPLE+ZOEUSPAA @@ -5063,33 +5036,81 @@ cartridge sha256:a35e846379ff252594ace83da2a1a1cb0692717b931055d1f6603812f18ad5c cartridge sha256:9575ec31c1c658fd6b77ae1d69e4861ecada8570e4eebf51409941486e4b4ef4 name:Castlevania II - Simon's Quest (USA) + cheat + description:Invincibility (enemies die) + code:LZUAINVI+OAUATYNE cheat description:Infinite health code:SZSSYLSA + cheat + description:Invincibility against water + code:EVUELANT+GKVYUVNN+KKVYSVNY+KNVYKVNY+PEVYXVNY+UEVYOVNN+VNUEGAEK+VKVYEVNN cheat description:Infinite lives code:GXOGGZVG cheat description:Infinite Laurels code:IAXIOPVG + cheat + description:Infinite Laurel time + code:SXOEPOVK cheat description:Infinite Garlic code:SZUISPVG cheat - description:Always daytime - code:SXOSLYSA + description:One hit kills + code:AAXAVPAG + cheat + description:Hit anywhere - whip + code:AAOANPYG+AAOEKPGI+AENESAPT + cheat + description:Hit anywhere - sub-weapons + code:ELEEOZAL+ELXANZAL cheat description:Small hearts worth 100 code:KATAZY + cheat + description:Enemies always drop large Hearts + code:EUXEPZEI+SXXETXSU+XNUAAZGE + cheat + description:Can use sub-weapons regardless of Heart count + code:EYNIVAEL cheat description:Multi-jump - code:VVSEVOSV+XVSEKPEN+EESEOPAP+ESSEXPLP+GESEUPEX+GKSESPAX+OESENPVE+PXSEEPLE+SNSANOGT+SXSAVOSZ+UNVEOPAE + code:EESEOPAP+ESSEXPLP+GESEUPEX+GKSESPAX+OESENPVE+PXSEEPLE+SNSANOGT+SXSAVOSZ+UNVEOPAE+VVSEVOSV+XVSEKPEN + cheat + description:Jump higher (4 1/3 blocks) + code:AXVENOAL + cheat + description:Buy a White Crystal and receive the Red Crystal and all of Dracula's Relics + code:NYXVOTAX + cheat + description:Buy Thorn Whip and receive the Flame Whip (do not buy any other whips) + code:GENTUIYA + cheat + description:Whip much faster + code:EIOIOGEY cheat description:Whip can destroy any block code:AALSPT+AAZSAT+APISIT+XVPIPV cheat description:Whip destroys all enemies/townspeople on screen code:INIEEA + cheat + description:Towns never sleep (can enter doors) + code:AEXEYYPP+EYKEYPEI + cheat + description:Ponds open instantly without needing a Crystal + code:EYNGEIEI + cheat + description:Faster dialog text + code:ESOVETEY + cheat + description:Always daytime + code:SXOSLYSA + cheat + description:Always get the best ending + code:SANXTPSZ cheat description:Start with 100 Experience (E) code:PAZNGO @@ -5179,7 +5200,7 @@ cartridge sha256:6e8d289635ac39479ff1d36733aa3f8b9650593ab972cedb8e2cdbfc03aaa73 code:AEELYXAP cheat description:Multi-jump - code:SASOUESX+SASPVESX+SZSPOAGA+SZUPOASA+TZSPXEOG+ZASPUEAE+AVVAELAP+EISOKAIV+EPSPKAEL+IASONATZ+IASOXEGA+IAVPOEAA+OZSOOAES+PSSPINYG+PSVPYUYG + code:AVVAELAP+EISOKAIV+EPSPKAEL+IASONATZ+IASOXEGA+IAVPOEAA+OZSOOAES+PSSPINYG+PSVPYUYG+SASOUESX+SASPVESX+SZSPOAGA+SZUPOASA+TZSPXEOG+ZASPUEAE cheat description:Start with 9500 seconds code:PALUYL @@ -5289,6 +5310,15 @@ cartridge sha256:6e8d289635ac39479ff1d36733aa3f8b9650593ab972cedb8e2cdbfc03aaa73 description:Start on stage 15 (glitchy if you die) code:0032:0E +cartridge sha256:52451a89296cfcb006beb6363ddc8486fcc88154338cbec778a846056c522f50 + name:Cat Ninden Teyandee (Japan) + cheat + description:Infinite health + code:003F:0B + cheat + description:Infinite magic energy + code:0040:FF + cartridge sha256:c20a8cc1b2dacb8a45e706b5763ac6c82c17b4ee4fb547ba4a853e4aabd6e35c name:Challenge of the Dragon (USA) (Unl) cheat @@ -5334,6 +5364,12 @@ cartridge sha256:d5b039637a2315458f71ec57a287f93b3532e6243b712b55767f07dc83c5a3c description:Always break in 9 or 10-ball - P2 code:OZVETASX+PAVEYEST +cartridge sha256:a8f18eb52126cdf3d004877f8c4c315ddf15f823f13f42b0154da17db21ecddd + name:Championship Rally (Europe) + cheat + description:Drive a short distance to finish lap + code:AASKSLAZ + cartridge sha256:ebdd748cd488c4acdc5d2c7321de692c1ab0b37044cf0c6ea043457176dbd306 name:Cheetahmen II (USA) (Unl) cheat @@ -5355,6 +5391,12 @@ cartridge sha256:ebdd748cd488c4acdc5d2c7321de692c1ab0b37044cf0c6ea043457176dbd30 description:Infinite lives - level 4 code:SXXUIXVK +cartridge sha256:b705f866955c7d19292b55a9b0f3ec0e970e3f2509c3da15708b7afd879d98ed + name:Chessmaster, The (USA) + cheat + description:Move pieces anywhere + code:AAVKNLTI+SZNGULSA+SZNKELSA + cartridge sha256:e84d90fefb92f2b6ab70e35bfb990978c7e384e357ec6b995c3880bff4c5b460 name:Chip 'n Dale - Rescue Rangers (USA) cheat @@ -6133,7 +6175,7 @@ cartridge sha256:d41e28b1a33b3b6768e7c39c9fdfb1fda4b49940542d14085911fabd399e1ca code:GXIIUX cheat description:Press Select to change weapons - P1 - code:GGXNIVNN+IZOYLVNY+KZOYZVNY+PZONYVNN+LAOYIVNY+SAXNPVNY+LIOYYVNY+SZXNLVNY+OGXYPVNN+YAXYAVNY+SYXNGVNY+OZXYIVNN+ZAXYGVNY+SZONIVNY+PAXNAVNY+ZPKILAIZ+TAONGVNN+PTXYYVNN+TGXNTVNY+PZONPVNN+VYKIGAEI+XZONTVNN+XZXNZVNN+AZONZVNY+EIONAVNY+EIXNYVNY+EIXYLVNY+EYONLVNY+EYOYGVNY+GAXYZVNY+GGKIZAKX+GGOYTVNN + code:AZONZVNY+EIONAVNY+EIXNYVNY+EIXYLVNY+EYONLVNY+EYOYGVNY+GAXYZVNY+GGKIZAKX+GGOYTVNN+GGXNIVNN+IZOYLVNY+KZOYZVNY+LAOYIVNY+LIOYYVNY+OGXYPVNN+OZXYIVNN+PAXNAVNY+PTXYYVNN+PZONPVNN+PZONYVNN+SAXNPVNY+SZXNLVNY+SYXNGVNY+SZONIVNY+TAONGVNN+TGXNTVNY+VYKIGAEI+XZONTVNN+XZXNZVNN+YAXYAVNY+ZAXYGVNY+ZPKILAIZ cheat description:Press Start to complete the level code:LLKSIAIX @@ -6633,6 +6675,75 @@ cartridge sha256:227e789fef94eabcf24a5ec9a3944de58b183bbc7d96140269d1c908f162b85 description:Start on level 20 code:OZEPOISE+GPEPXSVI +cartridge sha256:911fb75ec1f900a5c258635fae79e56520eeb4aec35b40737c44b735eeccdc56 + name:David Crane's A Boy and His Blob - Trouble on Blobolonia (USA) + cheat + description:Invincible (restart if you die underwater and get stuck by being unable to call your Blob) + code:AVOGAEOZ + cheat + description:Never take damage from enemies + code:AVOPVGEI + cheat + description:Infinite lives + code:GXXEOPVG + cheat + description:Infinite Jellybeans + code:AAVKIPPA + cheat + description:1 life only + code:AAULNGIA + cheat + description:Double lives + code:ZAULNGIE + cheat + description:Fast play + code:SXEEZAAX + cheat + description:Gives 10 Orange Jellybeans + code:APEUUIAA + cheat + description:10 Lime Jellybeans + code:AONUSGAA + cheat + description:99 Licorice Jellybeans + code:OONLOGZN + cheat + description:Double Strawberry Jellybeans + code:AUNLUGIP + cheat + description:Double Cola Jellybeans + code:TUNLNKAP + cheat + description:Double Cinnamon Jellybeans + code:AKNUOGGX + cheat + description:Double Apple Jellybeans + code:GXNUUGZP + cheat + description:Double Vanilla Jellybeans + code:AVNUNGAL + cheat + description:Double Ketchup Jellybeans + code:ZPELNITA + cheat + description:Triple Coconut Jellybeans + code:AONLSGTE + cheat + description:Triple Rootbeer Jellybeans + code:APELUITE + cheat + description:10 Vitamin A for Vita-Blaster + code:APEUSIAA + cheat + description:10 Vitamin B for Vita-Blaster + code:APEUNIAA + cheat + description:10 Vitamin C for Vita-Blaster + code:APOLOIAA + cheat + description:Start with 101 of all starting Jellybeans + code:SZXLXKSU+YYXLUGEY + cartridge sha256:41f949cfedf7167985f779c0782ee17ee83d82e35111c5f22ee5037f54313a06 name:Day Dreamin' Davey (USA) cheat @@ -6761,6 +6872,9 @@ cartridge sha256:9371fab4f58fa6d6e5211950fdaff2810cccff512fc301e88af9c5b1bf58625 cartridge sha256:0115356b0791cc8ddcb7d3163d6ef7aa664f3ff4e68dba561ffffb79eefcbca9 name:Deadly Towers (USA) + cheat + description:Invincibility + code:OXXOXOPX cheat description:Infinite HP code:GXSONPST @@ -7040,6 +7154,9 @@ cartridge sha256:44cd6b2aa05286c37e78bd04d15793018bb0656b24260e5c76fc5cfad39f699 cartridge sha256:6d082c801942ce6787b471428ab4c8a6acb3e21f3f38fa197f2aeb698d9a2d7e name:Destiny of an Emperor (USA) + cheat + description:No random battles + code:OZNNZGSK+SXSYYKPU cheat description:Buy 300 provisions for no money code:AEKPZZGT @@ -7073,6 +7190,9 @@ cartridge sha256:6d082c801942ce6787b471428ab4c8a6acb3e21f3f38fa197f2aeb698d9a2d7 cheat description:Leather costs nothing code:AEXUOKGZ+AEXUXGPA + cheat + description:Walk anywhere + code:SZUYTUGK cartridge sha256:163479e2b1571538cf2f0f147bcbdebaab8ed8b0251f87dabd9bc4c80d786ea1 name:Dick Tracy (USA) @@ -7414,7 +7534,7 @@ cartridge sha256:950ebe68e7f74219b9e5e104200b03165d59c24264f02e32c12be967fd311ac code:PAUIEZIA cartridge sha256:07dd16464d769429c651bd203ac2e74c7aa5852824482ca8877959d643bc8689 - name:Donkey Kong Jr. Math (USA, Europe).nes + name:Donkey Kong Jr. Math (USA, Europe) cheat description:Always get the correct answer code:AAKILSZA+AAUILSZP @@ -7925,6 +8045,9 @@ cartridge sha256:abc5bcb459316a7d245065149ea72b5a8317f62fa6ed578569e15b670d3c002 cartridge sha256:c15ab051ff066f018cf4b0159780c58026114bb47a6376ef81c1571a39a8fe9b name:Dragon Warrior II (USA) + cheat + description:One hit kills + code:ASUZYTEP cheat description:Prince of Midenhall starts with 50 HP code:ZUKLUSGP @@ -9323,6 +9446,12 @@ cartridge sha256:fa456d852372173ea31b192459ba1a2026f779df67793327ba6e132476c1d03 cheat description:999999+ Gold code:NYOUTAAE + cheat + description:Gain 65535 EXP from every battle + code:PEIOOT + cheat + description:Enemies don't attack + code:EAZLLL cheat description:Non-magic users can use level 1 magic code:ELEXVLEY+AESGANGA+AESGGNAA @@ -10054,7 +10183,7 @@ cartridge sha256:eedcf3fae4fe66102a1bf1338a1ea3276f5aadb3c3bc5770dd1d260e2fc44ba name:Formation Z (Japan) cheat description:Invincibility - code:SZOOTVSE+SZSXPESE+SZSXAKSE+SXXXVUSE+SXEPXNSE+SZVOTNSE+SXOXSXSE+SXUZONSE+SXNXKSSE+SZXOPVSE + code:SZSXPESE+SZSXAKSE+SXXXVUSE+SXEPXNSE+SZVOTNSE+SXOXSXSE+SXUZONSE+SXNXKSSE+SZXOPVSE+SZOOTVSE cheat description:Infinite fuel code:IXSOTTVG @@ -10602,6 +10731,54 @@ cartridge sha256:055fb73baaed0f3c4a31902402e7fe581d2d2cb948d3a2f5c3552050f316e6d description:Walk through walls code:APOEGLEP +cartridge sha256:a2039efb5b5b8d4941c31ae0977dacccec5aaa72fe307ae36af2a454d30d9e26 + name:Garry Kitchen's BattleTank (USA) + cheat + description:Infinite energy + code:SKOPAAVT + cheat + description:Infinite hits + code:SXOPAAVT+SXSLNPSA + cheat + description:Infinite fuel + code:SKUAANSE + cheat + description:Infinite weapons + code:SIXTEEVS+SGKVINVK + cheat + description:Infinite ammo + code:SLXTEEVS + cheat + description:Start with half 150mm ammo + code:TOVZIAZL + cheat + description:Start with double 150mm ammo + code:LVVZIAZL + cheat + description:Start with more wire guided shells + code:ZUVXTAPA + cheat + description:Start with max wire guided shells + code:LVVXTAPA + cheat + description:Start with more smoke shells + code:ZUNXAAPA + cheat + description:Start with max smoke shells + code:LVNXAAPA + cheat + description:Start with less 50mm shells + code:LGEZPPVO + cheat + description:Start with max 50mm shells + code:NYEZPPVO + cheat + description:Start with less 50mm ammo after mission 5 + code:GTEZIOEG + cheat + description:Start with max 50mm ammo after mission 5 + code:NYEZIOEK + cartridge sha256:fbc976422ca910d9391060898c8b58694f19b6e53a68bd33c457fb38dac1e5c6 name:Gauntlet (USA) (Unl) cheat @@ -10850,9 +11027,18 @@ cartridge sha256:ffa61d9f7bfb1d60662ddf246b21a8756d518292e8fdc0f58ac1c9b3fbad672 cartridge sha256:cf517940496d6085563bdbbe74f4a06d2c4eca48da8eb2b35d5cfe463df35ce4 name:George Foreman's KO Boxing (USA) + cheat + description:Invincibility + code:AOONKZEY+OXNYSXPK cheat description:Infinite health code:036E:43 + cheat + description:Can always use super punches + code:AAVTTNAA + cheat + description:Knock opponent down with 1 super punch + code:OXVNSAOU+PKVNVEVZ cheat description:Knock opponent down with 1 punch code:036F:01 @@ -11067,6 +11253,12 @@ cartridge sha256:c2383e5cd8670c7107d59887026b9001f30045aa5f07be4b687b7a6bc290db1 description:Infinite power code:0178:30 +cartridge sha256:c41555b61617e52cae950e0a94d4d655646eed4e4ce4c1d26740ddee0a9ae090 + name:Golf (USA) + cheat + description:Ball goes in from anywhere + code:AAVGIZLA+APVIYLEY+ILVSALPK + cartridge sha256:af24262bc78865b81b1a42d2842e222553fca27fb841a4eb8fbe26da7eba6163 name:Golf Grand Slam (USA) cheat @@ -13870,7 +14062,7 @@ cartridge sha256:f40341cf7e76480465ba8ab2d09e44644c3e3af7d647dc04c8b38357b26e014 name:Just Breed (Japan) cheat description:No health - all enemies - code:69E3:00+69E4:00+69E5:00+69E6:00+69DA:00+69DB:00+69DC:00+69DD:00+69DE:00+69DF:00+69E0:00+69E1:00+69E2:00 + code:69DA:00+69DB:00+69DC:00+69DD:00+69DE:00+69DF:00+69E0:00+69E1:00+69E2:00+69E3:00+69E4:00+69E5:00+69E6:00 cheat description:Lots of EXP after battle code:6F6E:FF @@ -14234,15 +14426,27 @@ cartridge sha256:56f1fe3a7881b2e9d69cd33a0971b2f26247e964c3c7dd4a6019715425ff225 cheat description:Invincibility code:OTXSVLON + cheat + description:No ordinary damage + code:SZUIKLSA + cheat + description:No damage from floor hazards + code:SKXGUYVG + cheat + description:No damage from Medusa + code:SZSLAPSA + cheat + description:Lava restores health + code:VVXGUYVG + cheat + description:Immune to becoming an eggplant + code:AAUEVAPA cheat description:Hit anywhere code:AANIOPPP+AOEIEPZE+XTNSNPEU cheat description:99 Hammers on pick-up code:EOSTEXOZ+KNSTOZPA - cheat - description:Small hearts worth 135 - code:NAKSXTPA cheat description:Small hearts worth 2 code:ZAKSXTPA @@ -14250,23 +14454,14 @@ cartridge sha256:56f1fe3a7881b2e9d69cd33a0971b2f26247e964c3c7dd4a6019715425ff225 description:Small hearts worth 5 code:IAKSXTPA cheat - description:Big hearts worth 255 - code:NYKSSVZA + description:Small hearts worth 135 + code:NAKSXTPA cheat description:Big hearts worth 20 code:GPKSSVZA cheat - description:Lave restores health - code:VVXGUYVG - cheat - description:Immune to becoming eggplant - code:AAUEVAPA - cheat - description:No damage from Medusa - code:SZSLAPSA - cheat - description:No damage from floor hazards - code:SKXGUYVG + description:Big hearts worth 255 + code:NYKSSVZA cheat description:Get best ending with 8uuuuu uuuuuu uuuuuu uuuuuu code code:PEEEZPAA @@ -14365,7 +14560,7 @@ cartridge sha256:81a77623adf819f10548052075555998c1ec1ef5f4dc4bf6ff6b6c3fa3541c1 code:NYUEXOEV cheat description:Multi-jump - code:KTEYSNNN+NNOOKXOE+OAENXNNN+OZEYKNNN+PPEYNNNN+SAEYVNNY+YIEYONNY+AANOVZAP+AEEPKXZA+AEOOUXIZ+APEYXNNY+ATENUNNY+AZENENNY+GAEYUNNY+GZEYENNY+IZENONNN + code:AANOVZAP+AEEPKXZA+AEOOUXIZ+APEYXNNY+ATENUNNY+AZENENNY+GAEYUNNY+GZEYENNY+IZENONNN+KTEYSNNN+NNOOKXOE+OAENXNNN+OZEYKNNN+PPEYNNNN+SAEYVNNY+YIEYONNY cheat description:Less time code:GAUELZTA+GEEPOTTA @@ -14410,7 +14605,7 @@ cartridge sha256:81e527e9c282f5078a3d08470ad3c032fea9a72f1559ee9d2702ea6b07fab45 code:AOOENSXE+ATUKLXSY+AVXAESAG cheat description:Multi-jump - code:LPENONNN+NYNPUXOE+OAENXNNN+OZEYKNNN+PPEYNNNN+SAEYVNNY+YIEYONNY+AANPXXLP+APEYXNNY+ATENUNNY+AZENENNY+GAEYUNNY+GZEYENNY+GZSOXZEY+GZSPKZEY+KTEYSNNN + code:AANPXXLP+APEYXNNY+ATENUNNY+AZENENNY+GAEYUNNY+GZEYENNY+GZSOXZEY+GZSPKZEY+KTEYSNNN+LPENONNN+NYNPUXOE+OAENXNNN+OZEYKNNN+PPEYNNNN+SAEYVNNY+YIEYONNY cheat description:Invincibility (glitchy) code:0088:00+00F4:00 @@ -14834,6 +15029,9 @@ cartridge sha256:0ba5e69962f6576d3729aa967092a7e8c98d00213cd98026dee343bff67b417 cheat description:Infinite health code:AUVZEGTA+VEVZOKSX + cheat + description:Infinite health and one hit kills + code:GPTGTG+UTYKTK cheat description:Infinite time code:SZUAOAAX @@ -15209,6 +15407,9 @@ cartridge sha256:d2a585ff6febf59447f9bd9fbb387ae4985385d6f6f61a70e145a5ee6952301 cartridge sha256:3b5627bc1ebaa7a84953d7337c7684a93beaf973f4a8b3a42b513dc1e0ab0a09 name:Legends of the Diamond - The Baseball Championship Game (USA) + cheat + description:Balls are considered strikes + code:OZUUZSPX cheat description:1 ball and you walk code:PEKLAIGA @@ -15294,14 +15495,11 @@ cartridge sha256:1849bb687d038a43971651b13392481768ea0bc15f3d04b6898f052bbfa356e cartridge sha256:ec0d4ebf6d2fcecd1d95fef7329954efe79676959bc281ea908b226459bc6dc2 name:Legend of Zelda, The (USA) (Rev A) cheat - description:Infinite health + description:Infinite life code:AVVLAUSZ cheat - description:Have the Pink Ring (infinite health) + description:Have the Pink Ring (infinite life) code:ZTSPSTIP - cheat - description:Infinite Bombs - code:SZNZVOVK cheat description:Have Blue Ring effect code:ESKUILTA @@ -15340,12 +15538,12 @@ cartridge sha256:ec0d4ebf6d2fcecd1d95fef7329954efe79676959bc281ea908b226459bc6dc code:NYKPOYZX cheat description:Invincibility - code:7AA7:60 + code:7B3A:60 cheat description:Invincibility (blinking) code:04F0:09 cheat - description:Infinite health (alt) + description:Infinite life (alt) code:0670:FF cheat description:Hit anywhere @@ -15353,9 +15551,6 @@ cartridge sha256:ec0d4ebf6d2fcecd1d95fef7329954efe79676959bc281ea908b226459bc6dc cheat description:Get items from anywhere code:7353:24+735F:24 - cheat - description:Infinite Bombs (alt) - code:0658:FF cheat description:Infinite Keys code:066E:03 @@ -15383,6 +15578,9 @@ cartridge sha256:ec0d4ebf6d2fcecd1d95fef7329954efe79676959bc281ea908b226459bc6dc cheat description:Have Blue Candle code:065B:01 + cheat + description:Have Bombs + code:0658:10 cheat description:Have Bow code:065A:01 @@ -15435,14 +15633,11 @@ cartridge sha256:ec0d4ebf6d2fcecd1d95fef7329954efe79676959bc281ea908b226459bc6dc cartridge sha256:085e5397a3487357c263dfa159fb0fe20a5f3ea8ef82d7af6a7e848d3b9364e8 name:Legend of Zelda, The (USA) cheat - description:Infinite health + description:Infinite life code:AVVLAUSZ cheat - description:Have the Pink Ring (infinite health) + description:Have the Pink Ring (infinite life) code:ZTSOOTIP - cheat - description:Infinite Bombs - code:SZNZVOVK cheat description:All items are free code:SZVXASVK+AEVEVALG @@ -15478,12 +15673,12 @@ cartridge sha256:085e5397a3487357c263dfa159fb0fe20a5f3ea8ef82d7af6a7e848d3b9364e code:NYKPOYZX cheat description:Invincibility - code:7AA7:60 + code:7B3A:60 cheat description:Invincibility (blinking) code:04F0:09 cheat - description:Infinite health (alt) + description:Infinite life (alt) code:0670:FF cheat description:Hit anywhere @@ -15491,9 +15686,6 @@ cartridge sha256:085e5397a3487357c263dfa159fb0fe20a5f3ea8ef82d7af6a7e848d3b9364e cheat description:Get items from anywhere code:7353:24+735F:24 - cheat - description:Infinite Bombs (alt) - code:0658:FF cheat description:Infinite Keys code:066E:03 @@ -15521,6 +15713,9 @@ cartridge sha256:085e5397a3487357c263dfa159fb0fe20a5f3ea8ef82d7af6a7e848d3b9364e cheat description:Have Blue Candle code:065B:01 + cheat + description:Have Bombs + code:0658:10 cheat description:Have Bow code:065A:01 @@ -15777,6 +15972,15 @@ cartridge sha256:cecc797ffc82c5764e89038262c00b325f44afc0d9fc4b5bef295ea227e1dd2 description:Infinite lives code:SXNEAKVK +cartridge sha256:475c35c18b5e958122473bcca52d54438e1734b1b74dc295492eba6d29927193 + name:Little League Baseball - Championship Series (USA) + cheat + description:Balls are considered strikes + code:OZUITLEN + cheat + description:Always hit a homerun (press B while the ball is in play) + code:AGOLPUNI+UPEUYLOG + cartridge sha256:68e98b1b8dc5da610321f92718b4b4c2b2b71b6c752ff25ca6926e26cd91c57f name:Little Mermaid, The (USA) cheat @@ -17839,7 +18043,7 @@ cartridge sha256:649db8035018f2512ccea70aca6606c3b3a6988cd9ed43953b38dc5103dec7b name:Metroid (USA) cheat description:Invincibility - code:PZNVGZZN+APKYKKKP+ATEPUVSZ+AVKYXTAZ+AVOYIXSL+AVUYTZAZ+AVVNYZAZ+EPKYUGAZ+EPNVLZKA+OXEPNOOK + code:APKYKKKP+ATEPUVSZ+AVKYXTAZ+AVOYIXSL+AVUYTZAZ+AVVNYZAZ+EPKYUGAZ+EPNVLZKA+OXEPNOOK+PZNVGZZN cheat description:Minimum energy of 30 code:SXSGNVSE @@ -18404,6 +18608,9 @@ cartridge sha256:5327792d8b5392cd5cec95ee254fc9f729777283c80f3d1f94d5147f3be7365 cartridge sha256:2ebab487204c42b0d9cf19c37bdc395e396226ca3eaa664907bf7f8216b3c4d3 name:Mike Tyson's Punch-Out!! (Japan, USA) (Rev A) + cheat + description:Invincibility + code:AEEAAAST+INUAIZSY cheat description:Infinite health code:ATEALIXZ @@ -18452,6 +18659,9 @@ cartridge sha256:2ebab487204c42b0d9cf19c37bdc395e396226ca3eaa664907bf7f8216b3c4d cheat description:First knockdown will be a TKO code:AXIONS + cheat + description:Skip intro + code:ENOZAZPE cheat description:Start with and have infinite stars code:ALVAYPEY @@ -18518,6 +18728,9 @@ cartridge sha256:2ebab487204c42b0d9cf19c37bdc395e396226ca3eaa664907bf7f8216b3c4d cartridge sha256:752f9d07450e6ec075b109f5be1b1933e8385ad687ceaf24f70a590767bb5a27 name:Mike Tyson's Punch-Out!! (Japan, USA) + cheat + description:Invincibility + code:AEEAAAST+INUAIZSY cheat description:Infinite health code:ATEALIXZ @@ -18557,6 +18770,9 @@ cartridge sha256:752f9d07450e6ec075b109f5be1b1933e8385ad687ceaf24f70a590767bb5a2 cheat description:Normal punches do more damage code:AAVETLGA + cheat + description:Skip intro + code:ENOZAZPE cheat description:Start with and have infinite stars code:ALVAYPEY @@ -18647,6 +18863,9 @@ cartridge sha256:bd84b27f752aa568374e1c8a6df948340a1374478b754f2ddc32e37d75b4a2b cheat description:Start with 10 lives - P1 code:ZAVKSPGE + cheat + description:Invincibility + code:0071:00 cartridge sha256:6eea421f6c0738ff3abfd6e059e91c3409eedd2150093d3e01d49dfaad4dbf80 name:Milon's Secret Castle (USA) @@ -18921,6 +19140,12 @@ cartridge sha256:219c94a1f0801ee255f4c8df6d7d1120bdcfd882fcaecba2c858b1e4c66d060 description:Start on level 8 code:YAKOZIAA +cartridge sha256:ce493dcb4ba133d9a31e234a4c446a365bcf98c5f99c13968f1e1c777747ac29 + name:Moon Crystal (Japan) + cheat + description:Multi-jump + code:AVSOGTTA+GESPTVGP+NOSOIVEP+SZNOLNSE + cartridge sha256:66cb74efa264a285a541277b935d4b6cc9c49a18653bce90b65f0de98b05aec0 name:Moon Ranger (USA) (Unl) cheat @@ -19061,6 +19286,9 @@ cartridge sha256:3ec56ffa686a0e45dc5dfa02d3216b6c9302177b01a0bba506739a436c4ba73 cheat description:Infinite lives code:00D4:09 + cheat + description:Ghosts stay blue until eaten + code:00C5:01 cheat description:Start on level 2 code:0127:01 @@ -19678,7 +19906,7 @@ cartridge sha256:ba5968f14a02f1adf8a6144fcf9c4acde80bce8a3e01bae54b555f258540dd4 code:SZVZIIVG cheat description:Multi-jump and infinite time - code:ZASXPIIE+AENXOAGP+AZSXGIZL+EPSXZSUA+GXUPZLEL+LASXLIEI+LPSXASNL+OZSXTSNK+SZNXIIVG+XISXIIVK + code:AENXOAGP+AZSXGIZL+EPSXZSUA+GXUPZLEL+LASXLIEI+LPSXASNL+OZSXTSNK+SZNXIIVG+XISXIIVK+ZASXPIIE cheat description:Less time code:VPKGXKXY @@ -20600,6 +20828,30 @@ cartridge sha256:4986c3862a04fcf5b22df58b1182ec2ad636e6083714ac7c069adc1639023eb cheat description:Infinite time code:0095:09+0096:99 + cheat + description:Infinite Bombs + code:005A:09 + cheat + description:Infinite health refills + code:005B:09 + cheat + description:Powered up Boomerang + code:005E:03 + cheat + description:Triple Boomerangs + code:0099:02 + cheat + description:One hit kills on bosses + code:04BA:00 + cheat + description:Moon jump (Can cause you to die in areas with no ceiling) + code:051D:C0 + cheat + description:Have Suit + code:009C:03 + cheat + description:Start on last stage + code:0059:3F cartridge sha256:6c462c3fa07aab70759376fe6b59e9c91e808f79fae2960f869bafc9cf20dca2 name:Power Blade 2 (USA) @@ -20703,8 +20955,8 @@ cartridge sha256:76cdd991b85e4a15c62275fe6b3ccd5132ee2d17e70fe4d2173b8ce5d1193ec description:Infinite lives in big mode code:SXXGZOVK cheat - description:Start with double lives - code:AAVKGPGE + description:Hit anywhere + code:ATEVEISZ+ATVTEISZ+ATXTOISZ+AVNTKGSZ+AVOVSISZ cheat description:Mega-jumps in jungle mode code:AEOETOPE @@ -20714,6 +20966,9 @@ cartridge sha256:76cdd991b85e4a15c62275fe6b3ccd5132ee2d17e70fe4d2173b8ce5d1193ec cheat description:Start each life with Laser Rifle code:LASEOELA+XLSEUEVX + cheat + description:Start with double lives + code:AAVKGPGE cheat description:Invincibility code:0010:02 @@ -21205,7 +21460,7 @@ cartridge sha256:882a02c538cb097531da74d0ad685f6896dcfb7fa9b1a0cd540b4274968a7c1 code:SZXZXUVK+SZXZSUVK cartridge sha256:745050dec23a692e1e759eb3e291f58ad7739fadb3a1308ec8d60085fefaec69 - name:Qix (USA) + name:QIX (USA) cheat description:1 life - P1 code:PEEAPZGA @@ -21861,7 +22116,7 @@ cartridge sha256:d79be89ff83550ba185d19fb586d2b5f988ad6743125b5233ab3bfe2cb814c9 cartridge sha256:b7b5fdf2b31c4b8c5340f93f166fb56aecf598f7c43a24b4334502bb81065143 name:Raid on Bungeling Bay (USA) cheat - description:Take no damage from anything + description:Infinite Damage code:SXVVPIAX cheat description:Infinite Bombs @@ -21884,6 +22139,12 @@ cartridge sha256:b7b5fdf2b31c4b8c5340f93f166fb56aecf598f7c43a24b4334502bb8106514 cheat description:Start on round 9 code:PEVKTYPE + cheat + description:Infinite Bombs (alt) + code:0254:2C + cheat + description:0 Damage + code:024D:23+024E:23 cartridge sha256:9866b51b16b503aa515967929060eb100ae4cbd851229a3125ecf3ee7c88346e name:Rally Bike (USA) @@ -22481,6 +22742,39 @@ cartridge sha256:5431ed49f22ee8188871be088da433c26b1ddeac972ef4b8f89df4eacd5e42c cheat description:Start with defense level at 8 code:AEVGIPPE + cheat + description:Always have 99 Medals + code:0058:63 + cheat + description:Always have 99 Super Boots + code:0061:63 + cheat + description:Always have 99 Clocks + code:0062:63 + cheat + description:Always have 99 Flash + code:0063:63 + cheat + description:Always have 99 CrossFires + code:0064:63 + cheat + description:Always have 99 Candles + code:0065:63 + cheat + description:Always have 99 Energy Capsule + code:0066:63 + cheat + description:Always have 99 Missles + code:0067:63 + cheat + description:Always have 99 Megaton Bombs + code:004D:63 + cheat + description:Always have 99 Life Vest + code:004E:63 + cheat + description:Always have 99 Lanterns + code:004F:63 cartridge sha256:100c394264b40c17f635a6356c884135558bf2aee1a7f60c9ce43441e48a06cb name:Robocco Wars (Japan) @@ -23029,7 +23323,7 @@ cartridge sha256:fade44d9c76173afe098fbe02d859735e06b2c509fd80da08b1cc85bfc01a55 code:GZOEIYVG cheat description:Multi-jump - code:NXSAGNUE+OAUXENNN+OYUXXNNY+PZUZXNNN+SZUZENNY+UAUXUNNN+AAUZUNNN+ATUXKNNY+AUSALYOY+AZUXONNY+AZUZVNNY+EYUZKNNY+EYUZNNNN+GAUZONNY+LAUZSNNY + code:AAUZUNNN+ATUXKNNY+AUSALYOY+AZUXONNY+AZUZVNNY+EYUZKNNY+EYUZNNNN+GAUZONNY+LAUZSNNY+NXSAGNUE+OAUXENNN+OYUXXNNY+PZUZXNNN+SZUZENNY+UAUXUNNN cheat description:Start with 1 life - P1 code:PAVSTPIA @@ -23098,7 +23392,7 @@ cartridge sha256:9bef1813dbcfa003b3b1978a66a8da3ff59c93dd74f1332801515aa4b633c51 code:LAVOLTGA cheat description:Multi-jump - code:ZZKXKIAX+APKXSIEY+ATOZTEOZ+AZKXXIGE+GASZOIIA+IZKXUSPZ+SAKXNSSX+SZKXOIXP+XGSZEIZL+XTKXESSX + code:APKXSIEY+ATOZTEOZ+AZKXXIGE+GASZOIIA+IZKXUSPZ+SAKXNSSX+SZKXOIXP+XGSZEIZL+XTKXESSX+ZZKXKIAX cheat description:Grappling Hook continues until it finds something code:SZUPOOVK+SZXXGZSA @@ -23161,7 +23455,7 @@ cartridge sha256:e3a7e0b559b18e8e2fd6f2bf0fdadbf9094be63a01bac50e5505413e1d7697a code:LAVOLTGA cheat description:Multi-jump - code:ZZKXKIAX+APKXSIEY+ATOZTEOZ+AZKXXIGE+GASZOIIA+IZKXUSPZ+SAKXNSSX+SZKXOIXP+XGSZEIZL+XTKXESSX + code:APKXSIEY+ATOZTEOZ+AZKXXIGE+GASZOIIA+IZKXUSPZ+SAKXNSSX+SZKXOIXP+XGSZEIZL+XTKXESSX+ZZKXKIAX cheat description:Grappling Hook continues until it finds something code:SZUPOOVK+SZXXGZSA @@ -23517,6 +23811,12 @@ cartridge sha256:6c705f7980a08b7a7a5d74ddfd175155492168248f65c7d9e3cef1a6b14a288 description:Quadruple usual shots per round code:ASUAIVAZ+EXXOVXAZ+SXVONOOU +cartridge sha256:648f68ae58f3420096e052a68255d8e453ae1fc09a4214adbeaa66ff841aaa33 + name:Side Pocket (USA) + cheat + description:Infinite turns - P1 + code:SXKXNLSA + cartridge sha256:37a5cfb1aacd9bb42746f20923441b5f613971d4dc99de68c216b10a8d7bcbfc name:Silent Service (USA) cheat @@ -26393,9 +26693,6 @@ cartridge sha256:959fdd32c71735d6fb2bd16a646d39f4ee65623273dd035e6a968e991bd13ef cheat description:Invincibility as miniture stone Mario code:EXKXGLIA - cheat - description:Never die from being hit while little (changes music) (PRG0 only) - code:GOZSXX cheat description:Invincibility as Super Mario code:XUKXGLIE @@ -26435,6 +26732,9 @@ cartridge sha256:959fdd32c71735d6fb2bd16a646d39f4ee65623273dd035e6a968e991bd13ef cheat description:Tail hits anywhere code:GZSSOLEP + cheat + description:1-up for each enemy you stomp + code:ZITGAG cheat description:1-up for each coin code:PEEULAGT+PEOLAAGT @@ -26619,7 +26919,7 @@ cartridge sha256:d77d17d34af24871d7ce1160ccd3330555835c8e940b7100e095ac38973d927 description:Invincibility as miniture stone Mario code:EXKXGLIA cheat - description:Never die from being hit while little (changes music) (PRG0 only) + description:Never die from being hit while little (changes music) code:GOZSXX cheat description:Invincibility as Super Mario @@ -26660,6 +26960,9 @@ cartridge sha256:d77d17d34af24871d7ce1160ccd3330555835c8e940b7100e095ac38973d927 cheat description:Tail hits anywhere code:GZSSOLEP + cheat + description:1-up for each enemy you stomp + code:ZITGAG cheat description:1-up for each coin code:PEEULAGT+PEOLAAGT @@ -27240,6 +27543,21 @@ cartridge sha256:f6e88113b5f64cf7ffd915dd60b49e55d7015aaeb8b232c87e9855d4b9759cb description:Infinite time (alt) code:00EB:09 +cartridge sha256:efb93dcae29f1ff85b58ccb9450c23d528073a019493d88a9abcabe4ca9aca4f + name:Tatakae! Chou Robot Seimeitai Transformers - Convoy no Nazo (Japan) + cheat + description:Invincibility + code:AIUKAZEY+AVXGPGSZ + cheat + description:Hit anywhere (enemies and platforms) + code:AEKGYZGZ+ASVKZZEP+SLEKLUSO + cheat + description:Moon jump + code:AAEOTOTZ+AAEPZOZL+AENOAAYZ + cheat + description:Solve level 9 maze using any path + code:AYNEAZEY + cartridge sha256:d088f4b91a03dd6a618245fffb492bcda127c7faa6d880596aa5e751fdac0181 name:Tecmo Bowl (USA) (Rev A) cheat @@ -27863,6 +28181,9 @@ cartridge sha256:667bcf3ca1ebcf6f71fccd412ced546f4aba3b8cd2fc30d173cf6d3b4c15846 cartridge sha256:2ae5fb18a1bf841077e3872ba05060f030ea0bfc573994b2f8fe2fb570dc7853 name:Tetris (USA) + cheat + description:Lines are cleared when a piece is dropped + code:AEOPKZYL cheat description:Disable Game Over (press start) code:GAOPEILA+GGOPSZEN+XPOPNZSX+YGOPVZAL @@ -27890,6 +28211,9 @@ cartridge sha256:2ae5fb18a1bf841077e3872ba05060f030ea0bfc573994b2f8fe2fb570dc785 cartridge sha256:9daa4bec3013ae7ef498318432f438d70374af294d1dce28edd3c466aaf6b740 name:Tetris (USA) (Unl) + cheat + description:Lines are cleared when a piece is dropped + code:AEXELNZZ+AEXEYYTZ cheat description:Always get straight pieces code:OZKPEPEN+PAKPOOOY @@ -28725,21 +29049,6 @@ cartridge sha256:a2812d80b3057aac9753f48247a7a46b29bea0b9aec04ca4c327180085c25b5 description:You don't have to score any points to qualify for Skeet Shooting, Triple Jump and Archery code:UKUKIGKG -cartridge sha256:efb93dcae29f1ff85b58ccb9450c23d528073a019493d88a9abcabe4ca9aca4f - name:Transformers - Convoy no Nazo (Japan) - cheat - description:Invincibility - code:AIUKAZEY+AVXGPGSZ - cheat - description:Hit anywhere (enemies and platforms) - code:AEKGYZGZ+ASVKZZEP+SLEKLUSO - cheat - description:Moon jump - code:AAEOTOTZ+AAEPZOZL+AENOAAYZ - cheat - description:Solve level 9 maze using any path - code:AYNEAZEY - cartridge sha256:58d2f6abe4445dadc332f37a34af54e78b6af47a8c0e6313ef898ef6db046f4f name:Treasure Master (USA) cheat @@ -28789,7 +29098,7 @@ cartridge sha256:a5ae39359aa5b16961a98a7aaeeb278787382d5282ee80b5b3a2de954283ebb code:VTESLOSX cheat description:Hit anywhere - code:GZOXYYEL+AAKENATI+AANNIKLP+AAOZLYIZ+AAVAXALG+AEENPKYA+AENIEUAP+AEUNIUUI+AEUYPLNT+AEVIULIZ + code:AAKENATI+AANNIKLP+AAOZLYIZ+AAVAXALG+AEENPKYA+AENIEUAP+AEUNIUUI+AEUYPLNT+AEVIULIZ+GZOXYYEL cheat description:Keep High-jump Boots on pick-up code:SXKVKXVK @@ -28841,6 +29150,51 @@ cartridge sha256:a5ae39359aa5b16961a98a7aaeeb278787382d5282ee80b5b3a2de954283ebb cheat description:Infinite health (alt) code:0335:08 + cheat + description:Have Key + code:0386:02 + cheat + description:Have High-jump Boots + code:03CB:0E + cheat + description:Have Speed-Up + code:03CC:FF + cheat + description:Have Power-Up + code:03CD:FF + cheat + description:Start on level 2-1 + code:03D1:02 + cheat + description:Start on level 2-2 + code:03D1:03 + cheat + description:Start on level 3-1 + code:03D1:04 + cheat + description:Start on level 3-2 + code:03D1:05 + cheat + description:Start on level 4-1 + code:03D1:06 + cheat + description:Start on level 4-2 + code:03D1:07 + cheat + description:Start on level 5-1 + code:03D1:08 + cheat + description:Start on level 5-2 + code:03D1:09 + cheat + description:Start on level 6-1 + code:03D1:0A + cheat + description:Start on level 6-2 + code:03D1:0B + cheat + description:Start on level 7-1 + code:03D1:0C cartridge sha256:0b5d1465b23e31f24e1caecf1490f97a60deb97ba873a36fa948adb016e9c0d2 name:Trolls on Treasure Island (USA) (Unl) @@ -28970,6 +29324,15 @@ cartridge sha256:af5ac55d6283b709bcd96889708a6e7ad3c77e3bdd377aae796fd87b4b90dc4 cheat description:Never lose magic code:KPVSUZOP + cheat + description:Never miss with the Fight command + code:AKNSPAEE + cheat + description:Can always attack with the Fight command + code:AESSGETP + cheat + description:One hit kills + code:EIXUUPEP cheat description:Rapid magic recovery code:AAUEPYPA+OLUAGYOI @@ -29196,6 +29559,15 @@ cartridge sha256:1e8966fd8c9baf57c514fbf4d67ddd8c1ffd184be164f99342ccdec62def8db description:Infinite Health - Iolo code:6A08:0F +cartridge sha256:8dda0b6bcb5d66fd6983f71f9257225ce053822cbb5edda5d072feeddec9358e + name:Ultimate Air Combat (USA) + cheat + description:Infinite Chaff + code:SZOXIEVK + cheat + description:Infinite Missiles + code:SXVZZSVK+SZEXGVVK + cartridge sha256:f4de2a91acb2eb3024fb75231859a30c130c0169be0e6ad24330805c8f766e03 name:Ultimate Stuntman, The (USA) (Unl) cheat @@ -29668,7 +30040,7 @@ cartridge sha256:60667bc0ed1c0c6355f59b5716c678954c5f3915064bdbfbb8e0195f2643eda code:03E1:FF cartridge sha256:50b6f1f87fb14c8ff74a54e60b85139e11adcaecb62eb24174aeb58a20b7698f - name:Wally Bear and the No! Gang (USA) (Unl).nes + name:Wally Bear and the No! Gang (USA) (Unl) cheat description:Invincibility code:AOUXYYEI @@ -29820,6 +30192,12 @@ cartridge sha256:ab6f1bbcda6f0c0bbe1450b5f2ab2b21a5e01ec39143a455701862965cdbd7b description:Have Gun in Werewolf form code:044F:01+044D:01 +cartridge sha256:84e3a018cbaaf2311d7e9414112cb05cf3b43608de0b9f8a2f77bc4da33ce8e6 + name:Wheel of Fortune - Junior Edition (USA) + cheat + description:Always spin $1000 - All players + code:0071:AA + cartridge sha256:a66195e11e38bee9f602abd279b7c04367528380dfa5b915dce0fa6fd272c23c name:Where's Waldo (USA) cheat @@ -29868,16 +30246,16 @@ cartridge sha256:b9a4542417439619239cdb2cefd8c7eced2407ba2954f026c0ab1ea7d4def3d description:Infinite health code:SZNATPSA cheat - description:Don't lose a life from energy loss + description:Don't lose a life from health loss code:SXEEZPVG cheat description:Creatures can't steal extra lives code:SXXOUPVG cheat - description:Keep buffalo headdress for present level + description:Keep Buffalo Headdress for present level code:SZKEGPVG cheat - description:Always have buffalo headdress + description:Always have Buffalo Headdress code:ZAKELOAA cheat description:Start with 1 life @@ -29895,7 +30273,7 @@ cartridge sha256:9d875583dbdf80a0631ce4ffb3099064454d80568b5e9fe748a5e850f8fa016 description:Invincibility code:ENNVEZEI cheat - description:Infinite health (except against spikes) + description:Infinite health (not against spikes) code:SXSLEKSE cheat description:Infinite health (only against spikes) @@ -29921,6 +30299,21 @@ cartridge sha256:9d875583dbdf80a0631ce4ffb3099064454d80568b5e9fe748a5e850f8fa016 cheat description:Infinite special code:058B:06 + cheat + description:Have Mouse Widget + code:0331:01 + cheat + description:Have Rock-Man Widget + code:0332:01 + cheat + description:Have Bird-Man Widget + code:0333:01 + cheat + description:Have Dolphin Widget + code:0334:01 + cheat + description:Have powered-up Gun + code:0594:03+0595:03 cartridge sha256:adff304553b64384f86f6c2b63571f43972b9d087f92359a1b9b93b54d523542 name:Wild Gunman (World) (Rev A) @@ -31050,7 +31443,7 @@ cartridge sha256:fd4884c98d9412eb362c0654c8f5475e7f24266984f11e19961495c2d642d38 description:Infinite lives code:SZEOUGVG cheat - description:Start with 2 + description:Start with 2 lives code:PEKSVGLA cheat description:Start with 7 lives @@ -31075,7 +31468,7 @@ cartridge sha256:c79202082042baeb3a45e747a1675c9530137f847c357c393270715efc32217 code:YYKSKIPE cartridge sha256:ec1d85479d72847d3adbd76e2e79221143e6c9324d5647be2c4a11aa87123f75 - name:Ys III - Wanderers from Ys (Japan).nes + name:Ys III - Wanderers from Ys (Japan) cheat description:Hit anywhere code:XTKXSAAV+XTNXUAAV+XTVZKAAV+XVOZXAAV @@ -31208,6 +31601,9 @@ cartridge sha256:4cfc55e1521e58039d502f2a5ff16c233b84c0a05b1048185c75c971f3814c1 cheat description:Keys not necessary to open doors code:XVTIUO+XVTIXP + cheat + description:Gain over 2048 EXP wen you defeat an enemy most of the time + code:AAVIIGAE cheat description:Gain 256 EXP when you defeat an enemy most of the time code:XTSSTKSE @@ -31229,6 +31625,9 @@ cartridge sha256:4cfc55e1521e58039d502f2a5ff16c233b84c0a05b1048185c75c971f3814c1 cheat description:Link can fly (hold A) code:AAUOLIAL + cheat + description:Walk through walls in Overworld + code:AAOETYZA cheat description:Swap Shield spell for Fire spell code:OYKEEVSA+NPKEOVVA @@ -31452,6 +31851,8 @@ cartridge sha256:061d1c3865ad62ae883bb30b9f0071e8f7aa572f15f61bfb91b3a755eeeb5eb description:Infinite lives code:OXNEAAVK +database revision=2013-06-09 + cartridge sha256:8808783f789ca6413364a7abea240f6f7291b5906026f360ba8cfdd2791fc179 name:2020 Super Baseball (USA) cheat @@ -31817,6 +32218,12 @@ cartridge sha256:bb83f982961c33b81fefc1f545e18ab572d1c43cf6c241948544f05a1a71f2b cheat description:Infinite time - seconds code:7E11A6:09 + cheat + description:Cannot be tackled (hold X) - diving tackles + code:0732-A469+C932-A409+DC32-A4A9+FD32-A7D9 + cheat + description:Cannot be tackled (hold X) - normal tackles + code:0032-A400+4732-A7D0+7D32-A4A0+C932-A4D0+DC32-A460 cheat description:Have 0 points - Team 1 code:7E1182:00 @@ -31949,6 +32356,9 @@ cartridge sha256:b8055844825653210d252d29a2229f9a3e7e512004e83940620173c57d8723f cheat description:Unlock professional mode code:DD67-D7AD + cheat + description:Unlock action mode (press start at title screen) + code:DD60-DD0D cheat description:Have Fire magic and 24 MP in professional mode code:69C4-AF6C+62C4-A7DC+CBC4-A46C+DFC4-A4AC @@ -34079,6 +34489,9 @@ cartridge sha256:0f474dafe5a26f3dea491d18073dd490d2f1f91313a7e91086565510d38d9a0 cheat description:Infinite lives code:C268-CF0D + cheat + description:Get Stars from anywhere + code:6D8B-4D29+FB8B-4FF9 cartridge sha256:14d3ece30898587eda20c661a4a55ec595ba6352ca1f0bfc177542aa0eef0039 name:Arkanoid - Doh It Again (USA) @@ -34086,10 +34499,13 @@ cartridge sha256:14d3ece30898587eda20c661a4a55ec595ba6352ca1f0bfc177542aa0eef003 description:Infinite lives code:82B8-1704 cheat - description:"S" capsule gives you the longest paddle + description:Paddle hits ball anywhere + code:6DBE-C460+DDBE-CFD0 + cheat + description:S" capsule gives you the longest paddle code:D762-14D5 cheat - description:"S" capsule gives you the laser paddle + description:S" capsule gives you the laser paddle code:D062-14D5 cheat description:Force field lasts until end of level @@ -34334,6 +34750,9 @@ cartridge sha256:2431f8dc067ba27c6c3a846929f3deac6a45aa53a9a9ac20ede8ec5ca6854ea cheat description:Have 3rd weapon - Needle Cracker code:7E0334:0B + cheat + description:Start a new game to view ending + code:DAB1-AFA7 cartridge sha256:9e6ebebcf14609c2a38a5f4409d0c8c859949cded70c5b6fd16fd15d9983d9d3 name:B.O.B. (USA) @@ -34546,7 +34965,7 @@ cartridge sha256:e2be173c77bd1957787be36d13334f655e14d32dad99cacb0fd5e5fc65d96fa code:CBEA-DF60+DFEA-DFA0+B2EA-D4D0+4BEA-D4A0 cartridge sha256:db1ac03cc8b7daaa812da239029bcf999b30b2afe1c03d51f7ae849a796617ea - name:BASS Masters Classic - Pro Edition (USA) + name:Bass Masters Classic - Pro Edition (USA) cheat description:Start with $65,380 code:EE40-BA86 @@ -35283,6 +35702,12 @@ cartridge sha256:6fa6b8a8804ff6544bdedf94339a86ba64ce0b6dbf059605abb1cd6f102d348 description:Timer continues to count when it is normally stopped (time-out by pressing start) code:DDB7-67DF +cartridge sha256:ec2d91e238c26a5ddf7067d104b3b3e2eaee89255377e1eb6c4df8f301300e64 + name:Bill Walsh College Football (USA) + cheat + description:Cannot be tackled (hold X) + code:57D3-546F+7DD3-57DF+C9D3-540F+DCD3-54AF+E9D3-570F + cartridge sha256:de1de85ad549a6aaf0431cceb47cbd07e1f6e81f9e16fd62575305e2c1f06240 name:BioMetal (USA) cheat @@ -35366,6 +35791,42 @@ cartridge sha256:328c8f57e2ea371f6fd5b8a9834c56e35eb3bfe710502dd80f370739f9ccb7e cheat description:3rd slot item mod code:7E187A:03 + cheat + description:Standard Shotgun + code:7E021C:00 + cheat + description:Unrestricted manual Shotgun without reload (more presses, more shots) + code:7E021C:01 + cheat + description:Very fast automatic Shotgun + code:7E021C:02 + cheat + description:Very fast automatic Shotgun with explosive shells + code:7E021C:03 + cheat + description:Normal automatic Shotgun + code:7E021C:04 + cheat + description:Infinite Iron Keys + code:7E1876:02 + cheat + description:Infinite Potions + code:7E1878:04 + cheat + description:Infinite Hover Bombs + code:7E187A:05 + cheat + description:Infinite Levitators + code:7E187C:06 + cheat + description:Infinite Bridge Keys + code:7E187E:07 + cheat + description:Infinite Remote Wasps + code:7E1880:08 + cheat + description:Infinite Fire Bombs + code:7E1882:0A cartridge sha256:0d4e0d134396bd1c7254cdc1da356eb944ca14910b6690f484a75a9c3a8106e7 name:BlaZeon - The Bio-Cyborg Challenge (USA) @@ -37185,6 +37646,12 @@ cartridge sha256:d6f6c30732dae8d00cd83628c3156acbdf26f99df701f779522e21de74dae5f description:Shot guide is always on ("challenge record" mode) code:333E-D721 +cartridge sha256:9590110a990e90f525d5c8d70fc2a3da10879378003173b6761afb8bf042ee0d + name:Capcom's MVP Football (USA) + cheat + description:Cannot be tackled (hold B) + code:3DA3-DF09+7DA3-DFD9+C2A3-DD09+D5A3-DD69+F7A3-DDA9 + cartridge sha256:2a117951adcfbc4298763673a834d502c3f7a3964db1e59650f113c07bb831fb name:Captain America and the Avengers (USA) cheat @@ -38125,7 +38592,7 @@ cartridge sha256:a93ea87fc835c530b5135c5294433d15eef6dbf656144b387e89ac19cf86499 code:82BC-646B cheat description:Multi-jump - code:D961-04D9+CB61-0409+EC61-0469+EE61-04A9+B961-07D9+F361-0709+C961-0D69+4661-0DA9+4B61-0FD9+DD61-0F09+6D61-0F69+ED61-0FA9 + code:EE61-04A9+B961-07D9+F361-0709+C961-0D69+4661-0DA9+4B61-0FD9+DD61-0F09+6D61-0F69+ED61-0FA9+D961-04D9+CB61-0409+EC61-0469 cheat description:Enable stage select code:40CC-67DF @@ -38192,9 +38659,21 @@ cartridge sha256:a93ea87fc835c530b5135c5294433d15eef6dbf656144b387e89ac19cf86499 cartridge sha256:c7d622391f7699fb0dc6367e141c894e700cc9bd8abca69f36785e7bc2f42a49 name:Cool Spot (USA) + cheat + description:Infinite health + code:7E00D0:07 cheat description:Infinite lives code:402C-D7D1 + cheat + description:Infinite lives (alt) + code:7E00D4:09 + cheat + description:Infinite time (disable after completing stage) + code:7E00CE:68 + cheat + description:100% Coolness (disable after completing stage) + code:7E00D2:64 cheat description:Less invincibility time code:FE89-DF69 @@ -38960,6 +39439,9 @@ cartridge sha256:752d24fab240f4dd1dfbfea5ec83438998316806ad44488bf8c84430ca5a2cd cheat description:Infinite health code:F989-376F + cheat + description:Infinite health (alt) + code:7E9F30:7F cheat description:Infinite lives code:C2AC-1FDD @@ -38985,6 +39467,21 @@ cartridge sha256:752d24fab240f4dd1dfbfea5ec83438998316806ad44488bf8c84430ca5a2cd description:Jump 8x higher code:D680-67DF +cartridge sha256:248217975279bbf9db8e74da11a906a6dd867a3ec88441b0b031ecf900466618 + name:Demon's Blazon - Makai Mura Monshou Hen (Japan) + cheat + description:Invincibility + code:7E103C:5A + cheat + description:Infinite health + code:7E1062:15 + cheat + description:Maximum health bar + code:7E1E50:15 + cheat + description:999 ZAM + code:7E1063:E7+7E1064:03 + cartridge sha256:18d40a807d5f88c5b6a1ad849eec7e0f189225d9a1586037c850f6680b5844de name:Demon's Crest (USA) cheat @@ -40306,7 +40803,7 @@ cartridge sha256:d45e26eb10c323ecd480e5f2326b223e29264c3adde67f48f0d2791128e519e code:D7CF-F953 cartridge sha256:8d4ada4f98464d176ae7f0fb8a20032056680f3241637a0f903f23f31f41ff36 - name:Doom Troopers (USA) + name:Doom Troopers - Mutant Chronicles (USA) cheat description:Invincibility code:7E0C99:01 @@ -41165,6 +41662,9 @@ cartridge sha256:0408e3d9f2259044344a3bfbd7a7ca3c3427f82108fbecd6e5c4c41e80cd303 cheat description:Start at stage 6 code:D937-DDDD+CB34-D7AD+DD37-DD0D + cheat + description:Start a new game to view ending + code:D667-6F0D cartridge sha256:a8fe2226728002786d68c27ddddf0b90a894db52e4dfe268fdf72a68cae5f02e name:EarthBound (USA) @@ -41445,6 +41945,12 @@ cartridge sha256:a6eec3329d956e1ddc4acfe3c738387622c10fc95fb9ab63dd5f45be8bec0b1 description:No random battles code:F6C0-57D0 +cartridge sha256:f14e30ee452ec930a6d08094094b287d0c40c8108f2017c418015242987649b3 + name:Emmitt Smith Football (USA) + cheat + description:Cannot be tackled (hold B) + code:3EAF-1404+99AF-1F64+C2AF-1F04+DFAF-1FA4 + cartridge sha256:cfd666f0bbabec59613d9fe189db7d0a060a78047bc084c0c365840769047bf2 name:Equinox (USA) cheat @@ -42038,6 +42544,9 @@ cartridge sha256:b9594d588816ae570ea5fea14577ed47de4db9ac9a40a116c84e0ad7a2ce58f cheat description:Enable Clown and Karnov code:7E09A4:01 + cheat + description:Enable sound test + code:3CDE-E469+4DDE-E409+CBDE-E4D9 cartridge sha256:f71817f55febd32fd1dce617a326a77b6b062dd0d4058ecd289f64af1b7a1d05 name:Final Fantasy - Mystic Quest (USA) (Rev 1) @@ -43069,7 +43578,7 @@ cartridge sha256:10eccc5d2fab81346dd759f6be478dcb682eef981e8d3d662da176e1f9a996b code:7E0201:80 cheat description:Have all Rage's - code:7E1D49:FF+7E1D42:FF+7E1D3B:FF+7E1D3E:FF+7E1D4A:FF+7E1D46:FF+7E1D43:FF+7E1D47:FF+7E1D3C:FF+7E1D32:FF+7E1D48:FF+7E1D4B:FF+7E1D33:FF+7E1D2C:FF+7E1D44:FF+7E1D34:FF+7E1D2D:FF+7E1D3D:FF+7E1D2E:FF+7E1D45:FF+7E1D2F:FF+7E1D30:FF+7E1D31:FF+7E1D35:FF+7E1D36:FF+7E1D37:FF+7E1D3F:FF+7E1D38:FF+7E1D40:FF+7E1D39:FF+7E1D41:FF+7E1D3A:FF + code:7E1D35:FF+7E1D36:FF+7E1D37:FF+7E1D3F:FF+7E1D38:FF+7E1D40:FF+7E1D39:FF+7E1D41:FF+7E1D3A:FF+7E1D49:FF+7E1D42:FF+7E1D3B:FF+7E1D4A:FF+7E1D43:FF+7E1D3C:FF+7E1D4B:FF+7E1D44:FF+7E1D3D:FF+7E1D45:FF+7E1D3E:FF+7E1D46:FF+7E1D47:FF+7E1D48:FF+7E1D2C:FF+7E1D2D:FF+7E1D2E:FF+7E1D2F:FF+7E1D30:FF+7E1D31:FF+7E1D32:FF+7E1D33:FF+7E1D34:FF cheat description:Celes - Level 99 code:7E16E6:63 @@ -43732,7 +44241,7 @@ cartridge sha256:0f51b4fca41b7fd509e4b8f9d543151f68efa5e97b08493e4b2a0c06f5d8d5e code:7E3C06:00+7E3C07:00 cheat description:Have all Rage's - code:7E1D49:FF+7E1D42:FF+7E1D3B:FF+7E1D3E:FF+7E1D4A:FF+7E1D46:FF+7E1D43:FF+7E1D47:FF+7E1D3C:FF+7E1D32:FF+7E1D48:FF+7E1D4B:FF+7E1D33:FF+7E1D2C:FF+7E1D44:FF+7E1D34:FF+7E1D2D:FF+7E1D3D:FF+7E1D2E:FF+7E1D45:FF+7E1D2F:FF+7E1D30:FF+7E1D31:FF+7E1D35:FF+7E1D36:FF+7E1D37:FF+7E1D3F:FF+7E1D38:FF+7E1D40:FF+7E1D39:FF+7E1D41:FF+7E1D3A:FF + code:7E1D35:FF+7E1D36:FF+7E1D37:FF+7E1D3F:FF+7E1D38:FF+7E1D40:FF+7E1D39:FF+7E1D41:FF+7E1D3A:FF+7E1D49:FF+7E1D42:FF+7E1D3B:FF+7E1D4A:FF+7E1D43:FF+7E1D3C:FF+7E1D4B:FF+7E1D44:FF+7E1D3D:FF+7E1D45:FF+7E1D3E:FF+7E1D46:FF+7E1D47:FF+7E1D48:FF+7E1D2C:FF+7E1D2D:FF+7E1D2E:FF+7E1D2F:FF+7E1D30:FF+7E1D31:FF+7E1D32:FF+7E1D33:FF+7E1D34:FF cheat description:Celes - Level 99 code:7E16E6:63 @@ -44196,6 +44705,27 @@ cartridge sha256:0f51b4fca41b7fd509e4b8f9d543151f68efa5e97b08493e4b2a0c06f5d8d5e description:Umaro - 255 Magic Power code:7E17FE:FF +cartridge sha256:c6858d5c02894a6cc71f4dd452c7f288b319d1952ca56fdb185b4bf5e26244a2 + name:Final Fantasy V (Japan) + cheat + description:Max / infinite Gil + code:7E0947:7F+7E0948:96+7E0949:98 + cheat + description:No random battles (overworld) + code:7E16A9:00 + cheat + description:No random battles (dungeons) + code:7E0B4F:00 + cheat + description:Walk faster + code:7E0AFA:7F + cheat + description:Walk through walls in overworld + code:C011B0:70 + cheat + description:Save anywhere + code:7E0A53:20 + cartridge sha256:60cca2592d0756b8c4c7a0a254fafa5ac47aa752521fd1f77dcbf4b6ee1bee90 name:Final Fight (USA) cheat @@ -44507,6 +45037,9 @@ cartridge sha256:6f32355bef68d4ad58822f50074b46bcc9a68357cd2c6a5470c96bf5344f84d cartridge sha256:a0106f9cff7abbf25e081e2531f6d4b4aedf6f0dc8d155a66506817bff267d12 name:Firemen, The (Europe) (En,Fr,De) + cheat + description:Invincibility + code:7E08C9:01 cheat description:Infinite life code:7E15C7:31 @@ -44519,6 +45052,12 @@ cartridge sha256:a0106f9cff7abbf25e081e2531f6d4b4aedf6f0dc8d155a66506817bff267d1 cartridge sha256:003dba0193acc5336840307194643ca3b1f848dcfc77580b4e17c605105b27f5 name:Firepower 2000 (USA) + cheat + description:Invincibility - Jeep + code:7E612A:C7 + cheat + description:Invincibility - Heli + code:7E612C:C7 cheat description:Infinite lives code:8263-4DDF @@ -44720,6 +45259,12 @@ cartridge sha256:4c1354337efa788169387458fa6bdbcf4be0c98369920af2bd876ad98d29070 cartridge sha256:064a880a8dfcf576f74ae8a17c3ec7b0a27e8cb0300a5e5959452fcc30422f14 name:Flashback - The Quest for Identity (USA) (En,Fr,De) + cheat + description:Invincibility against enemies + code:C2D7-8DAC + cheat + description:Infinite shield + code:7EC746:05 cheat description:Never lose a shield when shot (disable to kill enemies) code:3C1F-EDAC @@ -44970,6 +45515,108 @@ cartridge sha256:ca3dd4620c692b2b8d3dd49b7dbdb1daa251ee0f7943050cc8a036e209cd7a0 description:Always get Rank S for dungeons, regardless of time taken code:BA2B-3FC4 +cartridge sha256:1735f790ebcfa1bed2430aecde3abaf24c88ff99aa0186736f8f36b674bc9350 + name:Garry Kitchen's Super Battletank - War in the Gulf (USA) (Rev 1) + cheat + description:Infinite health against most enemies and mines + code:C9AC-0D67 + cheat + description:Infinite weapon ammo (except Smoke Screens and Machine Gun) + code:4ABD-DDA4 + cheat + description:More Machine Gun ammo on stages 1-4 + code:EE2E-D4D4 + cheat + description:Less Machine Gun ammo on stages 1-4 + code:482E-D4D4 + cheat + description:More Cannon ammo on each mission + code:1022-D7D4 + cheat + description:Less Cannon ammo on each mission + code:FB22-D7D4 + cheat + description:More Laser Shells on each mission + code:D923-DF04 + cheat + description:No Laser Shells on each mission + code:DD23-DF04 + cheat + description:More Smoke Screens on each mission + code:D923-D7A4 + cheat + description:No Smoke Screens on each mission + code:DD23-D7A4 + cheat + description:Infinite health against most enemies and mines (alt) + code:00CDA2:A5 + cheat + description:Infinite Fuel + code:7E05C4:FF + cheat + description:Infinite 120mm Cannon + code:7E049E:42 + cheat + description:Infinite Laser Missiles + code:7E04A0:01 + cheat + description:Infinite Smoke Screens + code:7E04A1:01 + cheat + description:Infinite 7.62mm Machine Gun + code:7E04A2:96 + +cartridge sha256:94496e73fc7fdf2f72f16bf2becb0c3935db2ebd97555eac73b63400acbceec6 + name:Garry Kitchen's Super Battletank - War in the Gulf (USA) + cheat + description:Infinite health against most enemies and mines + code:C9AC-0D67 + cheat + description:Infinite weapon ammo (except Smoke Screens and Machine Gun) + code:4ABD-DDA4 + cheat + description:More Machine Gun ammo on stages 1-4 + code:EE2E-D4D4 + cheat + description:Less Machine Gun ammo on stages 1-4 + code:482E-D4D4 + cheat + description:More Cannon ammo on each mission + code:1022-D7D4 + cheat + description:Less Cannon ammo on each mission + code:FB22-D7D4 + cheat + description:More Laser Shells on each mission + code:D923-DF04 + cheat + description:No Laser Shells on each mission + code:DD23-DF04 + cheat + description:More Smoke Screens on each mission + code:D923-D7A4 + cheat + description:No Smoke Screens on each mission + code:DD23-D7A4 + cheat + description:Infinite health against most enemies and mines (alt) + code:00CDA2:A5 + cheat + description:Infinite Fuel + code:7E05C4:FF + cheat + description:Infinite 120mm Cannon + code:7E049E:42 + cheat + description:Infinite Laser Missiles + code:7E04A0:01 + cheat + description:Infinite Smoke Screens + code:7E04A1:01 + cheat + description:Infinite 7.62mm Machine Gun + code:7E04A2:96 + cartridge sha256:b87874a2292fe045385a2888e33009d5d2eabf55e379059aa5ef6c73b0475ff2 name:Gekitotsu Dangan Jidousha Kessen - Battle Mobile (Japan) cheat @@ -46704,6 +47351,12 @@ cartridge sha256:c7b1706a0ee96f3e0d65cd043c05966bfe3d5c57d08bbd2df3118817424adf8 description:Start with 3 plungers code:D74B-E7D7 +cartridge sha256:8304d8bc55aa9e64bdd144d384f4b185af2426e7d64888c6c23dd41366a53981 + name:Irem Skins Game, The (USA) + cheat + description:Ball goes in from anywhere + code:6DA2-676F+6DA6-6FAF+6DA8-046F+6DA8-64AF+DDAE-0FA4 + cartridge sha256:8e0d620a307a225a757bbc9ef2a2a666792e5d533aa0279d3c0060a1b93ead82 name:Iron Commando - Koutetsu no Senshi (Japan) cheat @@ -46840,10 +47493,13 @@ cartridge sha256:62557ee2a3fc3b5a3f59431f966eb61bb380ba983ef6c7742cb55cf075f15f6 code:7E0258:98 cheat description:Have all items - code:7E02B0:FF+7E02B1:FF+7E02B2:FF+7E02B3:FF+7E02B4:FF+7E02B5:01+7E02AA:FF+7E02AB:FF+7E02AC:FF+7E02AD:FF+7E02AE:FF+7E02AF:FF + code:7E02B3:FF+7E02B4:FF+7E02B5:01+7E02AA:FF+7E02AB:FF+7E02AC:FF+7E02AD:FF+7E02AE:FF+7E02AF:FF+7E02B0:FF+7E02B1:FF+7E02B2:FF cartridge sha256:3ffbb6e0ccf8e9f5e4c72d9fe526a16371e562b71a91d6430e562bf358a5126b name:Jack Nicklaus Golf (USA) + cheat + description:Ball goes in from anywhere + code:03AC-D407+6DAC-D4D7 cheat description:Infinite mulligans code:82BF-6707 @@ -48412,7 +49068,7 @@ cartridge sha256:f9ec39546e18b15b8f6a738204d0227c1542cd8157e3e0ea16934e76f39e288 code:7E1F0B:08 cheat description:All enemies frozen - code:7EFA69:8D+7EFA6A:8D+7EFA6B:8D+7EFA73:8D+7EFA6C:8D+7EFA74:8D+7EFA6D:8D+7EFA75:8D+7EFA6E:8D+7EFA7D:8D+7EFA76:8D+7EFA6F:8D+7EFA7E:8D+7EFA77:8D+7EFA70:8D+7EFA7F:8D+7EFA78:8D+7EFA71:8D+7EFA79:8D+7EFA72:8D+7EFA7A:8D+7EFA7B:8D+7EFA7C:8D+7EFA60:8D+7EFA61:8D+7EFA62:8D+7EFA63:8D+7EFA64:8D+7EFA65:8D+7EFA66:8D+7EFA67:8D+7EFA68:8D + code:7EFA60:8D+7EFA61:8D+7EFA62:8D+7EFA63:8D+7EFA64:8D+7EFA65:8D+7EFA66:8D+7EFA67:8D+7EFA68:8D+7EFA69:8D+7EFA6A:8D+7EFA6B:8D+7EFA6C:8D+7EFA6D:8D+7EFA6E:8D+7EFA6F:8D+7EFA70:8D+7EFA71:8D+7EFA72:8D+7EFA73:8D+7EFA74:8D+7EFA75:8D+7EFA76:8D+7EFA77:8D+7EFA78:8D+7EFA79:8D+7EFA7A:8D+7EFA7B:8D+7EFA7C:8D+7EFA7D:8D+7EFA7E:8D+7EFA7F:8D cartridge sha256:7cc3693cc5e1e834d57795f04b048fab27864a898a9507e7ca383771e2035414 name:Kawasaki Caribbean Challenge (USA) @@ -48641,6 +49297,9 @@ cartridge sha256:7a5261f1a5e84b67483c79fb002ce1539f2360f88333bda60f12e617d86e0de cheat description:No health - P2 code:7E0D28:00+7E0D2A:00 + cheat + description:One button finishes and humiliations + code:DD84-C40D cheat description:CPU cannot move from starting position code:7E0E08:01 @@ -48662,6 +49321,9 @@ cartridge sha256:618a23636e07110e094277ec1d1e60c3620a6e9a5f386292808267593fa803a cheat description:Hit anywhere - P1 code:0AB5-3FA7+CFB5-3407+CFB5-34D7+D2B5-3F67+EDB5-3F07 + cheat + description:One button finishes and humiliations + code:DD84-CD6D cheat description:CPU cannot perform special or danger moves code:CB24-CFDF+DD24-CF0F @@ -49445,9 +50107,12 @@ cartridge sha256:46c811f0cacffe8f20e1d63072d25d7c47e9bb3fd5124851fd05aca9884d21f cheat description:Pit death disabled code:1DA9-04D1 - -cartridge sha256:Get 1 gold for each creature killed - name:1BB5-D769+DFB5-D7A9+3CB6-DDD9 + cheat + description:Hit anywhere + code:DD84-64D9 + cheat + description:Get 1 gold for each creature killed + code:1BB5-D769+DFB5-D7A9+3CB6-DDD9 cheat description:Get 100 gold for each creature killed code:1BB5-D769+10B5-D7A9+3CB6-DDD9 @@ -49552,7 +50217,7 @@ cartridge sha256:48cd9476fef1ed685b9c30dd1669b46048f7295cbbb2abcfa5b1a48699346ea name:Lamborghini American Challenge (USA) cheat description:Always finish first - code:58E6-CF18+6D60-C71C+ADE6-CD48+BBE6-CF38+DDE6-CD18+DDE6-CDC8+D4E6-CF48+E360-C7CC+F1E6-C418+FCE6-CFC8+1DE6-C4C8+2DE6-CD38+4D60-C74C+53E6-C448 + code:DDE6-CDC8+D4E6-CF48+E360-C7CC+F1E6-C418+FCE6-CFC8+1DE6-C4C8+2DE6-CD38+4D60-C74C+53E6-C448+58E6-CF18+6D60-C71C+ADE6-CD48+BBE6-CF38+DDE6-CD18 cheat description:Don't take damage in races code:8B81-34D7 @@ -49895,6 +50560,9 @@ cartridge sha256:66871d66be19ad2c34c927d6b14cd8eb6fc3181965b6e517cb361f7316009cf cheat description:Dash without charge up code:45B8-D49A + cheat + description:Walk on deep water + code:106A-A422+2327-6423+9827-64B3 cheat description:Use the Magic Mirror to warp between the Light and Dark Worlds freely code:6DC9-0D23 @@ -50753,6 +51421,15 @@ cartridge sha256:3bc5f296c3dbee012e93a5cf25568f9288ce87b34d74085401a560350eaca03 cheat description:Have Uzi - P2 code:7E1FBE:0C + cheat + description:Start a new game to enter the Konami Gun System Check Mode + code:D562-1F04 + cheat + description:Start a new game to enter the Sound Check Mode + code:FD62-1F04 + cheat + description:Start a new game to enter the Object Test + code:FF62-1F04 cartridge sha256:80c22cc92d51a54de9cd9fd00db5ff58a35fff35e822169c94e445d50834fba3 name:Lethal Weapon (USA) @@ -53350,7 +54027,7 @@ cartridge sha256:7c34ecb16c10f551120ed7b86cfbc947042f479b52ee74bb3c40e92fdd192b3 code:7E0B55:7F+7E0B56:96+7E0B57:98 cheat description:All warps - code:7E098D:FF+7E098E:FF+7E098F:FF+7E0981:FF+7E0990:FF+7E0982:FF+7E097B:FF+7E0983:FF+7E097C:FF+7E097D:FF+7E097E:FF+7E097F:FF+7E0980:FF+7E0986:FF+7E0988:FF+7E0989:FF+7E0991:FF+7E098A:FF+7E0992:FF+7E098B:FF+7E0996:FF+7E098C:FF + code:7E0986:FF+7E0988:FF+7E0989:FF+7E0991:FF+7E098A:FF+7E0992:FF+7E098B:FF+7E0996:FF+7E098C:FF+7E098D:FF+7E098E:FF+7E098F:FF+7E0990:FF+7E097B:FF+7E097C:FF+7E097D:FF+7E097E:FF+7E097F:FF+7E0980:FF+7E0981:FF+7E0982:FF+7E0983:FF cheat description:P1 - 999 HP code:7E0BBE:E7+7E0BBF:03 @@ -54489,31 +55166,31 @@ cartridge sha256:7bffa1dc31604fa3d61e06ce2c59168098cc8dd7e59998e1d5f30c49bdf8d61 description:Large Laser starts at 10,000 code:FD00-7128+4100-75F8 cheat - description:"Inferno" Short-Range Missiles start at 10 + description:Inferno" Short-Range Missiles start at 10 code:DC00-7198 cheat - description:"Inferno" Short-Range Missiles start at 50 + description:Inferno" Short-Range Missiles start at 50 code:7400-7198 cheat - description:"Inferno" Short-Range Missiles start at 250 + description:Inferno" Short-Range Missiles start at 250 code:EC00-7198 cheat - description:"Maelstrom" Long-Range Missiles start at 20 + description:Maelstrom" Long-Range Missiles start at 20 code:F009-7098 cheat - description:"Maelstrom" Long-Range Missiles start at 100 + description:Maelstrom" Long-Range Missiles start at 100 code:1009-7098 cheat - description:"Maelstrom" Long-Range Missiles start at 250 + description:Maelstrom" Long-Range Missiles start at 250 code:EC09-7098 cheat - description:"Thunder" Time-Delay Mines start at 10 + description:Thunder" Time-Delay Mines start at 10 code:DC00-7598 cheat - description:"Thunder" Time-Delay Mines start at 100 + description:Thunder" Time-Delay Mines start at 100 code:1000-7598 cheat - description:"Thunder" Time-Delay Mines start at 250 + description:Thunder" Time-Delay Mines start at 250 code:EC00-7598 cartridge sha256:ee1a030f30f3ab06361921447b3fcf84c987dd13d76e62964e44720e0ec82c56 @@ -54556,7 +55233,7 @@ cartridge sha256:a255fec32453739903a1954149f19bc9658f4a415600b44badf1d4e5e13a16f code:6DD8-7DD2 cheat description:Multi-jump - code:DC51-ED65+BD51-EDA5+D751-EFD5+4D51-EF05+8551-EF65+7451-EFA5+4D51-E4D5+BC51-E405+FF51-E465+1D51-E4A5+1DFC-E400+5EFC-E460+C951-EDD5+0951-ED05 + code:7451-EFA5+4D51-E4D5+BC51-E405+FF51-E465+1D51-E4A5+1DFC-E400+5EFC-E460+C951-EDD5+0951-ED05+DC51-ED65+BD51-EDA5+D751-EFD5+4D51-EF05+8551-EF65 cheat description:Always Shoot Shots code:FF40-E405 @@ -55607,6 +56284,27 @@ cartridge sha256:3c6d3e4a9c9af160f1c1cf11ce4ead531d9500c1f58f1cbe682c90a5eaa3efb cheat description:P1 nearly invincible in 2P game (go to options, move P1メs handicap bar all the way to the right) code:D881-404F + cheat + description:One button fatalities - Liu Kang (Press Down) + code:DD2D-146D + cheat + description:One button fatalities - Johnny Cage (Press Y) + code:D6A0-C404 + cheat + description:One button fatalities - Kano (Press B) + code:D62D-44AF + cheat + description:One button fatalities - Sonya (Press L or R) + code:DD2A-CDD4 + cheat + description:One button fatalities - Sub Zero (Press Y) + code:D6AE-4DD7 + cheat + description:One button fatalities - Raiden (Press Y) + code:D6AD-3D04 + cheat + description:One button fatalities - Scorpion (Press Up, L or R) + code:D227-47AD cheat description:All throws do more damage code:56B9-4DAD @@ -56140,7 +56838,7 @@ cartridge sha256:417874aa57856fe93eefdb24066fa1a9ca3f23c72c09d5247ae2b3ab4b3d09d code:A220-3FB6 cheat description:Hit anywhere - P1 - code:3DE6-3DDE+6D30-1462+C4E6-3F6E+D4E6-3D0E+DDE6-3D6E+EDE6-3DAE+D7E6-3FDE+EE30-14A2+0AE6-3F0E+0AE6-340E+0AE6-34DE+39E6-346E+39E6-3FAE + code:DDE6-3D6E+EDE6-3DAE+D7E6-3FDE+EE30-14A2+0AE6-3F0E+0AE6-340E+0AE6-34DE+39E6-346E+39E6-3FAE+3DE6-3DDE+6D30-1462+C4E6-3F6E+D4E6-3D0E cheat description:Press A on main menu for Sound Test code:D42E-44D8 @@ -57150,6 +57848,48 @@ cartridge sha256:8ef5d5c50ffeca1e62e88e4fe2909eaf191e28fbb5a9faf98b7b10bea72c9ed description:No 5-second violations code:C265-D4D7 +cartridge sha256:6a59115a9958d4a9fa167095505a2ddf222ca6291209d07618319e39a2be8b61 + name:NFL Quarterback Club (USA) + cheat + description:Cannot be tackled (hold X) + code:4EB6-4F08+C9B6-4FD8+DCB6-4F68+FDB6-4FA8 + +cartridge sha256:f43f8ec546b8060e9d191fca860c38caf5a43eda86a304f0073647c6fad7b2c9 + name:NFL Quarterback Club 96 (USA) + cheat + description:Cannot be tackled (hold X) + code:136C-14AC+C96C-146C+DC6C-17DC+FD6C-170C + +cartridge sha256:5132e1c0d466963e6adc09e8a608ebd90619ab94f7fc908d626bbaf6a99dfa19 + name:NHL '94 (USA) + cheat + description:Score from anywhere (hold X) + code:59BC-45E6+D3BC-4586+D5B8-4076+DEB8-4976+FDB8-4056 + +cartridge sha256:01c0b58d5fd5d5484fea988455a55a71ed9e606538d2b3ce3f216159cc6929b0 + name:NHL 95 (USA) + cheat + description:Score from anywhere (hold X while in the opponent's half of the rink) + code:0900-77FF+AD00-7FBF+C100-742F+C900-7F9F+DC00-7F2F+FD00-74FF + +cartridge sha256:d24c0175ee4eafed88e277691c5f5dafd4e197723097e2eb68aa6b40f449fff2 + name:NHL 96 (USA) + cheat + description:Score from anywhere (hold X while in the opponent's half of the rink) + code:8F08-EDF6+C90C-E726+DC08-ED96+DC08-EF96+FD08-EDB6 + +cartridge sha256:2a2dc2ef84efd9a773d1e8231b7e3e57f0de7e4528968670963f2f1f358eef39 + name:NHL 97 (USA) + cheat + description:Score from anywhere (hold X while in the opponent's half of the rink) + code:0904-7FFB+8F0F-77BB+5604-7D2B+C90F-779B+DC0F-772B+FD04-7DFB + +cartridge sha256:8113c2cedafc8fd5a56c8638ae340fb275f263ff5c5e18d04dc6c3ebc5cfffee + name:NHL 98 (USA) + cheat + description:Score from anywhere (hold X while in the opponent's half of the rink) + code:0501-879B+8F01-8F2B+AF01-87FB+C901-8FBB+DC01-84FB+FD01-849B + cartridge sha256:d44f487d84f5bb761955b7b70a5464b2f094e199875f595f312c88e04ac647ff name:NHL Stanley Cup (USA) (En,Fr) cheat @@ -58168,7 +58908,7 @@ cartridge sha256:db44f8b58a31b640a47aa4390101c3c6a5f613e4e49c636d44786278033dec1 code:D480-4F61 cartridge sha256:582548dc86598a3557e9e3c27285c81964b006a954affe5c73948da5375ea11c - name:Out of This World (USA) + name:Out of this World (USA) cheat description:First three shields are infinite code:7E0D84:E7+7E0D8A:E7+7E0D90:E7 @@ -58178,12 +58918,39 @@ cartridge sha256:582548dc86598a3557e9e3c27285c81964b006a954affe5c73948da5375ea11 cartridge sha256:54b2f03393109ac7fd36d8c7752f15a44d9607ab0187a371b853191db3592c01 name:Out to Lunch (USA) + cheat + description:Invincibility + code:7E0002:C8 cheat description:Infinite lives code:7E0088:63 + cheat + description:Infinite time + code:7E008A:A9 cheat description:Score modifier code:7E0009:63 + cheat + description:Start with Net + code:7E009E:01 + cheat + description:Start with Bag Of Flour (choose one) + code:7E009F:01 + cheat + description:Start with hot sauce attack (choose one) + code:7E009F:02 + cheat + description:Start with spoon (choose one) + code:7E009F:03 + cheat + description:Start with Cleats + code:7E00A2:01 + cheat + description:Exit is open + code:7E00BE:00 + cheat + description:Hidden warp is open (whenever available) + code:7E000B:01 cartridge sha256:10c8abce67b49f8afbe880d2f13e0fd6d5efc162df34d5941e4a94851f23b2ff name:Pac-Attack (USA) @@ -58192,7 +58959,7 @@ cartridge sha256:10c8abce67b49f8afbe880d2f13e0fd6d5efc162df34d5941e4a94851f23b2f code:7E160E:FF cartridge sha256:7fe4cb9c294d66589ff78e225774471ecb7db80df25f2b6199ca25671358072b - name:Pac-in-Time (USA) + name:Pac-In-Time (USA) cheat description:Infinite health code:7E1533:BF @@ -58889,6 +59656,60 @@ cartridge sha256:be1bf238d76b74bfcc0b86a899b8caedd0a49c105576c659b56045c85512a16 cheat description:Access all weapons (highlight weapon and press X to equip) code:B23B-34D9 + cheat + description:Invincibility + code:7E0410:DC + cheat + description:Moonjump + code:7E0294:06 + cheat + description:Have Wave Gun + code:7E0CD3:01 + cheat + description:Have Blank Space + code:7E0CD4:01 + cheat + description:Have Spread + code:7E0CD5:01 + cheat + description:Have Devestator + code:7E0CD6:01 + cheat + description:Have Homing Missile + code:7E0CD7:01 + cheat + description:Have Breaker + code:7E0CD8:01 + cheat + description:Have Boomerang + code:7E0CD9:01 + cheat + description:Have Explosive Pellets + code:7E0CDA:01 + cheat + description:Have Super Explosive Pellets + code:7E0CDB:01 + cheat + description:Have Flash Pellets + code:7E0CDC:01 + cheat + description:Have Fire Retardant Pellets + code:7E0CDD:01 + cheat + description:Have Shadow Panther + code:7E0CDE:01 + cheat + description:Have Invisibility + code:7E0CDF:01 + cheat + description:Have Armor + code:7E0CE0:01 + cheat + description:Have First Aid Kit + code:7E0CE1:01 + cheat + description:Have Energy Aid Kit + code:7E0CE2:01 cartridge sha256:b7291088f5c49e1fc55bf932076ec03f7b39f6e409ae06e884b57024c56cdc87 name:Phantom 2040 (USA) @@ -58904,6 +59725,60 @@ cartridge sha256:b7291088f5c49e1fc55bf932076ec03f7b39f6e409ae06e884b57024c56cdc8 cheat description:Access all weapons (highlight weapon and press X to equip) code:233E-3FD9 + cheat + description:Invincibility (alt) + code:7E0410:DC + cheat + description:Moonjump + code:7E0294:06 + cheat + description:Have Wave Gun + code:7E0FD3:01 + cheat + description:Have Blank Space + code:7E0FD4:01 + cheat + description:Have Spread + code:7E0FD5:01 + cheat + description:Have Devestator + code:7E0FD6:01 + cheat + description:Have Homing Missile + code:7E0FD7:01 + cheat + description:Have Breaker + code:7E0FD8:01 + cheat + description:Have Boomerang + code:7E0FD9:01 + cheat + description:Have Explosive Pellets + code:7E0FDA:01 + cheat + description:Have Super Explosive Pellets + code:7E0FDB:01 + cheat + description:Have Flash Pellets + code:7E0FDC:01 + cheat + description:Have Fire Retardant Pellets + code:7E0FDD:01 + cheat + description:Have Shadow Panther + code:7E0FDE:01 + cheat + description:Have Invisibility + code:7E0FDF:01 + cheat + description:Have Armor + code:7E0FE0:01 + cheat + description:Have First Aid Kit + code:7E0FE1:01 + cheat + description:Have Energy Aid Kit + code:7E0FE2:01 cartridge sha256:03d0127f5de3237e22ad00de0c20763274da7b71142dde693240ac96d10983a3 name:Pilotwings (USA) @@ -59412,6 +60287,12 @@ cartridge sha256:0288ec049723cd0c7f1148cdc1aef0b6922b8a756affe373c99d5690e0dfcea description:Start on level Road to Wolff Castle code:7E1874:03 +cartridge sha256:982a56e543995ca2221a4a58431cdeb03ac178e2874c2d6ac00be15bddc6eb02 + name:Power Soukoban (Japan) + cheat + description:Invincibility + code:DD3F-17D9 + cartridge sha256:8f387d083de1399bb79e5312c31a6f1757f2a536bfa25cecf1aea77bfd77058b name:Prehistorik Man (USA) (En,Fr,Es) cheat @@ -59477,6 +60358,9 @@ cartridge sha256:55376715f243b1bacd9aeecf1092bbc7837fe512592a2c1703d24b0829fc193 cartridge sha256:494190cd6d7fd68882cbe255a6e237d9c4bdaf3988615ede0297a5e285ad5dd9 name:Prince of Persia (USA) + cheat + description:Invincibility against enemies + code:C2BA-AFD0 cheat description:Infinite time code:6D32-0FA1+DC32-04D1 @@ -59492,6 +60376,9 @@ cartridge sha256:494190cd6d7fd68882cbe255a6e237d9c4bdaf3988615ede0297a5e285ad5dd cheat description:Falls do no damage except spikes (if you get stuck choose End Game and use a password to start the level over) code:6DC0-6701 + cheat + description:Walk on air (Can walk over pits. Run to any wall to fall down or walk to the edge of any floor to climb down.) + code:6DCE-ADD1 cheat description:All enemies have 1 health point code:C260-A701+DF6C-DFA0 @@ -59931,6 +60818,21 @@ cartridge sha256:475c9baa1c2b76a6b3119e47d32814dc1c08e84e23250ae015bb0bccea91563 description:Start on level 99 code:CB66-AD6F+6266-AF0F+1466-ADAF +cartridge sha256:ba135ad37fef9932c2f840cf6cf82d559c232dfe0f85ba068a34755f3ad5f778 + name:Putty Squad (Europe) + cheat + description:Infinite health + code:7E0026:4E + cheat + description:Infinite lives + code:7E0035:99 + cheat + description:99 Stars + code:7E004F:99 + cheat + description:All Putties saved + code:7E0024:00 + cartridge sha256:89d57bf308033ef17f770a80080cbeed2d112244635d5b5f860f2016398cd2f6 name:Q-bert 3 (USA) cheat @@ -60717,7 +61619,7 @@ cartridge sha256:ba54d715abf100b94fee801351986fa818e4309730cefbacf9b4fad36e284c1 description:Powdered Toast Shield lasts 85x longer code:EEE8-6DD6 cheat - description:"Socks" power-up lasts 200x longer + description:Socks" power-up lasts 200x longer code:EEEF-D7AB cheat description:Stimpy's mouth won't close @@ -60768,6 +61670,12 @@ cartridge sha256:82a9ee11b5640409c67772363f1148517b26127cef13aa2a8ffc2480b487d81 description:Best Yellow weapon code:7E0AA0:04 +cartridge sha256:b61addb0abd36ebd29e5c2988ae642b174bfec18a899cfe40866000dc934f658 + name:Return of Double Dragon (Japan) + cheat + description:Invincibility (blinking) + code:7E1F92:01 + cartridge sha256:5fb072c3c2e9d8e7f84bea9c4bf2253e6868eb2b1f13e35a7d75fdf05896d873 name:Revolution X (USA) cheat @@ -61498,7 +62406,7 @@ cartridge sha256:4fc2832e7aa01d105ca67977b38840ec1188869b5e74d20e58613c1cd127d78 code:7E0B97:FF cheat description:Have all CDs - code:306045:FF+306046:FF+306047:FF+306048:FF+306049:FF+30604A:FF+30604B:FF+30604C:1F+306040:FE+306041:FF+306042:FF+306043:FF+306044:FF + code:306049:FF+30604A:FF+30604B:FF+30604C:1F+306040:FE+306041:FF+306042:FF+306043:FF+306044:FF+306045:FF+306046:FF+306047:FF+306048:FF cheat description:One hit kills (alt) code:7E1A2F:01 @@ -61724,6 +62632,9 @@ cartridge sha256:00e78318926e5cae79bce0535fddd3dccaa732f5c70e43acefc2769a9899eae cheat description:One hit kills code:1028-CDD3 + cheat + description:Choose Dick to play as Super Dick + code:7E060A16+7E060B04 cartridge sha256:0aa16d6b588ba05ab00936201e68a694746fc5e1b2e4f2dbf7cda09265a81379 name:Sailormoon (France) @@ -62021,6 +62932,30 @@ cartridge sha256:17c864a76d498feb6479eee8e7d6807b951c66225033228622bb66754baab1d cartridge sha256:4c15013131351e694e05f22e38bb1b3e4031dedac77ec75abecebe8520d82d5f name:Secret of Mana (USA) + cheat + description:999 health - P1 + code:7EE182:E7+7EE183:03 + cheat + description:999 health - P2 + code:7EE382:E7+7EE383:03 + cheat + description:999 health - P3 + code:7EE582:E7+7EE583:03 + cheat + description:999 Max health - P1 + code:7EE184:E7+7EE185:03 + cheat + description:999 Max health - P2 + code:7EE384:E7+7EE385:03 + cheat + description:999 Max health - P3 + code:7EE584:E7+7EE585:03 + cheat + description:Infinite MP + code:7EE386:63+7EE586:63 + cheat + description:Infinite GP + code:7ECC6A:7F+7ECC6B:96+7ECC6C:98 cheat description:Protection from most hits (disable to kill enemies) code:8208-776D @@ -62210,18 +63145,24 @@ cartridge sha256:85092f4c566b4d34bd4bd70be55df92bfbda40f0030e63a15bafbb8f760c151 cartridge sha256:e6bc0a595d5c7c4bc0bbb61ffe35a70288a77eb78544ed74682d489a9e6f07f4 name:Shadowrun (USA) + cheat + description:Infinite health in the Matrix + code:C285-17A0 cheat description:Everything is free code:6DAE-4FA7+FFAE-44D7 cheat - description:Don't subtract karma for spells/skills (must have enough to advance) + description:Karma not subtracted for spells/skills (must have enough to advance) code:CEEF-4DDD cheat - description:Don't subtract karma for shooting people (ignore message saying you lost karma) + description:Karma not subtracted for shooting people (ignore message saying you lost karma) code:CE6D-47A4 cheat - description:Don't subtract spell points (works for all spell casters) (casting spells you aren't allowed to raises your spell points) + description:Spell points not subtracted (works for all spell casters) (casting spells you aren't allowed to raises your spell points) code:8E69-3DA4 + cheat + description:Walk through walls + code:6D6D-C709 cheat description:Going up 1 body point adds 20 stamina instead of 10 code:F0E1-1FDD @@ -62354,6 +63295,12 @@ cartridge sha256:e6bc0a595d5c7c4bc0bbb61ffe35a70288a77eb78544ed74682d489a9e6f07f cheat description:Start with 100 stamina code:10B8-4DA4 + cheat + description:Lots of Nuyen + code:7E3C0D:7F+7E3C0E:96+7E3C0F:98 + cheat + description:Infinite / max HP + code:7E33DE:C8+7E3C00:C8+7E3C01:01 cartridge sha256:c73757eea258e169e506eaef989227a59918060f94117917f338183db14c50b6 name:Shaq-Fu (USA) @@ -62729,6 +63676,21 @@ cartridge sha256:a4ba1483db79c3f6278082387bce216d8f3e3b11ca32d49516d27f5ac07135a cheat description:Infinite Warrior Force code:7E0089:FF + cheat + description:Hit anywhere + code:DD6F-D765+6D63-A4D1 + cheat + description:Get items from anywhere + code:6D83-AFDB + cheat + description:One hit kills + code:DDE5-64A5 + cheat + description:Enemies die automatically + code:6D66-A701+DD6F-D765+6D63-A4D1+DDE5-64A5 + cheat + description:All enemies frozen + code:7EFA60:8D+7EFA61:8D+7EFA62:8D+7EFA63:8D+7EFA64:8D+7EFA65:8D+7EFA66:8D+7EFA67:8D+7EFA68:8D+7EFA69:8D+7EFA6A:8D+7EFA6B:8D+7EFA6C:8D+7EFA6D:8D+7EFA6E:8D+7EFA6F:8D+7EFA70:8D+7EFA71:8D+7EFA72:8D+7EFA73:8D+7EFA74:8D+7EFA75:8D+7EFA76:8D+7EFA77:8D+7EFA78:8D+7EFA79:8D+7EFA7A:8D+7EFA7B:8D+7EFA7C:8D+7EFA7D:8D+7EFA7E:8D+7EFA7F:8D cheat description:Have 99 gems code:7E1F0E:63 @@ -62756,9 +63718,6 @@ cartridge sha256:a4ba1483db79c3f6278082387bce216d8f3e3b11ca32d49516d27f5ac07135a cheat description:Have Fiery Phoenix code:7E1F0B:08 - cheat - description:All enemies frozen - code:7EFA69:8D+7EFA6A:8D+7EFA6B:8D+7EFA73:8D+7EFA6C:8D+7EFA74:8D+7EFA6D:8D+7EFA75:8D+7EFA6E:8D+7EFA7D:8D+7EFA76:8D+7EFA6F:8D+7EFA7E:8D+7EFA77:8D+7EFA70:8D+7EFA7F:8D+7EFA78:8D+7EFA71:8D+7EFA79:8D+7EFA72:8D+7EFA7A:8D+7EFA7B:8D+7EFA7C:8D+7EFA60:8D+7EFA61:8D+7EFA62:8D+7EFA63:8D+7EFA64:8D+7EFA65:8D+7EFA66:8D+7EFA67:8D+7EFA68:8D cartridge sha256:cbca00fa5dfd6c72db2f21d010255657c33f7ac48de2554262035ead11bdf314 name:Smart Ball (USA) @@ -63594,81 +64553,6 @@ cartridge sha256:eaa06470734ea57eff9b888137aa468fcb7bb149a0870a85e68c9db123de467 description:1 Jewel needed for 1-up code:7E016A:63 -cartridge sha256:32d0f1ca5b91fd9b2caf81422fb9e8fb30bc091f0b2a429b9269dd307fcba4fd - name:Spawn - The Video Game (USA) - cheat - description:Invincibility after one hit (invisible) - code:C203-84D1 - cheat - description:Almost invincible (blinking) - code:3C03-8F61 - cheat - description:Infinite health - code:C208-87D1 - cheat - description:Hit anywhere - code:40F8-84B0 - cheat - description:Don't blink after getting hit - code:FDDB-5FB9 - cheat - description:Falling doesn't use life points - code:C2F4-7FD1 - cheat - description:Special moves don't use life points - code:C27D-8701 - cheat - description:Some bullets do 2x damage - code:D6D7-8F20 - cheat - description:Some bullets do no damage - code:DDD7-8F20 - cheat - description:Some bullets kill you - code:EED7-8F20 - cheat - description:Some enemy punches electrocute you - code:DB78-84B0 - cheat - description:Some enemy punches do no damage - code:DD78-84B0 - cheat - description:Some enemy punches kill you - code:EE78-84B0 - cheat - description:Guys with pipes do 2x damage - code:DBB0-EFA3+DBCF-8763 - cheat - description:Guys with pipes do no damage - code:DDB0-EFA3+DDCF-8763 - cheat - description:Guys with pipes kill - code:EEB0-EFA3+EECF-8763 - cheat - description:Flaming bottles do 2x damage - code:DB4B-7DF1+DB43-E4F9 - cheat - description:Flaming bottles do no damage - code:DD4B-7DF1+DD43-E4F9 - cheat - description:Flaming bottles kill - code:EE4B-7DF1+EE43-E4F9 - cheat - description:Start with 1/4 health - code:FDB0-E4DB - cheat - description:Start with 1/2 health - code:4CB0-E4DB - cheat - description:Start with 3/4 health - code:73B0-E4DB - cheat - description:Invincibility - code:7E1F56:1F - cheat - description:Infinite health (alt) - code:7E1F00:63 - cartridge sha256:fe2371bed45f5e244ce3ef8585894c0ffa4272e3f58c2f4795ef91fb1ee54b15 name:Spectre (USA) cheat @@ -64121,12 +65005,21 @@ cartridge sha256:e0196201e432fa33d46a2681f84fe6a0b5f952ba43f8e4dc325f892bb4a0b39 cartridge sha256:3857b5294ea8f7468849437bb2d8271564e8a0ff30774622e9c872bcbd53a84d name:Star Fox (USA) + cheat + description:Invincible right wing + code:7E0402:05 + cheat + description:Invincible left wing + code:7E03CC:05 cheat description:Infinite Shield code:79DB-2286 cheat description:Infinite Shield (alt) code:46DB-2286 + cheat + description:Infinite Shield (alt 2) + code:7E0396:35 cheat description:Infinite Shield - Slippy code:0DFC-FA8C @@ -64136,24 +65029,27 @@ cartridge sha256:3857b5294ea8f7468849437bb2d8271564e8a0ff30774622e9c872bcbd53a84 cheat description:Infinite Shield - Peppy code:0DFC-FA7C + cheat + description:Infinite Nova Bombs out + code:7E1528:01 cheat description:Infinite Bombs code:D9FC-9EEB - cheat - description:Infinite lives - code:DBF3-BE8B - cheat - description:Have Double Blaster - code:F4F2-F38B+DFF2-F35B - cheat - description:Infinite Shield (alt 2) - code:7E0396:35 cheat description:Infinite Bombs (alt) code:7E15AF:05 + cheat + description:Infinite lives + code:DBF3-BE8B cheat description:Infinite lives (alt) code:7E16EE:0A + cheat + description:All views available in all stages + code:7E14DE:05 + cheat + description:Have Double Blaster + code:F4F2-F38B+DFF2-F35B cheat description:Have Double Blaster (alt) code:7E14DA:12 @@ -65016,7 +65912,7 @@ cartridge sha256:05f14e6ed3394d9273e2397769a8acf1a9db646be6066e82269521e8eec5356 cartridge sha256:c04d80b84514202ff319384ca20641eb0189e975eed5612915bd9c224b2ab30a name:Stunt Race FX (USA) (Rev 1) cheat - description:Always first + description:Always first place code:182E-07FE cheat description:Choose any car @@ -65051,6 +65947,9 @@ cartridge sha256:e9c406d4f773697b9b671e7ddf2207c9d0ab242d7f23e502cdd453fbb264d39 cheat description:Infinite lives code:8232-3D0F + cheat + description:Start a new game for stage select and sound test + code:F065-44A4 cartridge sha256:190999122aacc2cff20c5677b3f60ed938d8a36b696d16cc1bf416705efe151e name:Super Adventure Island (USA) @@ -65074,7 +65973,7 @@ cartridge sha256:190999122aacc2cff20c5677b3f60ed938d8a36b696d16cc1bf416705efe151 code:2D83-64A2+6D83-6462+C983-6402+DD21-0D0D+F383-67D2 cheat description:Multi-jump - code:4D8C-640D+E28C-646D+C2E4-0DD7+E6E4-0D07+D8E4-0D67+06E4-0DA7+DCE4-0FD7+FDE4-0F07+D9E4-0F67+CBE4-0FA7+DDE4-04D7+ECE4-0407+B9E4-0467+FCE4-04A7+16E4-07D7+1DE4-0707+4D8C-64DD + code:D9E4-0F67+CBE4-0FA7+DDE4-04D7+ECE4-0407+B9E4-0467+FCE4-04A7+16E4-07D7+1DE4-0707+4D8C-64DD+4D8C-640D+E28C-646D+C2E4-0DD7+E6E4-0D07+D8E4-0D67+06E4-0DA7+DCE4-0FD7+FDE4-0F07 cheat description:Don't lose all weapon power when you die (may give you unusual weapons) code:79C0-A7DD+79C6-A4DD @@ -65553,108 +66452,6 @@ cartridge sha256:165938810948f3226f7446978fa36ae8bc781616d95b39cd126d5c8afbf6e2e description:5 strikes per out code:D9BD-67AA -cartridge sha256:1735f790ebcfa1bed2430aecde3abaf24c88ff99aa0186736f8f36b674bc9350 - name:Super Battletank - War in the Gulf (USA) (Rev 1) - cheat - description:Infinite health against most enemies and mines - code:C9AC-0D67 - cheat - description:Infinite weapon ammo (except Smoke Screens and Machine Gun) - code:4ABD-DDA4 - cheat - description:More Machine Gun ammo on stages 1-4 - code:EE2E-D4D4 - cheat - description:Less Machine Gun ammo on stages 1-4 - code:482E-D4D4 - cheat - description:More Cannon ammo on each mission - code:1022-D7D4 - cheat - description:Less Cannon ammo on each mission - code:FB22-D7D4 - cheat - description:More Laser Shells on each mission - code:D923-DF04 - cheat - description:No Laser Shells on each mission - code:DD23-DF04 - cheat - description:More Smoke Screens on each mission - code:D923-D7A4 - cheat - description:No Smoke Screens on each mission - code:DD23-D7A4 - cheat - description:Infinite health against most enemies and mines (alt) - code:00CDA2:A5 - cheat - description:Infinite Fuel - code:7E05C4:FF - cheat - description:Infinite 120mm Cannon - code:7E049E:42 - cheat - description:Infinite Laser Missiles - code:7E04A0:01 - cheat - description:Infinite Smoke Screens - code:7E04A1:01 - cheat - description:Infinite 7.62mm Machine Gun - code:7E04A2:96 - -cartridge sha256:94496e73fc7fdf2f72f16bf2becb0c3935db2ebd97555eac73b63400acbceec6 - name:Super Battletank - War in the Gulf (USA) - cheat - description:Infinite health against most enemies and mines - code:C9AC-0D67 - cheat - description:Infinite weapon ammo (except Smoke Screens and Machine Gun) - code:4ABD-DDA4 - cheat - description:More Machine Gun ammo on stages 1-4 - code:EE2E-D4D4 - cheat - description:Less Machine Gun ammo on stages 1-4 - code:482E-D4D4 - cheat - description:More Cannon ammo on each mission - code:1022-D7D4 - cheat - description:Less Cannon ammo on each mission - code:FB22-D7D4 - cheat - description:More Laser Shells on each mission - code:D923-DF04 - cheat - description:No Laser Shells on each mission - code:DD23-DF04 - cheat - description:More Smoke Screens on each mission - code:D923-D7A4 - cheat - description:No Smoke Screens on each mission - code:DD23-D7A4 - cheat - description:Infinite health against most enemies and mines (alt) - code:00CDA2:A5 - cheat - description:Infinite Fuel - code:7E05C4:FF - cheat - description:Infinite 120mm Cannon - code:7E049E:42 - cheat - description:Infinite Laser Missiles - code:7E04A0:01 - cheat - description:Infinite Smoke Screens - code:7E04A1:01 - cheat - description:Infinite 7.62mm Machine Gun - code:7E04A2:96 - cartridge sha256:b68e865b0b5fe6af421a171e94fb1cb0006ae3e412b6361f6f858c44adaa304b name:Super Battletank 2 (USA) cheat @@ -66259,7 +67056,7 @@ cartridge sha256:0ef6f4cce5a2273fa49fe1ce724e0048a8e39c91da6b00dbb693fe1ba909177 code:4DC5-04D4 cheat description:Multi-jump - code:C72B-6FA4+DD2B-64D4+3C2B-6404+186D-DDD6+C28A-A46F+18CF-6D0D+462B-6D04+DC2B-6D64+BD2B-6DA4+D02B-6FD4+442B-6F04+B42B-6F64 + code:186D-DDD6+C28A-A46F+18CF-6D0D+462B-6D04+DC2B-6D64+BD2B-6DA4+D02B-6FD4+442B-6F04+B42B-6F64+C72B-6FA4+DD2B-64D4+3C2B-6404 cheat description:Start with and always keep Dagger code:CBAA-6DAF+DFAA-6FDF+69AA-6F6F @@ -66537,6 +67334,18 @@ cartridge sha256:7468c271d7240cf4e0d08c16e9969a1b1b1caf5adc0e5adc568d93c92651a05 description:Have Goddess Ring code:7E14D3:0E +cartridge sha256:33dda5838264c93341ef865512e4b86e16fd4a0387eda04e331517bfaecf1c0b + name:Super Godzilla (USA) + cheat + description:Infinite health - Battle + code:C264-06F8 + cheat + description:Infinite health - Map + code:C22D-DFA9 + cheat + description:Infinite time + code:C32E-67A0 + cartridge sha256:3f8efb19eae68f24feb42c018b7dc7a819bfd8d993ab36899681caa7ee94b06e name:Super James Pond (USA) cheat @@ -66558,17 +67367,41 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB - Invincibility lasts longer code:9D2F-6DAE cheat - description:SMB - Infinite lives (alt) + description:SMB - Infinite lives code:C2C1-D4AA cheat description:SMB - Infinite time code:6D84-DF03 + cheat + description:SMB - Fireballs hit anywhere + code:4028-D4DE + cheat + description:SMB - Fireballs can kill Bullet Bill + code:4025-07AE + cheat + description:SMB - Fireballs can kill Buzzy Beetle + code:6D2E-DD6E + cheat + description:SMB - Run without holding the dash button + code:6D8C-0D02 + cheat + description:SMB - 1-up worth nothing + code:C26B-0FBF + cheat + description:SMB - Jump lower (disable if you get stuck) + code:CB81-0D02+E281-0D62+3C81-0DA2 + cheat + description:SMB - Super-jump + code:CB81-0D02+EC81-0D62+3C81-0DA2 + cheat + description:SMB - Mega-jump + code:CB81-0D02+E681-0D62+3C81-0DA2 cheat description:SMB - Multi-jump code:2D8E-D7D2 cheat - description:SMB - Run without holding the dash button - code:DD8E-D702 + description:SMB - Allows you to select any world for File A + code:D5DF-FADD cheat description:SMB - Start File A game with 2 lives code:DFDF-FAAD @@ -66582,20 +67415,38 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB - Start File A game with 100 lives code:17DF-FAAD cheat - description:SMB - 1-up worth nothing - code:C26B-0FBF + description:SMB - Invincibility (Starman) + code:7E07AF:0F cheat - description:SMB - Allows you to select any world for File A - code:D5DF-FADD + description:SMB - Infinite lives (alt) + code:7E075A:05 cheat - description:SMB - Jump lower (disable if you get stuck) - code:CB81-0D02+E281-0D62+3C81-0DA2 + description:LL - Invincible against most enemies + code:292A-0485 cheat - description:SMB - Super-jump - code:CB81-0D02+EC81-0D62+3C81-0DA2 + description:LL - Invincibility (get a power-up when an enemy touches you) + code:892A-0D85 cheat - description:SMB - Mega-jump - code:CB81-0D02+E681-0D62+3C81-0DA2 + description:LL - Infinite time + code:1D88-0F59 + cheat + description:LL - Multi-jump + code:DD86-6F80 + cheat + description:LL - Run without holding the dash button + code:6D80-A470 + cheat + description:LL - Death Mushrooms are 1-Ups + code:CE89-0455 + cheat + description:LL - There are no Death Mushrooms + code:C289-0455 + cheat + description:LL - All breakable bricks are coins when you're small + code:C281-0755 + cheat + description:LL - Allows you to select any world or level for File A + code:DADF-F30D+D7DF-F36D cheat description:LL - Start File A game with 2 lives code:DFDF-FEDD @@ -66609,26 +67460,41 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:LL - Start File A game with 100 lives code:17DF-FEDD cheat - description:LL - Infinite lives - code:C2B6-A455 + description:LL - Invincibility (blinking) + code:7E07AE:0F cheat - description:LL - Infinite time - code:6D82-0F79 + description:LL - Invincibility (Star effect) + code:7E07AF:0F cheat - description:LL - Allows you to select any world or level for File A - code:DADF-F30D+D7DF-F36D + description:LL - Always Fiery Mario + code:7E0756:02 cheat - description:LL - Infinite lives - code:C2B6-A455 + description:LL - Coins are worth 10 + code:7E07DF:09 cheat - description:LL - Multi-jump - code:DD86-6F80 + description:SMB2 - Infinite lives + code:C26E-D5A6 + cheat + description:SMB2 - Infinite hearts + code:DD32-6966 + cheat + description:SMB2 - Hit anywhere + code:0720-A0D8+3D27-A508+DD27-A568 cheat description:SMB2 - Multi-jump - all characters code:D966-6166 cheat description:SMB2 - Float - all characters code:6267-A5A6 + cheat + description:SMB2 - Jumping in place charges super jump + code:7A60-A966 + cheat + description:SMB2 - Run without holding the dash button + code:DD60-D10B+DD69-D1AB + cheat + description:SMB2 - Allows you to select any world for File A + code:D1D4-FA0D cheat description:SMB2 - 1 life after continue code:DF61-05D0 @@ -66644,9 +67510,6 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b cheat description:SMB2 - 99 lives after continue code:1761-05D0 - cheat - description:SMB2 - Infinite lives - code:C26E-D5A6 cheat description:SMB2 - Continue with 3 hearts instead of 2 code:DF6B-A9A1 @@ -66654,38 +67517,59 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB2 - Continue with 4 hearts code:D46B-A9A1 cheat - description:SMB2 - Infinite hearts - code:DD32-6966 + description:SMB2 - Invincibility + code:7E0085:3B cheat - description:SMB2 - Jumping in place charges super jump - code:7A60-A966 + description:SMB2 - Infinite float time - all characters + code:7E04CA:FF cheat - description:SMB2 - Allows you to select any world for File A - code:D1D4-FA0D + description:SMB2 - Always big + code:7E04C3:1F + cheat + description:SMB2 - Always small + code:7E04C3:0F cheat description:SMB3 - Infinite lives code:82BB-0C6D cheat description:SMB3 - Infinite time code:6D3D-6619 - cheat - description:SMB3 - Infinite flying time - code:EEA4-AB63 - cheat - description:SMB3 - Multi-jump - code:40AA-6803 cheat description:SMB3 - Fly at any time (run meter always full) code:DDAF-A8A3 + cheat + description:SMB3 - Infinite flying time + code:EEA4-AB63 cheat description:SMB3 - Fireballs hit anywhere code:4083-D8F3+408D-08F3 + cheat + description:SMB3 - Fireballs can kill most enemies + code:4084-0BB3 cheat description:SMB3 - Tail hits anywhere code:40C4-6C22 cheat - description:SMB3 - Fireballs can kill most enemies - code:4084-0BB3 + description:SMB3 - Multi-jump + code:40AA-6803 + cheat + description:SMB3 - Multi-jump (alt) + code:6DAA-6C03 + cheat + description:SMB3 - Power-jump + code:AD3E-6801 + cheat + description:SMB3 - Super-jump + code:863E-6801 + cheat + description:SMB3 - Mega-jump + code:8D3E-6801 + cheat + description:SMB3 - Ultra power-jump + code:C63E-6801 + cheat + description:SMB3 - Mega power-jump + code:DDA9-A603 cheat description:SMB3 - Change to Big Mario whenever you go to the map code:CB69-AC07+DF69-AC67 @@ -66711,7 +67595,7 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB3 - Collisions turn you into Big Mario code:D4A8-6CAA cheat - description:SMB3 - Collisions turn you into Fire Mario + description:SMB3 - Collisions turn you into Fiery Mario code:D7A8-6CAA cheat description:SMB3 - Collisions turn you into Raccoon Mario @@ -66759,23 +67643,8 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB3 - 50 coins needed for an extra life code:743E-6819 cheat - description:SMB3 - Power-jump - code:AD3E-6801 - cheat - description:SMB3 - Super-jump - code:863E-6801 - cheat - description:SMB3 - Mega-jump - code:8D3E-6801 - cheat - description:SMB3 - Ultra power-jump - code:C63E-6801 - cheat - description:SMB3 - Mega power-jump - code:DDA9-A603 - cheat - description:SMB3 - Select any world for File A game - code:D5D4-F36D + description:SMB3 - Move anywhere on the world map + code:6D69-686E+6D68-66D3 cheat description:SMB3 - Re-enter already beaten levels code:DD63-D6A5 @@ -66785,27 +67654,12 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b cheat description:SMB3 - Re-enter already beaten mushroom houses and special levels code:0D63-D605 + cheat + description:SMB3 - Select any world for File A game + code:D5D4-F36D cheat description:SMB3 - Start and continue as Big Mario code:E1A3-D60A - cheat - description:SMB - Invincibility (Starman) - code:7E07AF:0F - cheat - description:SMB - Infinite lives - code:7E075A:05 - cheat - description:SMB2 - Invincibility - code:7E0085:3B - cheat - description:SMB2 - Always big - code:7E04C3:1F - cheat - description:SMB2 - Always small - code:7E04C3:0F - cheat - description:SMB2 - Infinite float time - all characters - code:7E04CA:FF cheat description:SMB3 - Enable debug mode (in game) code:7E0160:80 @@ -66822,7 +67676,7 @@ cartridge sha256:a9e3e57d591e995e8e0dd228b619b6aed42205eaf55316fa8ff33f236b3a32b description:SMB3 - Always Big Mario code:7E00BB:01 cheat - description:SMB3 - Always Fire Mario + description:SMB3 - Always Fiery Mario code:7E00BB:02 cheat description:SMB3 - Always Raccoon Mario @@ -66852,26 +67706,116 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMB - Invincibility (Starman effect) code:292B-67DE cheat - description:SMB - Invincibility - code:62E7-A7D2+2DE7-A7A2 + description:SMB - Invincibility does not last as long + code:D62F-6DAE cheat - description:SMB - Always Fiery Mario after first hit - code:CB29-AF0E+D429-AF6E+CB8B-676A+DD8B-67AA + description:SMB - Invincibility lasts longer + code:9D2F-6DAE + cheat + description:SMB - Infinite lives + code:C2C1-D4AA + cheat + description:SMB - Infinite time + code:6D84-DF03 cheat description:SMB - Fireballs hit anywhere code:4028-D4DE + cheat + description:SMB - Fireballs can kill Bullet Bill + code:4025-07AE + cheat + description:SMB - Fireballs can kill Buzzy Beetle + code:6D2E-DD6E + cheat + description:SMB - Run without holding the dash button + code:6D8C-0D02 + cheat + description:SMB - 1-up worth nothing + code:C26B-0FBF + cheat + description:SMB - Jump lower (disable if you get stuck) + code:CB81-0D02+E281-0D62+3C81-0DA2 + cheat + description:SMB - Super-jump + code:CB81-0D02+EC81-0D62+3C81-0DA2 + cheat + description:SMB - Mega-jump + code:CB81-0D02+E681-0D62+3C81-0DA2 cheat description:SMB - Multi-jump code:2D8E-D7D2 cheat - description:SMB - Run without holding the dash button - code:DD8E-D702 + description:SMB - Allows you to select any world for File A + code:D5DF-FADD cheat - description:LL - Infinite lives - code:C2B6-A455 + description:SMB - Start File A game with 2 lives + code:DFDF-FAAD + cheat + description:SMB - Start File A game with 10 lives + code:DBDF-FAAD + cheat + description:SMB - Start File A game with 50 lives + code:7FDF-FAAD + cheat + description:SMB - Start File A game with 100 lives + code:17DF-FAAD + cheat + description:SMB - Invincibility (Starman) + code:7E07AF:0F + cheat + description:SMB - Infinite lives (alt) + code:7E075A:05 + cheat + description:LL - Invincible against most enemies + code:292A-0485 + cheat + description:LL - Invincibility (get a power-up when an enemy touches you) + code:892A-0D85 + cheat + description:LL - Infinite time + code:1D88-0F59 cheat description:LL - Multi-jump code:DD86-6F80 + cheat + description:LL - Run without holding the dash button + code:6D80-A470 + cheat + description:LL - Death Mushrooms are 1-Ups + code:CE89-0455 + cheat + description:LL - There are no Death Mushrooms + code:C289-0455 + cheat + description:LL - All breakable bricks are coins when you're small + code:C281-0755 + cheat + description:LL - Allows you to select any world or level for File A + code:DADF-F30D+D7DF-F36D + cheat + description:LL - Start File A game with 2 lives + code:DFDF-FEDD + cheat + description:LL - Start File A game with 10 lives + code:DBDF-FEDD + cheat + description:LL - Start File A game with 50 lives + code:7FDF-FEDD + cheat + description:LL - Start File A game with 100 lives + code:17DF-FEDD + cheat + description:LL - Invincibility (blinking) + code:7E07AE:0F + cheat + description:LL - Invincibility (Star effect) + code:7E07AF:0F + cheat + description:LL - Always Fiery Mario + code:7E0756:02 + cheat + description:LL - Coins are worth 10 + code:7E07DF:09 cheat description:SMB2 - Infinite lives code:C26E-D5A6 @@ -66887,15 +67831,165 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 cheat description:SMB2 - Float - all characters code:6267-A5A6 + cheat + description:SMB2 - Jumping in place charges super jump + code:7A60-A966 + cheat + description:SMB2 - Run without holding the dash button + code:DD60-D10B+DD69-D1AB + cheat + description:SMB2 - Allows you to select any world for File A + code:D1D4-FA0D + cheat + description:SMB2 - 1 life after continue + code:DF61-05D0 + cheat + description:SMB2 - 9 lives after continue + code:DB61-05D0 + cheat + description:SMB2 - 25 lives after continue + code:FB61-05D0 + cheat + description:SMB2 - 50 lives after continue + code:7461-05D0 + cheat + description:SMB2 - 99 lives after continue + code:1761-05D0 + cheat + description:SMB2 - Continue with 3 hearts instead of 2 + code:DF6B-A9A1 + cheat + description:SMB2 - Continue with 4 hearts + code:D46B-A9A1 + cheat + description:SMB2 - Invincibility + code:7E0085:3B + cheat + description:SMB2 - Infinite float time - all characters + code:7E04CA:FF + cheat + description:SMB2 - Always big + code:7E04C3:1F + cheat + description:SMB2 - Always small + code:7E04C3:0F + cheat + description:SMB3 - Infinite lives + code:82BB-0C6D + cheat + description:SMB3 - Infinite time + code:6D3D-6619 + cheat + description:SMB3 - Fly at any time (run meter always full) + code:DDAF-A8A3 + cheat + description:SMB3 - Infinite flying time + code:EEA4-AB63 cheat description:SMB3 - Fireballs hit anywhere code:4083-D8F3+408D-08F3 + cheat + description:SMB3 - Fireballs can kill most enemies + code:4084-0BB3 cheat description:SMB3 - Tail hits anywhere code:40C4-6C22 cheat - description:SMB3 - Fireballs can kill most enemies - code:4084-0BB3 + description:SMB3 - Multi-jump + code:40AA-6803 + cheat + description:SMB3 - Multi-jump (alt) + code:6DAA-6C03 + cheat + description:SMB3 - Power-jump + code:AD3E-6801 + cheat + description:SMB3 - Super-jump + code:863E-6801 + cheat + description:SMB3 - Mega-jump + code:8D3E-6801 + cheat + description:SMB3 - Ultra power-jump + code:C63E-6801 + cheat + description:SMB3 - Mega power-jump + code:DDA9-A603 + cheat + description:SMB3 - Change to Big Mario whenever you go to the map + code:CB69-AC07+DF69-AC67 + cheat + description:SMB3 - Change to Fire Mario whenever you go to the map + code:CB69-AC07+D469-AC67 + cheat + description:SMB3 - Change to Raccoon Mario whenever you go to the map + code:CB69-AC07+D769-AC67 + cheat + description:SMB3 - Change to Frog Mario whenever you go to the map + code:CB69-AC07+D069-AC67 + cheat + description:SMB3 - Change to Tanooki Mario whenever you go to the map + code:CB69-AC07+D969-AC67 + cheat + description:SMB3 - Change to Sledgehammer Mario when you go to the map + code:CB69-AC07+D169-AC67 + cheat + description:SMB3 - All power-ups turn you into Shoe Mario + code:D0A1-6C0A+E1A3-D60A + cheat + description:SMB3 - Collisions turn you into Big Mario + code:D4A8-6CAA + cheat + description:SMB3 - Collisions turn you into Fiery Mario + code:D7A8-6CAA + cheat + description:SMB3 - Collisions turn you into Raccoon Mario + code:D0A8-6CAA + cheat + description:SMB3 - Collisions turn you into Frog Mario + code:D9A8-6CAA + cheat + description:SMB3 - Collisions turn you into Tanooki Mario + code:D1A8-6CAA + cheat + description:SMB3 - Collisions turn you into Sledgehammer Mario + code:D5A8-6CAA + cheat + description:SMB3 - After getting star, invincible until end of level (may have to disable to jump) + code:C23B-680D + cheat + description:SMB3 - 1 life after continue + code:DFBB-DBAF + cheat + description:SMB3 - 10 lives after continue + code:DBBB-DBAF + cheat + description:SMB3 - 26 lives after continue + code:FBBB-DBAF + cheat + description:SMB3 - 51 lives after continue + code:74BB-DBAF + cheat + description:SMB3 - 100 lives after continue + code:17BB-DBAF + cheat + description:SMB3 - Gain lots of lives with each 5 coins + code:D93E-6C49 + cheat + description:SMB3 - 5 coins needed for an extra life + code:D93E-6819 + cheat + description:SMB3 - 10 coins needed for an extra life + code:DC3E-6819 + cheat + description:SMB3 - 25 coins needed for an extra life + code:FB3E-6819 + cheat + description:SMB3 - 50 coins needed for an extra life + code:743E-6819 + cheat + description:SMB3 - Move anywhere on the world map + code:6D69-686E+6D68-66D3 cheat description:SMB3 - Re-enter already beaten levels code:DD63-D6A5 @@ -66906,29 +68000,14 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMB3 - Re-enter already beaten mushroom houses and special levels code:0D63-D605 cheat - description:SMW - Nintendo's debug - code:DDA6-DF07 + description:SMB3 - Select any world for File A game + code:D5D4-F36D cheat - description:SMW - Infinite flying time for Yoshi - code:C2EC-0700 - cheat - description:SMB - Invincibility (Starman) - code:7E07AF:0F - cheat - description:SMB - Infinite lives - code:7E075A:05 - cheat - description:SMB2 - Invincibility - code:7E0085:3B - cheat - description:SMB2 - Infinite float time - all characters - code:7E04CA:FF + description:SMB3 - Start and continue as Big Mario + code:E1A3-D60A cheat description:SMB3 - Enable debug mode (in game) code:7E0160:80 - cheat - description:SMB3 - Infinite lives - code:20919A:BD cheat description:SMB3 - Invincibility code:7E0552:80 @@ -66942,7 +68021,7 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMB3 - Always Big Mario code:7E00BB:01 cheat - description:SMB3 - Always Fire Mario + description:SMB3 - Always Fiery Mario code:7E00BB:02 cheat description:SMB3 - Always Raccoon Mario @@ -66954,17 +68033,23 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMB3 - Always Tanooki Mario code:7E00BB:05 cheat - description:SMB3 - Always Hammer Bros Mario + description:SMB3 - Always Hammer Bros. Mario code:7E00BB:06 - cheat - description:SMB3 - Infinite flying time - code:23CB26:FF cheat description:SMB3 - Have Magic Whistle code:7E1D80:0C cheat description:SMB3 - Raccoon and Tanooki have P-Wing code:7E056E:FF + cheat + description:SMB3 - Fly for an unlimited amount of time + code:23CB26:FF + cheat + description:SMW - Infinite flying time for Yoshi + code:C2EC-0700 + cheat + description:SMW - Nintendo's debug + code:DDA6-DF07 cheat description:SMW - Invincibility code:7E1497:FF @@ -66981,8 +68066,11 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMW - Always Caped Mario code:7E0019:02 cheat - description:SMW - Always Fire Mario + description:SMW - Always Fiery Mario code:7E0019:03 + cheat + description:SMW - Always have Yoshi + code:7E0DC1:01 cheat description:SMW - Infinite time code:7E0F31:09+7E0F32:09+7E0F33:09 @@ -66990,14 +68078,11 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 description:SMW - Infinite P-Balloon time code:7E1891:FF cheat - description:SMW - Always have Yoshi - code:7E0DC1:01 + description:SMW - Multi-jump and float down (disable in water and to get on Yoshi) + code:7E1471:01 cheat description:SMW - Jump to automatically fly code:7E13E4:70 - cheat - description:SMW - Multi-jump and float down (disable in water and to get on Yoshi) - code:7E1471:01 cheat description:SMW - Activate yellow blocks (deactivate before entering the Yellow Switch Palace) code:7E1F28:01 @@ -67007,6 +68092,9 @@ cartridge sha256:a8806bfe07cd3c9945d9fd3fcea932ae1cd671cab5cae12bb7a2ae726cbf917 cheat description:SMW - Activate red blocks (deactivate before entering the Red Switch Palace) code:7E1F2A:01 + cheat + description:SMW - Automatically finish level + code:7E1493:01 cheat description:SMW - 8000 points for each enemy stomped code:7E1697:06 @@ -67327,7 +68415,7 @@ cartridge sha256:0838e531fe22c077528febe14cb3ff7c492f1f5fa8de354192bdff7137c27f5 code:F53F-6767+DD3F-67A7 cheat description:Press R to scroll through items in the items box - code:D2AF-6407+D2AF-6DD7+DFAF-6F67+17AF-6FD7+1DAF-6467+62AF-6FA7+A4AD-67A7+A4AD-67D7+A4AF-64D7+CBAF-6F07+D1AF-6D67+D2AD-6707 + code:17AF-6FD7+1DAF-6467+62AF-6FA7+A4AD-67A7+A4AD-67D7+A4AF-64D7+CBAF-6F07+D1AF-6D67+D2AD-6707+D2AF-6407+D2AF-6DD7+DFAF-6F67 cheat description:Low jump code:D02C-AF6F @@ -67486,7 +68574,7 @@ cartridge sha256:bd763c1a56365c244be92e6cffefd318780a2a19eda7d5baf1c6d5bd6c1b3e0 code:18CB-D727 cheat description:Multi-jump - code:D921-D496+C421-D4B6+E821-D426+6321-D7F6+C821-D796+1D21-D7B6+5421-DD26+1D21-DFF6+4B21-DF96+DD21-DFB6+6D21-DF26+ED21-D4F6 + code:6321-D7F6+C821-D796+1D21-D7B6+5421-DD26+1D21-DFF6+4B21-DF96+DD21-DFB6+6D21-DF26+ED21-D4F6+D921-D496+C421-D4B6+E821-D426 cheat description:Star timer doesn't decrease when hit code:7E0391:01+7E0392:00 @@ -67597,7 +68685,7 @@ cartridge sha256:9b4957466798bbdb5b43a450bbb60b2591ae81d95b891430f62d53ca62e8bc7 code:18CB-D727 cheat description:Multi-jump - code:D921-D496+C421-D4B6+E821-D426+6321-D7F6+C821-D796+1D21-D7B6+5421-DD26+1D21-DFF6+4B21-DF96+DD21-DFB6+6D21-DF26+ED21-D4F6 + code:6321-D7F6+C821-D796+1D21-D7B6+5421-DD26+1D21-DFF6+4B21-DF96+DD21-DFB6+6D21-DF26+ED21-D4F6+D921-D496+C421-D4B6+E821-D426 cheat description:Continue with 5 lives code:DC36-010D @@ -69627,6 +70715,12 @@ cartridge sha256:6e45a80ea148654514cb4e8604a0ffcbc726946e70f9e0b9860e36c0f3fa487 description:Super speed - Barb code:D060-AFAF+D761-AFAF+DD28-A7A5 +cartridge sha256:8dda3b0888a32005041f2feb9be4e14807d40291f951a4612461cf41dac9cb78 + name:Super Tetris 2 + Bombliss (Japan) + cheat + description:Drop pieces on left side of the board to clear that line + code:DFB4-64D7 + cartridge sha256:02cb7f1ed21ed6bfb9eaa0e91df2adb063a9bf4cbd6feb6cd024d676829e227e name:Super Troll Islands (USA) cheat @@ -69885,6 +70979,12 @@ cartridge sha256:96da3512a1aa05a40f1e5d61c48932b0d55d9f136d6418b848153a9fecab06d description:Start on level 17 code:7E007E:12 +cartridge sha256:fddc6634f727899152a5b8b1ca3b8938a4e4ccdd5a6adb9e1579363e3b676f20 + name:Super Uno (Japan) + cheat + description:Place any card on the stack regardless of color + code:6DCB-DD60 + cartridge sha256:792e615a34ceae5a1b9a4f54c5a5d9b53e39299332fece83e4bceca2c22efb21 name:Super Valis IV (USA) cheat @@ -71286,6 +72386,84 @@ cartridge sha256:08d808e9c5851e4301a38a56b350a20ea9e3adbef51546e87e1785d691d0f2d description:Allowed only 3 punches in punch meter - P2 code:D7B9-04DD+D765-A764 +cartridge sha256:32d0f1ca5b91fd9b2caf81422fb9e8fb30bc091f0b2a429b9269dd307fcba4fd + name:Todd McFarlane's Spawn - The Video Game (USA) + cheat + description:Invincibility after one hit (invisible) + code:C203-84D1 + cheat + description:Almost invincible (blinking) + code:3C03-8F61 + cheat + description:Infinite health + code:C208-87D1 + cheat + description:Infinite special moves + code:C27D-8701 + cheat + description:Hit anywhere + code:40F8-84B0 + cheat + description:Don't blink after getting hit + code:FDDB-5FB9 + cheat + description:Falling doesn't use life points + code:C2F4-7FD1 + cheat + description:Special moves don't use life points + code:C27D-8701 + cheat + description:Some bullets do 2x damage + code:D6D7-8F20 + cheat + description:Some bullets do no damage + code:DDD7-8F20 + cheat + description:Some bullets kill you + code:EED7-8F20 + cheat + description:Some enemy punches electrocute you + code:DB78-84B0 + cheat + description:Some enemy punches do no damage + code:DD78-84B0 + cheat + description:Some enemy punches kill you + code:EE78-84B0 + cheat + description:Guys with pipes do 2x damage + code:DBB0-EFA3+DBCF-8763 + cheat + description:Guys with pipes do no damage + code:DDB0-EFA3+DDCF-8763 + cheat + description:Guys with pipes kill + code:EEB0-EFA3+EECF-8763 + cheat + description:Flaming bottles do 2x damage + code:DB4B-7DF1+DB43-E4F9 + cheat + description:Flaming bottles do no damage + code:DD4B-7DF1+DD43-E4F9 + cheat + description:Flaming bottles kill + code:EE4B-7DF1+EE43-E4F9 + cheat + description:Start with 1/4 health + code:FDB0-E4DB + cheat + description:Start with 1/2 health + code:4CB0-E4DB + cheat + description:Start with 3/4 health + code:73B0-E4DB + cheat + description:Invincibility + code:7E1F56:1F + cheat + description:Infinite health (alt) + code:7E1F00:63 + cartridge sha256:4f500da19dbb1557a7bc0ce14437098c1402478d573fb569303b81c011f86fbf name:Tom and Jerry (USA) cheat @@ -71856,17 +73034,41 @@ cartridge sha256:72088194a65fc057f2910945a33d9f071682a4cecac8996f0bdabcdb5ef3996 cartridge sha256:47dd8ea2d12a6bb2a9774de1d492259fc4fb9f8ec7976383bbfd922532671f6b name:True Lies (USA) cheat - description:Infinite hand gun shells - code:7E00A5:0F - cheat - description:Infinite big gun shells - code:7E00A9:73 - cheat - description:Infinite Grenades on pick-up - code:7E00AB:03 + description:Infinite health + code:7E2D38:17 cheat description:Infinite lives code:7E1A57:05 + cheat + description:Infinite Aircraft Missiles + code:7E1A61:06 + cheat + description:Infinite Big Gun ammo + code:7E00A9:73 + cheat + description:Infinite Flamethrower fuel + code:7E00AF:63 + cheat + description:Infinite Grenades + code:7E00AB:09 + cheat + description:Infinite Mines + code:7E00AD:09 + cheat + description:Infinite Pistol ammo + code:7E00A5:0F + cheat + description:Infinite Shotgun Shells + code:7E00A7:63 + cheat + description:Infinite Uzi ammo + code:7E00AA:0A + cheat + description:Have all weapons + code:7E1A55:FF + cheat + description:No civilian kill limit (warning on first two deaths) + code:7E1A2A:00 cartridge sha256:8f62d014f513a7dcbca5aa76cbe476c3e4526100f34913af831bc05dab029bd1 name:Tuff E Nuff (USA) @@ -72409,7 +73611,7 @@ cartridge sha256:cb2fdfce61858063bf4c9da4228381c3ec3abe423f4d378cddd174ae4adb261 code:DF73-2A7C cheat description:Hit anywhere - P1 - code:46EB-3FB7+84EB-3497+BD3C-C49F+D4EB-3D97+DDEB-3DB7+D7EB-3FF7+EDEB-3D27+EE3C-C4BF+0AEB-3F97+0AEB-34F7+31EB-34B7+35EB-3F27+3DEB-3DF7 + code:DDEB-3DB7+D7EB-3FF7+EDEB-3D27+EE3C-C4BF+0AEB-3F97+0AEB-34F7+31EB-34B7+35EB-3F27+3DEB-3DF7+46EB-3FB7+84EB-3497+BD3C-C49F+D4EB-3D97 cheat description:Blank versus screen code:EE37-CF02 @@ -73152,6 +74354,24 @@ cartridge sha256:8579dd352d20589072ed5c026bde7adadd6229d18a022e7cb47cf5602b54015 description:Enter the password GRKKL to go to the ending code:74AC-DD2F +cartridge sha256:0fadb3b67bfb7d750d873e7601dd5ffdfd33b8ebda833a18a3c999c7f8aa9e15 + name:Waterworld (Europe) + cheat + description:Invincibility underwater + code:DDCB-C7A9 + cheat + description:Infinite health underwater + code:C2B7-34A0 + cheat + description:Infinite health - Overworld + code:7E0288:7F + cheat + description:Hit anywhere + code:6DA5-170D+4CA5-176D+1DAC-17DD + cheat + description:Get items from anywhere + code:6D36-CDA0+F636-CFD0 + cartridge sha256:56ba3d585bf6b701e342d86a0bd164ab0a97dfbd5df46b3a964506842633459c name:Wayne's World (USA) cheat @@ -73556,15 +74776,27 @@ cartridge sha256:e0165bafeb8d65be08a5a4079f8651104471f450c60794b761b1255853ca2d9 cheat description:Infinite health code:3CA3-DFAF + cheat + description:Infinite health (alt) + code:7E0636:14 cheat description:Infinite continues code:C2EC-6FAD cheat description:Infinite lives code:C9A6-A4AD + cheat + description:Infinite lives (alt) + code:7E029A:99 cheat description:Infinite Bombs code:C9A3-DD0F + cheat + description:Infinite Bombs (alt) + code:7E0298:99 + cheat + description:Infinite Projectiles + code:7E0296:99 cheat description:Stay in wolf form until next continue code:C2AE-A4DD+C2AE-A4AD @@ -73718,6 +74950,9 @@ cartridge sha256:159d5341d13d6801324e8271f7191c0223617c9d30984676319b2df7937c78c cartridge sha256:d4d9f1b41dad7e7a126a9adbe8d86c4b339e120c866156796de1cb0c9a214189 name:World League Soccer (USA) + cheat + description:Score from anywhere (hold X and kick to the goal line and out of bounds) + code:C961-0F0E+DC61-0FAE+0061-040E+7D61-04DE+7761-0F6E cheat description:Each goal worth 2 - P1 code:D4AC-ADA3 @@ -73767,6 +75002,12 @@ cartridge sha256:d4d9f1b41dad7e7a126a9adbe8d86c4b339e120c866156796de1cb0c9a21418 description:Each goal worth 9 - P2 code:DBAD-D7DE +cartridge sha256:2143bbd87ea1c5cfe5eaf46ae39e3ebb11a2e929d05cbb929904037f4d72acfe + name:World Soccer 94 - Road to Glory (USA) + cheat + description:Score from anywhere (press and hold A, kick to the goal line and out of bounds) + code:C2ED-C7AD+C9EF-CDDD+D2EF-CD0D+99EF-CDAD + cartridge sha256:0af7b0d3022acd24a1fb15865a076519f7f56e7a4b33f12b6d851b3a91e5388c name:WWF Raw (USA) cheat @@ -74293,10 +75534,10 @@ cartridge sha256:b0e74f0fe8d1e7fe2fe404341fea7c68e28f3a0ab78552d5092d413f2ecec41 code:7E129B:01 cheat description:Have all equipment - code:7E12B1:FF+7E12B2:FF+7E12A0:FF+7E12A8:FF+7E12A1:FF+7E12A2:FF+7E12A3:FF+7E12A4:FF+7E12A5:FF+7E12A6:FF+7E12A7:FF+7E12A9:FF+7E12AA:FF+7E12AB:FF+7E12B3:FF+7E12AC:FF+7E12AD:FF+7E12AE:FF+7E12AF:FF+7E12B0:FF + code:7E12A9:FF+7E12AA:FF+7E12AB:FF+7E12B3:FF+7E12AC:FF+7E12AD:FF+7E12AE:FF+7E12AF:FF+7E12B0:FF+7E12B1:FF+7E12B2:FF+7E12A0:FF+7E12A1:FF+7E12A2:FF+7E12A3:FF+7E12A4:FF+7E12A5:FF+7E12A6:FF+7E12A7:FF+7E12A8:FF cheat description:Have all inventory items - code:7E12BF:FF+7E12C0:FF+7E12C1:FF+7E12C2:FF+7E12C3:FF+7E12C4:FF+7E12B9:FF+7E12BA:FF+7E12BB:FF+7E12BC:FF+7E12BD:FF+7E12BE:FF + code:7E12C2:FF+7E12C3:FF+7E12C4:FF+7E12B9:FF+7E12BA:FF+7E12BB:FF+7E12BC:FF+7E12BD:FF+7E12BE:FF+7E12BF:FF+7E12C0:FF+7E12C1:FF cheat description:Have all statues code:7E12C5:FF+7E12C6:FF+7E12C7:FF+7E12C8:FF @@ -74314,7 +75555,7 @@ cartridge sha256:10d94f1acd8108552eaefe9e26069e5d83e8fc3e847df7af318c2e25b53d39c code:7E097B:FF+7E097C:FF cartridge sha256:d8d14c9f599cf915127440ba22fcbb7c33814f5688c9ae4f8855ed1f6ed42128 - name:Yuu Yuu Hakusho Final - Makai Saikyou Retsuden (Japan) + name:Yu Yu Hakusho Final - Makai Saikyou Retsuden (Japan) cheat description:Infinite health code:7E0A38:50 @@ -74328,6 +75569,18 @@ cartridge sha256:d8d14c9f599cf915127440ba22fcbb7c33814f5688c9ae4f8855ed1f6ed4212 description:Opponent has no power code:7E0F3C:00 +cartridge sha256:9b2cb155b270a78d122c46c44287f4973064dc96f75b0471c0843ca6a54bf41d + name:Zen-Nihon GT Senshuken (Japan) + cheat + description:Disable timer + code:7E16DC:00 + cheat + description:Always 1st + code:7E0CDC:00 + cheat + description:Lap modifier + code:7E149C:0X + cartridge sha256:7d414b7f5941f1eddc35259a22accbbbd7b47c517dfcf8bad86c4dcfa9e50b1e name:Zero the Kamikaze Squirrel (USA) cheat @@ -74832,6 +76085,53 @@ cartridge sha256:b27e2e957fa760f4f483e2af30e03062034a6c0066984f2e284cc2cb430b205 description:Infinite Weed Wacker - P2 code:7E1CF2:50 +database revision=2013-06-09 + +cartridge sha256:c8497ee7a25d1eb7cf4ef1604b2fd7836a64c5c30e8334f7a48f1ed2a27b5cc1 + name:1942 (USA, Europe) + cheat + description:Invincibility + code:18C-8BD-4CA+188-C5E-4CA + cheat + description:Hit anywhere + code:009-ECE-7F2+C99-F5E-806 + +cartridge sha256:da5eb5a56ab97f7b6779fa70b894cb94abf351aaf0c9430bd775156528a334a0 + name:4-in-1 Fun Pak (USA, Europe) + cheat + description:Chess - move anywhere + code:77E-D0A-190+18E-D1A-4CA + cheat + description:Checkers - move anywhere + code:184-BCA-4CA+184-CDA-6EA+183-9CA-4CA + +cartridge sha256:d16375478a455270b758eb61f9c9fb380fbf5187e32a8fe3fc93ba4f4a330959 + name:4-in-1 Fun Pak Volume II (USA, Europe) + cheat + description:Solitaire - move cards anywhere + code:008-E3B-B32+005-59B-19F + +cartridge sha256:f66a6c521c706bf3bf4536731becacf1336a711bd40658d853646cd6b20fdb2b + name:720 Degrees (USA, Europe) + cheat + description:Jump to get 1000 points + code:00D-A48-D5A + +cartridge sha256:52ee7edb02d42bfc7a9a5a52df082424cd8d9b3cbd2aa47fc84bd32f79cd059a + name:A-mazing Tater (USA) + cheat + description:Walk anywhere + code:00F-68F-91E + +cartridge sha256:fa9fe020c07a5194dcd61ab33be44779ce5c9de4074fac3eb68bae9311d7c2f6 + name:Action Man - Search for Base X (USA, Europe) + cheat + description:Invincibility + code:FA6-D89-4C1 + cheat + description:Hit anywhere + code:007-3A9-7FA + cartridge sha256:18746d4607424feca05aee056c3ed5f840195c792409881e9145d4bd96800dbd name:Addams Family, The - Pugsley's Scavenger Hunt (USA, Europe) cheat @@ -74856,10 +76156,10 @@ cartridge sha256:18746d4607424feca05aee056c3ed5f840195c792409881e9145d4bd96800db description:Lose 1 heart to become invincible code:FAA-DCF-4C1 cheat - description:Start each life with 1 energy heart + description:Start each life with 1 heart code:01F-E98-E66 cheat - description:Start each life with 5 energy hearts + description:Start each life with 5 hearts code:05F-E98-E66 cheat description:Start with 1 life @@ -74882,6 +76182,9 @@ cartridge sha256:f267738e785f43a09c92511bcbb7f16d2e8acbe43b36f75bee35ff3fb0c2162 cheat description:Infinite weapon code:BE8-688-3BE + cheat + description:Hit anywhere + code:009-FDB-C4A cartridge sha256:7771919d5f5a114fb8685345eab290be22e99c59d8798ed9c5f29e3079c11c56 name:Adventure Island (USA, Europe) @@ -74912,6 +76215,9 @@ cartridge sha256:bbb38ee1e9877404dd999ef7067aa238a1039ca603b987f8adeff4488e31833 cheat description:Infinite lives (alt) code:BE6-DCB-B31 + cheat + description:Hit anywhere + code:C9C-A1E-C49+C39-22E-A21 cheat description:No gradual loss of energy, but can still be drained by obstacles and enemies code:00E-28F-E6E @@ -74934,6 +76240,12 @@ cartridge sha256:bbb38ee1e9877404dd999ef7067aa238a1039ca603b987f8adeff4488e31833 description:Start on level 1-4 code:080-57B-E6E +cartridge sha256:4c156c4d826b9cba5741feb621de60c6294adb36553fc43971794bd2a4ffb34a + name:Adventures of Lolo (Europe) (SGB Enhanced) + cheat + description:Walk anywhere + code:009-28B-F72 + cartridge sha256:50c3a2193005c9134699ab00de16510fb946db10cdbc33bfacd8a3132926b72e name:Adventures of Pinocchio, The (USA) (Proto) cheat @@ -75023,6 +76335,15 @@ cartridge sha256:cb1d45fca310ef4b7013d094663bddcd209362f272bb3e54ce10540828c8c21 cheat description:Infinite jump code:BE8-70E-6E9 + cheat + description:Hit anywhere + code:C9E-93D-E69+3EF-E0D-5D6+18F-DFD-2AA + +cartridge sha256:efee40857f6310f5437732198d998779711f86d80673e72cfc93a3378ca26303 + name:AirForce Delta (USA) + cheat + description:Invincibility + code:185-688-08A cartridge sha256:8e45c7d6b5498d4048653e92b2a792bb2eea00b2897a7711fb7be1b6bed0534f name:Akumajou Dracula - Shikkoku Taru Zensoukyoku - Dark Night Prelude (Japan) (SGB Enhanced) @@ -75050,6 +76371,9 @@ cartridge sha256:4940bf228fb2095daa6b382d84ebd0cf05cd81fc2e6e5244a03ab458593e53f cheat description:Infinite Apples code:BE1-6DD-19E + cheat + description:Hit anywhere - Sword + code:00C-54A-E69+00C-4AA-809 cartridge sha256:944df9d20c715099ef6bf0e418d928684b284d4a4562391a661a7978fa7f5417 name:Alfred Chicken (USA) @@ -75128,6 +76452,9 @@ cartridge sha256:ed8070e011713527bdc03e2b9cec9f9c4a7e3aaa00e57e8786a186b265da1bb cheat description:Infinite lives code:BE7-EEF-19E + cheat + description:Hit anywhere - Paddle + code:00C-D1F-D56 cartridge sha256:04c5507efe0beb40ea1a887538bd8a04acc70622bf9ef800951a71f4804c9cbc name:All-Star Baseball 99 (USA) @@ -75150,6 +76477,24 @@ cartridge sha256:04c5507efe0beb40ea1a887538bd8a04acc70622bf9ef800951a71f4804c9cb description:Shot clock for human player is 9 seconds - 1-on-1 game code:095-FB9-7FA+093-3DD-7FA+095-C49-7FA +cartridge sha256:21d507b3ee6acbde8427d8e5cc5de1083eec03df8bd55745e4384ee0be14460e + name:All-Star Baseball 2000 (USA, Europe) + cheat + description:Balls are considered strikes + code:003-F8A-D5A+003-EAA-802+003-DCA-4CA + +cartridge sha256:c0bd16cfe156f36a0bcbf70c537a172ad4780641da6e23eacf47cc5f155d2640 + name:All-Star Baseball 2001 (USA) + cheat + description:Balls are considered strikes + code:3E3-F7A-2AA+003-EAA-802+003-DCA-4CA + +cartridge sha256:995dc210efdf7c12ae7d4c731e2ea0ae758554fc7f545dae72aa97a99dd10ed7 + name:Alone in the Dark - The New Nightmare (USA) (En,Fr,Es) + cheat + description:Invincibility + code:183-D5B-08A + cartridge sha256:4f6450321ee163d5fd8a942816b10af1ce41bbcad62185a550c97b16cac125a1 name:Altered Space - A 3-D Alien Adventure (USA) cheat @@ -75158,6 +76503,9 @@ cartridge sha256:4f6450321ee163d5fd8a942816b10af1ce41bbcad62185a550c97b16cac125a cartridge sha256:db4e590899aab75bceb31e84a2ec77c34b561838a61fd9dc9fda004a0507a01c name:Amazing Penguin (USA, Europe) + cheat + description:Invincibility + code:C91-9FE-E69 cheat description:Infinite lives code:BE2-28D-19E @@ -75171,6 +76519,66 @@ cartridge sha256:a52b036d637b59950749de679208785480b8ad2d5e95c0ea2a6f638750cc645 description:Hit anywhere code:008-EAD-809+008-8CD-7FF +cartridge sha256:c4eb652e47d458b8faba7fd753a3eff8e875658f2b4cee0ae6194dc8cb0783e7 + name:Amida (Japan) + cheat + description:Invincibility + code:003-EBF-F72+185-E2F-6EA + +cartridge sha256:4d2cca30eb8804ed6fffa07da2dea1992ff1ce12bded2195d05cf912b879b951 + name:Animaniacs (USA) (SGB Enhanced) + cheat + description:Multi-jump + code:00A-0EB-E69+00A-0BB-E69 + cheat + description:Get Stars from anywhere + code:000-60B-E6B + +cartridge sha256:23b432a52aefcca6731fccace793f58ee5cac030b27ad18ac8d354430a388f01 + name:Arcade Classics - Battlezone & Super Breakout (USA, Europe) (SGB Enhanced) + cheat + description:Paddle hits ball anywhere + code:00F-6DF-08F+18F-70F-08A + +cartridge sha256:7cebe1e446c56061f71e94b99cf6dfb7267cac0e21cb37b0f9a8118d5a127eb0 + name:Arcade Classic No. 2 - Centipede & Millipede (USA, Europe) (SGB Enhanced) + cheat + description:Centipede - Invincibility + code:C36-28A-A21 + cheat + description:Millipede - Invincibility + code:FA5-438-4C1+375-738-088 + +cartridge sha256:c504be420e7bfdcf9905fc4d6674fd4b7466e832976a7a48660b901086536d1f + name:Army Men (USA, Europe) (En,Fr,De) + cheat + description:Invincibility + code:18D-008-08A + cheat + description:Infinite ammo - all weapons + code:00C-D1F-3BE + cheat + description:Get items from anywhere + code:FA3-45C-A21+FA3-2CC-A21 + +cartridge sha256:6da0357c4b00a1b8393f4e9fb5dbbe620e9b1680a7c4032303a058178fa245b7 + name:Army Men 2 (USA, Europe) (En,Fr,De) + cheat + description:Invincibility + code:189-6A8-6EA + cheat + description:Infinite ammo - all weapons + code:00C-DAF-3BE + +cartridge sha256:801660458dc65c29701f21985943ba84c1f55cf57c9be3527b17548c33be260d + name:Asterix - Search for Dogmatix (Europe) (En,Fr,De,Es,It,Nl) + cheat + description:Invincibility + code:3E0-43E-4CA+C97-B2B-C49 + cheat + description:Hit anywhere + code:FAD-14E-A21 + cartridge sha256:3f0688ed9219c44ce133647f0668cde50fdcba7ed8f04c34c3a0fc5ce596bfe5 name:Asteroids (USA, Europe) cheat @@ -75192,6 +76600,12 @@ cartridge sha256:3f0688ed9219c44ce133647f0668cde50fdcba7ed8f04c34c3a0fc5ce596bfe description:Start with 9 lives code:093-15F-E66 +cartridge sha256:3f0688ed9219c44ce133647f0668cde50fdcba7ed8f04c34c3a0fc5ce596bfe5 + name:Asteroids (USA, Europe) + cheat + description:Invincibility + code:C95-49A-A29 + cartridge sha256:d5306853c8dc7d402808cc340064fdf48d930bbc5a531c8ece3661bfa7f7ff55 name:Atlantis - The Lost Empire (USA, Europe) cheat @@ -75209,6 +76623,12 @@ cartridge sha256:2df8eb5d48a204d9609e0c12fed81304cc0b23421c5015ab2296d51ffc8b36a cheat description:Invincibility and infinite time code:092-5EF-F77+752-5DF-B38+919-76F-195 + cheat + description:Hit anywhere - Mode A + code:206-72E-08A+3D6-71E-A2A+8B6-70E-191+F06-6FE-802 + cheat + description:Hit anywhere - Mode B + code:C87-EEA-809+007-EDA-A2A+C37-EAA-C43+007-E9A-C4B+217-E8A-D5D cartridge sha256:ac3656cb5b86c13ad67a486d11d21643fdec306500d989fbd770b5939bab22f0 name:Attack of the Killer Tomatoes (USA, Europe) @@ -75222,19 +76642,34 @@ cartridge sha256:ac3656cb5b86c13ad67a486d11d21643fdec306500d989fbd770b5939bab22f cartridge sha256:0d80b2ad776053f50c3eb0e0e32c675f24acf94923bf3ac4c156c7c28bc76a6e name:Avenging Spirit (USA, Europe) cheat - description:Infinite energy except if weapon is used against you + description:Invincibility except against spikes + code:C95-92C-081+C9E-82D-E69 + cheat + description:Invincibility against spikes + code:C95-4DA-E69 + cheat + description:Infinite health except if weapon is used against you code:FA5-AFC-4C1+FAE-C2D-4C1 cheat - description:Infinite L energy except against spikes + description:Infinite L health except against spikes code:FAE-B5D-4C1 cheat - description:Start with 1/2 energy + description:Hit anywhere + code:FAD-4DD-4C1+00D-30D-2A6 + cheat + description:Get items from anywhere + code:FA5-509-C41 + cheat + description:Multi-jump + code:00F-A6B-809 + cheat + description:Start with 1/2 health code:0A3-2BC-B3A cheat - description:Start with 1/4 energy + description:Start with 1/4 health code:053-2BC-B3A cheat - description:Start with 3/4 energy + description:Start with 3/4 health code:0F3-2BC-B3A cheat description:Start on level 2 (brings you back to level 2) @@ -75246,6 +76681,15 @@ cartridge sha256:0d80b2ad776053f50c3eb0e0e32c675f24acf94923bf3ac4c156c7c28bc76a6 description:Start on level 6 (brings you back to level 2) code:069-B9C-E6E +cartridge sha256:6340ba86bf9500ece66d8acbcca90c4ab8c42de26804fde393311d62eaab3b61 + name:B.C. Kid 2 (Europe) (SGB Enhanced) + cheat + description:Invincibility + code:00A-ABA-A22+18F-26B-6EA + cheat + description:Hit anywhere + code:18D-CEA-4CA+FAC-08A-D5D + cartridge sha256:1b48b454bb421836c33c2d572c61f69145a077ebcecbf8194dfb05fc6581ff82 name:Balloon Kid (USA, Europe) cheat @@ -75285,6 +76729,12 @@ cartridge sha256:86e5b7037d7c61248adfdc316d61b5c58fe46c5d3fe376bcdfeda9d6538b197 description:Infinite health code:FA7-FAF-4C1 +cartridge sha256:debc4ac9d7587166f4754d99955c8ed8c5ae014bb10e91764fe9e632cdbcb3fc + name:Baseball (World) + cheat + description:Balls are counted as strikes + code:000-479-809 + cartridge sha256:0eedbdd6530f30adcc8ee88b32e852b7983de8bba8122ddd2c1adaf2805a454c name:Bases Loaded for Game Boy (USA) cheat @@ -75324,6 +76774,36 @@ cartridge sha256:0eedbdd6530f30adcc8ee88b32e852b7983de8bba8122ddd2c1adaf2805a454 description:No scoring - disable to score code:008-1FF-E6E+008-11F-E6E +cartridge sha256:2eb0708771791f2e126bd97e672a365c70c3d7064ecc391433545352133dad60 + name:Battle Crusher (Japan) (SGB Enhanced) + cheat + description:Hit anywhere - P1 + code:003-DEA-F7E + cheat + description:Invincibility (except throws) - P1 + code:183-CCA-4CA + cheat + description:Blocking disabled - both players + code:003-CBD-E6E + +cartridge sha256:ea30dd015164e6895547d518a96cee60a17767f985b68c50d07ca560c80956ae + name:Battle of Olympus, The (Europe) (En,Fr,De,Es,It) + cheat + description:Hit anywhere + code:37A-7BD-3B4 + cheat + description:Get items from anywhere (press down) + code:001-A69-A2E + +cartridge sha256:c38fc7e54ed27bd82c9829a6535f5be0d2ff81822863ab9c088bf345ab01b734 + name:BattleCity (Japan) + cheat + description:Invincibility + code:C36-68C-801 + cheat + description:Invincibility - Base + code:00E-99C-E6E + cartridge sha256:9ac1f4a299d32ba21cf65f67ab210afeb4c629adbd8e5779f76b6667ca3a0a4a name:Batman - The Animated Series (USA, Europe) cheat @@ -75360,6 +76840,33 @@ cartridge sha256:9ac1f4a299d32ba21cf65f67ab210afeb4c629adbd8e5779f76b6667ca3a0a4 description:Start with about 2x energy code:0E4-8ED-F76 +cartridge sha256:d0e4ff010ab013e519abd9950ab465f3369c76e23d82927c0f39b5e259d4febf + name:Batman - The Video Game (World) + cheat + description:Invincibility + code:018DA1FF + cheat + description:Infinite health + code:FAE-C1B-4C1 + cheat + description:Infinite health (alt) + code:0104C8C0 + cheat + description:Infinite lives + code:FA9-5DF-4C1 + cheat + description:Infinite lives (alt) + code:0103C7C0 + cheat + description:Hit anywhere + code:002-75B-B3B+18E-16D-2AA+23E-17D-A22 + cheat + description:Hit anywhere - Bosses + code:28E-CAD-7FE+18E-C9D-08A + cheat + description:Multi-jump + code:187-5BC-4CA + cartridge sha256:152fc252bba7130e786d408eed310b3009b8e05834f8003dfbf514ec804cbaea name:Batman - Return of the Joker (USA, Europe) cheat @@ -75374,6 +76881,12 @@ cartridge sha256:152fc252bba7130e786d408eed310b3009b8e05834f8003dfbf514ec804cbae cheat description:Select any weapon from menu code:006-BCA-7F1 + cheat + description:Hit anywhere + code:006-B5D-5DB+006-ACD-3BF + cheat + description:Multi-jump + code:18F-4BE-4CA+C30-03D-C41+00A-34E-6E2 cheat description:5 Batarangs on pick-up code:05D-A0B-C42 @@ -75396,6 +76909,21 @@ cartridge sha256:152fc252bba7130e786d408eed310b3009b8e05834f8003dfbf514ec804cbae description:Start with max of 8 HP code:102-01F-C42 +cartridge sha256:bfb324176949811c6e116cb8e3d434b4937634d95b4f9bdfb54e0157c612dea0 + name:Batman Beyond - Return of the Joker (USA) + cheat + description:Hit anywhere + code:00E-67B-A29 + +cartridge sha256:519ca6523e54b67a4b4dcc7f525d56df986e0d77c84699dcf9e022f0ae6fbd0e + name:Battle Arena Toshinden (USA) (SGB Enhanced) + cheat + description:Hit anywhere - both players + code:FAE-01B-C41 + cheat + description:Blocking disabled - both players + code:00A-8F9-E62 + cartridge sha256:b9909506f566ea7998d6170e9610bad62dbda7d38e42830cd187592e262acfed name:Battle Unit Zeoth (USA, Europe) cheat @@ -75486,6 +77014,12 @@ cartridge sha256:436918dc75ffe606f458206caad6c063369ecbf650afcf96499eb98b2b85a72 description:Infinite lives code:FA7-EFC-4C1 +cartridge sha256:0e825ec2c23a16fac1f33cdfd7402f218e3813961e95ddb4ca9fed19bfd79d04 + name:Bill & Ted's Excellent Game Boy Adventure (USA, Europe) + cheat + description:Invincibility + code:18E-B7D-4CA + cartridge sha256:378435aa66290a4d8a930e000eddf08dcb7b00fd36341991b0abedc488bb8c5d name:Bill Elliott's NASCAR Fast Tracks (USA) cheat @@ -75570,6 +77104,66 @@ cartridge sha256:9338af642104f7f286687b2e6e55759917c0db35bc89ef398a92c18570bff68 description:9 penalty shots in shoot-out code:095-B6A-F7E +cartridge sha256:e0258871c84d18cb0b4cf9a41e1be2ad010c04fad45d97b23baca7746edcfa76 + name:Blaster Master - Enemy Below (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility + code:C9E-F3F-E69+C96-81E-E69 + cheat + description:Invincibility when falling from very high (on foot) + code:C96-82E-6EE + cheat + description:Hit anywhere + code:FAD-D59-D5D+18D-BE9-4CA + cheat + description:Get items from anywhere + code:18C-3B9-4CA + cheat + description:Multi-jump (vehical) + code:186-05B-4CA+3E5-FFB-4CA + cheat + description:Multi-jump (on foot) + code:00D-05B-E69 + cheat + description:Infinite POW meter - Vehicle + code:014024C1 + cheat + description:Infinite POW meter - Jason + code:014025C1 + cheat + description:Infinite HOV meter - Vehicle + code:014026C1 + cheat + description:Infinite Gun meter - Jason + code:014027C1 + cheat + description:Infinite Homing Missiles + code:016328C1 + cheat + description:Infinite Thunderbolts + code:016329C1 + cheat + description:Infinite 3-Way Missiles + code:01632AC1 + cheat + description:All vehicle upgrades + code:01FF06C1+01FF07C1 + +cartridge sha256:01bb3527ea235380895b8df07a864829b2ad9e399f8cd90bb816110e2bfb1693 + name:Blaster Master Boy (USA) + cheat + description:Invincibility + code:10D-06D-7FA+18D-05D-4CA + cheat + description:Hit anywhere + code:7B5-9BE-5D4 + cheat + description:One hit kills - normal enemies + code:AF7-CBC-19E + cheat + description:One hit kills - bosses + code:3E8-49C-2AA + cartridge sha256:04aeb80ff35bd863c3922ad9b8cac7ee379e78feac4ce3cef2d58ccca142fc03 name:Blues Brothers, The (USA, Europe) cheat @@ -75597,6 +77191,51 @@ cartridge sha256:04aeb80ff35bd863c3922ad9b8cac7ee379e78feac4ce3cef2d58ccca142fc0 description:Start with 9 lives code:090-15B-E62 +cartridge sha256:9053443a6c786a54bebc2fa9c10acd3875887134c953e5bdf0a07dc554721fb6 + name:Bo Jackson - Two Games in One (USA) + cheat + description:Baseball - 1 ball and you walk + code:01F-13C-F7A + cheat + description:Baseball - 2 balls and you walk + code:02F-13C-F7A + cheat + description:Baseball - 5 balls and you walk + code:05F-13C-F7A + cheat + description:Baseball - Strikes aren't counted - ignore message, you need 4 balls to walk + code:00E-C5C-3BA + cheat + description:Baseball - Outs aren't counted + code:003-E88-3BA + cheat + description:Baseball - 1 strike and you're out + code:01E-87C-E66 + cheat + description:Baseball - 2 strikes and you're out + code:02E-87C-E66 + cheat + description:Baseball - No scoring - disable to score + code:008-3C8-3BA+008-268-3BA + cheat + description:Football - Infinite time + code:F05-6EC-6E9 + cheat + description:Football - Infinite timeouts + code:000-12A-3BE + cheat + description:Football - Always 1st down + code:F07-D0B-6E9 + cheat + description:Football - Start with 1 timeout + code:010-68B-E66 + cheat + description:Football - Start with 2 timeouts + code:020-68B-E66 + cheat + description:Football - Start with 10 timeouts + code:0A0-68B-E66 + cartridge sha256:195f5a9e97bfec6f071bfd6b82a39ffa25185b687a26a1f2937f9718c4d4d16e name:Boggle Plus (USA) cheat @@ -75663,6 +77302,66 @@ cartridge sha256:16d6a4650566ede0ec9e3e23a85544737faab4154d6381668e8547047340eee description:Bombs can break any block code:006-C28-F7E +cartridge sha256:27d2eb237362b5647b020d0b22a08b079b40e50347dacc43b732830b9519a852 + name:Bomberman Max - Blue Champion (USA) + cheat + description:Invincibility + code:001-B9A-195+C32-EBA-C41 + cheat + description:Hit anywhere + code:F25-E2C-6E2+C25-E3C-F71 + cheat + description:Walk anywhere + code:FAB-16B-4C1 + cheat + description:Infinite health + code:010204C3 + cheat + description:Infinite lives + code:010AF7C2 + cheat + description:Infinite time + code:01FF01C3 + cheat + description:Max Bombs + code:0109F3C2 + cheat + description:Max Explosion + code:0109F4C2 + cheat + description:All enemies frozen + code:0100FFC2 + +cartridge sha256:5f7c1cdf6adbe6d6dcef488bd37d0da82fa356b79fd579b2022a149e983abc39 + name:Bomberman Max - Red Challenger (USA) + cheat + description:Invincibility + code:AF2-EAA-7F4+181-9DA-08A + cheat + description:Hit anywhere + code:C25-F1C-F71+F25-F0C-6E2 + cheat + description:Walk anywhere + code:00B-15B-E6E + cheat + description:Infinite health + code:010204C3 + cheat + description:Infinite lives + code:010AF7C2 + cheat + description:Infinite time + code:01FF01C3 + cheat + description:Max Bombs + code:0109F3C2 + cheat + description:Max Explosion + code:0109F4C2 + cheat + description:All enemies frozen + code:0100FFC2 + cartridge sha256:6081309e7f5b63e4f6694965060c68baf82a775eb18e667c2c89898096e6e3d8 name:Bonk's Adventure (USA) cheat @@ -75684,50 +77383,11 @@ cartridge sha256:6081309e7f5b63e4f6694965060c68baf82a775eb18e667c2c89898096e6e3d description:Start with 10 lives code:091-AFF-E66 -cartridge sha256:9053443a6c786a54bebc2fa9c10acd3875887134c953e5bdf0a07dc554721fb6 - name:Bo Jackson - Two Games in One (USA) +cartridge sha256:6ac93cc5186a2e92e13260fd61951c1b28f0df2278b9003b2bcb1ddcbf51543c + name:Boomer's Adventure in ASMIK World (USA) cheat - description:Baseball - 1 ball and you walk - code:01F-13C-F7A - cheat - description:Baseball - 2 balls and you walk - code:02F-13C-F7A - cheat - description:Baseball - 5 balls and you walk - code:05F-13C-F7A - cheat - description:Baseball - Strikes aren't counted - ignore message, you need 4 balls to walk - code:00E-C5C-3BA - cheat - description:Baseball - Outs aren't counted - code:003-E88-3BA - cheat - description:Baseball - 1 strike and you're out - code:01E-87C-E66 - cheat - description:Baseball - 2 strikes and you're out - code:02E-87C-E66 - cheat - description:Baseball - No scoring - disable to score - code:008-3C8-3BA+008-268-3BA - cheat - description:Football - Infinite time - code:F05-6EC-6E9 - cheat - description:Football - Infinite timeouts - code:000-12A-3BE - cheat - description:Football - Always 1st down - code:F07-D0B-6E9 - cheat - description:Football - Start with 1 timeout - code:010-68B-E66 - cheat - description:Football - Start with 2 timeouts - code:020-68B-E66 - cheat - description:Football - Start with 10 timeouts - code:0A0-68B-E66 + description:Always have key + code:003-C7D-C49 cartridge sha256:b164bafab4da7f92a33a2cdfce706b35407f3aa0ac379cd770fe2f78447bdf7a name:Bram Stoker's Dracula (USA, Europe) @@ -75741,6 +77401,12 @@ cartridge sha256:b164bafab4da7f92a33a2cdfce706b35407f3aa0ac379cd770fe2f78447bdf7 description:Infinite ammo code:FA1-21E-4C1 +cartridge sha256:5ffda4ca9e2712e2ecc44e75bfd8c7307f4ed5fbcbb82a0f5cd9ad19e3bac6c2 + name:Brave Saga - Shinshou Astaria (Japan) + cheat + description:No random battles + code:C92-CFB-C49 + cartridge sha256:c5ddbb08e8509633853346c5f35850cc3abe5afaabb0d0ee294b40e804253b7f name:Bubble Bobble (USA, Europe) cheat @@ -75789,6 +77455,18 @@ cartridge sha256:29f17b604be580c0132a6d0bd7a966c82930069ca82f83798c955d532c6b469 description:Start on round 60 code:3E8-39F-081+3B8-3AF-D5E+008-3BF-E6D +cartridge sha256:a0bd5d25545de941e719437f7829f4edf32b3a140a399387f96dda2f8059fe4e + name:Bugs Bunny Crazy Castle, The (USA, Europe) + cheat + description:Invincibility + code:186-CCC-08A + cheat + description:Get carrots from anywhere (entire level) + code:00C-E2D-C4E+00C-DDD-D52 + cheat + description:Get carrots from anywhere (horizontal position) + code:00C-DDD-D52 + cartridge sha256:cf1a8d9c9d4fc9e58740f6e008e5280ff2831c099aecab642e64e5195c0ad0bc name:Bugs Bunny Crazy Castle 2, The (USA) cheat @@ -75797,15 +77475,33 @@ cartridge sha256:cf1a8d9c9d4fc9e58740f6e008e5280ff2831c099aecab642e64e5195c0ad0b cheat description:Infinite lives code:BE6-00E-19E + cheat + description:Get keys from anywhere (except from the ones inside of doors) + code:16F-D5A-E6E+18F-D4A-4CA + +cartridge sha256:89e43fdc94ec1d2a67aaab39d72afa50dd01df4323df7bf3d0909247cc490c24 + name:Bugs Bunny - Crazy Castle 3 (USA, Europe) + cheat + description:Invincibility + code:C91-979-E69 + cheat + description:Get Keys from anywhere + code:000-699-2A6+000-6E9-5D2 + cheat + description:Open locked doors without having 8 Keys + code:18C-65B-4CA + cheat + description:Enter any door to clear level + code:05A-B6E-F76 cartridge sha256:e5abce2a219fe38e53d1a572d371008f3b6d70be4607c1722139a9ea95fa7422 name:Bug's Life, A (USA) (SGB Enhanced) - cheat - description:Infinite lives - code:006-2FD-3BE cheat description:Invincibility (can still drown) code:000-EEE-081 + cheat + description:Infinite lives + code:006-2FD-3BE cartridge sha256:2f4254faaa4bda89486c4820c601917cd034c7965eae075ba81acef4295fa8bd name:BurgerTime Deluxe (World) @@ -75818,6 +77514,36 @@ cartridge sha256:2f4254faaa4bda89486c4820c601917cd034c7965eae075ba81acef4295fa8b cheat description:Infinite weapon code:FEB-76D-B31 + cheat + description:Touch Burgers from anywhere + code:000-C0D-082 + +cartridge sha256:2fbf14a5bffb070e183537c3ff4cd8e05626a94b3949785ed240b28642d0a259 + name:Bust-A-Move Millennium (USA, Europe) + cheat + description:Hit one bubble to clear level - Challenge Mode + code:AF3-3AB-19E+C22-EEB-080 + cheat + description:Hit one bubble to clear level - Puzzle Mode + code:184-69A-4CA + cheat + description:Win automatically - Story Mode + code:075-ABB-C42+185-AAB-4CA+065-93B-F7A + +cartridge sha256:2223993b7a91a5f2ccca1f43652df0062528e3fb37128f61a0ec8a779bcf65a1 + name:Buster Bros. (USA) + cheat + description:Hit anywhere - main weapon + code:5B5-59D-A2D+FA5-31D-A21 + +cartridge sha256:ce892641c500ddd0ccb804208556113ad4b9736f89cc94c6822f863508eb81f0 + name:Buzz Lightyear of Star Command (USA, Europe) + cheat + description:Infinite health + code:0164DACC + cheat + description:Always have five coins + code:0105C8CC cartridge sha256:f0b147eb3429b1b480424a31eb2d800b5676d01a701b494b2c9e9d2de63d31c5 name:Captain America and the Avengers (USA) @@ -75933,6 +77659,18 @@ cartridge sha256:f0b147eb3429b1b480424a31eb2d800b5676d01a701b494b2c9e9d2de63d31c description:Start on stage 5-6 code:3E3-A8F-912+1C3-A9F-E6A+E03-AAF-2A9 +cartridge sha256:1ff537c010391d6b865b5113d03a9c6601e43659f341f5db2bfc5cc501b6aa04 + name:Casper (USA) + cheat + description:Infinite Brass Keys + code:0163A9C1 + cheat + description:Infinite Iron Keys + code:0163A8C1 + cheat + description:Infinite Weights + code:0163ABC1 + cartridge sha256:17570ceec1b22153604622c4412d048dd8f7ccb4626daf9ddea96de8a062dbf2 name:Castlevania II - Belmont's Revenge (USA, Europe) cheat @@ -75946,7 +77684,7 @@ cartridge sha256:17570ceec1b22153604622c4412d048dd8f7ccb4626daf9ddea96de8a062dbf code:872-94B-E62+C82-95B-E69+E62-96B-19E+102-97B-C41+202-98B-B39+152-99B-E67+C9D-47F-809 cartridge sha256:edb101e924f22149bdcbcfe6603801fdb4ec0139a40493d700fa0205f6dab30c - name:Castlevania Adventure, The (USA) + name:Castlevania - The Adventure (USA) cheat description:Infinite energy code:00A-F28-3B7 @@ -76024,7 +77762,37 @@ cartridge sha256:56d3dee063b8801704a284bd1bc229b94f15a3a448f485d347f04283d9bd16d code:4B3-49D-803+C94-5CA-D5D cheat description:Multi-jump - code:CD7-34A-F75+FA1-70A-4C1+037-33A-3B6+287-32A-081+517-36A-E62+557-2EA-80A+597-35A-191+677-31A-E69+C97-37A-C49+C9F-E4E-A29+CB7-30A-3B4 + code:037-33A-3B6+287-32A-081+517-36A-E62+557-2EA-80A+597-35A-191+677-31A-E69+C97-37A-C49+C9F-E4E-A29+CB7-30A-3B4+CD7-34A-F75+FA1-70A-4C1 + +cartridge sha256:7e483524aa104928149e4e56f01b7e98c6eed70dcd30ac5d65cd9d2387cde5ff + name:Chessmaster, The (USA) + cheat + description:Move pieces anywhere + code:189-D8E-4CA+18A-12E-4CA+00A-00E-80D + +cartridge sha256:0a44d1f127436d73fc2f64201da0e0fd40793a414e533bba0a08e02dfb51cb10 + name:Chessmaster, The (USA) (Rev A) + cheat + description:Move pieces anywhere + code:18A-B6E-4CA+18A-F8E-4CA+00A-E6E-A2D + +cartridge sha256:781b31deb923c544b42b2116d973a103fd5c21b3cf25e920968ef392a5df917b + name:Chessmaster (USA, Europe) + cheat + description:Move pieces anywhere + code:007-83D-A2D+187-95D-4CA+187-53D-4CA + +cartridge sha256:2eb1ab19a19e688ebc047497922b17218da3cb673084846999bd81a4dd73eba4 + name:Chiki Chiki Tengoku (Japan) + cheat + description:Clear level automatically + code:3EA-FEC-2AA+00B-17C-E66+3EB-0AC-6EA + +cartridge sha256:53199f624a81f566104c143b835ca648ee9bbccc2c10efa21a3f4b3f5b5e7ea7 + name:College Slam (USA) + cheat + description:Dunk and layup from anywhere + code:00C-099-A26 cartridge sha256:d8e44a2c2aa67f9afa49365f62802160842aef48d2003a69daeb109813f6f20c name:Contra - The Alien Wars (USA) (SGB Enhanced) @@ -76074,6 +77842,57 @@ cartridge sha256:8e765a4e381462a29632b7a3c5421080be3e8445e5913d7e904a8e80d688ca8 description:Multi-jump code:005-8CA-B3F+260-E6F-195+460-E9F-195+520-E7F-195+550-EAF-195+C90-EBF-195+CD0-E5F-195+CD0-E8F-195+E55-8BA-F73 +cartridge sha256:aa993ef6fd692435f869c63add9d49bf08db6fc8d6ee7baa9b406982d7b38c7c + name:Cool Bricks (Europe) (En,Fr,De,Es,It) + cheat + description:Paddle hits ball anywhere + code:008-58E-4C6+008-55E-5D2 + +cartridge sha256:805c18920e01f4b5746827c201e9a88554f085a8c297ed45f119700fe54da52e + name:Cool Spot (USA) + cheat + description:Hit anywhere + code:00B-D8E-C4F+FA8-67E-A21 + +cartridge sha256:e0dafd8b66cc6c19c3b64471d198e1dc87f3e5e1000c4fd8d71122a004fea5ae + name:Cosmo Tank (USA) + cheat + description:Invincibility + code:189-9FA-08A + cheat + description:Hit anywhere + code:00D-4FB-A22 + +cartridge sha256:5437ce255372eca79a5e33cfca4158e70c7a9d46fd93c6a38ed1e1a13cab4b73 + name:Croc (USA, Europe) + cheat + description:Invincibility + code:C91-149-E69 + cheat + description:Enemies die on contact + code:18B-D9A-4CA + +cartridge sha256:002ad8e22b4d846d3185c2e42af284dcb5f9b040bb174c9b5e9670de4df79278 + name:Croc 2 (USA, Europe) + cheat + description:Invincibility + code:C95-C9A-E69+C95-95A-E69 + cheat + description:Enemies die on contact + code:185-80A-6EA + cheat + description:Walk over pits + code:C97-31B-081 + +cartridge sha256:3c86f30b11442c93b011287310dfea0a9c23a182527d8447769226e52ef29d5e + name:Crystal Quest (USA) + cheat + description:Invincibility (allows you to exit the level at anytime) + code:C90-00E-C49+18D-79F-2AA + cheat + description:Hit anywhere + code:008-B9F-3B7+3E8-63F-2AA + cartridge sha256:d5a1c0e7af970859449c47fcc80a5f4dfa4f456b20fdfcd49e753ce46f2dc3da name:Cyraid (USA) cheat @@ -76109,6 +77928,9 @@ cartridge sha256:06d2f49483cf16f00580ba227d86174fdb9f72e555d9a9afea6aebcbfff012e cheat description:Infinite time code:00D-62D-3BA + cheat + description:Place any piece to clear level + code:1B1-15E-A29 cheat description:Get password to select any level after completing level 1 code:3E1-9AF-191+0A1-9BF-7FA @@ -76125,6 +77947,27 @@ cartridge sha256:30faf530573519d690d066093e9fae3b461d79df37c025a9ec9115f5fc5786e description:Infinite jet pack + hit anywhere code:AF4-01C-19A+C3D-F2C-E61+18D-D5C-6EA+FAD-EBC-801+FAE-B2C-801 +cartridge sha256:e4a40a4c961f937950a69da5a9de654a121ebffe307d3ad9e834731b68d4e347 + name:Daikatana (Europe) (En,Fr,It) + cheat + description:Invincibilities against enemies + code:C32-2BA-801 + cheat + description:Infinite ammo - sub-weapons + code:FAA-3B9-4C1 + cheat + description:Hit anywhere + code:182-D5A-801+1E2-D6A-2A3 + cheat + description:Hit anywhere - sub-weapons + code:29F-04B-F7D+18F-03B-801 + cheat + description:Get items from anywhere + code:18F-189-801+20F-199-2A4 + cheat + description:Multi-jump + code:00B-7C9-A2F + cartridge sha256:b482f9a96a292dea1fcc94bdeae24b664a3222c9eb820795388aab274eebdaf0 name:Darkman (USA, Europe) cheat @@ -76163,6 +78006,12 @@ cartridge sha256:122a1d3bd99c87a337f770fbdef2b7cf8538673df1595585af6684d4d480761 cheat description:Infinite ammo on pick-up code:FAD-398-4C1 + cheat + description:Hit anywhere + code:3E0-CEB-2AA + cheat + description:One hit kills + code:181-02B-4CA cheat description:Invincibility time lasts 4 seconds code:AA0-64B-A2B @@ -76192,7 +78041,7 @@ cartridge sha256:122a1d3bd99c87a337f770fbdef2b7cf8538673df1595585af6684d4d480761 code:099-F0F-F7A cartridge sha256:61d632a2e17526cc55cc8e107abaf9aa11830cd4dd94c0b0f94d10a12a0c9f71 - name:David Crane's The Rescue of Princess Blobette starring A Boy and His Blob (USA) + name:David Crane's The Rescue of Princess Blobette Starring A Boy and His Blob (USA) cheat description:Infinite jellybeans code:000-56D-E6E @@ -76352,6 +78201,9 @@ cartridge sha256:a089bea1d6eec0e99f03276744aea293fe3fe3a2889791ab8f3a00b83e2cf58 cartridge sha256:2d8fb80ece07198260fb47b6a2e8d0097e2d6ca27fb21bc3c439f90d7880317d name:Dig Dug (USA) + cheat + description:Invincibility + code:FA3-C1D-4C1 cheat description:Infinite lives code:008-1BB-19E @@ -76380,6 +78232,12 @@ cartridge sha256:2d8fb80ece07198260fb47b6a2e8d0097e2d6ca27fb21bc3c439f90d7880317 description:Start on level 9 (display still says level 1) code:3EC-D9A-O8A+09C-DAA-E62 +cartridge sha256:0ee26b1a12c91560ab852510a792b13d7391c2fcebf4c0c0a1d8323194eb473a + name:Donald Duck - Goin' Quackers (USA) (En,Fr,De,Es,It) + cheat + description:Get blue items from anywhere + code:3E4-A28-4CA + cartridge sha256:2781f6b1014336e3318073f162cadd970329c8148fc62b5e795441cd6fd57051 name:Donkey Kong (Japan) (En) (SGB Enhanced) cheat @@ -76417,7 +78275,7 @@ cartridge sha256:eaf831ddd75e7cbc9990e478a139ac162034c03377670fdb79615a9aa2cc570 code:00D-9DB-3BE+21D-A0B-E61 cheat description:Multi-jump - code:CD5-AFA-081+F65-B4A-2AA+005-B5A-D5E+015-AAA-D5A+1F5-ACA-B36+295-B1A-F71+2D5-B2A-191+305-ADA-08A+365-B3A-F72+BD5-B0A-C46+CA5-ABA-F71 + code:005-B5A-D5E+015-AAA-D5A+1F5-ACA-B36+295-B1A-F71+2D5-B2A-191+305-ADA-08A+365-B3A-F72+BD5-B0A-C46+CA5-ABA-F71+CD5-AFA-081+F65-B4A-2AA cheat description:Always save game at end of level, regardless if you have KONG letters or not code:C30-CBB-C41 @@ -76460,6 +78318,33 @@ cartridge sha256:75f902ab8674c3cd379438fbd54cfe7e87ca3ddf9727679547261d1b77db720 cheat description:One hit kills (bosses die after three hits) code:00A-DA9-4CA+00B-629-F7A + cheat + description:Start on Mission 1 (slum) (disable code to advance to next stage) + code:010050C6 + cheat + description:Start on Mission 1 (area with boxes) (disable code to advance to next stage) + code:010150C6 + cheat + description:Start on Mission 1 (boss) (disable code to advance to next stage) + code:010250C6 + cheat + description:Start on Mission 2 (disable code to advance to next stage) + code:010350C6 + cheat + description:Start on Mission 3 (woods) (disable code to advance to next stage) + code:010450C6 + cheat + description:Start on Mission 3 (cave) (disable code to advance to next stage) + code:010550C6 + cheat + description:Start on Mission 4 (outside enemy's base) (disable code to advance to next stage) + code:010650C6 + cheat + description:Start on Mission 4 (enemy's base) (disable code to advance to next stage) + code:010750C6 + cheat + description:Start on Ending (disable code to advance to next stage) + code:010850C6 cartridge sha256:21639689078496d4c2d000b120d493b69e7df603e5c2b5cd337974665e597878 name:Double Dragon II (USA, Europe) @@ -76527,6 +78412,18 @@ cartridge sha256:936df4d0f74620c784129259a22fc3216eea04f70c10cab6005457a0f681e31 description:When selecting skill level, keep pressing down. Bleeping will continue, and computer will become more and more skillful. code:FFA-0BE-E66 +cartridge sha256:15fecc6e3d9f72e9cf3f5af7c1f034cc94a2007d29ea0a204976adcc0ff9a52e + name:Dragon's Lair - The Legend (USA) + cheat + description:Have all Life Stones + code:010143C3+010944C3+010445C3 + +cartridge sha256:8dab48cc81d14bcee7c73274df09cf5c4dd44c3b93d10a5a3175e04fead25dee + name:Dragon Ball Z - Legendary Super Warriors (USA) + cheat + description:Opponent doesn't attack + code:C98-FC9-081 + cartridge sha256:34f11935cb3c23102462aab9d96c09e25b81b35eef91f5e5456b2c3665734f0e name:Dragon Warrior III (USA) cheat @@ -76542,6 +78439,18 @@ cartridge sha256:64d791cadae2500ddd7dfd3ebedc48a182fdc0e027f9bfd74c8ff65b56371db description:Reset to see ending code:081-6FF +cartridge sha256:4d754abe2502f79396790f04963468f5c614eb4768e2b3f9b5c79c8e28b55dcb + name:Elevator Action EX (Europe) (En,Fr,De,Es,It) + cheat + description:Invincibility + code:18E-E8A-08A+C39-FAA-E61 + cheat + description:Hit anywhere + code:3EC-83B-4CA+3EB-C7B-4CA + cheat + description:Don't get crushed by elevators + code:18E-AFA-4CA+187-2DB-4CA + cartridge sha256:9eee3454a1198c01c7adb9562507f2eb5791888c63885bea2e933948f66f6321 name:Extra Bases! (USA) cheat @@ -76712,6 +78621,15 @@ cartridge sha256:2d89231f9e264a024d634bcf7d00de5a66d8a45f6f4ca33e1fc1602a35b9840 cheat description:Infinite HP (don't heal or stay and Inn) code:B90-64B-A9E + cheat + description:0 HP - enemies + code:AF4-8CB-19B+AF4-89B-19F + cheat + description:Infinite item usage + code:00D-28A-3BE+001-F0B-A22 + cheat + description:Items are free + code:005-5B9-2AA+FA5-5C9-D5D cheat description:Get extra GP and Meat code:C9D-23B-2AA @@ -76722,7 +78640,7 @@ cartridge sha256:2d89231f9e264a024d634bcf7d00de5a66d8a45f6f4ca33e1fc1602a35b9840 description:Engage in a fight every second code:37F-C5D-36E cheat - description:All characters start with 15,163 HP (shows only 999) + description:Start with 15,163 HP (shows only 999) - All characters code:005-96F-08B+005-9CF-08B cheat description:Start with 9 HP @@ -76802,6 +78720,12 @@ cartridge sha256:da62ce2133b788e88605fad8f8d15582457d2a08de88124f231ef943ffba880 cheat description:No energy loss from weapons thrown code:21F-A5F-4C1 + cheat + description:Hit anywhere - both players + code:000-D0E-F72+180-D5E-2AA + cheat + description:One hit kills + code:00E-10F-C4E cheat description:Start on level 5 code:05B-CCE-E6E @@ -76848,6 +78772,51 @@ cartridge sha256:44bd5dd98b6ca3730435197d5af7f4fb6fa0f86fecf9b74005d5a76c28870f8 description:Enable everyone for tournament mode code:00C-9BF-E6E+13C-A0F-D56 +cartridge sha256:06643cffc888b1c0c80ccae3cef66babb9b878ee594c29de8c9216bddd48287f + name:Fortified Zone (USA, Europe) + cheat + description:Hit anywhere + code:183-179-191+143-189-195 + +cartridge sha256:f07e6f63023d997a83066b422024242d6a7b61cee1af0c1fc41e6fbf4b54b65b + name:Frogger (USA) + cheat + description:Invincibility + code:FAD-14F-4C1+FAA-7FF-4C1 + cheat + description:Infinite lives + code:FAB-6DF-4C1 + cheat + description:Infinite time + code:00E-84F-3B7 + +cartridge sha256:1f60f516020ef685d353dcbff810e4d93d09a4bcf6f6e87803768ea776c85929 + name:Frogger (USA) + cheat + description:Invincibility + code:C9D-12F-192+18A-7BF-6EA + cheat + description:Infinite time + code:C9E-71F-E69 + +cartridge sha256:8c144ddebdc63631949ba0f946ae4a745be4aaf1082736676cb1af61887ab7a2 + name:Frogger 2 (USA) + cheat + description:Invincibility + code:C9E-5FF-192+C9E-3DF-192 + cheat + description:Infinite time + code:003-6DF-3BA + +cartridge sha256:d96da0c0c17a164c398b2d5b02cbe92e7eafbfa755fee649d159b46e61814dc6 + name:Galaga - Destination Earth (USA) + cheat + description:Invincibility + code:181-B2A-4CA+186-4C8-2AA + cheat + description:Hit anywhere + code:FAA-5AA-A21+FAA-8BA-A21+FAA-71A-801 + cartridge sha256:af4fda51b28e426f6cab8b48037cf2cbc18ad6c1f02311ad901365aa52c918b7 name:Ganso!! Yancha Maru (Japan) cheat @@ -76863,6 +78832,30 @@ cartridge sha256:af4fda51b28e426f6cab8b48037cf2cbc18ad6c1f02311ad901365aa52c918b description:Infinite time code:00B-B9F-3B7 +cartridge sha256:ad6f9fe97a40418279d3b834a64d9c6c52c0da209f430718f2bd02611892326f + name:Gargoyle's Quest (USA, Europe) + cheat + description:Invincibility + code:C9E-179-C49 + cheat + description:Hit anywhere + code:3EB-B08-2AA+3EB-A68-2AA + +cartridge sha256:b7774eb039d335d8870b28e05ff7bc0869c46d0accc0d7f467affd71bbae8871 + name:Gauntlet II (USA, Europe) + cheat + description:Invincibility + code:C33-2DB-A21 + +cartridge sha256:4bbf52ae46599bed5e08c6ea97f05220a4a5244f35519003d9b66e9d77328fe1 + name:Gekitou Power Modeller (Japan) (SGB Enhanced) + cheat + description:Invincibility against normal attacks - P1 + code:189-0E8-4CA + cheat + description:Hit anywhere + code:0B8-788-193+848-748-5D0 + cartridge sha256:78d35816612a521315e0b0618886e4b9e1005c58e459248c7e7585d8c04e71ac name:George Foreman's KO Boxing (USA, Europe) cheat @@ -76875,6 +78868,51 @@ cartridge sha256:78d35816612a521315e0b0618886e4b9e1005c58e459248c7e7585d8c04e71a description:Infinite super punch code:3E7-EEE-08A +cartridge sha256:ca9d168e068492644cf054a2e35f0bccc31af5899e54c05a2cbc740247014a51 + name:Gex - Enter the Gecko (USA, Europe) + cheat + description:Invincibility + code:C96-BFF-D5D + cheat + description:Hit anywhere + code:001-BFA-A29+001-C9A-A29 + cheat + description:Get Skulls from anywhere (the ones that are not dropped by enemies) + code:005-169-D5E+005-0C9-B36 + cheat + description:Moon jump + code:022-79B-6EA+D52-77B-A21+9F2-76B-C4E + +cartridge sha256:af1c1c11d7039fbf03932b17629b8ad17c275d1cb638fdb2e00dab5084919cb9 + name:Gex 3 - Deep Pocket Gecko (USA) + cheat + description:Invincibility + code:77F-94B-3BE+3EF-92B-4CA + cheat + description:Hit anywhere + code:945-66A-19D+C35-65A-E61 + cheat + description:Get Butterflies from anywhere (the ones that are not dropped by enemies) + code:001-C99-C42+001-BF9-B3A + cheat + description:Moon jump + code:4E8-C0B-7F3+DA8-BEB-809+D78-BDB-F7E + +cartridge sha256:895524c63a57b94718e63cd8f71db21617e1692788659cd7cec8e3470b7921f2 + name:Ghosts'n Goblins (USA, Europe) + cheat + description:Invincibility + code:C93-35C-2A9 + cheat + description:Hit anywhere + code:001-D8D-086 + +cartridge sha256:1d47b7e1d6654747e41bd38bf2f6064c23537e9bcea280634f263cdccc6ec5e4 + name:Ghostbusters II (USA, Europe) + cheat + description:Get visible ghosts from anywhere (press B) + code:3E7-95B-4CA+007-72B-4CE + cartridge sha256:dc898d66af6c2ada73946f1cb68f1539c16240060f72e31da5bee2ba2655fcbc name:Goal! (USA) cheat @@ -76911,18 +78949,69 @@ cartridge sha256:185f092bbebd5fa29a82ffb7d18c8242f75d6f8fee968cf6dee00b32a879feb description:Final boss has no HP code:005-D68-E66 +cartridge sha256:0f129d30e71c578d737cc9ca6be57abe68d8ba12a934da7d90a3949e192b0dfb + name:Gold and Glory - The Road to El Dorado (USA) + cheat + description:Invincibility + code:006-03A-806+3E5-F9A-B31 + cheat + description:Hit anywhere + code:C9D-D99-2A9+37D-D89-F77 + cheat + description:Multi-jump + code:E03-E3A-5D9+003-E1A-6EA+183-B5A-6EA+003-A2A-917 + cartridge sha256:896d9ffbdfe35c802cdcb66b5a6ce84a4ad6bc356c85067904883944a621cbb4 name:Golf (World) cheat description:Wind power is 10 mph code:3ED-87E-08A+5ED-88E-C4E +cartridge sha256:4c4397870b96a88e3232f7437945ba122ab2e951b3fe2bb7775d99843d1d6aa5 + name:Grandia - Parallel Trippers (Japan) + cheat + description:Walk anywhere + code:FAC-57B-4C1+FAC-65B-4C1 + cheat + description:Skip battles + code:FA9-C89-4C1+18A-349-2AA + cartridge sha256:2ed249eb86d4fd01e10efd1787a545f4921c19dc0e00b5c516b8bbdfe4c4aedc name:Gradius - The Interstellar Assault (USA) cheat description:Invincibility code:C91-18A-081 +cartridge sha256:77e9ab506b0995d958fa4b320b9076ee3408de063f76140663c01ae6c32ae3aa + name:Grand Theft Auto (USA) + cheat + description:Infinite ammo + code:006-FBB-3BE + cheat + description:Jesus mode + code:C9B-4DE-4CA + +cartridge sha256:da9bbcdbd8baba652599419c3d828697c206fb9290b9e008c2ed9ca6103561e8 + name:Great Greed (USA) + cheat + description:No random battles + code:009-34B-F73 + cheat + description:One hit kills + code:7CC-1FB-914 + cheat + description:Enemies don't attack + code:186-6FB-4CA + cheat + description:Walk through walls + code:00E-60B-B3F + +cartridge sha256:6281ee9af82cbd882250de4802465876a630239b1bc27c1c58b2b3c4ac6fa5d3 + name:Hatris (Japan, USA) + cheat + description:Eliminate a stack with two hats + code:3E1-E6C-6EA+C32-0BC-A21 + cartridge sha256:bfbed25beef74dec194a7330e3f4864a4b82f28927121cf03d9b871965553420 name:Heavyweight Championship Boxing (USA) cheat @@ -76984,7 +79073,7 @@ cartridge sha256:6bf16580b0047f7b0dbaf2bf9a2d34095e057efe70414feeda48de8dcf8952f code:FF8-D8F-E65 cartridge sha256:f6bdf9f2c4148ce7da23986524781ee844729f360ff9ef27d695ecf0886ff9e0 - name:Hit the Ice (USA, Europe) + name:Hit the Ice - VHL - The Official Video Hockey League (USA, Europe) cheat description:Infinite timer code:00A-54E-E6E @@ -77027,12 +79116,21 @@ cartridge sha256:f6bdf9f2c4148ce7da23986524781ee844729f360ff9ef27d695ecf0886ff9e cartridge sha256:2449307e540566135734977b01ca488a3feb2ce9d887f69a275a308b5a78cc3f name:Home Alone (USA, Europe) + cheat + description:Invincibility + code:C9A-BDD-A29 cheat description:Infinite hit points code:00B-5AD-19E + cheat + description:Hit anywhere + code:FAC-B6D-A21+FAC-C7D-A21 cheat description:No enemies code:214-34F-081 + cheat + description:Multi-jump + code:009-33E-192 cheat description:Need 1 treasure to finish level 1 code:013-E5D-7FA @@ -77088,6 +79186,15 @@ cartridge sha256:a04db245f19a55cd3ff43e2b3fc51cc747fc048a551c4e18639fef4af77553e description:Start with 15 humans code:0FD-609-D5A +cartridge sha256:690f7b634282d9e8d0ba74f32164f08be45eab1f213bd2c4f02f2b75e22b1773 + name:Ikari no Yousai 2 (Japan) + cheat + description:Invincibility + code:3E4-BBE-4CA + cheat + description:Hit anywhere + code:00C-AFF-809+00C-B1F-A29+00C-CCF-809+FAA-D3F-4C1+00C-CEF-A29 + cartridge sha256:ef563c4a4b063ea045d71b435dd078c19d0738f85079928803167cee8f34a4ec name:Incredible Crash Dummies, The (USA, Europe) cheat @@ -77148,16 +79255,34 @@ cartridge sha256:616202e0c2bea4898268c9b3a4eb22e198f1b559e29406057e039dded3db963 description:Race 3 laps shorter code:04B-F0A-E6E +cartridge sha256:7459baee09bf535b8a5402c4c9f9ffc91642a473b7a0ef6085f1df47a35354a0 + name:Jeopardy! (USA) + cheat + description:Always correct (even if you enter nothing) + code:002-4CE-C49+182-52E-4CA + +cartridge sha256:5eaa028521fbff19dd87cd65a89a1a964ab098e343f4df6a94acae0d24b65e7d + name:Jeopardy! - Sports Edition (USA) + cheat + description:Always correct (even if you enter nothing) + code:182-63E-4CA+002-5DE-C49 + +cartridge sha256:9f8a2dec7c3faa1ca2c12dd819cb36dc331a0ff7c2bb1b49786568e9df016357 + name:Jeopardy! - Teen Tournament (USA) (SGB Enhanced) + cheat + description:Always correct (even if you enter nothing) + code:182-89E-4CA+002-83E-C49 + cartridge sha256:873d813fc51b735571c721c12922e85f200ee66f0cb742a60e4a9a63aea74944 name:Jetsons, The - Robot Panic (USA, Europe) cheat description:Infinite lives code:00F-C7F-E6E cheat - description:Infinite energy - some robots can't be killed (disable to fight them) + description:Infinite health - some robots can't be killed (disable to fight them) code:009-088-3B7 cheat - description:Max collectible energy + description:Max collectible health code:09F-1EC-F7E cheat description:Capped robots on first Elroy stage take 1 hit to kill @@ -77181,7 +79306,7 @@ cartridge sha256:bbc006dcf175f1fec822c533bed6abc136a98bcb3b6f8d726cc87c8e17c62e1 description:Infinite lives code:002-37D-E6E cheat - description:Infinite energy + description:Infinite health code:FAB-E9C-4C1 cheat description:Take one hit and lose life @@ -77295,6 +79420,24 @@ cartridge sha256:6b13a664a3c74e6e61b019f4024f65b3fb301ee5518a9cf9e2a27dc41bbdd56 description:Start with 9 hearts - 1st life code:093-9BF-F7A +cartridge sha256:5b3e8b6b22662607933bac74e03059ceb7274b6ed3dc2c8752cab45472584a3a + name:Karate Joe (Europe) (Unl) + cheat + description:Invincibility + code:77E-82E-3BE+3EE-80E-4CA + cheat + description:Hit anywhere + code:FAF-C1F-A21+FAF-BBF-801+FAF-A2F-A21+FAF-9CF-801 + cheat + description:Hit anywhere - Boss + code:FA0-E6E-A21+FA0-E0E-801+FA0-C7E-A21+FA0-C1E-801 + +cartridge sha256:5759871de43dd530b6e54bbd8025018576c0e5f97a2aa7128c091df33554ea91 + name:Ken Griffey Jr.'s Slugfest (USA) + cheat + description:Balls are considered strikes + code:188-029-6EA + cartridge sha256:b0a1019b6199c923a6a764c15e7bf6d1bb0bef8a042c383f3e3ead74ab171ede name:Kid Dracula (USA, Europe) cheat @@ -77342,6 +79485,15 @@ cartridge sha256:92c1fbf422abb8f09ca7fdbb563d1284108cc042e60e1222422986d9a59f9d9 cartridge sha256:4a091956a579de541aa2eef831e6d0c07d8324255cff7cc889c8ed9b70847769 name:Killer Instinct (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility - P1 + code:C90-D1A-E69+C3B-4CB-A21 + cheat + description:Hit anywhere - P1 + code:22B-01B-7F6+C3B-00B-A21 + cheat + description:Disable blocking - P2 + code:C35-18B-C41+C30-1CA-C41 cheat description:Infinite health code:FA7-B0B-4C1 @@ -77403,6 +79555,15 @@ cartridge sha256:4a091956a579de541aa2eef831e6d0c07d8324255cff7cc889c8ed9b7084776 description:Start with 3/4 energy code:B42-EAD-919 +cartridge sha256:0eac0600e7d9b243c5c648fc3d9f8b5d9962e3634d6ff0d6f1873281d31e8ff7 + name:King of Fighters '95, The (USA) (SGB Enhanced) + cheat + description:Hit anywhere - P1 + code:008-2DB-A26+007-78B-D52 + cheat + description:Blocking disabled - both players + code:9EC-57D-911 + cartridge sha256:0f6dba94fae248d419083001c42c02a78be6bd3dff679c895517559e72c98d58 name:Kirby's Dream Land (USA, Europe) cheat @@ -77526,6 +79687,30 @@ cartridge sha256:43bbc3111fe66b5d87940da810a1a0839ab7d48b50c327807538026241b4029 description:Start with 9 balls code:094-7CF-E66 +cartridge sha256:841bb9ea4b253145b2ed2225e6e81d396ddc4260a7ef6b42d54f0a7e25fef90d + name:Kizuchida Quiz da Gen-san da! (Japan) + cheat + description:Infinite time to answer + code:005-2DC-3BA + cheat + description:Always correct + code:537-51C-91F + +cartridge sha256:214710311150029f87ab0c8d67713ac446f3b75057cbebdc8960455acb1824eb + name:Knockout Kings (USA, Europe) + cheat + description:Invincibility + code:C37-94A-E61 + cheat + description:Hit anywhere + code:FA8-2EA-E61+FA8-0CA-E61+FA8-1AA-C41+FAF-6DB-C41+FA7-FFA-E61 + +cartridge sha256:7c7fb68ae4693ee68fa67e6ac0aef20554b697411d859c30da778290be7b9280 + name:Koushien Pocket (Japan) (SGB Enhanced) + cheat + description:Balls are considered strikes + code:006-579-A26 + cartridge sha256:cca2e1e06b50869a16b0b7bcef0095ff7d53af926419808da2b82fbab3762750 name:Krusty's Fun House (USA, Europe) cheat @@ -77559,12 +79744,27 @@ cartridge sha256:dff23b973c6c5e85da109dfb346ee396625fa7f934bc7c4b853ce4f237dfa42 description:Mostly invincible code:009-FFF-3BE+00A-42F-A28 cheat - description:Freeze timer (disable to complete level) + description:Infinite time (disable to complete level) code:00C-8EA-3BE + cheat + description:Hit anywhere + code:003-8DE-E62 cheat description:Touch weak enemies to defeat them code:009-E6F-F72 +cartridge sha256:e1340810c6dd12f55ab5928f08fbec92975f2303bda68e2a4b94cd8bc5ddec33 + name:Kwirk - He's A-maze-ing! (USA, Europe) + cheat + description:Walk through walls + code:181-D6E-4CA+1E1-D7E-5D7 + +cartridge sha256:4804741a60591a637103a54a6e3a5611bd775097c457fdf85775d74da93ab600 + name:Kyoro-chan Land (Japan) + cheat + description:Invincibility + code:3E9-EED-08A + cartridge sha256:dbcecd9ed9ee70e8f3a231eb0bda95c882ff0e9697d52fe919a02f076962de91 name:Lamborghini American Challenge (USA, Europe) cheat @@ -77598,6 +79798,33 @@ cartridge sha256:2451d61085652f25d36e35f1fa50dc7e6b51c6e20a50120decc33efcf1c9110 description:Level select (# = level 1-9 or A for ending credits) code:0#1-88F-E6E +cartridge sha256:26c7fd748c4f34b6c091870ebaa0d4798216df6389642493681deb644752508c + name:Lawnmower Man, The (Europe) + cheat + description:Invincibility - Sidescrolling levels + code:FA0-37B-F79+FA0-30B-F79 + cheat + description:Invincibility - Cyber Tube + code:C32-9EB-801 + cheat + description:Invincibility - Virtual World + code:18F-1FA-2AA+184-099-2AA + cheat + description:Infinite lives + code:FA6-FDB-4C1+FAA-6DA-4C1+003-15B-3BE+FAF-AFF-4C1+FA5-54B-4C1 + +cartridge sha256:96db9c11cff58dd637efbdc11416580d1a05bb6cc119d9efa0b17bfb0d0f80ad + name:Lazlos' Leap (USA) + cheat + description:Move one piece to clear level (move a piece over another) + code:07F-A0E-F72 + +cartridge sha256:7fcf3eec2ce487e804115b814b8ddc3f833bdae8d7e01df8975a1af029edefcd + name:Legend (Japan) + cheat + description:No random battles + code:C9E-EFC-A29 + cartridge sha256:21f712e213f43f9efb93ca039a5190fc09325d5d932af1fb2f8e90b4f9fd169f name:Legend of Zelda, The - Link's Awakening (USA, Europe) cheat @@ -77625,38 +79852,134 @@ cartridge sha256:21f712e213f43f9efb93ca039a5190fc09325d5d932af1fb2f8e90b4f9fd169 cartridge sha256:c95dd3d9cb798e86c28e3269554e458d434bf3277b96cadf5bc81cfacfb5ee60 name:Legend of Zelda, The - Link's Awakening DX (USA, Europe) (SGB Enhanced) cheat - description:Walk through walls. Be careful of entering doors from the wrong side. If you get stuck on the edge of a screen, try diagonal and straight movement in all directions to get yourself unstuck. Allows you to go through walls starting from locations in the water. Doesn't work for underground passages. + description:Invincibility + code:C9D-739-081 + cheat + description:Walk through walls. Be careful of entering doors from the wrong side. If you get stuck on the edge of a screen, try diagonal and straight movement in all directions to free yourself. Allows you to go through walls starting from locations in the water. Doesn't work for underground passages. code:AF4-5B8-3B0 +cartridge sha256:6285ba6201f17bc8595c600ebc2477d52561f0aff29b11f7fc3343bacb2e230b + name:Legend of Zelda, The - Link's Awakening DX (USA, Europe) (Rev A) (SGB Enhanced) + cheat + description:Invincibility + code:C9D-689-081 + cheat + description:Hit anywhere + code:FAE-8D9-A21+FAE-6D9-A21+90A-03A-A29+903-239-A29 + cheat + description:Shop items are free + code:18A-2C8-2AA + cheat + description:Revive infinite times + code:043-C99-B3F+183-C89-4CA + cheat + description:Cut down almost anything with your sword + code:006-33E-E69+FA6-16E-C41+186-21E-4CA + cheat + description:Horse pieces always land standing + code:006-918-F7A+006-908-E6E + cheat + description:Easier Wing Egg puzzle + code:0DA-908-F76+02A-8E8-190+79A-8C8-80E+FEA-8D8-08F + +cartridge sha256:5dee5816ed9b46cfc4a2d94f275e555dd3c5080eca00ded975a41a881a6d4c06 + name:Legend of Zelda, The - Link's Awakening DX (USA, Europe) (Rev B) (SGB Enhanced) + cheat + description:Invincibility + code:C9D-689-081 + cheat + description:Hit anywhere + code:FAE-8D9-A21+FAE-6D9-A21+90A-03A-A29+903-239-A29 + cheat + description:Shop items are free + code:18A-2C8-2AA + cheat + description:Revive infinite times + code:043-C99-B3F+183-C89-4CA + cheat + description:Cut down almost anything with your sword + code:006-33E-E69+FA6-16E-C41+186-21E-4CA + cheat + description:Horse pieces always land standing + code:006-918-F7A+006-908-E6E + cheat + description:Easier Wing Egg puzzle + code:0DA-908-F76+02A-8E8-190+79A-8C8-80E+FEA-8D8-08F + cartridge sha256:0b56b78a9e45452e98c33edd111234931f1e034dc097f6f23082eb8db6055474 name:Legend of Zelda, The - Oracle of Ages (USA) cheat - description:Defeat 1 enemy for fully grown Gashas/Maple meeting - code:002-46F-E69 + description:Invincibility + code:C97-DFB-087 cheat description:Infinite Seed/Bomb use on pick-up code:007-D3E-E6E cheat - description:Each Seed/Gasha/Bomb worth 99 - code:005-92B-E62 + description:Hit anywhere + code:FE4-E4B-190+FC3-3CA-19D+C32-B5B-801+00E-C79-5D4 cheat - description:Walk through walls. It's not hard to get stuck, so save where it's safe. - code:AFD-A5A-802 - -cartridge sha256:862a51368fb30539279d336b3fe193b43876d2cb15c87a36f5da517804ab3971 - name:Legend of Zelda, The - Oracle of Seasons (USA) + description:Get items from anywhere + code:002-14B-A29+00B-7BB-A29 + cheat + description:Moon-jump + code:183-28A-6EA+063-29A-4CA cheat description:Defeat 1 enemy for fully grown Gashas/Maple meeting code:002-46F-E69 + cheat + description:Each Seed/Gasha/Bomb worth 99 + code:005-92B-E62 + cheat + description:Cut down almost anything with your sword + code:018-E18-082+3A9-368-91A+007-51B-A29+007-62B-C49 + cheat + description:Walk through walls. It's not hard to get stuck, so save where it's safe. + code:AFD-A5A-802 + cheat + description:Always win shooting gallery mini-game + code:180-85A-6EA + cheat + description:Never miss in Goron Dance + code:189-088-4CA+1A9-098-91E + cheat + description:Mermaid Suite - hold down button instead of continuously pressing + code:299-10A-4C2 + +cartridge sha256:862a51368fb30539279d336b3fe193b43876d2cb15c87a36f5da517804ab3971 + name:Legend of Zelda, The - Oracle of Seasons (USA) + cheat + description:Invincibility + code:C97-C7B-087 cheat description:Infinite Seed/Bomb use on pick-up code:007-ACE-E6E + cheat + description:Hit anywhere + code:00A-32A-4C5+304-8EB-3BA+007-808-A29+FE4-CCB-190+C32-9DB-801+007-499-19E+00E-3F9-A29+C96-3FB-6E3 + cheat + description:Get items from anywhere + code:002-0DB-A29+002-21B-A29 + cheat + description:Moon-jump + code:181-5DA-6EA+061-5EA-2AE+001-82A-E62 + cheat + description:Defeat 1 enemy for fully grown Gashas/Maple meeting + code:002-46F-E69 cheat description:Each Seed/Gasha/Bomb worth 99 code:005-98B-E62 + cheat + description:Cut down almost anything with your sword + code:564-37B-19E+017-4C8-6ED+007-41B-C49+007-30B-A29 cheat description:Walk through walls. It's not hard to get stuck, so save where it's safe. code:AFC-96A-802 + cheat + description:Touch any button to enter desert with pirate ship + code:000-149-F76 + cheat + description:Lost woods - no need to change seasons to move on (Noble Sword direction - L, L, L, L. Level 6 direction - L, D, R, U.) + code:00E-0CA-E66 cartridge sha256:68e708010f14daa6013370d43b9ee00a2305b1a95285e7daafa6642a0677b8c2 name:Lethal Weapon (USA, Europe) @@ -77676,6 +79999,18 @@ cartridge sha256:68e708010f14daa6013370d43b9ee00a2305b1a95285e7daafa6642a0677b8c description:Start with life energy on 1/2 code:239-C3E-E6B +cartridge sha256:c24d7fdc7706cf0e01cbdb8c67ce4fb8079015e2b533a731a520844126073d77 + name:Little Magic (Japan) + cheat + description:Invincibility + code:EA4-CBB-081 + cheat + description:Stairs always open + code:FAB-4DA-E61 + cheat + description:Walk anywhere + code:007-21B-C4A+007-04B-C4A+007-5BB-C4A+007-3EB-C4A + cartridge sha256:f15722ebebdae93e08bd6642d642614114f2d128778d6a131748c9855603e052 name:Little Mermaid, The (USA) cheat @@ -77721,6 +80056,96 @@ cartridge sha256:f15722ebebdae93e08bd6642d642614114f2d128778d6a131748c9855603e05 description:See end of game credits code:068-07F-195 +cartridge sha256:0d6c56da2fdb6b27d388912604ad97c2f71729604a075d76c1fcd923f29e6915 + name:Lock'n Chase (World) + cheat + description:Invincibility + code:3E7-64E-4CA + cheat + description:Press A to clear level (except final level) + code:B65-5ED-5D0+3D5-60D-7F4 + +cartridge sha256:17b55c1a46af87f5dae066b0fdbe2b7cac05c29c3d86800e0717ed4c6325af3e + name:Looney Tunes (USA) + cheat + description:Infinite time + code:008-90F-19A + cheat + description:Hit anywhere + code:FA8-458-A21+FA8-0A8-A21+FA8-008-A21 + cheat + description:Multi-jump + code:004-80B-E66 + +cartridge sha256:a62f8d94d9eb0633c03d6a67100b354ffee92bee2fff26c0de8c35796a544a53 + name:Looney Tunes (USA, Europe) + cheat + description:Infinite time + code:008-90F-19A + cheat + description:Hit anywhere + code:FA8-458-A21+378-098-19C+377-FF8-198 + cheat + description:Multi-jump + code:FA4-81B-E61 + +cartridge sha256:53c29bbf5a96a600e4879374215c3bc840df0343bce7ef37a2b7f043b383cb1c + name:Looney Tunes - Carrot Crazy (USA) (En,Fr,Es) + cheat + description:Invincibility + code:F07-E0E-6E9 + cheat + description:Invincible from high falls + code:188-BBD-6EA + cheat + description:Hit anywhere + code:3E8-CC8-2AA+3E8-F68-6EA+3E9-0E8-08A+3E9-088-6EA + +cartridge sha256:59971b1b4a49e14b4870dd500682ece31f1654ce2f34a3799e5dcdeda5f5e73e + name:Looney Tunes Collector - Martian Revenge! (Europe) (En,Fr,De,Es,It,Nl) + cheat + description:Invincibility + code:C9E-EEC-E69 + cheat + description:Hit anywhere + code:9BA-B7F-D5A + cheat + description:Infinite ammo + code:00D-B3A-3B7 + cheat + description:Get items from anywhere + code:006-9EA-C49+00A-80A-C49 + cheat + description:Walk over space + code:C91-9BA-C49 + +cartridge sha256:ff9b75f13d25595ebf286d284f6bb951648f3d67f0fd043947d3c48132441c7f + name:Lucky Luke (USA) (En,Fr,De,Es) + cheat + description:Invincibility + code:F06-478-6E9+F02-C7C-6E9 + cheat + description:Infinite ammo + code:009-16E-3B7 + +cartridge sha256:4231fd9f25a5729208475d2d6aa6c2a6e53b1e918e7731a1eee3ce532993301b + name:Lufia - The Legend Returns (USA) + cheat + description:0 HP - Enemies + code:AF7-4B9-4C2+477-4C9-F73 + cheat + description:No random battles + code:AF0-34B-19A + cheat + description:Enemies always miss + code:C92-958-3BD + cheat + description:Walk anywhere + code:C35-E6A-C41+005-DDA-E6E + +cartridge sha256:2e102efe39e0825933f1fbf4b0b8cc2dbef42f3df809311a5c8a8c1d84899bf7 + name:M&M's Minis Madness (USA) + cartridge sha256:bf4cae27bd0dfdede3838d50f92d03cb7cd183a15091bd2a76c7b3fc7b3e718b name:Madden '95 (USA, Europe) (SGB Enhanced) cheat @@ -77766,9 +80191,30 @@ cartridge sha256:0d479d68a4ac800ab9fde8b3db016af718c13a979163b3eb34b00af96550cd3 cartridge sha256:2c45623446cf82896830712223079e9be5e79b3e5faf550c07f92f082bef419e name:Maru's Mission (USA) cheat - description:Infinite energy + description:Infinite health code:009-7CC-A2C+009-80C-808 +cartridge sha256:3fe6e53d0a44081f90a91004aa2ea4253a5a5933fff940c22e30e84029e4b2ef + name:Max (Europe) + cheat + description:Infinite Rockets + code:FA8-DDF-4C1 + cheat + description:Hit anywhere + code:185-1AA-08A+185-0DA-08A+184-B5A-08A+184-A8A-08A + +cartridge sha256:550995df4740397fccdc70d480c9a595260afb59bfcea0b0ec50cb5d55cfe9b0 + name:McDonaldland (Europe) + cheat + description:Invincibility + code:3E6-39D-4CA + cheat + description:Hit anywhere - Throwing and pickup up blocks + code:FAA-AAC-A21 + cheat + description:Multi-jump + code:3EF-A6C-4CA + cartridge sha256:33d16365318411f063edd9100c79458aabb7ea71bb1873e30f38b93814f0ec6e name:Mega Man - Dr. Wily's Revenge (USA) cheat @@ -77800,7 +80246,7 @@ cartridge sha256:be3fc7ab2d7eb79a9e2538b090bdecc2694740f3beda933f34cb1e4059b10a1 code:00A-14C-A28 cheat description:Multi-jump - code:012-45E-E6A+CD0-F0F-195+D40-F1F-195+0F0-F2F-195+C90-F3F-195+CD2-26E-081+F02-27E-5D7+002-28E-D55+182-2AE-4CA+002-44E-6EA + code:CD0-F0F-195+D40-F1F-195+0F0-F2F-195+C90-F3F-195+CD2-26E-081+F02-27E-5D7+002-28E-D55+182-2AE-4CA+002-44E-6EA+012-45E-E6A cartridge sha256:7344a36fcfc8151098238529218762e44c5a1546fab7e7fd5d32927e06cbf5a8 name:Mega Man III (USA) @@ -77910,6 +80356,48 @@ cartridge sha256:7a108770a7c1ad592b52d0c46d7ead422d0a20961abaafca3d40086e3f2f588 description:Start with about 3/4 energy code:709-44F-808 +cartridge sha256:638225d961484c8749ff8ceba1c865d267a5401b0d37a3a84cac7a6fb6bd8b9a + name:Mega Man Xtreme (USA, Europe) + cheat + description:Invincibility + code:18D-0ED-4CA + cheat + description:Infinite secondary weapons + code:008-449-3BE + cheat + description:Hit anywhere + code:0BD-62D-3B7+2FD-63D-5DE + cheat + description:Get items from anywhere + code:0BB-D48-3B7+2FB-D58-5DE + +cartridge sha256:e37a14a8e61bd64f2226dacc26a7ee75dd90abfcf88c5016eb97b76ecda0ddca + name:Mega Man Xtreme 2 (USA, Europe) + cheat + description:Invincibility + code:188-5ED-4CA + cheat + description:Infinite secondary weapons + code:006-A99-3B7 + cheat + description:Hit anywhere + code:2A8-B5D-4CA+9D8-B4D-C45 + cheat + description:get items from anywhere + code:005-F38-C4E + +cartridge sha256:bed7986ba7428470bf946a174810db1a49494f05a0985270a7c6d1ab6fe86f2b + name:Megalit (USA, Europe) + cheat + description:Infinite lives + code:FA2-6AF-4C1 + cheat + description:Infinite time - Quest mode + code:FAD-31D-4C1 + cheat + description:Blocks don't break + code:00F-7FD-3BA + cartridge sha256:56a69d19ba26941a25adad8bdf17c7baba12245097e901999f4c897eec877ddb name:Metal Gear Solid (USA) cheat @@ -77918,6 +80406,18 @@ cartridge sha256:56a69d19ba26941a25adad8bdf17c7baba12245097e901999f4c897eec877dd cheat description:Enemies don't see you code:C94-A88-3B4+C94-E89-081 + cheat + description:Cameras don't see you (normal game and VR training) + code:C93-698-C49 + +cartridge sha256:58130b462d7760624fa150938f5e3958f9185ef827644855acdef38ff6d55749 + name:Metal Walker (USA) + cheat + description:1 HP - enemies + code:3CE-2BB-08F+AFE-24B-08B + cheat + description:No random battles + code:C92-3EA-E69 cartridge sha256:3080bcc2eb9965de463f5f4e02f0dabbb13b060e1654a18da8b50948c10af4a6 name:Metroid II - Return of Samus (World) @@ -77937,6 +80437,21 @@ cartridge sha256:3080bcc2eb9965de463f5f4e02f0dabbb13b060e1654a18da8b50948c10af4a description:Multi-jump code:14D-46F-A26+98D-45F-91C+CDD-44F-E61+FA4-30E-4C1+FA4-61E-4C1 +cartridge sha256:7c96841877908473f7873c91373b06bfd3749b341b4c4180c8fd2cc8b8308b68 + name:Mickey Mouse (Europe) + cheat + description:Invincibility + code:182-5E9-6EA + cheat + description:Can open locked doors without 8 Keys + code:FA8-ABB-E61 + +cartridge sha256:bc14dac53de625535cc2825efa3d2399bf0c8c661f8a9417c4b97414a630cd0e + name:Mickey Mouse - Magic Wand (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility + code:3EE-92F-C49 + cartridge sha256:fedb0c8100987cb466c116a3ac3a6572675b6aa721a7a8930cec1ae39f677bc6 name:Mickey's Dangerous Chase (USA) cheat @@ -77952,6 +80467,33 @@ cartridge sha256:fedb0c8100987cb466c116a3ac3a6572675b6aa721a7a8930cec1ae39f677bc description:Start with 99 lives code:634-B6F-E66 +cartridge sha256:573798e5dfa80c13f2c7f77795fa3460c0c41ffbc49ab3b830fb4bf30c89f179 + name:Mighty Morphin Power Rangers (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility + code:C9C-B9D-6E9+C9D-1ED-6EE+C9C-9FD-2A9 + cheat + description:Hit anywhere + code:3EE-1ED-2AA+18E-2AD-08A + cheat + description:One hit kills - bosses + code:18E-4AD-4CA + cheat + description:Multi-jump + code:006-C9D-08A+3E5-35D-6EA + +cartridge sha256:67f16ea0f0afdb20fa75cc988466c0726203412a57a36e0f866eb341ede5d311 + name:Mighty Morphin Power Rangers - The Movie (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility + code:C9C-7BB-A29 + cheat + description:Hit anywhere + code:000-41B-E66 + cheat + description:Can always use power + code:008-6DB-E69 + cartridge sha256:70124937963d44c034d73e3e3c7ecf9c3440cdb934cd1a8b6fd4629381343d02 name:Milon's Secret Castle (USA, Europe) cheat @@ -77976,14 +80518,26 @@ cartridge sha256:70124937963d44c034d73e3e3c7ecf9c3440cdb934cd1a8b6fd4629381343d0 description:Start with 9 energy bars code:096-EA8-F7E +cartridge sha256:b136c40a4ca52d6567e7f71790690b1e71ddad3b9df8d1ee98135ac46a2e7637 + name:Minesweeper - Soukaitei (Japan) + cheat + description:Never miss + code:180-6BC-4CA+181-40C-4CA + cartridge sha256:d74962fe1750b3918c6b5e34dd30851df50e33eaeb27659097d52090c9803705 - name:Miner 2049er (USA) + name:Miner 2049er Starring Bounty Bob (USA) + cheat + description:Invincibility + code:C32-39A-A21+C32-DDA-A21+FAC-A4B-4C1 cheat description:Infinite time code:002-239-E6E cheat description:Infinite lives code:002-3DB-E6E + cheat + description:Take 1 step to complete level + code:FAF-26C-A21 cheat description:Nasties are invincible code:039-CAF-E6A @@ -78005,6 +80559,9 @@ cartridge sha256:f6d779c4882e032919903b4874dec1b6f06716911f77eb9f8acd1727215eb79 cheat description:Invincible bases code:FF6-BBD-191 + cheat + description:Hit anywhere + code:C3F-4DE-801+37F-A8E-5D4 cheat description:New York code:02F-28E-E6A @@ -78024,6 +80581,45 @@ cartridge sha256:f6d779c4882e032919903b4874dec1b6f06716911f77eb9f8acd1727215eb79 description:San Francisco code:18F-28E-E6A +cartridge sha256:0b3e5a9611551cc135cebfa67fe3f9aa1a54ef9855c0888b715351035908e126 + name:Missile Command (USA) + cheat + description:Hit anywhere + code:C3F-4DE-801+37F-A8E-5D4 + cheat + description:Infinite Missiles + code:FA2-4CE-4C1+FA2-9BE-4C1 + +cartridge sha256:3b0aaea526447c2d682139c9494eec82045b36e5e684cc56132391ba9a2ef689 + name:Momotarou Dengeki (Japan) + cheat + description:Hit anywhere + code:FA1-84A-E61+FA1-D8A-E61+FA1-B1A-E61+FA1-57A-E61 + cheat + description:Multi-jump + code:291-12D-6E6+FA0-A1D-E61 + +cartridge sha256:f1bf118bd383a91ecf81f7ee759ce702b85cfee9f8cf11d8365cb243d555c607 + name:Momotarou Dengeki 2 (Japan) (SGB Enhanced) + cheat + description:Hit anywhere + code:183-33A-08A+183-82A-08A+183-41A-08A+183-8FA-08A + cheat + description:Multi-jump + code:FA1-13B-E61+1D1-9EB-4C6 + +cartridge sha256:003097c7a363da268fa2853262c1924ee72fe23fc546834b247c359f69a684aa + name:Montezuma's Return! (USA) (En,Es) + cheat + description:Invincibility against enemies + code:C95-80A-E69+189-0DB-2AA + cheat + description:Invincibility against fire + code:189-E0B-4CA + cheat + description:Invincibility against high falls + code:18A-2FB-4CA + cartridge sha256:84686cd3c77c533926fc2c56783613ecc5781de1bff7065e00112a69d17a5e69 name:Mortal Kombat (USA, Europe) cheat @@ -78180,8 +80776,20 @@ cartridge sha256:29d69e0f71b692f348a0954cc3aaa86dcd9a32d8a7268ce6b76ba26b0c0e462 cartridge sha256:6c2733c0a57bbfe5075bec42e0735c685c934780db45b33f899f62dfea549f69 name:Mortal Kombat 3 (USA) cheat - description:Invincibility expect for throws and projectiles + description:Invincibility except for throws and projectiles code:00A-25E-081+00A-26E-7F5+7DA-27E-E69+14A-29E-D56+C8A-2AE-E69+C9D-57E-C49 + cheat + description:Hit anywhere - P1 + code:00D-30E-F7A + +cartridge sha256:cd999acce90fb40bb1231fda253fa8a0db9e26517ed4723353429aedf4ddf5db + name:Mortal Kombat 4 (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility - normal attacks + code:C9C-E0E-C49 + cheat + description:Hit anywhere - normal attacks + code:00C-CBE-D56 cartridge sha256:abc725f10251ae954a23c46b7e33b101bc52203fed4ffad49018858d82361964 name:Motocross Maniacs (USA) @@ -78222,11 +80830,23 @@ cartridge sha256:e493b87e119d61268af2f97c9e16e65daab3c8223c15261214656667108cc81 description:Start with 8 lives code:083-38F-E62 +cartridge sha256:6e4876c4e6516d8f3325a7341bea05a275d91de178af080e174d697a4e3d5921 + name:Mr. Chin's Gourmet Paradise (USA) + cheat + description:Can eat momos without zapping them + code:FAC-51E-C41+FAD-4DE-C41+FAC-F9E-C41+FAC-A5E-C41 + cartridge sha256:c19f7ec9ff29fa438d7ef189f81711dcaedaa55c86b192d6d9020f5f7dc22702 name:Mr. Do! (USA) + cheat + description:Invincibility + code:18C-39E-2AA cheat description:Infinite lives code:FA7-28C-4C1 + cheat + description:Only 1 Cherry needed to complete level + code:AFE-35C-19E cheat description:Keep 1 map layout thru game (still will progress from map to map, but layout stays the same) code:3E8-2CE-191+098-2DE-C42+188-2EE-6EA @@ -78243,6 +80863,42 @@ cartridge sha256:c19f7ec9ff29fa438d7ef189f81711dcaedaa55c86b192d6d9020f5f7dc2270 description:Start with 9 lives code:095-B2E-E66 +cartridge sha256:ccf89ab34bbea5c54cf8da205bd5db9364c1e81136a8ffd009fa0f822d0373a8 + name:Mr. Driller (USA) + cheat + description:Invincibility + code:185-04D-4CA + cheat + description:Infinite air + code:FA6-4ED-4C1 + cheat + description:Break brown blocks faster + code:3EE-038-6EA+C97-3ED-F7D + cheat + description:Dig faster (hold A) + code:1A4-89D-806 + +cartridge sha256:46c4a36696d1594ffa3441db352d80c8e4927794373d9d2712dcd425664936fe + name:Mr Nutz (Europe) (En,Fr,De,Es,It,Nl) + cheat + description:Invincibility + code:3EC-EEB-C45 + cheat + description:Hit anywhere - Nuts + code:44E-01B-E6E+18E-00B-2AA + cheat + description:Hit anywhere - Tail + code:61D-3BB-A24+18D-3AB-E61 + cheat + description:One hit kills - Bosses + code:189-63B-08A + cheat + description:Always have Nuts + code:11E-E5E-F72+18E-E4E-4CA + cheat + description:Moon jump + code:00F-54E-6EA+3EF-4CE-6EA + cartridge sha256:21db857936d7eff3d57d576f0a01a52e012d0dcf5dc8f2a6cdb0e92a131a72b6 name:Ms. Pac-Man (USA) cheat @@ -78252,8 +80908,29 @@ cartridge sha256:21db857936d7eff3d57d576f0a01a52e012d0dcf5dc8f2a6cdb0e92a131a72b description:Get fruit from anywhere code:00B-21E-D56 +cartridge sha256:8e556307f484b3451429f695391820e896202b1046312473911abb72222acee3 + name:Ms. Pac-Man - Special Color Edition (USA) (SGB Enhanced) + cheat + description:Ms. Pac-Man - Invincibility + code:182-1EA-2AA + cheat + description:Ms. Pac-Man - Infinite lives + code:FA7-D19-4C1 + cheat + description:Ms. Pac-Man - Get fruits from anywhere + code:3E6-CDC-2AA + cheat + description:Super Pac - Invincibility + code:C39-C09-C41 + cheat + description:Super Pac - Infinite lives + code:FAA-239-4C1 + cartridge sha256:ba1afcea3239c1acc9af228cebe6872f5547ad04480e71652e2e56dcd4e2f08e name:Mysterium (USA) + cheat + description:Invincibility + code:C97-F8C-E69 cheat description:Infinite lives code:FA3-98C-4C1 @@ -78273,6 +80950,21 @@ cartridge sha256:ba1afcea3239c1acc9af228cebe6872f5547ad04480e71652e2e56dcd4e2f08 description:Start with 9 lives code:09D-008-E66 +cartridge sha256:220915c980318a194273d11d7a22836734ae6365ea2d8658956c3be374fc89f0 + name:Mystical Ninja Starring Goemon (USA) (SGB Enhanced) + cheat + description:Invincibility + code:C91-CFB-E69 + cheat + description:Hit anywhere - main weapon + code:DA2-2BB-197+002-19B-C49 + cheat + description:Hit anywhere - ninja stars + code:3C2-55B-C49+002-41B-C49 + cheat + description:Walk over water and pits + code:185-E9B-6EA + cartridge sha256:424ca9fc4d842444a01c4dbf7375558035f4cb04a7d7056a4c1a1a18b769643d name:Nail'n Scale (USA, Europe) cheat @@ -78285,6 +80977,12 @@ cartridge sha256:424ca9fc4d842444a01c4dbf7375558035f4cb04a7d7056a4c1a1a18b769643 description:Start with 9 lives code:084-B5F-F7A +cartridge sha256:24797d8f8f74f56fd619f346db92b1829b2262c979a0dca58875ae86d93abe66 + name:NBA Jam (USA, Europe) + cheat + description:Dunk and layup from anywhere + code:C36-42C-801+006-23C-6E2+FA4-66B-D5D+006-1BC-C49 + cartridge sha256:e807eef2018cb12c73a5395a47936ce0b24b1e8876c10e3dff6b2d30873e52f3 name:Nemesis (Europe) cheat @@ -78315,6 +81013,15 @@ cartridge sha256:58c4da647070388c9e77ddf1a0fce6777c63ff96efcd804d0917f555c3e0236 description:Get items from anywhere code:007-55D-A29 +cartridge sha256:9ee539f631e964cb0fbf3564de53f8261b55ad61ca4b022ee423bfc8367f5002 + name:Nettou Garou Densetsu 2 (Japan) (SGB Enhanced) + cheat + description:Invincibility - P1 + code:180-54B-4CA+180-B5B-4CA + cheat + description:Hit anywhere (except projectiles) + code:000-A5B-F7E + cartridge sha256:e8b4326469231ba798657cfa8032bc6c2000c0a61e11fbad8406711642a184eb name:NFL Football (USA) cheat @@ -78339,6 +81046,60 @@ cartridge sha256:f513d07ace08618cb2d8a39471b617982f23e0b4f7814a62809b9969ff41635 description:Hit anywhere (can get items from anywhere by punching) code:00E-279-C43 +cartridge sha256:efc3b14064153fd16b690034c078188d7d1f424ad210b585aaa4e7b0f7f171ee + name:Ninja Gaiden Shadow (USA) + cheat + description:Invincibility + code:C96-9C9-E69 + cheat + description:Invincibility (alt) + code:C92-C1D-081 + cheat + description:Infinite health + code:003-1DD-19E + cheat + description:Infinite lives + code:003-1CE-19E + cheat + description:Hit anywhere + code:007-30D-806+CD7-1DD-919 + cheat + description:One hit kills - bosses + code:010011C4 + cheat + description:Start each new life with 5 firewheel markers + code:05B-01F-E6E+05B-29F-E6E + cheat + description:Start at stage 1 boss (Spider) + code:02A-E6F-E6A + cheat + description:Start at beginning of stage 2 + code:04A-E6F-E6A + cheat + description:Start at stage 2 boss (Jack & Gregory) + code:07A-E6F-E6A + cheat + description:Start at beginning of stage 3 + code:08A-E6F-E6A + cheat + description:Start at stage 3 boss (Colonel Allen) + code:0BA-E6F-E6A + cheat + description:Start at beginning of stage 4 + code:0CA-E6F-E6A + cheat + description:Start at stage 4 boss (Evil Nobleman Who-kisai) + code:0FA-E6F-E6A + cheat + description:Start at beginning of stage 5 + code:10A-E6F-E6A + +cartridge sha256:58ce4e32820b1313d86c96555abcc53220c9c221ae785338b0ebcf360eb5aaa7 + name:Ninja Taro (USA) + cheat + description:Infinite health + code:010997FF + cartridge sha256:ea284fad45e612ab2fcd721152ab815fe8e58062155ab6e182195f637d7b6da4 name:Nintendo World Cup (USA, Europe) cheat @@ -78450,6 +81211,18 @@ cartridge sha256:d07986785d76db33e96ccbbe840ac962542f1c359e5b896e6478afd5cf9586b description:Get fruit from anywhere code:009-22E-E69+009-28E-E69 +cartridge sha256:dcbbc8f8128940a35c9b09624a9987a80cecb2edc8db8e48605de30b4887a3a9 + name:Pac-Man - Special Color Edition (USA) (SGB Enhanced) + cheat + description:Invincibility + code:C96-27A-A29 + cheat + description:Infinite lives + code:00C-89B-3BE + cheat + description:Get fruits from anywhere + code:007-D2A-E69+007-CCA-E69 + cartridge sha256:8b81c75dd11e24ba5e1d2f439a6fabf7313024829df397409a20dd37995122cb name:Pagemaster, The (USA) (SGB Enhanced) cheat @@ -78504,6 +81277,12 @@ cartridge sha256:8b81c75dd11e24ba5e1d2f439a6fabf7313024829df397409a20dd37995122c description:Start with 11,111,111 points code:3C1-CDF-5D4 +cartridge sha256:b36e2bb2642a385ce67c059e8fb2a1cc4f63ccff56c023a3f211d81ebd4a8a77 + name:Paperboy (USA, Europe) + cheat + description:Invincibility (except for training courses) + code:C91-8C9-D5D+C92-DC9-B3D + cartridge sha256:5c357df199e755eae719588a3424d49bc5212289922f11968e47954276941d6a name:Paperboy 2 (USA, Europe) cheat @@ -78549,6 +81328,30 @@ cartridge sha256:3bcf1b2fe43907d96e58b9aca893a9124bfb3c35774926279f9368a97566508 description:Start with 11 lives code:0BA-93D-E66 +cartridge sha256:b5c0c1e3bc4ee2f1ca3cba1bed9483707f4ab72b87e517ca80f1bbb612fd86cd + name:Penguin Land (Japan) + cheat + description:Infinite time + code:FA0-0AD-4C1 + +cartridge sha256:d84a2382b358d83a0891d40b2de65494f060d8be1a048d5aa8721282218b04b6 + name:Pinball - Revenge of the 'Gator (USA, Europe) + cheat + description:Infinite supply of balls + code:007-E1F-3BE + cheat + description:Disable left flipper + code:21F-24D-D5D + cheat + description:Disable right flipper + code:C9F-2AD-7F1 + cheat + description:Start with 1 ball + code:016-EDF-E66 + cheat + description:Start with 9 balls + code:096-EDF-E66 + cartridge sha256:ec2420a8d1b129379435e9a217ef8e6be7fcece10a17d72affa8b1b2449888cb name:Pinball Dreams (USA, Europe) cheat @@ -78576,6 +81379,18 @@ cartridge sha256:ec2420a8d1b129379435e9a217ef8e6be7fcece10a17d72affa8b1b2449888c description:Start with 9 balls code:098-1BF-E66 +cartridge sha256:11347375400080c6e2bfac1ae908d571b91bd4a5406b823c912eb9df1bd3d014 + name:Pitfall - Beyond the Jungle (USA, Europe) + cheat + description:Invincibility + code:C91-9D8-E69 + cheat + description:Hit anywhere + code:FA7-339-E61+FA7-AB9-E61+FA7-649-E61+FA7-ED9-E61 + cheat + description:Walk on air + code:C9F-6EE-192 + cartridge sha256:027a8bb2843c3f96373ca60830f58fbc2fcf15d51756649e002b87a97f438a41 name:Play Action Football (USA) cheat @@ -78594,6 +81409,102 @@ cartridge sha256:027a8bb2843c3f96373ca60830f58fbc2fcf15d51756649e002b87a97f438a4 description:Only need 5 yards for 1st down code:053-419-C42 +cartridge sha256:d6702e353dcbe2d2c69183046c878ef13a0dae4006e8cdff521cca83dd1582fe + name:Pokemon - Crystal Version (USA, Europe) + cheat + description:One hit kills + code:3ED-49A-2AA + cheat + description:Opponent doesn't attack + code:C96-DEB-D5D + cheat + description:No random battles + code:180-EA9-2AA + cheat + description:Skip trainer battles + code:008-2C9-806 + +cartridge sha256:fdcc3c8c43813cf8731fc037d2a6d191bac75439c34b24ba1c27526e6acdc8a2 + name:Pokemon - Crystal Version (USA, Europe) (Rev A) + cheat + description:One hit kills + code:3ED-49A-2AA + cheat + description:Opponent doesn't attack + code:C96-DEB-D5D + cheat + description:No random battles + code:180-EA9-2AA + cheat + description:Skip trainer battles + code:008-2C9-806 + +cartridge sha256:fb0016d27b1e5374e1ec9fcad60e6628d8646103b5313ca683417f52b97e7e4e + name:Pokemon - Gold Version (USA, Europe) (SGB Enhanced) + cheat + description:One hit kills + code:00E-86A-D52 + cheat + description:Opponent doesn't attack + code:C96-86B-D5D + cheat + description:No random battles + code:186-469-2AA + cheat + description:Skip trainer battles + code:007-6B9-806 + +cartridge sha256:72b190859a59623cbef6c49d601f8de52c1d2331b4f08a8d2acc17274fc19a8c + name:Pokemon - Silver Version (USA, Europe) (SGB Enhanced) + cheat + description:One hit kills + code:3EE-85A-2AA + cheat + description:Opponent doesn't attack + code:C96-86B-D5D + cheat + description:No random battles + code:186-469-2AA + cheat + description:Skip trainer battles (the only way to fight them is to talk to them) + code:007-6B9-806 + +cartridge sha256:a54515bb6b3e364964d3c0226f5a6b0c8c0f7318c9296ef2e321df0bbb8541ce + name:Pokemon Trading Card Game (USA) (SGB Enhanced) + cheat + description:Always your turn + code:C97-BE9-6E9 + cheat + description:Attack without energy cards + code:187-4FB-2AA + +cartridge sha256:952660d14941a2ab77810c3fe36658c8e8dd490e2c4e744fb3d41ce2eb31e703 + name:Pocket Bomberman (USA, Europe) (SGB Enhanced) + cheat + description:Invincibility + code:005-8AB-E6E+00C-54D-F7E + cheat + description:Bomb hits anywhere when placed on the ground + code:000-C2B-F76 + +cartridge sha256:2f74f1a512d862372e0bccf09260ffb91a676cdb2391fd91f2f6bc8487d75974 + name:Pong - The Next Level (USA, Europe) + cheat + description:Right side player cannot hit ball + code:288-FCB-6EA+DF8-FDB-6EA+038-FBB-E62 + +cartridge sha256:cfff247d91c3c448d3588a5c5fc3ee4c19b0031e45679022bdbdadae6d545802 + name:Pop'n TwinBee (Europe) + cheat + description:Invincibility + code:18A-52C-2AA+C3E-8DC-A21 + cheat + description:Hit anywhere - normal enemies + code:3E2-DDC-2AA+3E2-CEC-2AA + cheat + description:Hit anywhere - bosses + code:3E0-D09-2AA+3E0-C39-2AA + cartridge sha256:4a1c9750f77deffb8e003b8938d2ffe5f520fb43143aedd309909b8a9907856d name:Popeye 2 (USA) cheat @@ -78630,6 +81541,24 @@ cartridge sha256:4a1c9750f77deffb8e003b8938d2ffe5f520fb43143aedd309909b8a9907856 description:Start with 9 continues code:093-F7A-F7E +cartridge sha256:584f8fcfde1ae9f262747be425df0ed4d1a7421d24b8d62af05b075875b1cb35 + name:Project S-11 (USA) + cheat + description:Invincibility + code:C36-BBB-E61 + cheat + description:Hit anywhere - normal enemies + code:3E5-B0B-2AA+3E5-A4B-08A+3E5-B5B-08A+3E5-9FB-2AA + cheat + description:Hit anywhere - bosses + code:3E6-5DB-08A+3E6-6EB-08A+3E6-69B-2AA+3E6-58B-2AA + cheat + description:One hit kills - normal enemies + code:185-E2B-08A + cheat + description:One hit kills - bosses + code:3E6-87B-2AA + cartridge sha256:e1b69e85caebf764bfa6cece5c1d33b67b370cf055480f309644b937e4a7ebdb name:Prophecy - The Viking Child (USA) cheat @@ -78657,6 +81586,18 @@ cartridge sha256:e1b69e85caebf764bfa6cece5c1d33b67b370cf055480f309644b937e4a7ebd description:Start with 10 lives code:094-A0F-E6E +cartridge sha256:459ccbbab8580bd93a2a0d5d66ca4ae42c8f664f3106687ffc31c7aef7dd677b + name:Puzzle Boy II (Japan) + cheat + description:Walk anywhere + code:3EF-67F-6EA + +cartridge sha256:cfc6560d1385808cfd5c242a9f3aa38892c6ab2cb242d0767115144c633708b6 + name:Puzzled (USA) + cheat + description:Clear level automatically + code:C32-4AB-C41+FA2-96B-E61 + cartridge sha256:567aef8ea27486a4fa38ef4a4ae6ebae2a9138dc8a6a675d155895936e1318d8 name:Pyramids of Ra (USA) cheat @@ -78675,11 +81616,44 @@ cartridge sha256:567aef8ea27486a4fa38ef4a4ae6ebae2a9138dc8a6a675d155895936e1318d description:Start on level 500 code:F41-ABF-E6E+011-ACF-E6A +cartridge sha256:4e624ad741077f574c1d0b57cbc45171ed4ca9f23fa89dfd8f282897aa53ab9a + name:Q Billion (USA) + cheat + description:Pressing Select in Game B once gives you 246 seconds + code:00B-9FE-C42 + cheat + description:Infinite timer + code:007-55E-19E + cheat + description:Level select - Game A + code:3EB-61F-08A+0DB-62F-B3E+00B-63F-08F + +cartridge sha256:878a21de57986965bf2c68774119180d21dbd5111eef4a9a70ffd0f9f6bdbf7b + name:Q-bert (USA) + cheat + description:Invincibility + code:FAE-61C-801 + cheat + description:Step on one cube to clear level + code:C38-2CB-C41 + cartridge sha256:ed110933b5a41ed89d2b980e6e984733833fa6b2c15e5235eff1f5df54175df4 - name:Qix (World) + name:QIX (World) cheat description:Invincibility code:AFE-DBC-3B4 + cheat + description:Create any shape to clear level + code:000-9AB-F7A + +cartridge sha256:0ccfd1166f7e6158c8d4189e5dc9a11724fce01f375f2a78f54ed4a41d7beb0c + name:QIX Adventure (Europe) + cheat + description:Invincibility + code:FA9-BDB-4C1+C33-8D8-E61 + cheat + description:Create any shape to clear level + code:3E5-33A-6EA+3E5-38A-08A cartridge sha256:7d8e122f6f70f6ca49521f2c24fd987e91f621977da2912702285735438be901 name:Quarth (USA, Europe) @@ -78699,17 +81673,23 @@ cartridge sha256:7d8e122f6f70f6ca49521f2c24fd987e91f621977da2912702285735438be90 description:Blocks drop super fast code:3E6-2BE-081+806-2CE-2AB+006-2DE-F79 -cartridge sha256:4e624ad741077f574c1d0b57cbc45171ed4ca9f23fa89dfd8f282897aa53ab9a - name:Q Billion (USA) +cartridge sha256:3f6cdd669637c8a3aaaf02c9ae833e820a3e7f9e882e5cbb246bda5aa616ff87 + name:Quest - Fantasy Challenge (USA) (SGB Enhanced) cheat - description:Pressing Select in Game B once gives you 246 seconds - code:00B-9FE-C42 + description:Invincibility + code:C32-7D9-A21+C9E-92A-192 cheat - description:Infinite timer - code:007-55E-19E + description:Hit anywhere + code:183-BAA-4CA+183-A7A-2AA+183-9AA-2AA + +cartridge sha256:6242b49e85e9652c278ceae22fd5c888495222b4ba78c0a82bb925f2acf66ac1 + name:Quest RPG - Brian's Journey (USA) cheat - description:Level select - Game A - code:3EB-61F-08A+0DB-62F-B3E+00B-63F-08F + description:Invincibility + code:FA6-F6B-D5D+C96-16B-E69 + cheat + description:One hit kills + code:C31-8FA-801+C31-9CA-801 cartridge sha256:b3f2838cb64dfa12f93ab4767c3b0786cba0993015fefe1f592146f9d8f47d40 name:Radar Mission (USA, Europe) @@ -78756,6 +81736,24 @@ cartridge sha256:9e30f9c36cfa1bc1fd6f111fa38a43f3c5907c26d81a65309279eec54a3d05d description:Start with 3/4 time code:75A-9AA-89C +cartridge sha256:1a8bfa0e55e89241a9843e440e8e2a93dae906c654378e8b27df27e360de826c + name:Rampage - World Tour (USA, Europe) + cheat + description:Invincibility + code:00A-068-E6E + cheat + description:Knock down buildings with one punch + code:3EA-BCA-2AA+3EA-BAA-4CA + +cartridge sha256:ff3915dab21e648cc8f30b28702db6d6784c8e01792d9a5c17a50a9f5994e48c + name:Rampage 2 - Universal Tour (USA, Europe) + cheat + description:Invincibility + code:187-8AB-08A+00C-7D8-E6E+00C-288-E6E + cheat + description:Knock down buildings with one punch + code:3E1-279-2AA + cartridge sha256:ad5d681fa599b6cf9dae135c304317ac41f33bee0a5a583d7fa2a178ca66506f name:Rampart (USA, Europe) cheat @@ -78830,6 +81828,9 @@ cartridge sha256:46cfbba977f7d4cb8df51d5cb51f00dc0a4d9c129868a1ed88f2b0fa9745490 cartridge sha256:9a97678cbd8da02c8763e977674e17f460c06ea8b73bad35c52fe6817f506d44 name:Resident Evil Gaiden (USA) + cheat + description:Invincibility + code:00B-18B-F7A+00B-12B-7F2 cheat description:Infinite ammo on pick-up code:004-26B-E65 @@ -78839,27 +81840,30 @@ cartridge sha256:9a97678cbd8da02c8763e977674e17f460c06ea8b73bad35c52fe6817f506d4 cheat description:All Herbs cure poison code:004-908-C49 + cheat + description:Rapid fire + code:005-6BB-E62+CB1-D0B-D59 -cartridge sha256:d84a2382b358d83a0891d40b2de65494f060d8be1a048d5aa8721282218b04b6 - name:Pinball - Revenge of the 'Gator (USA, Europe) +cartridge sha256:ebe140f2c6dcd4e99192d5676b4cfe443a071daa9ff243a23a26ae98a53fead8 + name:Return of the Ninja (USA) cheat - description:Infinite supply of balls - code:007-E1F-3BE + description:Invincibility + code:C98-4DD-3BD cheat - description:Disable left flipper - code:21F-24D-D5D + description:Hit anywhere + code:FA8-A1B-A21+FA8-91B-A21 cheat - description:Disable right flipper - code:C9F-2AD-7F1 + description:Hit anywhere on bosses + code:3EC-29E-2AA+3EC-19E-2AA cheat - description:Start with 1 ball - code:016-EDF-E66 + description:Cannot be detected by enemies + code:187-EDB-2AA cheat - description:Start with 9 balls - code:096-EDF-E66 + description:Can always use special attack + code:04D-4FE-19A cartridge sha256:c6d02170734d6b533d4599b6fca10ac83141e5ffe4902c4a98001aa61c00dffc - name:RoboCop 2 (USA) + name:RoboCop 2 (USA, Europe) cheat description:Infinite health on scrolling levels code:C95-9CE-C49 @@ -78917,6 +81921,9 @@ cartridge sha256:9fb0e41e4c8afe737a688dbdc1b6f7019874f7e9ef4c0a27cba2b8be329ce45 cartridge sha256:92e8d1acd4d2d3297a961409d4bb0ed49c784be4a6e91cfceabd05ab11894f3d name:Roger Clemens' MVP Baseball (USA) + cheat + description:Balls are counted as strikes + code:00F-E2B-A28+001-13A-A29+001-10A-809 cheat description:No walks code:014-68A-F7D @@ -78984,11 +81991,17 @@ cartridge sha256:2b059983d79efc5a4f77b41a4efbad68c65ae259715dc008f20a3c11226a943 cartridge sha256:e0a07f84198e062c9ba8d617ef15679ba044f96510e5c62309ea1f743499a2c9 name:Samurai Shodown (USA, Europe) (SGB Enhanced) cheat - description:Computer takes all damage - even when you get hit + description:Computer takes all damage, even when you get hit code:3EB-60D-7F1 cheat description:Infinite time code:FA2-46D-4C1 + cheat + description:Hit anywhere - both players + code:186-C3E-6EA + cheat + description:Blocking disabled - both players + code:FA0-45B-E61 cheat description:Start timer at 30 seconds code:3EF-80E-D57+1EF-81E-08F @@ -79103,6 +82116,9 @@ cartridge sha256:52924262f2c60fc1c387a92bfdb43835c84968daf4ba465e7cc6627774e7b8a cheat description:Infinite missiles on pick-up code:00F-B0E-E69 + cheat + description:Win immediately + code:C33-B9F-E61+FA5-0DF-A21 cheat description:Start with 5 missiles code:057-C9D-E6A @@ -79224,8 +82240,29 @@ cartridge sha256:534478ebd2558ab6a871540062fadbb0ea27808d7f6860942b2e6805fd15e87 description:Start with 15 lives code:0E0-7D9-CCE +cartridge sha256:28b2b87a43285afb3e55a96136f71c6a858b0bbe25caaa59f4ef3a6e6d5f64e8 + name:Smurfs, The (Europe) (En,Fr,De,Es) + cheat + description:Invincibility + code:186-B1A-6EA + cheat + description:Multi-jump (don't jump off screen) + code:180-679-6EA+0A0-689-7F2+8B0-5E9-C40 + +cartridge sha256:5d9c9ce079923b92034c7c2d172b5abfad9ec37332102cb247ea849393db9a99 + name:Smurfs, The (USA, Europe) (En,Fr,De) (Rev A) (SGB Enhanced) + cheat + description:Invincibility + code:187-C3A-6EA + cheat + description:Multi-jump (don't jump off screen) + code:0A1-469-7F2+181-459-6EA+8B1-3C9-C40 + cartridge sha256:a1e0c6d8385ab8c39569217f28cb335ccac8c85d31e01c9a2343c79494164478 name:Snoopy - Magic Show (USA, Europe) + cheat + description:Invincibility + code:183-D6B-6EA cheat description:Start on level 2 code:3E7-3FD-4C1+027-40D-087+007-41D-E65 @@ -79287,6 +82324,42 @@ cartridge sha256:fece5b09e599c1f8116602fcabd558cc8dbbfe1c6c253853c5e871b0d732c11 description:Start on stage 6 code:065-0AF-E6E +cartridge sha256:b876faa05d3fa8c9e6d2812a7e17cbc8be83463e1d1536f13e9719ba0e7108b5 + name:Solomon's Club (USA) + cheat + description:Invincibility + code:187-2AF-6EA + cheat + description:Hit anywhere - fireball + code:146-63F-08A+186-62F-2AA + cheat + description:Always have fireball + code:082-2AB-911+182-29B-6EA + cheat + description:Items are free + code:09F-70E-081+18F-6FE-801 + +cartridge sha256:3d6fd2f730d66266215b06c7d40ebd060aca9a48f8117d25a4411fa5d644ff57 + name:Solitaire FunPak (USA, Europe) + cheat + description:Klondike - Move cards to any stack + code:18C-D2B-6EA+18B-B3B-6EA+34B-B4B-C4E+FAC-F2B-D5D+00C-F1B-91E + cheat + description:Freecell - Move cards to any stack + code:6DB-35B-2AB+C3B-34B-C41+009-FEB-7FE + +cartridge sha256:b9b4ee32ab8b74ffd90d7606715893f4b6bd2a3b97c14b2ac2fc6683cfbe1986 + name:Soukoban (Japan) + cheat + description:Walk through walls + code:FA7-1AF-C41 + +cartridge sha256:ed0ab3bfcbc6ac96cc1c8eebb9cdabf0c52e1a562d115eefe47b2078746bc691 + name:Soukoban 2 (Japan) + cheat + description:Walk through walls + code:FA8-27F-E61+FF8-03F-E6E + cartridge sha256:6ffe31b21d429801b8e5a460e58bd857e41aef888d19297fc558cf25def0d10d name:Spanky's Quest (USA) cheat @@ -79374,6 +82447,15 @@ cartridge sha256:5bfae99484fe74c42b55a0dd8835861cfeb7d05590882aab8f4253e4e7138b9 description:Start with 3/4 time code:07E-F6C-C4E +cartridge sha256:290f9d2ebd3221142873aa9650dc3276b577f1cfaf4ea2bc407f66a1ae110139 + name:Speedy Gonzales - Aztec Adventure (USA, Europe) + cheat + description:Invincibility + code:C96-CDF-E69 + cheat + description:Walk on air + code:3EE-CFE-4CA + cartridge sha256:89c4151a31f00dc0f20133ee5ec8f71f3023331de93e017e97d66dc497eb2aa9 name:Spider-Man 2 (USA, Europe) cheat @@ -79785,6 +82867,12 @@ cartridge sha256:a62719fa767547a11ac20e0ad5d1fd43b68f92908a5c81dd3aba95f921458c5 description:Start with all force abilities in inventory - still need to get force power to activate code:011-D7F-E6A+001-CFF-5D4 +cartridge sha256:5393db89f3763c973438d8a6abd4ff83c404fe6cd58a8041adf2cd6d85535835 + name:Street Fighter Alpha - Warriors' Dreams (USA) + cheat + description:Hit anywhere - both players + code:00F-269-C49+007-E19-C49 + cartridge sha256:8730c69cb2aa82260ac07257e0e29d61f598de2f8fa3e65da1d694790fa5db16 name:Street Fighter II (USA, Europe) (Rev A) (SGB Enhanced) cheat @@ -79986,6 +83074,24 @@ cartridge sha256:79da9658fdd3b92910f0a63ba6c7a45fb680b0e0ebe03ad1ed982d3dc92edae description:Start with very little fuel code:15E-72D-195 +cartridge sha256:fbd32fe43df00f5821f290e0b2010b9944e46fd687eabf34cf78451e4a62be68 + name:Super Bombliss (Japan) (SGB Enhanced) + cheat + description:Drop one piece to clear level + code:3EB-69B-6EA+01A-A2B-E6A + +cartridge sha256:f607ad68fdfd8cbaabe554fea2075050a7055f0fafef9a0fd2825a67b2fd038a + name:Super Breakout (USA) + cheat + description:Paddle hits ball from anywhere (ball goes down the screen at times) + code:3C7-36F-B3D+C37-35F-801 + +cartridge sha256:be805b8c607bbf1fdaade6345f244da20ba6ca8ac587402445b8f272a0d708d7 + name:Super Breakout! (USA) + cheat + description:Paddle hits ball from anywhere (ball goes down the screen at times) + code:3C7-36F-B3D+C37-35F-801 + cartridge sha256:dab87fd694aa1358278b4850371ff1303dea2295b7b7cc14842c969014a73fb1 name:Super Chase H.Q. (USA, Europe) cheat @@ -80031,6 +83137,39 @@ cartridge sha256:1a3841dfc6ccf87167d7b1f0ce17f3bbf9fd64445611e249f5902e8824e1748 description:Infinite lives code:475-5AA-C4D +cartridge sha256:af5a78f29f7e5e70bfe4d0122bdb99d5d0e38a3e8912ff49c2630c7d6be7db67 + name:Super Mario Bros. Deluxe (USA, Europe) + cheat + description:Invincibility - Star effect + code:01FFDAC1+01FFDBC1 + cheat + description:Fireballs hit anywhere + code:180-BBB-4CA+180-CBB-4CA+FA3-01D-801+FA3-0FD-801 + cheat + description:Fireballs go through all enemies and obstacles + code:180-BBB-4CA+180-CBB-4CA + +cartridge sha256:db81dd4acbd0c7a3b9004f169ee278450c764c842ae777abd28073fbedf4078b + name:Super Mario Bros. Deluxe (USA, Europe) (Rev A) + cheat + description:Invincibility - Star effect + code:01FFDAC1+01FFDBC1 + cheat + description:Fireballs hit anywhere + code:180-BBB-4CA+180-CBB-4CA+FA3-01D-801+FA3-0FD-801 + cheat + description:Fireballs go through all enemies and obstacles + code:180-BBB-4CA+180-CBB-4CA + +cartridge sha256:c06af1a1c2a804e4169fd9bfd6eee7073545d88c97febc96c345dd10efd77547 + name:Super Mario Bros. Deluxe (USA, Europe) (Rev B) + cheat + description:Invincibility - Star effect + code:01FFDAC1+01FFDBC1 + cheat + description:Fireballs go through all enemies and obstacles + code:180-BBB-4CA+180-CBB-4CA + cartridge sha256:49fbd2f61f953d5ef28cab73e357e524c3009ad19fcf30f6a9ee0ae273be41dc name:Super Mario Land (World) (Rev A) cheat @@ -80167,7 +83306,7 @@ cartridge sha256:5450dce1bd0c073964c374b5b5b5729dce8d00f2e807892c34af32b8bce1392 code:002-CBC-E69 cartridge sha256:91bd1f24827bde4dbb58ead76a8b4e5a507431ec9b6bbc7ef9473b852538a4d5 - name:Super Off Road (USA) + name:Super Off Road (USA, Europe) cheat description:Infinite money code:FAD-A2B-4C1 @@ -80324,6 +83463,9 @@ cartridge sha256:1f3c9ff627b0445e57a7425bc433c0476a0eeafe25ea5c6522b102d1ef8f875 cartridge sha256:f4ef2ca5506f493f48833c16dff5eaa2b18ba488c352ed5bc03059d150e46620 name:Teenage Mutant Ninja Turtles - Fall of the Foot Clan (USA) + cheat + description:Infinite health + code:010981C9 cheat description:Hit anywhere code:B8D-E2C-6EC+B8E-26C-6EC+3ED-DFC-D52+3EE-23C-D52 @@ -80394,8 +83536,17 @@ cartridge sha256:5fa11359e8147b295bebd1e5631c7b96908c649d9d33fdc45a2dd3de8d69ca7 description:Start with 1/2 energy code:70E-59D-6E9 +cartridge sha256:7fde11dd4e594a6905deccd57943d2909ecb37665a030741c42155aeb346323b + name:Tetris (Japan) (En) + cheat + description:Drop a piece on the far left side of the board to clear the section + code:001-B9D-3B5 + cartridge sha256:0d6535aef23969c7e5af2b077acaddb4a445b3d0df7bf34c8acef07b51b015c3 name:Tetris (World) (Rev A) + cheat + description:Drop a piece on the far left side of the board to clear the section + code:001-5ED-3B5 cheat description:Keep stack displayed while paused code:CEC-30E-C45 @@ -80426,6 +83577,9 @@ cartridge sha256:0d6535aef23969c7e5af2b077acaddb4a445b3d0df7bf34c8acef07b51b015c cartridge sha256:d349dc93423c6abcd775d3b6a8797df715a44a42ec837afb21bf17ae43b40a9e name:Tetris DX (World) (SGB Enhanced) + cheat + description:Drop pieces on the left side of the board to clear lines + code:00A-8BA-3B5 cheat description:Score increases a lot code:1F3-C9A-F70 @@ -80441,6 +83595,9 @@ cartridge sha256:d349dc93423c6abcd775d3b6a8797df715a44a42ec837afb21bf17ae43b40a9 cartridge sha256:771d24adf7dd11ff166fc43d3f2be66dd7a24251b8920e813956c62514813051 name:Tetris 2 (USA) + cheat + description:Drop one piece to clear level + code:00D-F6A-F72 cheat description:No next piece screen code:C98-E9A-081 @@ -80460,6 +83617,24 @@ cartridge sha256:771d24adf7dd11ff166fc43d3f2be66dd7a24251b8920e813956c6251481305 description:In versus mode, no blocks added to top of screen code:FA8-CB8-4C1 +cartridge sha256:2c3bc48a4ec9b6c640b83ce6524570f472db329d4a96d0b527b34abd42b7d695 + name:Tetris 2 (USA, Europe) (SGB Enhanced) + cheat + description:Drop one piece to clear level + code:00F-67A-F72 + +cartridge sha256:b8765e752153310f835e10d6ceaee80b0e0913cdadf832b9516af8bf974e9666 + name:Tetris Attack (USA) (SGB Enhanced) + cheat + description:Rows clear automatically (except in Puzzle Mode) + code:007-34B-80D + +cartridge sha256:252e9981ba15054b5b8e2eeab22ccbae7ac3cbe9d7cd7a895c75fb35054717f9 + name:Tetris Attack (USA, Europe) (Rev A) (SGB Enhanced) + cheat + description:Rows clear automatically (except in Puzzle Mode) + code:007-32B-80D + cartridge sha256:379f9034b2702f06247e1dd4a6e21d51a76aff84d12ff851e4e962b105094d10 name:Tiny Toon Adventures 2 - Montana's Movie Madness (USA, Europe) cheat @@ -80604,8 +83779,17 @@ cartridge sha256:4d078174031509ca7b63c237e176e9f5c0aed88b42352ad23aee98a777d3a0d description:Start on level 1, part 2 code:003-BAF-5D4 +cartridge sha256:17e1629cd8a95ef8d09643d62f7336efa7c0983f03ceda5038632d2125885fa6 + name:Toki Tori (USA, Europe) (En,Ja,Fr,De,Es) + cheat + description:Get eggs from anywhere + code:330-CEB-7F6+180-CDB-08A + cartridge sha256:597f70c8d600427fee6f3a3714115bad30b24402dd830c36dc010a7b3a92a7a3 name:Tom & Jerry (USA, Europe) + cheat + description:Invincibility + code:EA5-5CB-081+3E5-5AB-6EA cheat description:Infinite lives code:008-54D-B3D @@ -80618,6 +83802,9 @@ cartridge sha256:597f70c8d600427fee6f3a3714115bad30b24402dd830c36dc010a7b3a92a7a cheat description:Infinite time code:FAC-3FE-4C1+FAC-43E-4C1 + cheat + description:Moon jump + code:3E0-DAB-4CA cheat description:Every time you collect one cheese you get 11 (can't go over 100) code:110-67B-E6E @@ -80664,6 +83851,33 @@ cartridge sha256:bcd52c83f3662165baaeff2527fd221c04b734214d5dacb8cdda6fbcb95fbc3 description:Start with 15 minutes on the timer - ignore counter code:0F0-DEC-F7E +cartridge sha256:ebcba74ab890e56676a4c1720f89719a489b73c7c688d1fd0c6a98074dc7afeb + name:Tomb Raider (USA, Europe) (En,Fr,De,Es,It) + cheat + description:Invincibility against enemies + code:3E0-F3B-4CA+770-F5B-3BE + cheat + description:Hit anywhere + code:009-27A-7FF + +cartridge sha256:a75109b2730df5bef628f05660d670f07a1be6c6249d73f7f88375061c3f3bbb + name:Tomb Raider - Curse of the Sword (USA, Europe) + cheat + description:Invincibility + code:771-BCB-3BE+3E1-BAB-4CA + cheat + description:Hit anywhere (only when standing and not against a wall) + code:00D-E8A-4C7 + cheat + description:One hit kills + code:FE6-15A-3B7+CB6-14A-A28 + +cartridge sha256:1878a9fa68e052362b0fbb13421db1ae822ffd74b69db34217455f9e43ce61dd + name:Top Gear Pocket (USA) + cheat + description:No slowdown (except for drifting) + code:C9F-7CE-6EE+C3E-F2E-801 + cartridge sha256:bb2f56c5035b47183c55b197bc380ea02df00dd733ce732d062f7c7695bd330f name:Top Gun - Guts & Glory (USA, Europe) cheat @@ -80736,6 +83950,12 @@ cartridge sha256:eae3b192006eff607dffdae3d7720af579f85335be81e6cacb55276bfc32424 description:Max angle on triple jump code:454-D1A-E68 +cartridge sha256:9047447e6ff5b0b510732befa3f48a464aebfa9ba06274b3cf6120b25e8dd033 + name:Triple Play 2001 (USA, Europe) + cheat + description:Balls are considered strikes + code:003-F28-2A2 + cartridge sha256:3990c42543e74387c30ac935eb45067e291b4a5e93702d5520acd0e91d14f34f name:Tumble Pop (USA, Europe) cheat @@ -80784,6 +84004,54 @@ cartridge sha256:954ed263a5133c608636af442c4c0ade7f9b7dfdc768e7bfbf31d2528a8d779 description:Start with more Aim-9 missiles code:7C2-8BE-08F +cartridge sha256:0ca41e5faef09acc0f440ddb57624fb66cfb5f945145b7acc9390dd6ab07803c + name:Turok - Battle of the Bionosaurs (USA, Europe) (En,Fr,De,Es) + cheat + description:Invincibility + code:C9A-9C9-E69 + cheat + description:Hit anywhere + code:3A4-949-A2E+184-939-4CA + cheat + description:Multi-jump + code:3DF-16A-7F4+8BF-15A-C45 + +cartridge sha256:0e82076895f9aa7f8b787d5c76a33d72394f611bd0ac93ecd550873b7ce21b60 + name:Turok - Rage Wars (USA, Europe) (En,Fr,De,Es) + cheat + description:Invincibility + code:C9B-78F-081 + cheat + description:Infinite ammo + code:000-9FA-3B7 + cheat + description:Hit anywhere + code:181-98B-6EA+221-99B-5D + +cartridge sha256:21f2b0f417dd94f8aaa75adf09b849c97780ab9140b1d7d53ed4516f33233037 + name:Turok 2 - Seeds of Evil (USA, Europe) (En,Fr,De,Es) + cheat + description:Invincibility + code:3E9-34B-4CA+C9D-8EB-A29 + cheat + description:Hit anywhere (you have to be in line with them on the streets) + code:3A5-0C8-A2E+185-0B8-4CA + cheat + description:Multi-jump + code:8BB-C5B-C45+3DB-C6B-7F4 + +cartridge sha256:1710b81824ea2044e7c475c3a8befe52fb8ba92f5dfc8866d7362c1e11393859 + name:Turok 3 - Shadow of Oblivion (USA, Europe) (En,Fr,De,Es) + cheat + description:Invincibility + code:183-F9B-6EA + cheat + description:Infinite ammo + code:00E-FDB-3B7 + cheat + description:Hit anywhere + code:6C4-A8B-195+504-52B-80F+184-51B-2AA + cartridge sha256:9008df8d950b4e6966b38218e43bc3baf9bad91ef44b271b558aee6f38c993d7 name:Ultima - Runes of Virtue (USA) cheat @@ -80865,6 +84133,54 @@ cartridge sha256:850a429b64b7ebcb8034da2c25789dff631d64682b1ce65f8de346c9744ae31 description:Start with 9 power lines code:096-ACE-E66 +cartridge sha256:102dabffa56271534c651579445c13a375e7978f37bdcccc3271e9320c3710fa + name:Uno (USA) + cheat + description:Place any card on the stack regardless of color + code:FA8-91A-C41 + +cartridge sha256:56b00fb68b829dabe56e88f3074316ee2f3022a15c6f45bd70bda5e8f62c2e8f + name:Uno - Small World (Japan) + cheat + description:Can place any color card on the stack + code:188-9FA-2AA + +cartridge sha256:88773be9e71529b35ce03d39f417e866f48df97cdfb894943f729dab7beefb90 + name:Uno 2 - Small World (Japan) (SGB Enhanced) + cheat + description:Place any card on the stack + code:187-01A-2AA+187-B7A-2AA + +cartridge sha256:19e8ccfe0df0647cbd6517a456fcffa39c3a9ecc1e40dd31bd193423b4779020 + name:Velious - Roland no Majuu (Japan) + cheat + description:Invincibility + code:00B-B6C-195 + cheat + description:Hit anywhere + code:B7D-5AC-5D4 + cheat + description:Walk through walls + code:183-8BF-4CA + +cartridge sha256:2b3ed695acb2fcd3aa8159b12373a55b01a72ae3a9e0867ef8446fd8abddec51 + name:Velious II - Fukushuu no Jashin (Japan) + cheat + description:Invincibility + code:AFE-3CC-3B4 + cheat + description:Infinite TP + code:F0E-01F-6E9 + cheat + description:Hit anywhere - main weapon + code:00F-A7C-A29+00F-98C-809+00F-A2C-809+00F-9DC-A29 + cheat + description:Hit anywhere - sub-weapon + code:00F-70C-A29+00F-6BC-809+00F-66C-A29+00F-61C-809 + cheat + description:Walk through walls + code:183-1DF-4CA + cartridge sha256:1af2d4b29552fb2cf141955e1d77f8dd99e856b1f04fbff5240d5a1c3c2c41bf name:Wario Blast featuring Bomberman! (USA, Europe) (SGB Enhanced) cheat @@ -81003,6 +84319,21 @@ cartridge sha256:a3bd35fb1d2466868b5308a45e8ad3844925bd5dfa819b27ff67d0391b8e351 description:Faster timer code:023-3ED-E6E +cartridge sha256:e424a9893faed6a486d66002ed606cf32d68dab71971ec461103396042800b63 + name:Wendy - Every Witch Way (USA, Europe) + cheat + description:Infinite time + code:00F-AB8-6E2 + cheat + description:Hit anywhere + code:AFA-FA9-6EA+C9A-FB9-917 + +cartridge sha256:b915f6ffe0dd3ab9fe8972468013334a0c6d3f664982bc8ed8888e54d5bbbebf + name:Who Wants to Be a Millionaire - 2nd Edition (USA) + cheat + description:Always correct + code:188-FFE-4CA + cartridge sha256:db8029c84c99c1bff1724656d0887636497986fac02892f4d4334c60f646c84f name:Wild Snake (USA) (SGB Enhanced) cheat @@ -81117,6 +84448,57 @@ cartridge sha256:0ba3d3b9be8c615bd29956887584aff9446a88fb2606bfb8ccc75907164c4cf description:No out of ring timer code:00C-0FD-E6E +cartridge sha256:770a3c6cd89d34af0d452eb4f52cd5a2f9d2651b9b54b247de349ff701f59a52 + name:WWF Raw (USA, Europe) + cheat + description:Infinite health - P1 + code:015410CF + cheat + description:No health - P2 + code:01004FCF + +cartridge sha256:e5971b4a0c14a8dc06386844975ea76a65a9f81539e43bbe90a6bed198990b15 + name:WWF WrestleMania 2000 (USA, Europe) + cheat + description:Infinite health - P1 + code:0164B8C0 + cheat + description:Infinite health - P2 + code:0184F9C0 + cheat + description:No health - P1 + code:0100B8C0 + cheat + description:No health - P2 + code:0100F9C0 + cheat + description:Always fight in cage + code:010294C6 + cheat + description:Always fight in ring + code:010194C6 + +cartridge sha256:85c5368af171f9c47e02157222f140ad44ee9f9307f31838ffe9430793d80c65 + name:X-Men - Mutant Academy (USA, Europe) + cheat + description:Hit anywhere - both players + code:184-65A-4CA+124-66A-E6E+C92-E6A-A29 + +cartridge sha256:e8b42d935ea865f0b00f2a5447c8695799116e33dea30eaec5159ce7df225348 + name:X-Men - Mutant Wars (USA, Europe) + cheat + description:Invincibility + code:186-99E-2AA + cheat + description:Hit anywhere + code:005-FAE-3BE + cheat + description:One hit kills + code:182-258-4CA + cheat + description:One hit kills - bosses + code:180-A4B-08A + cartridge sha256:3843f2cdb0746ff0cf7dc97e1aab4fc6a15219e7ac8e1970ead475a835c57aea name:Xenon 2 - Megablast (USA, Europe) cheat @@ -81153,6 +84535,15 @@ cartridge sha256:3843f2cdb0746ff0cf7dc97e1aab4fc6a15219e7ac8e1970ead475a835c57ae description:Start with 10 lives code:0A1-75C-F7E +cartridge sha256:79847fc3769d81c17f95f7d4797b25129c5bf416e9da2a16ab2d09d71e9b9bbe + name:Yogi Bear - Great Balloon Blast (USA) + cheat + description:Power-up after almost every shot + code:007-CB8-4CA + cheat + description:Power-up after almost every shot (alt) + code:092826C9 + cartridge sha256:98fb28e23fa2bdb969317544bf0fd5c24fb377134cac12897b29889bc67f6ca6 name:Yogi Bear in Yogi Bear's Goldrush (USA) cheat diff --git a/higan/data/higan.Manifest b/data/higan.Manifest old mode 100755 new mode 100644 similarity index 100% rename from higan/data/higan.Manifest rename to data/higan.Manifest diff --git a/higan/data/higan.desktop b/data/higan.desktop old mode 100755 new mode 100644 similarity index 100% rename from higan/data/higan.desktop rename to data/higan.desktop diff --git a/higan/data/higan.ico b/data/higan.ico old mode 100755 new mode 100644 similarity index 100% rename from higan/data/higan.ico rename to data/higan.ico diff --git a/higan/data/higan.png b/data/higan.png old mode 100755 new mode 100644 similarity index 100% rename from higan/data/higan.png rename to data/higan.png diff --git a/higan/data/higan512.png b/data/higan512.png similarity index 100% rename from higan/data/higan512.png rename to data/higan512.png diff --git a/higan/emulator/emulator.hpp b/emulator/emulator.hpp old mode 100755 new mode 100644 similarity index 98% rename from higan/emulator/emulator.hpp rename to emulator/emulator.hpp index ac1a8bd7..5b1a8aae --- a/higan/emulator/emulator.hpp +++ b/emulator/emulator.hpp @@ -3,7 +3,7 @@ namespace Emulator { static const char Name[] = "higan"; - static const char Version[] = "092.10"; + static const char Version[] = "093"; static const char Author[] = "byuu"; static const char License[] = "GPLv3"; static const char Website[] = "http://byuu.org/"; diff --git a/higan/emulator/interface.hpp b/emulator/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/emulator/interface.hpp rename to emulator/interface.hpp diff --git a/higan/fc/Makefile b/fc/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/Makefile rename to fc/Makefile diff --git a/higan/fc/apu/apu.cpp b/fc/apu/apu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/apu.cpp rename to fc/apu/apu.cpp diff --git a/higan/fc/apu/apu.hpp b/fc/apu/apu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/apu.hpp rename to fc/apu/apu.hpp diff --git a/higan/fc/apu/dmc.cpp b/fc/apu/dmc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/dmc.cpp rename to fc/apu/dmc.cpp diff --git a/higan/fc/apu/dmc.hpp b/fc/apu/dmc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/dmc.hpp rename to fc/apu/dmc.hpp diff --git a/higan/fc/apu/envelope.cpp b/fc/apu/envelope.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/envelope.cpp rename to fc/apu/envelope.cpp diff --git a/higan/fc/apu/envelope.hpp b/fc/apu/envelope.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/envelope.hpp rename to fc/apu/envelope.hpp diff --git a/higan/fc/apu/noise.cpp b/fc/apu/noise.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/noise.cpp rename to fc/apu/noise.cpp diff --git a/higan/fc/apu/noise.hpp b/fc/apu/noise.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/noise.hpp rename to fc/apu/noise.hpp diff --git a/higan/fc/apu/pulse.cpp b/fc/apu/pulse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/pulse.cpp rename to fc/apu/pulse.cpp diff --git a/higan/fc/apu/pulse.hpp b/fc/apu/pulse.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/pulse.hpp rename to fc/apu/pulse.hpp diff --git a/higan/fc/apu/serialization.cpp b/fc/apu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/serialization.cpp rename to fc/apu/serialization.cpp diff --git a/higan/fc/apu/sweep.cpp b/fc/apu/sweep.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/sweep.cpp rename to fc/apu/sweep.cpp diff --git a/higan/fc/apu/sweep.hpp b/fc/apu/sweep.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/sweep.hpp rename to fc/apu/sweep.hpp diff --git a/higan/fc/apu/triangle.cpp b/fc/apu/triangle.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/triangle.cpp rename to fc/apu/triangle.cpp diff --git a/higan/fc/apu/triangle.hpp b/fc/apu/triangle.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/apu/triangle.hpp rename to fc/apu/triangle.hpp diff --git a/higan/fc/cartridge/board/bandai-fcg.cpp b/fc/cartridge/board/bandai-fcg.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/bandai-fcg.cpp rename to fc/cartridge/board/bandai-fcg.cpp diff --git a/higan/fc/cartridge/board/board.cpp b/fc/cartridge/board/board.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/board.cpp rename to fc/cartridge/board/board.cpp diff --git a/higan/fc/cartridge/board/board.hpp b/fc/cartridge/board/board.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/board.hpp rename to fc/cartridge/board/board.hpp diff --git a/higan/fc/cartridge/board/konami-vrc1.cpp b/fc/cartridge/board/konami-vrc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc1.cpp rename to fc/cartridge/board/konami-vrc1.cpp diff --git a/higan/fc/cartridge/board/konami-vrc2.cpp b/fc/cartridge/board/konami-vrc2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc2.cpp rename to fc/cartridge/board/konami-vrc2.cpp diff --git a/higan/fc/cartridge/board/konami-vrc3.cpp b/fc/cartridge/board/konami-vrc3.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc3.cpp rename to fc/cartridge/board/konami-vrc3.cpp diff --git a/higan/fc/cartridge/board/konami-vrc4.cpp b/fc/cartridge/board/konami-vrc4.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc4.cpp rename to fc/cartridge/board/konami-vrc4.cpp diff --git a/higan/fc/cartridge/board/konami-vrc6.cpp b/fc/cartridge/board/konami-vrc6.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc6.cpp rename to fc/cartridge/board/konami-vrc6.cpp diff --git a/higan/fc/cartridge/board/konami-vrc7.cpp b/fc/cartridge/board/konami-vrc7.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/konami-vrc7.cpp rename to fc/cartridge/board/konami-vrc7.cpp diff --git a/higan/fc/cartridge/board/nes-axrom.cpp b/fc/cartridge/board/nes-axrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-axrom.cpp rename to fc/cartridge/board/nes-axrom.cpp diff --git a/higan/fc/cartridge/board/nes-bnrom.cpp b/fc/cartridge/board/nes-bnrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-bnrom.cpp rename to fc/cartridge/board/nes-bnrom.cpp diff --git a/higan/fc/cartridge/board/nes-cnrom.cpp b/fc/cartridge/board/nes-cnrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-cnrom.cpp rename to fc/cartridge/board/nes-cnrom.cpp diff --git a/higan/fc/cartridge/board/nes-exrom.cpp b/fc/cartridge/board/nes-exrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-exrom.cpp rename to fc/cartridge/board/nes-exrom.cpp diff --git a/higan/fc/cartridge/board/nes-fxrom.cpp b/fc/cartridge/board/nes-fxrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-fxrom.cpp rename to fc/cartridge/board/nes-fxrom.cpp diff --git a/higan/fc/cartridge/board/nes-gxrom.cpp b/fc/cartridge/board/nes-gxrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-gxrom.cpp rename to fc/cartridge/board/nes-gxrom.cpp diff --git a/higan/fc/cartridge/board/nes-hkrom.cpp b/fc/cartridge/board/nes-hkrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-hkrom.cpp rename to fc/cartridge/board/nes-hkrom.cpp diff --git a/higan/fc/cartridge/board/nes-nrom.cpp b/fc/cartridge/board/nes-nrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-nrom.cpp rename to fc/cartridge/board/nes-nrom.cpp diff --git a/higan/fc/cartridge/board/nes-pxrom.cpp b/fc/cartridge/board/nes-pxrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-pxrom.cpp rename to fc/cartridge/board/nes-pxrom.cpp diff --git a/higan/fc/cartridge/board/nes-sxrom.cpp b/fc/cartridge/board/nes-sxrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-sxrom.cpp rename to fc/cartridge/board/nes-sxrom.cpp diff --git a/higan/fc/cartridge/board/nes-txrom.cpp b/fc/cartridge/board/nes-txrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-txrom.cpp rename to fc/cartridge/board/nes-txrom.cpp diff --git a/higan/fc/cartridge/board/nes-uxrom.cpp b/fc/cartridge/board/nes-uxrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/nes-uxrom.cpp rename to fc/cartridge/board/nes-uxrom.cpp diff --git a/higan/fc/cartridge/board/sunsoft-5b.cpp b/fc/cartridge/board/sunsoft-5b.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/board/sunsoft-5b.cpp rename to fc/cartridge/board/sunsoft-5b.cpp diff --git a/higan/fc/cartridge/cartridge.cpp b/fc/cartridge/cartridge.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/cartridge.cpp rename to fc/cartridge/cartridge.cpp diff --git a/higan/fc/cartridge/cartridge.hpp b/fc/cartridge/cartridge.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/cartridge.hpp rename to fc/cartridge/cartridge.hpp diff --git a/higan/fc/cartridge/chip/chip.cpp b/fc/cartridge/chip/chip.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/chip.cpp rename to fc/cartridge/chip/chip.cpp diff --git a/higan/fc/cartridge/chip/chip.hpp b/fc/cartridge/chip/chip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/chip.hpp rename to fc/cartridge/chip/chip.hpp diff --git a/higan/fc/cartridge/chip/mmc1.cpp b/fc/cartridge/chip/mmc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/mmc1.cpp rename to fc/cartridge/chip/mmc1.cpp diff --git a/higan/fc/cartridge/chip/mmc3.cpp b/fc/cartridge/chip/mmc3.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/mmc3.cpp rename to fc/cartridge/chip/mmc3.cpp diff --git a/higan/fc/cartridge/chip/mmc5.cpp b/fc/cartridge/chip/mmc5.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/mmc5.cpp rename to fc/cartridge/chip/mmc5.cpp diff --git a/higan/fc/cartridge/chip/mmc6.cpp b/fc/cartridge/chip/mmc6.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/mmc6.cpp rename to fc/cartridge/chip/mmc6.cpp diff --git a/higan/fc/cartridge/chip/vrc1.cpp b/fc/cartridge/chip/vrc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc1.cpp rename to fc/cartridge/chip/vrc1.cpp diff --git a/higan/fc/cartridge/chip/vrc2.cpp b/fc/cartridge/chip/vrc2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc2.cpp rename to fc/cartridge/chip/vrc2.cpp diff --git a/higan/fc/cartridge/chip/vrc3.cpp b/fc/cartridge/chip/vrc3.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc3.cpp rename to fc/cartridge/chip/vrc3.cpp diff --git a/higan/fc/cartridge/chip/vrc4.cpp b/fc/cartridge/chip/vrc4.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc4.cpp rename to fc/cartridge/chip/vrc4.cpp diff --git a/higan/fc/cartridge/chip/vrc6.cpp b/fc/cartridge/chip/vrc6.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc6.cpp rename to fc/cartridge/chip/vrc6.cpp diff --git a/higan/fc/cartridge/chip/vrc7.cpp b/fc/cartridge/chip/vrc7.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cartridge/chip/vrc7.cpp rename to fc/cartridge/chip/vrc7.cpp diff --git a/higan/fc/cheat/cheat.cpp b/fc/cheat/cheat.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cheat/cheat.cpp rename to fc/cheat/cheat.cpp diff --git a/higan/fc/cheat/cheat.hpp b/fc/cheat/cheat.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cheat/cheat.hpp rename to fc/cheat/cheat.hpp diff --git a/higan/fc/cpu/cpu.cpp b/fc/cpu/cpu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cpu/cpu.cpp rename to fc/cpu/cpu.cpp diff --git a/higan/fc/cpu/cpu.hpp b/fc/cpu/cpu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cpu/cpu.hpp rename to fc/cpu/cpu.hpp diff --git a/higan/fc/cpu/serialization.cpp b/fc/cpu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cpu/serialization.cpp rename to fc/cpu/serialization.cpp diff --git a/higan/fc/cpu/timing.cpp b/fc/cpu/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/cpu/timing.cpp rename to fc/cpu/timing.cpp diff --git a/higan/fc/fc.hpp b/fc/fc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/fc.hpp rename to fc/fc.hpp diff --git a/higan/fc/input/input.cpp b/fc/input/input.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/input/input.cpp rename to fc/input/input.cpp diff --git a/higan/fc/input/input.hpp b/fc/input/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/input/input.hpp rename to fc/input/input.hpp diff --git a/higan/fc/input/serialization.cpp b/fc/input/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/input/serialization.cpp rename to fc/input/serialization.cpp diff --git a/higan/fc/interface/interface.cpp b/fc/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/interface/interface.cpp rename to fc/interface/interface.cpp diff --git a/higan/fc/interface/interface.hpp b/fc/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/interface/interface.hpp rename to fc/interface/interface.hpp diff --git a/higan/fc/memory/memory.cpp b/fc/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/memory/memory.cpp rename to fc/memory/memory.cpp diff --git a/higan/fc/memory/memory.hpp b/fc/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/memory/memory.hpp rename to fc/memory/memory.hpp diff --git a/higan/fc/ppu/ppu.cpp b/fc/ppu/ppu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/ppu/ppu.cpp rename to fc/ppu/ppu.cpp diff --git a/higan/fc/ppu/ppu.hpp b/fc/ppu/ppu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/ppu/ppu.hpp rename to fc/ppu/ppu.hpp diff --git a/higan/fc/ppu/serialization.cpp b/fc/ppu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/ppu/serialization.cpp rename to fc/ppu/serialization.cpp diff --git a/higan/fc/scheduler/scheduler.cpp b/fc/scheduler/scheduler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/scheduler/scheduler.cpp rename to fc/scheduler/scheduler.cpp diff --git a/higan/fc/scheduler/scheduler.hpp b/fc/scheduler/scheduler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/scheduler/scheduler.hpp rename to fc/scheduler/scheduler.hpp diff --git a/higan/fc/system/serialization.cpp b/fc/system/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/system/serialization.cpp rename to fc/system/serialization.cpp diff --git a/higan/fc/system/system.cpp b/fc/system/system.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/system/system.cpp rename to fc/system/system.cpp diff --git a/higan/fc/system/system.hpp b/fc/system/system.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/system/system.hpp rename to fc/system/system.hpp diff --git a/higan/fc/video/video.cpp b/fc/video/video.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/video/video.cpp rename to fc/video/video.cpp diff --git a/higan/fc/video/video.hpp b/fc/video/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/fc/video/video.hpp rename to fc/video/video.hpp diff --git a/higan/gb/Makefile b/gb/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/Makefile rename to gb/Makefile diff --git a/higan/gb/apu/apu.cpp b/gb/apu/apu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/apu.cpp rename to gb/apu/apu.cpp diff --git a/higan/gb/apu/apu.hpp b/gb/apu/apu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/apu.hpp rename to gb/apu/apu.hpp diff --git a/higan/gb/apu/master/master.cpp b/gb/apu/master/master.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/master/master.cpp rename to gb/apu/master/master.cpp diff --git a/higan/gb/apu/master/master.hpp b/gb/apu/master/master.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/master/master.hpp rename to gb/apu/master/master.hpp diff --git a/higan/gb/apu/noise/noise.cpp b/gb/apu/noise/noise.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/noise/noise.cpp rename to gb/apu/noise/noise.cpp diff --git a/higan/gb/apu/noise/noise.hpp b/gb/apu/noise/noise.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/noise/noise.hpp rename to gb/apu/noise/noise.hpp diff --git a/higan/gb/apu/serialization.cpp b/gb/apu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/serialization.cpp rename to gb/apu/serialization.cpp diff --git a/higan/gb/apu/square1/square1.cpp b/gb/apu/square1/square1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/square1/square1.cpp rename to gb/apu/square1/square1.cpp diff --git a/higan/gb/apu/square1/square1.hpp b/gb/apu/square1/square1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/square1/square1.hpp rename to gb/apu/square1/square1.hpp diff --git a/higan/gb/apu/square2/square2.cpp b/gb/apu/square2/square2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/square2/square2.cpp rename to gb/apu/square2/square2.cpp diff --git a/higan/gb/apu/square2/square2.hpp b/gb/apu/square2/square2.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/square2/square2.hpp rename to gb/apu/square2/square2.hpp diff --git a/higan/gb/apu/wave/wave.cpp b/gb/apu/wave/wave.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/wave/wave.cpp rename to gb/apu/wave/wave.cpp diff --git a/higan/gb/apu/wave/wave.hpp b/gb/apu/wave/wave.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/apu/wave/wave.hpp rename to gb/apu/wave/wave.hpp diff --git a/higan/gb/cartridge/cartridge.cpp b/gb/cartridge/cartridge.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/cartridge.cpp rename to gb/cartridge/cartridge.cpp diff --git a/higan/gb/cartridge/cartridge.hpp b/gb/cartridge/cartridge.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/cartridge.hpp rename to gb/cartridge/cartridge.hpp diff --git a/higan/gb/cartridge/huc1/huc1.cpp b/gb/cartridge/huc1/huc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/huc1/huc1.cpp rename to gb/cartridge/huc1/huc1.cpp diff --git a/higan/gb/cartridge/huc1/huc1.hpp b/gb/cartridge/huc1/huc1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/huc1/huc1.hpp rename to gb/cartridge/huc1/huc1.hpp diff --git a/higan/gb/cartridge/huc3/huc3.cpp b/gb/cartridge/huc3/huc3.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/huc3/huc3.cpp rename to gb/cartridge/huc3/huc3.cpp diff --git a/higan/gb/cartridge/huc3/huc3.hpp b/gb/cartridge/huc3/huc3.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/huc3/huc3.hpp rename to gb/cartridge/huc3/huc3.hpp diff --git a/higan/gb/cartridge/mbc0/mbc0.cpp b/gb/cartridge/mbc0/mbc0.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc0/mbc0.cpp rename to gb/cartridge/mbc0/mbc0.cpp diff --git a/higan/gb/cartridge/mbc0/mbc0.hpp b/gb/cartridge/mbc0/mbc0.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc0/mbc0.hpp rename to gb/cartridge/mbc0/mbc0.hpp diff --git a/higan/gb/cartridge/mbc1/mbc1.cpp b/gb/cartridge/mbc1/mbc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc1/mbc1.cpp rename to gb/cartridge/mbc1/mbc1.cpp diff --git a/higan/gb/cartridge/mbc1/mbc1.hpp b/gb/cartridge/mbc1/mbc1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc1/mbc1.hpp rename to gb/cartridge/mbc1/mbc1.hpp diff --git a/higan/gb/cartridge/mbc2/mbc2.cpp b/gb/cartridge/mbc2/mbc2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc2/mbc2.cpp rename to gb/cartridge/mbc2/mbc2.cpp diff --git a/higan/gb/cartridge/mbc2/mbc2.hpp b/gb/cartridge/mbc2/mbc2.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc2/mbc2.hpp rename to gb/cartridge/mbc2/mbc2.hpp diff --git a/higan/gb/cartridge/mbc3/mbc3.cpp b/gb/cartridge/mbc3/mbc3.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc3/mbc3.cpp rename to gb/cartridge/mbc3/mbc3.cpp diff --git a/higan/gb/cartridge/mbc3/mbc3.hpp b/gb/cartridge/mbc3/mbc3.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc3/mbc3.hpp rename to gb/cartridge/mbc3/mbc3.hpp diff --git a/higan/gb/cartridge/mbc5/mbc5.cpp b/gb/cartridge/mbc5/mbc5.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc5/mbc5.cpp rename to gb/cartridge/mbc5/mbc5.cpp diff --git a/higan/gb/cartridge/mbc5/mbc5.hpp b/gb/cartridge/mbc5/mbc5.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mbc5/mbc5.hpp rename to gb/cartridge/mbc5/mbc5.hpp diff --git a/higan/gb/cartridge/mmm01/mmm01.cpp b/gb/cartridge/mmm01/mmm01.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mmm01/mmm01.cpp rename to gb/cartridge/mmm01/mmm01.cpp diff --git a/higan/gb/cartridge/mmm01/mmm01.hpp b/gb/cartridge/mmm01/mmm01.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/mmm01/mmm01.hpp rename to gb/cartridge/mmm01/mmm01.hpp diff --git a/higan/gb/cartridge/serialization.cpp b/gb/cartridge/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cartridge/serialization.cpp rename to gb/cartridge/serialization.cpp diff --git a/higan/gb/cheat/cheat.cpp b/gb/cheat/cheat.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cheat/cheat.cpp rename to gb/cheat/cheat.cpp diff --git a/higan/gb/cheat/cheat.hpp b/gb/cheat/cheat.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cheat/cheat.hpp rename to gb/cheat/cheat.hpp diff --git a/higan/gb/cpu/cpu.cpp b/gb/cpu/cpu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/cpu.cpp rename to gb/cpu/cpu.cpp diff --git a/higan/gb/cpu/cpu.hpp b/gb/cpu/cpu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/cpu.hpp rename to gb/cpu/cpu.hpp diff --git a/higan/gb/cpu/memory.cpp b/gb/cpu/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/memory.cpp rename to gb/cpu/memory.cpp diff --git a/higan/gb/cpu/mmio.cpp b/gb/cpu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/mmio.cpp rename to gb/cpu/mmio.cpp diff --git a/higan/gb/cpu/serialization.cpp b/gb/cpu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/serialization.cpp rename to gb/cpu/serialization.cpp diff --git a/higan/gb/cpu/timing.cpp b/gb/cpu/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/cpu/timing.cpp rename to gb/cpu/timing.cpp diff --git a/higan/gb/gb.hpp b/gb/gb.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/gb.hpp rename to gb/gb.hpp diff --git a/higan/gb/interface/interface.cpp b/gb/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/interface/interface.cpp rename to gb/interface/interface.cpp diff --git a/higan/gb/interface/interface.hpp b/gb/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/interface/interface.hpp rename to gb/interface/interface.hpp diff --git a/higan/gb/memory/memory.cpp b/gb/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/memory/memory.cpp rename to gb/memory/memory.cpp diff --git a/higan/gb/memory/memory.hpp b/gb/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/memory/memory.hpp rename to gb/memory/memory.hpp diff --git a/higan/gb/ppu/cgb.cpp b/gb/ppu/cgb.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/cgb.cpp rename to gb/ppu/cgb.cpp diff --git a/higan/gb/ppu/dmg.cpp b/gb/ppu/dmg.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/dmg.cpp rename to gb/ppu/dmg.cpp diff --git a/higan/gb/ppu/mmio.cpp b/gb/ppu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/mmio.cpp rename to gb/ppu/mmio.cpp diff --git a/higan/gb/ppu/ppu.cpp b/gb/ppu/ppu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/ppu.cpp rename to gb/ppu/ppu.cpp diff --git a/higan/gb/ppu/ppu.hpp b/gb/ppu/ppu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/ppu.hpp rename to gb/ppu/ppu.hpp diff --git a/higan/gb/ppu/serialization.cpp b/gb/ppu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/ppu/serialization.cpp rename to gb/ppu/serialization.cpp diff --git a/higan/gb/scheduler/scheduler.cpp b/gb/scheduler/scheduler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/scheduler/scheduler.cpp rename to gb/scheduler/scheduler.cpp diff --git a/higan/gb/scheduler/scheduler.hpp b/gb/scheduler/scheduler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/scheduler/scheduler.hpp rename to gb/scheduler/scheduler.hpp diff --git a/higan/gb/system/serialization.cpp b/gb/system/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/system/serialization.cpp rename to gb/system/serialization.cpp diff --git a/higan/gb/system/system.cpp b/gb/system/system.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/system/system.cpp rename to gb/system/system.cpp diff --git a/higan/gb/system/system.hpp b/gb/system/system.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/system/system.hpp rename to gb/system/system.hpp diff --git a/higan/gb/video/video.cpp b/gb/video/video.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/video/video.cpp rename to gb/video/video.cpp diff --git a/higan/gb/video/video.hpp b/gb/video/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gb/video/video.hpp rename to gb/video/video.hpp diff --git a/higan/gba/Makefile b/gba/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/Makefile rename to gba/Makefile diff --git a/higan/gba/apu/apu.cpp b/gba/apu/apu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/apu.cpp rename to gba/apu/apu.cpp diff --git a/higan/gba/apu/apu.hpp b/gba/apu/apu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/apu.hpp rename to gba/apu/apu.hpp diff --git a/higan/gba/apu/fifo.cpp b/gba/apu/fifo.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/fifo.cpp rename to gba/apu/fifo.cpp diff --git a/higan/gba/apu/mmio.cpp b/gba/apu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/mmio.cpp rename to gba/apu/mmio.cpp diff --git a/higan/gba/apu/noise.cpp b/gba/apu/noise.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/noise.cpp rename to gba/apu/noise.cpp diff --git a/higan/gba/apu/registers.cpp b/gba/apu/registers.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/registers.cpp rename to gba/apu/registers.cpp diff --git a/higan/gba/apu/registers.hpp b/gba/apu/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/registers.hpp rename to gba/apu/registers.hpp diff --git a/higan/gba/apu/sequencer.cpp b/gba/apu/sequencer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/sequencer.cpp rename to gba/apu/sequencer.cpp diff --git a/higan/gba/apu/serialization.cpp b/gba/apu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/serialization.cpp rename to gba/apu/serialization.cpp diff --git a/higan/gba/apu/square.cpp b/gba/apu/square.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/square.cpp rename to gba/apu/square.cpp diff --git a/higan/gba/apu/square1.cpp b/gba/apu/square1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/square1.cpp rename to gba/apu/square1.cpp diff --git a/higan/gba/apu/square2.cpp b/gba/apu/square2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/square2.cpp rename to gba/apu/square2.cpp diff --git a/higan/gba/apu/wave.cpp b/gba/apu/wave.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/apu/wave.cpp rename to gba/apu/wave.cpp diff --git a/higan/gba/cartridge/cartridge.cpp b/gba/cartridge/cartridge.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/cartridge.cpp rename to gba/cartridge/cartridge.cpp diff --git a/higan/gba/cartridge/cartridge.hpp b/gba/cartridge/cartridge.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/cartridge.hpp rename to gba/cartridge/cartridge.hpp diff --git a/higan/gba/cartridge/eeprom.cpp b/gba/cartridge/eeprom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/eeprom.cpp rename to gba/cartridge/eeprom.cpp diff --git a/higan/gba/cartridge/flashrom.cpp b/gba/cartridge/flashrom.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/flashrom.cpp rename to gba/cartridge/flashrom.cpp diff --git a/higan/gba/cartridge/memory.hpp b/gba/cartridge/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/memory.hpp rename to gba/cartridge/memory.hpp diff --git a/higan/gba/cartridge/serialization.cpp b/gba/cartridge/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cartridge/serialization.cpp rename to gba/cartridge/serialization.cpp diff --git a/higan/gba/cpu/cpu.cpp b/gba/cpu/cpu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/cpu.cpp rename to gba/cpu/cpu.cpp diff --git a/higan/gba/cpu/cpu.hpp b/gba/cpu/cpu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/cpu.hpp rename to gba/cpu/cpu.hpp diff --git a/higan/gba/cpu/dma.cpp b/gba/cpu/dma.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/dma.cpp rename to gba/cpu/dma.cpp diff --git a/higan/gba/cpu/memory.cpp b/gba/cpu/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/memory.cpp rename to gba/cpu/memory.cpp diff --git a/higan/gba/cpu/mmio.cpp b/gba/cpu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/mmio.cpp rename to gba/cpu/mmio.cpp diff --git a/higan/gba/cpu/registers.cpp b/gba/cpu/registers.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/registers.cpp rename to gba/cpu/registers.cpp diff --git a/higan/gba/cpu/registers.hpp b/gba/cpu/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/registers.hpp rename to gba/cpu/registers.hpp diff --git a/higan/gba/cpu/serialization.cpp b/gba/cpu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/serialization.cpp rename to gba/cpu/serialization.cpp diff --git a/higan/gba/cpu/state.hpp b/gba/cpu/state.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/state.hpp rename to gba/cpu/state.hpp diff --git a/higan/gba/cpu/timer.cpp b/gba/cpu/timer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/cpu/timer.cpp rename to gba/cpu/timer.cpp diff --git a/higan/gba/gba.hpp b/gba/gba.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/gba.hpp rename to gba/gba.hpp diff --git a/higan/gba/interface/interface.cpp b/gba/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/interface/interface.cpp rename to gba/interface/interface.cpp diff --git a/higan/gba/interface/interface.hpp b/gba/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/interface/interface.hpp rename to gba/interface/interface.hpp diff --git a/higan/gba/memory/memory.cpp b/gba/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/memory/memory.cpp rename to gba/memory/memory.cpp diff --git a/higan/gba/memory/memory.hpp b/gba/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/memory/memory.hpp rename to gba/memory/memory.hpp diff --git a/higan/gba/memory/mmio.cpp b/gba/memory/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/memory/mmio.cpp rename to gba/memory/mmio.cpp diff --git a/higan/gba/memory/serialization.cpp b/gba/memory/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/memory/serialization.cpp rename to gba/memory/serialization.cpp diff --git a/higan/gba/ppu/background.cpp b/gba/ppu/background.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/background.cpp rename to gba/ppu/background.cpp diff --git a/higan/gba/ppu/memory.cpp b/gba/ppu/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/memory.cpp rename to gba/ppu/memory.cpp diff --git a/higan/gba/ppu/mmio.cpp b/gba/ppu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/mmio.cpp rename to gba/ppu/mmio.cpp diff --git a/higan/gba/ppu/mosaic.cpp b/gba/ppu/mosaic.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/mosaic.cpp rename to gba/ppu/mosaic.cpp diff --git a/higan/gba/ppu/object.cpp b/gba/ppu/object.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/object.cpp rename to gba/ppu/object.cpp diff --git a/higan/gba/ppu/ppu.cpp b/gba/ppu/ppu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/ppu.cpp rename to gba/ppu/ppu.cpp diff --git a/higan/gba/ppu/ppu.hpp b/gba/ppu/ppu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/ppu.hpp rename to gba/ppu/ppu.hpp diff --git a/higan/gba/ppu/registers.cpp b/gba/ppu/registers.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/registers.cpp rename to gba/ppu/registers.cpp diff --git a/higan/gba/ppu/registers.hpp b/gba/ppu/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/registers.hpp rename to gba/ppu/registers.hpp diff --git a/higan/gba/ppu/screen.cpp b/gba/ppu/screen.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/screen.cpp rename to gba/ppu/screen.cpp diff --git a/higan/gba/ppu/serialization.cpp b/gba/ppu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/serialization.cpp rename to gba/ppu/serialization.cpp diff --git a/higan/gba/ppu/state.hpp b/gba/ppu/state.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/ppu/state.hpp rename to gba/ppu/state.hpp diff --git a/higan/gba/scheduler/scheduler.cpp b/gba/scheduler/scheduler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/scheduler/scheduler.cpp rename to gba/scheduler/scheduler.cpp diff --git a/higan/gba/scheduler/scheduler.hpp b/gba/scheduler/scheduler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/scheduler/scheduler.hpp rename to gba/scheduler/scheduler.hpp diff --git a/higan/gba/system/bios.cpp b/gba/system/bios.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/system/bios.cpp rename to gba/system/bios.cpp diff --git a/higan/gba/system/serialization.cpp b/gba/system/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/system/serialization.cpp rename to gba/system/serialization.cpp diff --git a/higan/gba/system/system.cpp b/gba/system/system.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/system/system.cpp rename to gba/system/system.cpp diff --git a/higan/gba/system/system.hpp b/gba/system/system.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/system/system.hpp rename to gba/system/system.hpp diff --git a/higan/gba/video/video.cpp b/gba/video/video.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/video/video.cpp rename to gba/video/video.cpp diff --git a/higan/gba/video/video.hpp b/gba/video/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/gba/video/video.hpp rename to gba/video/video.hpp diff --git a/higan/nall/base64.hpp b/higan/nall/base64.hpp deleted file mode 100755 index bfa89488..00000000 --- a/higan/nall/base64.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef NALL_BASE64_HPP -#define NALL_BASE64_HPP - -#include -#include - -namespace nall { - -struct base64 { - static bool encode(char*& output, const uint8_t* input, unsigned inlength) { - output = new char[inlength * 8 / 6 + 8](); - - unsigned i = 0, o = 0; - while(i < inlength) { - switch(i % 3) { - - case 0: { - output[o++] = enc(input[i] >> 2); - output[o] = enc((input[i] & 3) << 4); - break; - } - - case 1: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 4)); - output[o] = enc((input[i] & 15) << 2); - break; - } - - case 2: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 6)); - output[o++] = enc(input[i] & 63); - break; - } - - } - - i++; - } - - return true; - } - - static string encode(const string& data) { - char* buffer = nullptr; - encode(buffer, (const uint8_t*)(const char*)data, data.length()); - string result = buffer; - delete[] buffer; - return result; - } - - static bool decode(uint8_t*& output, unsigned& outlength, const char* input) { - unsigned inlength = strlen(input), infix = 0; - output = new uint8_t[inlength + 1](); - - unsigned i = 0, o = 0; - while(i < inlength) { - uint8_t x = dec(input[i]); - - switch(i++ & 3) { - - case 0: { - output[o] = x << 2; - break; - } - - case 1: { - output[o++] |= x >> 4; - output[o] = (x & 15) << 4; - break; - } - - case 2: { - output[o++] |= x >> 2; - output[o] = (x & 3) << 6; - break; - } - - case 3: { - output[o++] |= x; - break; - } - - } - } - - outlength = o; - return true; - } - - static string decode(const string& data) { - uint8_t* buffer = nullptr; - unsigned size = 0; - decode(buffer, size, (const char*)data); - string result = (const char*)buffer; - delete[] buffer; - return result; - } - -private: - static char enc(uint8_t n) { - //base64 for URL encodings (URL = -_, MIME = +/) - static char lookup_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - return lookup_table[n & 63]; - } - - static uint8_t dec(char n) { - if(n >= 'A' && n <= 'Z') return n - 'A'; - if(n >= 'a' && n <= 'z') return n - 'a' + 26; - if(n >= '0' && n <= '9') return n - '0' + 52; - if(n == '-') return 62; - if(n == '_') return 63; - return 0; - } -}; - -} - -#endif diff --git a/higan/nall/dsp.hpp b/higan/nall/dsp.hpp deleted file mode 100755 index a2400ec7..00000000 --- a/higan/nall/dsp.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef NALL_DSP_HPP -#define NALL_DSP_HPP - -#include -#ifdef __SSE__ - #include -#endif - -#define NALL_DSP_INTERNAL_HPP -#include -#undef NALL_DSP_INTERNAL_HPP - -#endif diff --git a/higan/nall/dsp/settings.hpp b/higan/nall/dsp/settings.hpp deleted file mode 100755 index 3a8f24c6..00000000 --- a/higan/nall/dsp/settings.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -void DSP::setChannels(unsigned channels) { - assert(channels > 0); - buffer.setChannels(channels); - output.setChannels(channels); - settings.channels = channels; -} - -void DSP::setPrecision(unsigned precision) { - settings.precision = precision; - settings.intensity = 1 << (settings.precision - 1); - settings.intensityInverse = 1.0 / settings.intensity; -} - -void DSP::setFrequency(real frequency) { - settings.frequency = frequency; - resampler->setFrequency(); -} - -void DSP::setVolume(real volume) { - settings.volume = volume; -} - -void DSP::setBalance(real balance) { - settings.balance = balance; -} - -void DSP::setResampler(ResampleEngine engine) { - if(resampler) delete resampler; - - switch(engine) { - case ResampleEngine::Nearest: resampler = new ResampleNearest(*this); return; - case ResampleEngine::Linear: resampler = new ResampleLinear (*this); return; - case ResampleEngine::Cosine: resampler = new ResampleCosine (*this); return; - case ResampleEngine::Cubic: resampler = new ResampleCubic (*this); return; - case ResampleEngine::Hermite: resampler = new ResampleHermite(*this); return; - case ResampleEngine::Average: resampler = new ResampleAverage(*this); return; - case ResampleEngine::Sinc: resampler = new ResampleSinc (*this); return; - } - - throw; -} - -void DSP::setResamplerFrequency(real frequency) { - resampler->frequency = frequency; - resampler->setFrequency(); -} - -#endif diff --git a/higan/nall/endian.hpp b/higan/nall/endian.hpp deleted file mode 100755 index 1f834b5b..00000000 --- a/higan/nall/endian.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_ENDIAN_HPP -#define NALL_ENDIAN_HPP - -#include - -#if defined(ENDIAN_LSB) - //little-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201 - #define order_lsb2(a,b) a,b - #define order_lsb3(a,b,c) a,b,c - #define order_lsb4(a,b,c,d) a,b,c,d - #define order_lsb5(a,b,c,d,e) a,b,c,d,e - #define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h - #define order_msb2(a,b) b,a - #define order_msb3(a,b,c) c,b,a - #define order_msb4(a,b,c,d) d,c,b,a - #define order_msb5(a,b,c,d,e) e,d,c,b,a - #define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a -#elif defined(ENDIAN_MSB) - //big-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304 - #define order_lsb2(a,b) b,a - #define order_lsb3(a,b,c) c,b,a - #define order_lsb4(a,b,c,d) d,c,b,a - #define order_lsb5(a,b,c,d,e) e,d,c,b,a - #define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a - #define order_msb2(a,b) a,b - #define order_msb3(a,b,c) a,b,c - #define order_msb4(a,b,c,d) a,b,c,d - #define order_msb5(a,b,c,d,e) a,b,c,d,e - #define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h -#else - #error "Unknown endian. Please specify in nall/intrinsics.hpp" -#endif - -#endif diff --git a/higan/nall/interpolation.hpp b/higan/nall/interpolation.hpp deleted file mode 100755 index afc7108b..00000000 --- a/higan/nall/interpolation.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NALL_INTERPOLATION_HPP -#define NALL_INTERPOLATION_HPP - -namespace nall { - -struct Interpolation { - static inline double Nearest(double mu, double a, double b, double c, double d) { - return (mu <= 0.5 ? b : c); - } - - static inline double Sublinear(double mu, double a, double b, double c, double d) { - mu = ((mu - 0.5) * 2.0) + 0.5; - if(mu < 0) mu = 0; - if(mu > 1) mu = 1; - return b * (1.0 - mu) + c * mu; - } - - static inline double Linear(double mu, double a, double b, double c, double d) { - return b * (1.0 - mu) + c * mu; - } - - static inline double Cosine(double mu, double a, double b, double c, double d) { - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - return b * (1.0 - mu) + c * mu; - } - - static inline double Cubic(double mu, double a, double b, double c, double d) { - double A = d - c - a + b; - double B = a - b - A; - double C = c - a; - double D = b; - return A * (mu * mu * mu) + B * (mu * mu) + C * mu + D; - } - - static inline double 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.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - 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); - } -}; - -} - -#endif diff --git a/higan/nall/mosaic.hpp b/higan/nall/mosaic.hpp deleted file mode 100755 index 16fd0bfd..00000000 --- a/higan/nall/mosaic.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef NALL_MOSAIC_HPP -#define NALL_MOSAIC_HPP - -#define NALL_MOSAIC_INTERNAL_HPP -#include -#include -#include -#undef NALL_MOSAIC_INTERNAL_HPP - -#endif diff --git a/higan/nall/stream.hpp b/higan/nall/stream.hpp deleted file mode 100755 index 586ccda7..00000000 --- a/higan/nall/stream.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NALL_STREAM_HPP -#define NALL_STREAM_HPP - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define NALL_STREAM_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STREAM_INTERNAL_HPP - -#endif diff --git a/higan/nall/traits.hpp b/higan/nall/traits.hpp deleted file mode 100755 index 6a140c2b..00000000 --- a/higan/nall/traits.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef NALL_TRAITS_HPP -#define NALL_TRAITS_HPP - -#include - -namespace nall { - -template class has_default_constructor { - template class receive_size{}; - template static signed sfinae(receive_size*); - template static char sfinae(...); - -public: - enum : bool { value = sizeof(sfinae(0)) == sizeof(signed) }; -}; - -template struct enable_if { typedef T type; }; -template struct enable_if {}; - -template struct type_if { typedef T type; }; -template struct type_if { typedef F type; }; - -template struct static_and { enum { value = false }; }; -template<> struct static_and { enum { value = true }; }; - -template struct static_or { enum { value = false }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; - -} - -#endif diff --git a/higan/nall/xorg/xorg.hpp b/higan/nall/xorg/xorg.hpp deleted file mode 100755 index bcf48b46..00000000 --- a/higan/nall/xorg/xorg.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef NALL_XORG_XORG_HPP -#define NALL_XORG_XORG_HPP - -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/higan/phoenix/core/keyboard.hpp b/higan/phoenix/core/keyboard.hpp deleted file mode 100755 index ed04ec05..00000000 --- a/higan/phoenix/core/keyboard.hpp +++ /dev/null @@ -1,45 +0,0 @@ -//each code refers to a physical key -//names are taken assuming: NumLock on, CapsLock off, Shift off -//layout uses US-104 keyboard -enum class Scancode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - - Limit, -}; - -//each enum refers to a translated scancode (eg Shift+1 = !) -enum class Keycode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, SysRq, ScrollLock, Pause, Break, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - Tilde, Exclamation, At, Pound, Dollar, Percent, Power, Ampersand, Asterisk, ParenthesisLeft, ParenthesisRight, Underscore, Plus, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - BraceLeft, BraceRight, Pipe, Colon, Quote, CaretLeft, CaretRight, Question, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - KeypadInsert, KeypadDelete, KeypadHome, KeypadEnd, KeypadPageUp, KeypadPageDown, KeypadUp, KeypadDown, KeypadLeft, KeypadRight, KeypadCenter, - - Limit, -}; diff --git a/higan/phoenix/windows/phoenix.Manifest b/higan/phoenix/windows/phoenix.Manifest deleted file mode 100755 index 45fbb4cd..00000000 --- a/higan/phoenix/windows/phoenix.Manifest +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - true - - - diff --git a/higan/phoenix/windows/phoenix.rc b/higan/phoenix/windows/phoenix.rc deleted file mode 100755 index 89fb8dc2..00000000 --- a/higan/phoenix/windows/phoenix.rc +++ /dev/null @@ -1 +0,0 @@ -1 24 "phoenix.Manifest" diff --git a/kaijuu/Makefile b/kaijuu/Makefile deleted file mode 100644 index 63b1d771..00000000 --- a/kaijuu/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# for Linux only; to synchronize includes and resources -# use cc32.bat and cc64.bat for Windows compilation - -include nall/Makefile - -resource: force - sourcery resource/resource.xml resource/resource.cpp resource/resource.hpp - -sync: - if [ -d ./nall ]; then rm -r ./nall; fi - if [ -d ./phoenix ]; then rm -r ./phoenix; fi - cp -r ../nall ./nall - cp -r ../phoenix ./phoenix - rm -r nall/test - rm -r phoenix/nall - rm -r phoenix/test - -force: diff --git a/kaijuu/cc32.bat b/kaijuu/cc32.bat deleted file mode 100755 index 60caa857..00000000 --- a/kaijuu/cc32.bat +++ /dev/null @@ -1,8 +0,0 @@ -windres --target=pe-i386 kaijuu.rc kaijuu-resource.o -g++ -m32 -I. -std=gnu++0x -O3 -fomit-frame-pointer -c kaijuu.cpp -g++ -m32 -shared -static-libgcc -Wl,kaijuu.def -Wl,-enable-stdcall-fixup -s -o kaijuu32.dll kaijuu.o -lm -lole32 -luuid -lshlwapi -g++ -m32 -I. -std=gnu++0x -O3 -fomit-frame-pointer -o phoenix.o -c phoenix/phoenix.cpp -DPHOENIX_WINDOWS -g++ -m32 -I. -std=gnu++0x -O3 -fomit-frame-pointer -c interface.cpp -g++ -m32 -mwindows -s -o kaijuu32.exe interface.o kaijuu-resource.o phoenix.o -lkernel32 -luser32 -lgdi32 -ladvapi32 -lole32 -lcomctl32 -lcomdlg32 -lshlwapi -@pause -@del *.o diff --git a/kaijuu/cc64.bat b/kaijuu/cc64.bat deleted file mode 100755 index 01b65370..00000000 --- a/kaijuu/cc64.bat +++ /dev/null @@ -1,8 +0,0 @@ -windres kaijuu.rc kaijuu-resource.o -g++ -m64 -I. -std=gnu++0x -O3 -fomit-frame-pointer -c kaijuu.cpp -g++ -m64 -shared -static-libgcc -Wl,kaijuu.def -Wl,-enable-stdcall-fixup -s -o kaijuu64.dll kaijuu.o -lm -lole32 -luuid -lshlwapi -g++ -m64 -I. -std=gnu++0x -O3 -fomit-frame-pointer -o phoenix.o -c phoenix/phoenix.cpp -DPHOENIX_WINDOWS -g++ -m64 -I. -std=gnu++0x -O3 -fomit-frame-pointer -c interface.cpp -g++ -m64 -mwindows -s -o kaijuu64.exe interface.o kaijuu-resource.o phoenix.o -lkernel32 -luser32 -lgdi32 -ladvapi32 -lole32 -lcomctl32 -lcomdlg32 -lshlwapi -@pause -@del *.o diff --git a/kaijuu/extension.cpp b/kaijuu/extension.cpp deleted file mode 100644 index 512a4184..00000000 --- a/kaijuu/extension.cpp +++ /dev/null @@ -1,175 +0,0 @@ -CShellExt::CShellExt() { - instanceCount = 0; - referenceCount++; -} - -CShellExt::~CShellExt() { - referenceCount--; -} - -STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID *ppv) { - *ppv = nullptr; - - if(IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown)) { - *ppv = (IShellExtInit*)this; - } else if(IsEqualIID(riid, IID_IContextMenu)) { - *ppv = (IContextMenu*)this; - } - - if(*ppv) { - AddRef(); - return NOERROR; - } - - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) CShellExt::AddRef() { - return ++instanceCount; -} - -STDMETHODIMP_(ULONG) CShellExt::Release() { - if(--instanceCount) return instanceCount; - delete this; - return 0; -} - -STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, IDataObject *pDataObject, HKEY hRegKey) { - fileList.reset(); - - if(pDataObject) { - wchar_t filename[PATH_MAX]; - STGMEDIUM medium; - FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - HDROP hDrop; - - if(FAILED(pDataObject->GetData(&fe, &medium))) return E_INVALIDARG; - hDrop = (HDROP)GlobalLock(medium.hGlobal); - if(hDrop == NULL) return E_INVALIDARG; - - fileList.reset(); - unsigned count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0); - for(unsigned i = 0; i < count; i++) { - DragQueryFileW((HDROP)medium.hGlobal, i, filename, PATH_MAX); - string name = (const char*)utf8_t(filename); - name.transform("/", "\\"); - if(name.endswith("\\")) name.rtrim<1>("\\"); - fileList.append(name); - } - GlobalUnlock(medium.hGlobal); - ReleaseStgMedium(&medium); - } - - return S_OK; -} - -STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { - settings.load(); - unsigned idCmd = idCmdFirst; - bool firstDefault = true; - - auto ruleIDs = matchedRules(); - for(auto &ruleID : ruleIDs) { - auto &rule = settings.rules(ruleID); - if(idCmd < idCmdLast) { - InsertMenuW(hMenu, indexMenu, MF_STRING | MF_BYPOSITION, idCmd++, (const wchar_t*)utf16_t(rule.name)); - if(rule.defaultAction && firstDefault) { - firstDefault = false; //there can be only one default menu item - SetMenuDefaultItem(hMenu, indexMenu, TRUE); - } - indexMenu++; - } - } - - return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(idCmd - idCmdFirst)); -} - -STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, LPUINT lpReserved, LPSTR pszName, UINT uMaxNameLen) { - if(idCmd < settings.rules.size()) return S_OK; - return E_INVALIDARG; -} - -STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { - if(HIWORD(lpcmi->lpVerb) != 0) return E_INVALIDARG; //ignore actual string verbs - - settings.load(); - unsigned id = LOWORD(lpcmi->lpVerb); - auto ruleIDs = matchedRules(); - auto &rule = settings.rules(ruleIDs(id)); - - string nameID = fileList(0); - string pathnameID = dir(nameID).rtrim<1>("\\"); - string filenameID = notdir(nameID); - string basenameID = notdir(nall::basename(nameID)); - string extensionID = extension(nameID); - - string pathID = {"\"", pathnameID, "\""}; - string fileID = {"\"", nameID, "\""}; - - string pathsID, filesID; - for(auto &filename : fileList) pathsID.append("\"", dir(filename).rtrim<1>("\\"), "\"", " "); - for(auto &filename : fileList) filesID.append("\"", filename, "\"", " "); - pathsID.rtrim<1>(" "), filesID.rtrim<1>(" "); - - lstring params = rule.command.qsplit<1>(" "); - params(1).replace("{name}", nameID); - params(1).replace("{pathname}", pathnameID); - params(1).replace("{filename}", filenameID); - params(1).replace("{basename}", basenameID); - params(1).replace("{extension}", extensionID); - - params(1).replace("{path}", pathID); - params(1).replace("{file}", fileID); - - params(1).replace("{paths}", pathsID); - params(1).replace("{files}", filesID); - - if((intptr_t)ShellExecuteW(NULL, L"open", utf16_t(params(0)), utf16_t(params(1)), utf16_t(pathnameID), SW_SHOWNORMAL) <= 32) { - MessageBoxW(0, L"Error opening associated program.", L"kaijuu", MB_OK); - } - - return S_OK; -} - -vector CShellExt::matchedRules() { - vector matched; - if(fileList.size() == 0) return matched; - - for(unsigned id = 0; id < settings.rules.size(); id++) { - auto &rule = settings.rules(id); - if(rule.multiSelection == false && fileList.size() > 1) continue; - bool proceed = true; - for(auto &filename : fileList) { - string name = filename; - if(directory::exists(name)) { - if(rule.matchFolders == false) { - proceed = false; - break; - } - } else { - if(rule.matchFiles == false) { - proceed = false; - break; - } - } - name = notdir(name); - - lstring patternList = rule.pattern.split(";"); - bool found = false; - for(auto &pattern : patternList) { - if(name.wildcard(pattern)) { - found = true; - break; - } - } - if(found == false) { - proceed = false; - break; - } - } - if(proceed == false) continue; - matched.append(id); - } - - return matched; -} diff --git a/kaijuu/extension.hpp b/kaijuu/extension.hpp deleted file mode 100644 index 424ba4d5..00000000 --- a/kaijuu/extension.hpp +++ /dev/null @@ -1,23 +0,0 @@ -struct CShellExt : IContextMenu, IShellExtInit { -protected: - unsigned instanceCount; - lstring fileList; - -public: - CShellExt(); - ~CShellExt(); - - STDMETHODIMP QueryInterface(REFIID, LPVOID*); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - STDMETHODIMP QueryContextMenu(HMENU, UINT, UINT, UINT, UINT); - STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO); - STDMETHODIMP GetCommandString(UINT_PTR, UINT, UINT FAR*, LPSTR, UINT); - STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY); - -private: - vector matchedRules(); -}; - -typedef CShellExt *LPCSHELLEXT; \ No newline at end of file diff --git a/kaijuu/factory.cpp b/kaijuu/factory.cpp deleted file mode 100644 index 86503ab1..00000000 --- a/kaijuu/factory.cpp +++ /dev/null @@ -1,40 +0,0 @@ -CShellExtClassFactory::CShellExtClassFactory() { - instanceCount = 0; - referenceCount++; -} - -CShellExtClassFactory::~CShellExtClassFactory() { - referenceCount--; -} - -STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) { - *ppv = (LPCLASSFACTORY)this; - AddRef(); - return NOERROR; - } - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef() { - return ++instanceCount; -} - -STDMETHODIMP_(ULONG) CShellExtClassFactory::Release() { - if(--instanceCount) return instanceCount; - delete this; - return 0; -} - -STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnknownOuter, REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if(pUnknownOuter) return CLASS_E_NOAGGREGATION; - CShellExt *pShellExt = new CShellExt(); - if(pShellExt == NULL) return E_OUTOFMEMORY; - return pShellExt->QueryInterface(riid, ppv); -} - -STDMETHODIMP CShellExtClassFactory::LockServer(BOOL fLock) { - return NOERROR; -} diff --git a/kaijuu/factory.hpp b/kaijuu/factory.hpp deleted file mode 100644 index 48d305b1..00000000 --- a/kaijuu/factory.hpp +++ /dev/null @@ -1,17 +0,0 @@ -struct CShellExtClassFactory : IClassFactory { -protected: - unsigned instanceCount; - -public: - CShellExtClassFactory(); - ~CShellExtClassFactory(); - - STDMETHODIMP QueryInterface(REFIID, LPVOID FAR*); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR*); - STDMETHODIMP LockServer(BOOL); -}; - -typedef CShellExtClassFactory *LPCSHELLEXTCLASSFACTORY; diff --git a/kaijuu/guid.hpp b/kaijuu/guid.hpp deleted file mode 100644 index 815d6702..00000000 --- a/kaijuu/guid.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef _WIN64 - DEFINE_GUID(CLSID_ShellExtension, 0x5c8ee773, 0xb9dc, 0xcec7, 0x63, 0x31, 0x98, 0x6c, 0x16, 0x2b, 0x15, 0x0a); - const char classID[] = "{5c8ee773-b9dc-cec7-6331-986c162b150a}"; - const char classDescription[] = "KaijuuOpenShEx64"; - const char classDriver[] = "kaijuu64.dll"; -#else - DEFINE_GUID(CLSID_ShellExtension, 0xa2f1781c, 0x2e37, 0x9bcd, 0x66, 0x93, 0xc9, 0xe4, 0x52, 0x89, 0xc4, 0xc2); - const char classID[] = "{a2f1781c-2e37-9bcd-6693-c9e45289c4c2}"; - const char classDescription[] = "KaijuuOpenShEx32"; - const char classDriver[] = "kaijuu32.dll"; -#endif diff --git a/kaijuu/interface.cpp b/kaijuu/interface.cpp deleted file mode 100644 index 68b4b19f..00000000 --- a/kaijuu/interface.cpp +++ /dev/null @@ -1,307 +0,0 @@ -#include "interface.hpp" -Application *application = nullptr; -RuleEditor *ruleEditor = nullptr; - -#include "resource/resource.hpp" -#include "resource/resource.cpp" - -Application::Application(const string &pathname) : pathname(pathname) { - setTitle("kaijuu v05"); - setFrameGeometry({64, 64, 725, 480}); - - layout.setMargin(5); - statusLabel.setFont("Tahoma, 8, Bold"); - uninstallButton.setText("Uninstall"); - installButton.setText("Install"); - settingList.setHeaderText("Name", "Default", "Match", "Pattern", "Command"); - settingList.setHeaderVisible(); - appendButton.setText("Append"); - modifyButton.setText("Modify"); - moveUpButton.setText("Move Up"); - moveDownButton.setText("Move Down"); - removeButton.setText("Remove"); - resetButton.setText("Reset"); - helpButton.setText("Help ..."); - - append(layout); - layout.append(installLayout, {~0, 0}, 5); - installLayout.append(statusLabel, {~0, 0}, 5); - installLayout.append(uninstallButton, {80, 0}, 5); - installLayout.append(installButton, {80, 0}); - layout.append(settingLayout, {~0, ~0}); - settingLayout.append(settingList, {~0, ~0}, 5); - settingLayout.append(controlLayout, {0, ~0}); - controlLayout.append(appendButton, {80, 0}, 5); - controlLayout.append(modifyButton, {80, 0}, 5); - controlLayout.append(moveUpButton, {80, 0}, 5); - controlLayout.append(moveDownButton, {80, 0}, 5); - controlLayout.append(removeButton, {80, 0}, 5); - controlLayout.append(spacer, {0, ~0}); - controlLayout.append(resetButton, {80, 0}, 5); - controlLayout.append(helpButton, {80, 0}, 5); - controlLayout.append(canvas, {80, 88}); - - canvas.setImage({resource::icon, sizeof resource::icon}); - canvas.update(); - - onClose = &OS::quit; - installButton.onActivate = {&Application::install, this}; - uninstallButton.onActivate = {&Application::uninstall, this}; - settingList.onActivate = {&Application::modifyAction, this}; - settingList.onChange = {&Application::synchronize, this}; - appendButton.onActivate = {&Application::appendAction, this}; - modifyButton.onActivate = {&Application::modifyAction, this}; - moveUpButton.onActivate = {&Application::moveUpAction, this}; - moveDownButton.onActivate = {&Application::moveDownAction, this}; - removeButton.onActivate = {&Application::removeAction, this}; - resetButton.onActivate = {&Application::resetAction, this}; - helpButton.onActivate = [&] { nall::invoke("kaijuu.html"); }; - refresh(); - synchronize(); - setVisible(); -} - -void Application::synchronize() { - if(registry::read({"HKLM/Software/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved/", classID}) == classDescription) { - statusLabel.setText("Extension status: installed"); - installButton.setEnabled(false); - uninstallButton.setEnabled(true); - } else { - statusLabel.setText("Extension status: not installed"); - installButton.setEnabled(true); - uninstallButton.setEnabled(false); - } - modifyButton.setEnabled(settingList.selected()); - moveUpButton.setEnabled(settingList.selected() && settings.rules.size() > 1 && settingList.selection() != 0); - moveDownButton.setEnabled(settingList.selected() && settings.rules.size() > 1 && settingList.selection() < settings.rules.size() - 1); - removeButton.setEnabled(settingList.selected()); - resetButton.setEnabled(settings.rules.size() > 0); -} - -void Application::refresh() { - settings.load(); - settingList.reset(); - for(auto &rule : settings.rules) { - string match = "Nothing"; - if(rule.matchFiles && rule.matchFolders) match = "Everything"; - else if(rule.matchFiles) match = "Files"; - else if(rule.matchFolders) match = "Folders"; - settingList.append(rule.name, rule.defaultAction ? "Yes" : "No", match, rule.pattern, rule.command); - } - settingList.autoSizeColumns(); -} - -void Application::install() { - string command = {"regsvr32 \"", pathname, classDriver, "\""}; - _wsystem(utf16_t(command)); - synchronize(); -} - -void Application::uninstall() { - string command = {"regsvr32 /u \"", pathname, classDriver, "\""}; - _wsystem(utf16_t(command)); - synchronize(); -} - -void Application::appendAction() { - ruleEditor->show(); -} - -void Application::modifyAction() { - if(settingList.selected() == false) return; - unsigned selection = settingList.selection(); - ruleEditor->show(selection); -} - -void Application::moveUpAction() { - if(settingList.selected() == false) return; - if(settingList.selection() == 0) return; - unsigned selection = settingList.selection(); - auto temp = settings.rules(selection - 1); - settings.rules(selection - 1) = settings.rules(selection); - settings.rules(selection) = temp; - settings.save(); - refresh(); - settingList.setSelection(selection - 1); - synchronize(); -} - -void Application::moveDownAction() { - if(settingList.selected() == false) return; - if(settingList.selection() >= settings.rules.size() - 1) return; - unsigned selection = settingList.selection(); - auto temp = settings.rules(selection + 1); - settings.rules(selection + 1) = settings.rules(selection); - settings.rules(selection) = temp; - settings.save(); - refresh(); - settingList.setSelection(selection + 1); - synchronize(); -} - -void Application::removeAction() { - if(settingList.selected() == false) return; - unsigned selection = settingList.selection(); - settings.rules.remove(selection); - settings.save(); - refresh(); - synchronize(); -} - -void Application::resetAction() { - if(MessageWindow::question(*this, "Warning: this will permanently remove all rules! Are you sure you want to do this?") - == MessageWindow::Response::No) return; - settings.rules.reset(); - settings.save(); - refresh(); - synchronize(); -} - -RuleEditor::RuleEditor() : index(-1) { - setTitle("Rule Editor"); - setFrameGeometry({128, 256, 500, 160}); - - layout.setMargin(5); - nameLabel.setText("Name:"); - patternLabel.setText("Pattern:"); - commandLabel.setText("Command:"); - commandSelect.setText("Select ..."); - defaultAction.setText("Default Action"); - filesAction.setText("Match Files"); - foldersAction.setText("Match Folders"); - assignButton.setText("Assign"); - - Font font("Tahoma, 8"); - unsigned length = 0; - length = max(length, font.geometry("Name:").width); - length = max(length, font.geometry("Pattern:").width); - length = max(length, font.geometry("Command:").width); - - append(layout); - layout.append(nameLayout, {~0, 0}, 5); - nameLayout.append(nameLabel, {length, 0}, 5); - nameLayout.append(nameValue, {~0, 0}); - layout.append(patternLayout, {~0, 0}, 5); - patternLayout.append(patternLabel, {length, 0}, 5); - patternLayout.append(patternValue, {~0, 0}); - layout.append(commandLayout, {~0, 0}, 5); - commandLayout.append(commandLabel, {length, 0}, 5); - commandLayout.append(commandValue, {~0, 0}, 5); - commandLayout.append(commandSelect, {80, 0}); - layout.append(controlLayout, {~0, 0}); - controlLayout.append(defaultAction, {0, 0}, 5); - controlLayout.append(filesAction, {0, 0}, 5); - controlLayout.append(foldersAction, {0, 0}, 5); - controlLayout.append(spacer, {~0, 0}); - controlLayout.append(assignButton, {80, 0}); - - Geometry geometry = Window::geometry(); - geometry.height = layout.minimumGeometry().height; - setGeometry(geometry); - - onClose = [&] { - modal = false; - }; - - nameValue.onChange = - patternValue.onChange = - commandValue.onChange = - {&RuleEditor::synchronize, this}; - - commandSelect.onActivate = [&] { - string pathname = DialogWindow::fileOpen(*this, application->pathname, "Programs (*.exe)", "All Files (*)"); - if(pathname.empty() == false) { - pathname.transform("/", "\\"); - commandValue.setText({"\"", pathname, "\" {file}"}); - } - synchronize(); - }; - - nameValue.onActivate = - patternValue.onActivate = - commandValue.onActivate = - assignButton.onActivate = [&] { - Settings::Rule rule = { - nameValue.text(), - patternValue.text(), - defaultAction.checked(), - filesAction.checked(), - foldersAction.checked(), - commandValue.text() - }; - if(index == -1) { - settings.rules.append(rule); - } else { - settings.rules(index) = rule; - } - settings.save(); - application->refresh(); - application->synchronize(); - setVisible(false); - modal = false; - }; -} - -void RuleEditor::synchronize() { - bool enable = true; - if(nameValue.text().empty()) enable = false; - if(patternValue.text().empty()) enable = false; - if(commandValue.text().empty()) enable = false; - assignButton.setEnabled(enable); -} - -void RuleEditor::show(signed ruleID) { - Settings::Rule rule{"", "", false, true, false, "", false}; - if(ruleID >= 0) rule = settings.rules(ruleID); - - index = ruleID; - nameValue.setText(rule.name); - patternValue.setText(rule.pattern); - commandValue.setText(rule.command); - defaultAction.setChecked(rule.defaultAction); - filesAction.setChecked(rule.matchFiles); - foldersAction.setChecked(rule.matchFolders); - synchronize(); - setVisible(); - setFocused(); - nameValue.setFocused(); - - setModal(modal = true); - while(modal == true) { - OS::processEvents(); - } - setModal(false); - application->setFocused(); -} - -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); - -bool isWow64() { - LPFN_ISWOW64PROCESS fnIsWow64Process; - fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandleW(L"kernel32"), "IsWow64Process"); - if(!fnIsWow64Process) return false; - BOOL result = FALSE; - fnIsWow64Process(GetCurrentProcess(), &result); - return result == TRUE; -} - -int CALLBACK WinMain(HINSTANCE module, HINSTANCE, LPSTR, int) { - if(isWow64()) { - MessageWindow::critical(Window::none(), "Error: you must run kaijuu64.exe on 64-bit Windows."); - return 0; - } - - wchar_t filename[MAX_PATH]; - GetModuleFileNameW(module, filename, MAX_PATH); - - string pathname = (const char*)utf8_t(filename); - pathname.transform("\\", "/"); - pathname = dir(pathname); - - application = new Application(pathname); - ruleEditor = new RuleEditor; - application->setFocused(); - OS::main(); - - return 0; -} diff --git a/kaijuu/interface.hpp b/kaijuu/interface.hpp deleted file mode 100644 index 656cb7e3..00000000 --- a/kaijuu/interface.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -using namespace nall; - -#include -using namespace phoenix; - -#include "guid.hpp" -#include "settings.hpp" - -struct Application : Window { - VerticalLayout layout; - HorizontalLayout installLayout; - Label statusLabel; - Button uninstallButton; - Button installButton; - HorizontalLayout settingLayout; - ListView settingList; - VerticalLayout controlLayout; - Button appendButton; - Button modifyButton; - Button moveUpButton; - Button moveDownButton; - Button removeButton; - Button resetButton; - Widget spacer; - Button helpButton; - Canvas canvas; - - Application(const string &pathname); - void synchronize(); - void refresh(); - void install(); - void uninstall(); - void appendAction(); - void modifyAction(); - void moveUpAction(); - void moveDownAction(); - void removeAction(); - void resetAction(); - - string pathname; -}; - -struct RuleEditor : Window { - VerticalLayout layout; - HorizontalLayout nameLayout; - Label nameLabel; - LineEdit nameValue; - HorizontalLayout patternLayout; - Label patternLabel; - LineEdit patternValue; - HorizontalLayout commandLayout; - Label commandLabel; - LineEdit commandValue; - Button commandSelect; - HorizontalLayout controlLayout; - CheckBox defaultAction; - CheckBox filesAction; - CheckBox foldersAction; - Widget spacer; - Button assignButton; - - bool modal; - signed index; - - RuleEditor(); - void synchronize(); - void show(signed rule = -1); -}; diff --git a/kaijuu/kaijuu.Manifest b/kaijuu/kaijuu.Manifest deleted file mode 100644 index 28987b10..00000000 --- a/kaijuu/kaijuu.Manifest +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - true - - - - - - - - - - diff --git a/kaijuu/kaijuu.cpp b/kaijuu/kaijuu.cpp deleted file mode 100644 index d9eaa535..00000000 --- a/kaijuu/kaijuu.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "kaijuu.hpp" -#include "extension.cpp" -#include "factory.cpp" - -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstance, DWORD dwReason, LPVOID lpReserved) { - if(dwReason == DLL_PROCESS_ATTACH) { - module = hinstance; - } - - if(dwReason == DLL_PROCESS_DETACH) { - } - - return TRUE; -} - -STDAPI DllCanUnloadNow() { - return referenceCount == 0 ? S_OK : S_FALSE; -} - -STDAPI DllRegisterServer() { - wchar_t fileName[MAX_PATH]; - GetModuleFileNameW(module, fileName, MAX_PATH); - registry::write({"HKCR/CLSID/", classID, "/"}, classDescription); - registry::write({"HKCR/CLSID/", classID, "/shellex/MayChangeDefaultMenu/"}); - registry::write({"HKCR/CLSID/", classID, "/InprocServer32/"}, (const char*)utf8_t(fileName)); - registry::write({"HKCR/CLSID/", classID, "/InprocServer32/ThreadingModel"}, "Apartment"); - registry::write({"HKCR/*/shellex/ContextMenuHandlers/", classDescription, "/"}, classID); - registry::write({"HKCR/Directory/shellex/ContextMenuHandlers/", classDescription, "/"}, classID); - registry::write({"HKLM/Software/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved/", classID}, classDescription); - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); - return S_OK; -} - -STDAPI DllUnregisterServer() { - registry::remove({"HKCR/CLSID/", classID, "/"}); - registry::remove({"HKCR/*/shellex/ContextMenuHandlers/", classDescription, "/"}); - registry::remove({"HKCR/Directory/shellex/ContextMenuHandlers/", classDescription, "/"}); - registry::remove({"HKLM/Software/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved/", classID}); - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); - return S_OK; -} - -STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if(IsEqualIID(rclsid, CLSID_ShellExtension)) { - CShellExtClassFactory *pcf = new CShellExtClassFactory; - return pcf->QueryInterface(riid, ppv); - } - return CLASS_E_CLASSNOTAVAILABLE; -} diff --git a/kaijuu/kaijuu.def b/kaijuu/kaijuu.def deleted file mode 100644 index ce78749c..00000000 --- a/kaijuu/kaijuu.def +++ /dev/null @@ -1,5 +0,0 @@ -EXPORTS - DllRegisterServer private - DllUnregisterServer private - DllCanUnloadNow private - DllGetClassObject private diff --git a/kaijuu/kaijuu.hpp b/kaijuu/kaijuu.hpp deleted file mode 100644 index 93e4f3ab..00000000 --- a/kaijuu/kaijuu.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include -#include -#include -using namespace nall; - -#define INITGUID -#include -#include -#include -#include -#include -#include -#include -#define IDM_CFOPEN 0 - -HINSTANCE module = NULL; -unsigned referenceCount = 0; - -#include "guid.hpp" -#include "settings.hpp" -#include "extension.hpp" -#include "factory.hpp" diff --git a/kaijuu/kaijuu.html b/kaijuu/kaijuu.html deleted file mode 100644 index 65bcdb59..00000000 --- a/kaijuu/kaijuu.html +++ /dev/null @@ -1,200 +0,0 @@ - - - kaijuu User Manual - - - -

kaijuu v05

- Author: byuu
- License: ISC
-
- -

Overview

-

kaijuu is a Windows context menu shell extension. The context - menu is the list you see when you right-click on a file or folder. - kaijuu allows you to add your own custom actions to this menu.

- -

Think of opening an unknown file type: Windows will ask you to - associate a program with the file type. From there forward, - double-clicking the file will open the file with that program.

- -

kaijuu is a far more powerful version of this same concept. With - kaijuu, you can assign as many rules as you want. You can apply the - same rule to multiple file patterns. You can have more complex - pattern matching for names. You can apply rules to folders. You can - specify rules about how to handle single-file versus multi-file - selection. You can send custom command-line parameters to the - program. You can have rules on a per-user basis. And you can do all - of this from an easy-to-use GUI.

- -

Installation

-

kaijuu comes in 32-bit and 64-bit flavors, you will need to use - the one for your operating system. If you are unsure, try running - kaijuu32.exe. It will tell you if you need to use the 64-bit - version.

- -

Now place the appropriate kaijuu EXE and DLL files into a folder - where you intend to keep them. The DLL cannot be moved after - installation, otherwise Explorer will not be able to locate the - shell extension. C:\Program Files\kaijuu would be a recommended - location.

- -

Now run the kaijuu EXE, and click on Install. You must - have administrator access to use the kaijuu EXE, as this is - necessary to install and uninstall shell extensions.

- -

Removal and Upgrading

-

To remove or upgrade kaijuu, you must first uninstall the shell - extension. Run the kaijuu EXE, and click on Uninstall. You - must now close all open instances of Windows Explorer, in order for - the DLL to be completely unloaded. In the worst case, restart the - computer.

- -

If you intend to upgrade kaijuu, I recommend using the - Reset button to erase all saved settings. There is no - guarantee of backward-compatibility between kaijuu revisions.

- -

Configuration

-

The kaijuu EXE not only handles installation and removal, it also - handles modifying the rules.

- -

kaijuu stores a unique list of rules for every user account. - You are free to modify rules even while kaijuu is installed. They - will take immediate effect.

- -

The main interface lists all rules, sorted in order of their - priority. For instance, if two rules match and both are marked as - the default action; the item higher in the list will be marked as - the default. You can also quickly determine if the extension is - currently installed.

- -

Append will add new rules, Modify will edit an - existing rule, Move Up and Move Down can be used to - modify the priority ordering, Remove can delete the selected - rule, and Reset can delete all rules.

- -

Rules

-

You can have as many rules as you like. You will see every - matched rule in the context menu when you right-click on files or - folders.

- -

Name is the string that will show up in the context menu. - It would be wise to name the rule something like "Open with X" or - "Edit with Y"

- -

Pattern is a semicolon-separated list of patterns to test - the selected file or folder names against. You must specify one or - more patterns.

- -

Example 1: *.txt;*.doc will match anything ending - in .txt or in .doc.

- -

Example 2: * will match everything always.

- -

Example 3: Manifest will only match items named - Manifest.

- -

Example 4: *.?? will match any two-letter - extension, such as .gb

- - Command is the program to be executed when a rule is - activated. You can use the Select button to quickly navigate - to a program to use.

- -

Note the way the program name is typically quoted, for instance - "c:\my program.exe". If there is a space in the path, this is - required to differentiate the program name from its arguments. If - you were to type your own rule, you could take advantage of two - things: first, the PATH command-line variable allows - specifying system programs without the full path. For instance, - "cmd" will invoke the command-prompt; and second, if the - program path contains no spaces, the quotes are no longer necessary. - So you could say cmd to invoke the command-prompt.

- -

After the program name, you can specify the program arguments. - kaijuu has many special identifiers built-in, that are replaced with - the file and/or folder names that were selected. When using the - Select button, {file} is automatically appended for - convenience, which should be sufficient for most cases. You can of - course customize the rule afterward with the following identifiers: -

- -
-{name}      = c:\path\file.txt
-{pathname}  = c:\path
-{filename}  = file.txt
-{basename}  = file
-{extension} = txt
-
-{path}  = "c:\path"
-{file}  = "c:\path\file.txt"
-
-{paths} = "c:\path1" "c:\path2"
-{files} = "c:\path1\file1.txt" "c:\path2\file2.txt"
-
- -

Note that if you use the first group, you must add your own - quotes around the identifiers, eg notepad "{name}".

- -

If the command includes {files} or {paths} within - the string, then kaijuu will match this rule when one or more files - are selected. If neither of these patterns are found, then kaijuu - will only check the rule if a single file is selected.

- -

You will want to use {file} and {path} for programs - that can only open a single item a a time; and {files} and - {paths} for programs that can open multiple items at the same - time, such as music players.

- -

Default Action, when checked, will mark this rule as the - default action to take when a file or folder is double-clicked on. -

- -

Match Files will allow selections with files in them to - be valid. If a file is selected without this checked, the rule will - fail.

- -

Match Folders will allow selections with folders in them - to be valid. If a file is selected without this checked, the rule - will fail.

- -

Assign will create the new rule or modify an existing - rule, depending upon which button you clicked from the main window. -

- -

Caution: be very careful when using a pattern of * - along with Default Action checked. For instance, you could - find that double-clicking executables no longer opens then, and - requires you to use the right-click context menu. In the worst case, - you will have to reboot into safe mode and delete the rule or kaijuu - DLL.

- -

Rule Examples

- - - - - - -
NameDefaultMatchPatternCommand
Open terminal hereNoFolders*cmd /k cd /d {path}
Edit MakefileYesFilesMakefilenotepad {file}
Play song(s)NoFiles*.mp3"c:\winamp.exe" {files}
Load as Game FolderYesFolders*.fc;*.sfc;*.gba"c:\bsnes.exe" {path}
- - diff --git a/kaijuu/kaijuu.rc b/kaijuu/kaijuu.rc deleted file mode 100644 index 6de3fb51..00000000 --- a/kaijuu/kaijuu.rc +++ /dev/null @@ -1 +0,0 @@ -1 24 "kaijuu.manifest" diff --git a/kaijuu/nall/Makefile b/kaijuu/nall/Makefile deleted file mode 100644 index bbc4b029..00000000 --- a/kaijuu/nall/Makefile +++ /dev/null @@ -1,118 +0,0 @@ -# Makefile -# author: byuu -# license: public domain - -[A-Z] = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -[a-z] = a b c d e f g h i j k l m n o p q r s t u v w x y z -[0-9] = 0 1 2 3 4 5 6 7 8 9 -[markup] = ` ~ ! @ \# $$ % ^ & * ( ) - _ = + [ { ] } \ | ; : ' " , < . > / ? -[all] = $([A-Z]) $([a-z]) $([0-9]) $([markup]) -[space] := -[space] += - -##### -# platform detection -##### - -ifeq ($(platform),) - uname := $(shell uname -a) - ifeq ($(uname),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Windows,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring CYGWIN,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Darwin,$(uname)),) - platform := osx - delete = rm -f $1 - else - platform := x - delete = rm -f $1 - endif -endif - -ifeq ($(compiler),) - ifeq ($(platform),win) - compiler := gcc - else ifeq ($(platform),osx) - compiler := gcc-mp-4.7 - else - compiler := gcc-4.7 - endif -endif - -c := $(compiler) -std=gnu99 -cpp := $(subst cc,++,$(compiler)) -std=gnu++0x - -ifeq ($(prefix),) - prefix := /usr/local -endif - -##### -# function rwildcard(directory, pattern) -##### -rwildcard = \ - $(strip \ - $(filter $(if $2,$2,%), \ - $(foreach f, \ - $(wildcard $1*), \ - $(eval t = $(call rwildcard,$f/)) \ - $(if $t,$t,$f) \ - ) \ - ) \ - ) - -##### -# function strtr(source, from, to) -##### -strtr = \ - $(eval __temp := $1) \ - $(strip \ - $(foreach c, \ - $(join $(addsuffix :,$2),$3), \ - $(eval __temp := \ - $(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) - -##### -# function strupper(source) -##### -strupper = $(call strtr,$1,$([a-z]),$([A-Z])) - -##### -# function strlower(source) -##### -strlower = $(call strtr,$1,$([A-Z]),$([a-z])) - -##### -# function strlen(source) -##### -strlen = \ - $(eval __temp := $(subst $([space]),_,$1)) \ - $(words \ - $(strip \ - $(foreach c, \ - $([all]), \ - $(eval __temp := \ - $(subst $c,$c ,$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) \ - ) - -##### -# function streq(source) -##### -streq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),,1) - -##### -# function strne(source) -##### -strne = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),1,) diff --git a/kaijuu/nall/algorithm.hpp b/kaijuu/nall/algorithm.hpp deleted file mode 100644 index 037f0bb7..00000000 --- a/kaijuu/nall/algorithm.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NALL_ALGORITHM_HPP -#define NALL_ALGORITHM_HPP - -#undef min -#undef max - -namespace nall { - template T min(const T &t, const U &u) { - return t < u ? t : u; - } - - template T max(const T &t, const U &u) { - return t > u ? t : u; - } -} - -#endif diff --git a/kaijuu/nall/any.hpp b/kaijuu/nall/any.hpp deleted file mode 100644 index 7661a2a4..00000000 --- a/kaijuu/nall/any.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef NALL_ANY_HPP -#define NALL_ANY_HPP - -#include -#include - -namespace nall { - struct any { - bool empty() const { return container; } - const std::type_info& type() const { return container ? container->type() : typeid(void); } - - template any& operator=(const T& value_) { - typedef typename type_if< - std::is_array::value, - typename std::remove_extent::type>::type*, - T - >::type auto_t; - - if(type() == typeid(auto_t)) { - static_cast*>(container)->value = (auto_t)value_; - } else { - if(container) delete container; - container = new holder((auto_t)value_); - } - - return *this; - } - - any() : container(nullptr) {} - ~any() { if(container) delete container; } - template any(const T& value_) : container(nullptr) { operator=(value_); } - - private: - struct placeholder { - virtual const std::type_info& type() const = 0; - } *container; - - template struct holder : placeholder { - T value; - const std::type_info& type() const { return typeid(T); } - holder(const T& value_) : value(value_) {} - }; - - template friend T any_cast(any&); - template friend T any_cast(const any&); - template friend T* any_cast(any*); - template friend const T* any_cast(const any*); - }; - - template T any_cast(any &value) { - typedef typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T any_cast(const any &value) { - typedef const typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T* any_cast(any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } - - template const T* any_cast(const any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } -} - -#endif diff --git a/kaijuu/nall/atoi.hpp b/kaijuu/nall/atoi.hpp deleted file mode 100644 index 26756c79..00000000 --- a/kaijuu/nall/atoi.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_ATOI_HPP -#define NALL_ATOI_HPP - -#include - -namespace nall { - -//note: this header is intended to form the base for user-defined literals; -//once they are supported by GCC. eg: -//unsigned operator "" b(const char *s) { return binary(s); } -//-> signed data = 1001b; -//(0b1001 is nicer, but is not part of the C++ standard) - -constexpr inline uintmax_t binary_(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? binary_(s + 1, (sum << 1) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t octal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '7' ? octal_(s + 1, (sum << 3) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t decimal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '9' ? decimal_(s + 1, (sum * 10) + *s - '0') : - sum - ); -} - -constexpr inline uintmax_t hex_(const char *s, uintmax_t sum = 0) { - return ( - *s >= 'A' && *s <= 'F' ? hex_(s + 1, (sum << 4) | *s - 'A' + 10) : - *s >= 'a' && *s <= 'f' ? hex_(s + 1, (sum << 4) | *s - 'a' + 10) : - *s >= '0' && *s <= '9' ? hex_(s + 1, (sum << 4) | *s - '0') : - sum - ); -} - -// - -constexpr inline uintmax_t binary(const char *s) { - return ( - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '%' ? binary_(s + 1) : - binary_(s) - ); -} - -constexpr inline uintmax_t octal(const char *s) { - return ( - octal_(s) - ); -} - -constexpr inline intmax_t integer(const char *s) { - return ( - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -constexpr inline uintmax_t decimal(const char *s) { - return ( - decimal_(s) - ); -} - -constexpr inline uintmax_t hex(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '$' ? hex_(s + 1) : - hex_(s) - ); -} - -constexpr inline intmax_t numeral(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '0' ? octal_(s + 1) : - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -inline double fp(const char *s) { - return atof(s); -} - -} - -#endif diff --git a/kaijuu/nall/base64.hpp b/kaijuu/nall/base64.hpp deleted file mode 100644 index a0afd8b1..00000000 --- a/kaijuu/nall/base64.hpp +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef NALL_BASE64_HPP -#define NALL_BASE64_HPP - -#include -#include - -namespace nall { - struct base64 { - static bool encode(char *&output, const uint8_t* input, unsigned inlength) { - output = new char[inlength * 8 / 6 + 6](); - - unsigned i = 0, o = 0; - while(i < inlength) { - switch(i % 3) { - case 0: { - output[o++] = enc(input[i] >> 2); - output[o] = enc((input[i] & 3) << 4); - } break; - - case 1: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 4)); - output[o] = enc((input[i] & 15) << 2); - } break; - - case 2: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 6)); - output[o++] = enc(input[i] & 63); - } break; - } - - i++; - } - - return true; - } - - static bool decode(uint8_t *&output, unsigned &outlength, const char *input) { - unsigned inlength = strlen(input), infix = 0; - output = new uint8_t[inlength](); - - unsigned i = 0, o = 0; - while(i < inlength) { - uint8_t x = dec(input[i]); - - switch(i++ & 3) { - case 0: { - output[o] = x << 2; - } break; - - case 1: { - output[o++] |= x >> 4; - output[o] = (x & 15) << 4; - } break; - - case 2: { - output[o++] |= x >> 2; - output[o] = (x & 3) << 6; - } break; - - case 3: { - output[o++] |= x; - } break; - } - } - - outlength = o; - return true; - } - - private: - static char enc(uint8_t n) { - //base64 for URL encodings - static char lookup_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - return lookup_table[n & 63]; - } - - static uint8_t dec(char n) { - if(n >= 'A' && n <= 'Z') return n - 'A'; - if(n >= 'a' && n <= 'z') return n - 'a' + 26; - if(n >= '0' && n <= '9') return n - '0' + 52; - if(n == '-') return 62; - if(n == '_') return 63; - return 0; - } - }; -} - -#endif diff --git a/kaijuu/nall/bit.hpp b/kaijuu/nall/bit.hpp deleted file mode 100644 index 63403eb0..00000000 --- a/kaijuu/nall/bit.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef NALL_BIT_HPP -#define NALL_BIT_HPP - -#include - -namespace nall { - template - inline uintmax_t uclamp(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), y = b * 2 - 1 }; - return y + ((x - y) & -(x < y)); //min(x, y); - } - - template - inline uintmax_t uclip(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return (x & m); - } - - template - inline intmax_t sclamp(const intmax_t x) { - enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 }; - return (x > m) ? m : (x < -b) ? -b : x; - } - - template - inline intmax_t sclip(const intmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return ((x & m) ^ b) - b; - } - - namespace bit { - constexpr inline uintmax_t mask(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) : - *s == ' ' || *s == '_' ? mask(s + 1, sum) : - *s ? mask(s + 1, sum << 1) : - sum - ); - } - - constexpr inline uintmax_t test(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) : - *s == ' ' || *s == '_' ? test(s + 1, sum) : - *s ? test(s + 1, sum << 1) : - sum - ); - } - - //lowest(0b1110) == 0b0010 - constexpr inline uintmax_t lowest(const uintmax_t x) { - return x & -x; - } - - //clear_lowest(0b1110) == 0b1100 - constexpr inline uintmax_t clear_lowest(const uintmax_t x) { - return x & (x - 1); - } - - //set_lowest(0b0101) == 0b0111 - constexpr inline uintmax_t set_lowest(const uintmax_t x) { - return x | (x + 1); - } - - //count number of bits set in a byte - inline unsigned count(uintmax_t x) { - unsigned count = 0; - do count += x & 1; while(x >>= 1); - return count; - } - - //round up to next highest single bit: - //round(15) == 16, round(16) == 16, round(17) == 32 - inline uintmax_t round(uintmax_t x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } - } -} - -#endif diff --git a/kaijuu/nall/bmp.hpp b/kaijuu/nall/bmp.hpp deleted file mode 100644 index 33cdf4dc..00000000 --- a/kaijuu/nall/bmp.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef NALL_BMP_HPP -#define NALL_BMP_HPP - -#include - -//BMP reader / writer -//author: byuu -//note: only 24-bit RGB and 32-bit ARGB uncompressed images supported - -namespace nall { - -struct bmp { - inline static bool read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height); - inline static bool write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha = false); -}; - -bool bmp::read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height) { - file fp; - if(fp.open(filename, file::mode::read) == false) return false; - if(fp.size() < 0x36) return false; - - if(fp.readm(2) != 0x424d) return false; - fp.seek(0x000a); - unsigned offset = fp.readl(4); - unsigned dibsize = fp.readl(4); - if(dibsize != 40) return false; - signed headerWidth = fp.readl(4); - if(headerWidth < 0) return false; - signed headerHeight = fp.readl(4); - fp.readl(2); - unsigned bitsPerPixel = fp.readl(2); - if(bitsPerPixel != 24 && bitsPerPixel != 32) return false; - unsigned compression = fp.readl(4); - if(compression != 0) return false; - fp.seek(offset); - - bool noFlip = headerHeight < 0; - width = headerWidth, height = abs(headerHeight); - data = new uint32_t[width * height]; - - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - for(unsigned y = 0; y < height; y++) { - uint32_t *p = noFlip ? data + y * width : data + (height - 1 - y) * width; - for(unsigned x = 0; x < width; x++, p++) { - *p = fp.readl(bytesPerPixel); - if(bytesPerPixel == 3) *p |= 255 << 24; - } - if(paddingLength) fp.readl(paddingLength); - } - - fp.close(); - return true; -} - -bool bmp::write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - - unsigned bitsPerPixel = alpha ? 32 : 24; - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - unsigned imageSize = alignedWidth * height; - unsigned fileSize = 0x36 + imageSize; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - fp.writem(0x424d, 2); //signature - fp.writel(fileSize, 4); //file size - fp.writel(0, 2); //reserved - fp.writel(0, 2); //reserved - fp.writel(0x36, 4); //offset - - fp.writel(40, 4); //DIB size - fp.writel(width, 4); //width - fp.writel(-height, 4); //height - fp.writel(1, 2); //color planes - fp.writel(bitsPerPixel, 2); //bits per pixel - fp.writel(0, 4); //compression method (BI_RGB) - fp.writel(imageSize, 4); //image data size - fp.writel(3780, 4); //horizontal resolution - fp.writel(3780, 4); //vertical resolution - fp.writel(0, 4); //palette size - fp.writel(0, 4); //important color count - - for(unsigned y = 0; y < height; y++) { - const uint32_t *p = (const uint32_t*)((const uint8_t*)data + y * pitch); - for(unsigned x = 0; x < width; x++) fp.writel(*p++, bytesPerPixel); - if(paddingLength) fp.writel(0, paddingLength); - } - - fp.close(); - return true; -} - -} - -#endif diff --git a/kaijuu/nall/bps/delta.hpp b/kaijuu/nall/bps/delta.hpp deleted file mode 100644 index 6cee56a3..00000000 --- a/kaijuu/nall/bps/delta.hpp +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef NALL_BPS_DELTA_HPP -#define NALL_BPS_DELTA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsdelta { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpsdelta::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpsdelta::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpsdelta::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpsdelta::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpsdelta::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t sourceChecksum = ~0, modifyChecksum = ~0; - unsigned sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - Node *sourceTree[65536], *targetTree[65536]; - for(unsigned n = 0; n < 65536; n++) sourceTree[n] = 0, targetTree[n] = 0; - - //source tree creation - for(unsigned offset = 0; offset < sourceSize; offset++) { - uint16_t symbol = sourceData[offset + 0]; - sourceChecksum = crc32_adjust(sourceChecksum, symbol); - if(offset < sourceSize - 1) symbol |= sourceData[offset + 1] << 8; - Node *node = new Node; - node->offset = offset; - node->next = sourceTree[symbol]; - sourceTree[symbol] = node; - } - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - while(outputOffset < targetSize) { - unsigned maxLength = 0, maxOffset = 0, mode = TargetRead; - - uint16_t symbol = targetData[outputOffset + 0]; - if(outputOffset < targetSize - 1) symbol |= targetData[outputOffset + 1] << 8; - - { //source read - unsigned length = 0, offset = outputOffset; - while(offset < sourceSize && offset < targetSize && sourceData[offset] == targetData[offset]) { - length++; - offset++; - } - if(length > maxLength) maxLength = length, mode = SourceRead; - } - - { //source copy - Node *node = sourceTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(x < sourceSize && y < targetSize && sourceData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = SourceCopy; - node = node->next; - } - } - - { //target copy - Node *node = targetTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(y < targetSize && targetData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = TargetCopy; - node = node->next; - } - - //target tree append - node = new Node; - node->offset = outputOffset; - node->next = targetTree[symbol]; - targetTree[symbol] = node; - } - - { //target read - if(maxLength < 4) { - maxLength = min((unsigned)Granularity, targetSize - outputOffset); - mode = TargetRead; - } - } - - if(mode != TargetRead) targetReadFlush(); - - switch(mode) { - case SourceRead: - encode(SourceRead | ((maxLength - 1) << 2)); - break; - case TargetRead: - //delay write to group sequential TargetRead commands into one - targetReadLength += maxLength; - break; - case SourceCopy: - case TargetCopy: - encode(mode | ((maxLength - 1) << 2)); - signed relativeOffset; - if(mode == SourceCopy) { - relativeOffset = maxOffset - sourceRelativeOffset; - sourceRelativeOffset = maxOffset + maxLength; - } else { - relativeOffset = maxOffset - targetRelativeOffset; - targetRelativeOffset = maxOffset + maxLength; - } - encode((relativeOffset < 0) | (abs(relativeOffset) << 1)); - break; - } - - outputOffset += maxLength; - } - - targetReadFlush(); - - sourceChecksum = ~sourceChecksum; - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/kaijuu/nall/bps/linear.hpp b/kaijuu/nall/bps/linear.hpp deleted file mode 100644 index df840283..00000000 --- a/kaijuu/nall/bps/linear.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_BPS_LINEAR_HPP -#define NALL_BPS_LINEAR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpslinear { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpslinear::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpslinear::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpslinear::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpslinear::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpslinear::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t modifyChecksum = ~0; - unsigned targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - while(outputOffset < targetSize) { - unsigned sourceLength = 0; - for(unsigned n = 0; outputOffset + n < min(sourceSize, targetSize); n++) { - if(sourceData[outputOffset + n] != targetData[outputOffset + n]) break; - sourceLength++; - } - - unsigned rleLength = 0; - for(unsigned n = 1; outputOffset + n < targetSize; n++) { - if(targetData[outputOffset] != targetData[outputOffset + n]) break; - rleLength++; - } - - if(rleLength >= 4) { - //write byte to repeat - targetReadLength++; - outputOffset++; - targetReadFlush(); - - //copy starting from repetition byte - encode(TargetCopy | ((rleLength - 1) << 2)); - unsigned relativeOffset = (outputOffset - 1) - targetRelativeOffset; - encode(relativeOffset << 1); - outputOffset += rleLength; - targetRelativeOffset = outputOffset - 1; - } else if(sourceLength >= 4) { - targetReadFlush(); - encode(SourceRead | ((sourceLength - 1) << 2)); - outputOffset += sourceLength; - } else { - targetReadLength += Granularity; - outputOffset += Granularity; - } - } - - targetReadFlush(); - - uint32_t sourceChecksum = crc32_calculate(sourceData, sourceSize); - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/kaijuu/nall/bps/metadata.hpp b/kaijuu/nall/bps/metadata.hpp deleted file mode 100644 index 46759e6f..00000000 --- a/kaijuu/nall/bps/metadata.hpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef NALL_BPS_METADATA_HPP -#define NALL_BPS_METADATA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsmetadata { - inline bool load(const string &filename); - inline bool save(const string &filename, const string &metadata); - inline string metadata() const; - -protected: - file sourceFile; - string metadataString; -}; - -bool bpsmetadata::load(const string &filename) { - if(sourceFile.open(filename, file::mode::read) == false) return false; - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - if(read() != 'B') return false; - if(read() != 'P') return false; - if(read() != 'S') return false; - if(read() != '1') return false; - decode(); - decode(); - unsigned metadataSize = decode(); - char data[metadataSize + 1]; - for(unsigned n = 0; n < metadataSize; n++) data[n] = read(); - data[metadataSize] = 0; - metadataString = (const char*)data; - - return true; -} - -bool bpsmetadata::save(const string &filename, const string &metadata) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - if(sourceFile.open() == false) return false; - sourceFile.seek(0); - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - uint32_t checksum = ~0; - - auto write = [&](uint8_t data) { - targetFile.write(data); - checksum = crc32_adjust(checksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - for(unsigned n = 0; n < 4; n++) write(read()); - encode(decode()); - encode(decode()); - unsigned sourceLength = decode(); - unsigned targetLength = metadata.length(); - encode(targetLength); - sourceFile.seek(sourceLength, file::index::relative); - for(unsigned n = 0; n < targetLength; n++) write(metadata[n]); - unsigned length = sourceFile.size() - sourceFile.offset() - 4; - for(unsigned n = 0; n < length; n++) write(read()); - uint32_t outputChecksum = ~checksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - targetFile.close(); - return true; -} - -string bpsmetadata::metadata() const { - return metadataString; -} - -} - -#endif diff --git a/kaijuu/nall/bps/patch.hpp b/kaijuu/nall/bps/patch.hpp deleted file mode 100644 index 85c4dcae..00000000 --- a/kaijuu/nall/bps/patch.hpp +++ /dev/null @@ -1,219 +0,0 @@ -#ifndef NALL_BPS_PATCH_HPP -#define NALL_BPS_PATCH_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpspatch { - inline bool modify(const uint8_t *data, unsigned size); - inline void source(const uint8_t *data, unsigned size); - inline void target(uint8_t *data, unsigned size); - - inline bool modify(const string &filename); - inline bool source(const string &filename); - inline bool target(const string &filename); - - inline string metadata() const; - inline unsigned size() const; - - enum result : unsigned { - unknown, - success, - patch_too_small, - patch_invalid_header, - source_too_small, - target_too_small, - source_checksum_invalid, - target_checksum_invalid, - patch_checksum_invalid, - }; - - inline result apply(); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - - filemap modifyFile; - const uint8_t *modifyData; - unsigned modifySize; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - uint8_t *targetData; - unsigned targetSize; - - unsigned modifySourceSize; - unsigned modifyTargetSize; - unsigned modifyMarkupSize; - string metadataString; -}; - -bool bpspatch::modify(const uint8_t *data, unsigned size) { - if(size < 19) return false; - modifyData = data; - modifySize = size; - - unsigned offset = 4; - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = modifyData[offset++]; - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - - char buffer[modifyMarkupSize + 1]; - for(unsigned n = 0; n < modifyMarkupSize; n++) buffer[n] = modifyData[offset++]; - buffer[modifyMarkupSize] = 0; - metadataString = (const char*)buffer; - - return true; -} - -void bpspatch::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpspatch::target(uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpspatch::modify(const string &filename) { - if(modifyFile.open(filename, filemap::mode::read) == false) return false; - return modify(modifyFile.data(), modifyFile.size()); -} - -bool bpspatch::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpspatch::target(const string &filename) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(modifyTargetSize); - fp.close(); - - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -string bpspatch::metadata() const { - return metadataString; -} - -unsigned bpspatch::size() const { - return modifyTargetSize; -} - -bpspatch::result bpspatch::apply() { - if(modifySize < 19) return result::patch_too_small; - - uint32_t modifyChecksum = ~0, targetChecksum = ~0; - unsigned modifyOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto read = [&]() -> uint8_t { - uint8_t data = modifyData[modifyOffset++]; - modifyChecksum = crc32_adjust(modifyChecksum, data); - return data; - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - auto write = [&](uint8_t data) { - targetData[outputOffset++] = data; - targetChecksum = crc32_adjust(targetChecksum, data); - }; - - if(read() != 'B') return result::patch_invalid_header; - if(read() != 'P') return result::patch_invalid_header; - if(read() != 'S') return result::patch_invalid_header; - if(read() != '1') return result::patch_invalid_header; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - for(unsigned n = 0; n < modifyMarkupSize; n++) read(); - - if(modifySourceSize > sourceSize) return result::source_too_small; - if(modifyTargetSize > targetSize) return result::target_too_small; - - while(modifyOffset < modifySize - 12) { - unsigned length = decode(); - unsigned mode = length & 3; - length = (length >> 2) + 1; - - switch(mode) { - case SourceRead: - while(length--) write(sourceData[outputOffset]); - break; - case TargetRead: - while(length--) write(read()); - break; - case SourceCopy: - case TargetCopy: - signed offset = decode(); - bool negative = offset & 1; - offset >>= 1; - if(negative) offset = -offset; - - if(mode == SourceCopy) { - sourceRelativeOffset += offset; - while(length--) write(sourceData[sourceRelativeOffset++]); - } else { - targetRelativeOffset += offset; - while(length--) write(targetData[targetRelativeOffset++]); - } - break; - } - } - - uint32_t modifySourceChecksum = 0, modifyTargetChecksum = 0, modifyModifyChecksum = 0; - for(unsigned n = 0; n < 32; n += 8) modifySourceChecksum |= read() << n; - for(unsigned n = 0; n < 32; n += 8) modifyTargetChecksum |= read() << n; - uint32_t checksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) modifyModifyChecksum |= read() << n; - - uint32_t sourceChecksum = crc32_calculate(sourceData, modifySourceSize); - targetChecksum = ~targetChecksum; - - if(sourceChecksum != modifySourceChecksum) return result::source_checksum_invalid; - if(targetChecksum != modifyTargetChecksum) return result::target_checksum_invalid; - if(checksum != modifyModifyChecksum) return result::patch_checksum_invalid; - - return result::success; -} - -} - -#endif diff --git a/kaijuu/nall/compositor.hpp b/kaijuu/nall/compositor.hpp deleted file mode 100644 index 6b9245f6..00000000 --- a/kaijuu/nall/compositor.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_COMPOSITOR_HPP -#define NALL_COMPOSITOR_HPP - -#include - -namespace nall { - -struct compositor { - inline static bool enabled(); - inline static bool enable(bool status); - - #if defined(PLATFORM_X) - enum class Compositor : unsigned { Unknown, Metacity, Xfwm4 }; - inline static Compositor detect(); - - inline static bool enabled_metacity(); - inline static bool enable_metacity(bool status); - - inline static bool enabled_xfwm4(); - inline static bool enable_xfwm4(bool status); - #endif -}; - -#if defined(PLATFORM_X) - -//Metacity - -bool compositor::enabled_metacity() { - FILE *fp = popen("gconftool-2 --get /apps/metacity/general/compositing_manager", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_metacity(bool status) { - FILE *fp; - if(status) { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager true", "r"); - } else { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager false", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//Xfwm4 - -bool compositor::enabled_xfwm4() { - FILE *fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing'", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_xfwm4(bool status) { - FILE *fp; - if(status) { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'true'", "r"); - } else { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'false'", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//General - -compositor::Compositor compositor::detect() { - Compositor result = Compositor::Unknown; - - FILE *fp; - char buffer[512]; - - fp = popen("pidof metacity", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Metacity; - pclose(fp); - - fp = popen("pidof xfwm4", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Xfwm4; - pclose(fp); - - return result; -} - -bool compositor::enabled() { - switch(detect()) { - case Compositor::Metacity: return enabled_metacity(); - case Compositor::Xfwm4: return enabled_xfwm4(); - default: return false; - } -} - -bool compositor::enable(bool status) { - switch(detect()) { - case Compositor::Metacity: return enable_metacity(status); - case Compositor::Xfwm4: return enable_xfwm4(status); - default: return false; - } -} - -#elif defined(PLATFORM_WINDOWS) - -bool compositor::enabled() { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmIsCompositionEnabled = (HRESULT (WINAPI*)(BOOL*))GetProcAddress(module, "DwmIsCompositionEnabled"); - if(pDwmIsCompositionEnabled == 0) return false; - - BOOL result; - if(pDwmIsCompositionEnabled(&result) != S_OK) return false; - return result; -} - -bool compositor::enable(bool status) { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmEnableComposition = (HRESULT (WINAPI*)(UINT))GetProcAddress(module, "DwmEnableComposition"); - if(pDwmEnableComposition == 0) return false; - - if(pDwmEnableComposition(status) != S_OK) return false; - return true; -} - -#else - -bool compositor::enabled() { - return false; -} - -bool compositor::enable(bool) { - return false; -} - -#endif - -} - -#endif diff --git a/kaijuu/nall/config.hpp b/kaijuu/nall/config.hpp deleted file mode 100644 index 94be7dc1..00000000 --- a/kaijuu/nall/config.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_CONFIG_HPP -#define NALL_CONFIG_HPP - -#include -#include -#include - -namespace nall { - namespace configuration_traits { - template struct is_boolean { enum { value = false }; }; - template<> struct is_boolean { enum { value = true }; }; - - template struct is_signed { enum { value = false }; }; - template<> struct is_signed { enum { value = true }; }; - - template struct is_unsigned { enum { value = false }; }; - template<> struct is_unsigned { enum { value = true }; }; - - template struct is_double { enum { value = false }; }; - template<> struct is_double { enum { value = true }; }; - - template struct is_string { enum { value = false }; }; - template<> struct is_string { enum { value = true }; }; - } - - class configuration { - public: - enum type_t { boolean_t, signed_t, unsigned_t, double_t, string_t, unknown_t }; - struct item_t { - uintptr_t data; - string name; - string desc; - type_t type; - - inline string get() const { - switch(type) { - case boolean_t: return { *(bool*)data }; - case signed_t: return { *(signed*)data }; - case unsigned_t: return { *(unsigned*)data }; - case double_t: return { *(double*)data }; - case string_t: return { "\"", *(string*)data, "\"" }; - } - return "???"; - } - - inline void set(string s) { - switch(type) { - case boolean_t: *(bool*)data = (s == "true"); break; - case signed_t: *(signed*)data = integer(s); break; - case unsigned_t: *(unsigned*)data = decimal(s); break; - case double_t: *(double*)data = fp(s); break; - case string_t: s.trim("\""); *(string*)data = s; break; - } - } - }; - vector list; - - template - inline void append(T &data, const char *name, const char *desc = "") { - item_t item = { (uintptr_t)&data, name, desc }; - if(configuration_traits::is_boolean::value) item.type = boolean_t; - else if(configuration_traits::is_signed::value) item.type = signed_t; - else if(configuration_traits::is_unsigned::value) item.type = unsigned_t; - else if(configuration_traits::is_double::value) item.type = double_t; - else if(configuration_traits::is_string::value) item.type = string_t; - else item.type = unknown_t; - list.append(item); - } - - //deprecated - template - inline void attach(T &data, const char *name, const char *desc = "") { - append(data, name, desc); - } - - inline virtual bool load(const string &filename) { - string data; - if(data.readfile(filename) == true) { - data.replace("\r", ""); - lstring line; - line.split("\n", data); - - for(unsigned i = 0; i < line.size(); i++) { - if(auto position = qstrpos(line[i], "#")) line[i][position()] = 0; - if(!qstrpos(line[i], " = ")) continue; - - lstring part; - part.qsplit(" = ", line[i]); - part[0].trim(); - part[1].trim(); - - for(unsigned n = 0; n < list.size(); n++) { - if(part[0] == list[n].name) { - list[n].set(part[1]); - break; - } - } - } - - return true; - } else { - return false; - } - } - - inline virtual bool save(const string &filename) const { - file fp; - if(fp.open(filename, file::mode::write)) { - for(unsigned i = 0; i < list.size(); i++) { - string output; - output.append(list[i].name, " = ", list[i].get()); - if(list[i].desc != "") output.append(" # ", list[i].desc); - output.append("\r\n"); - fp.print(output); - } - - fp.close(); - return true; - } else { - return false; - } - } - }; -} - -#endif diff --git a/kaijuu/nall/crc32.hpp b/kaijuu/nall/crc32.hpp deleted file mode 100644 index ad36fbf6..00000000 --- a/kaijuu/nall/crc32.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef NALL_CRC32_HPP -#define NALL_CRC32_HPP - -#include - -namespace nall { - const uint32_t crc32_table[256] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; - - inline uint32_t crc32_adjust(uint32_t crc32, uint8_t input) { - return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff]; - } - - inline uint32_t crc32_calculate(const uint8_t *data, unsigned length) { - uint32_t crc32 = ~0; - for(unsigned i = 0; i < length; i++) { - crc32 = crc32_adjust(crc32, data[i]); - } - return ~crc32; - } -} - -#endif diff --git a/kaijuu/nall/directory.hpp b/kaijuu/nall/directory.hpp deleted file mode 100644 index 4dba2b70..00000000 --- a/kaijuu/nall/directory.hpp +++ /dev/null @@ -1,189 +0,0 @@ -#ifndef NALL_DIRECTORY_HPP -#define NALL_DIRECTORY_HPP - -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include -#else - #include - #include - #include -#endif - -namespace nall { - -struct directory { - static bool create(const string &pathname, unsigned permissions = 0755); //recursive - static bool remove(const string &pathname); - static bool exists(const string &pathname); - static lstring folders(const string &pathname, const string &pattern = "*"); - static lstring files(const string &pathname, const string &pattern = "*"); - static lstring contents(const string &pathname, const string &pattern = "*"); -}; - -#if defined(PLATFORM_WINDOWS) - inline bool directory::create(const string &pathname, unsigned permissions) { - string fullpath = pathname, path; - fullpath.transform("/", "\\"); - fullpath.rtrim<1>("\\"); - lstring pathpart = fullpath.split("\\"); - bool result = false; - for(auto &part : pathpart) { - path.append(part, "\\"); - result = _wmkdir(utf16_t(path)) == 0; - } - return result; - } - - inline bool directory::remove(const string &pathname) { - return _wrmdir(utf16_t(pathname)) == 0; - } - - inline bool directory::exists(const string &pathname) { - string name = pathname; - name.trim<1>("\""); - DWORD result = GetFileAttributes(utf16_t(name)); - if(result == INVALID_FILE_ATTRIBUTES) return false; - return (result & FILE_ATTRIBUTE_DIRECTORY); - } - - inline lstring directory::folders(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - while(FindNextFile(handle, &data) != false) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - } - FindClose(handle); - } - if(list.size() > 0) list.sort(); - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::files(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - while(FindNextFile(handle, &data) != false) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - FindClose(handle); - } - if(list.size() > 0) list.sort(); - return list; - } - - inline lstring directory::contents(const string &pathname, const string &pattern) { - lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files - lstring files = directory::files(pathname, pattern); - for(auto &file : files) folders.append(file); - return folders; - } -#else - inline bool directory::create(const string &pathname, unsigned permissions) { - string fullpath = pathname, path = "/"; - fullpath.trim<1>("/"); - lstring pathpart = fullpath.split("/"); - for(auto &part : pathpart) { - if(!directory::exists(path)) mkdir(path, permissions); - path.append(part, "/"); - } - return mkdir(path, permissions) == 0; - } - - inline bool directory::remove(const string &pathname) { - return rmdir(pathname) == 0; - } - - inline bool directory::exists(const string &pathname) { - DIR *dp = opendir(pathname); - if(!dp) return false; - closedir(dp); - return true; - } - - inline lstring directory::folders(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if(ep->d_type & DT_DIR) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - if(list.size() > 0) list.sort(); - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::files(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if((ep->d_type & DT_DIR) == 0) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - if(list.size() > 0) list.sort(); - return list; - } - - inline lstring directory::contents(const string &pathname, const string &pattern) { - lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files - lstring files = directory::files(pathname, pattern); - for(auto &file : files) folders.append(file); - return folders; - } -#endif - -} - -#endif diff --git a/kaijuu/nall/dl.hpp b/kaijuu/nall/dl.hpp deleted file mode 100644 index 3bd7d4d2..00000000 --- a/kaijuu/nall/dl.hpp +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NALL_DL_HPP -#define NALL_DL_HPP - -//dynamic linking support - -#include -#include -#include -#include - -#if defined(PLATFORM_X) || defined(PLATFORM_OSX) - #include -#elif defined(PLATFORM_WINDOWS) - #include - #include -#endif - -namespace nall { - struct library { - bool opened() const { return handle; } - bool open(const char*, const char* = ""); - bool open_absolute(const char*); - void* sym(const char*); - void close(); - - library() : handle(0) {} - ~library() { close(); } - - library& operator=(const library&) = delete; - library(const library&) = delete; - - private: - uintptr_t handle; - }; - - #if defined(PLATFORM_X) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".so"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_OSX) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".dylib"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_WINDOWS) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - string filepath(path, *path && !strend(path, "/") && !strend(path, "\\") ? "\\" : "", name, ".dll"); - handle = (uintptr_t)LoadLibraryW(utf16_t(filepath)); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)LoadLibraryW(utf16_t(name)); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return (void*)GetProcAddress((HMODULE)handle, name); - } - - inline void library::close() { - if(!handle) return; - FreeLibrary((HMODULE)handle); - handle = 0; - } - #else - inline bool library::open(const char*, const char*) { return false; } - inline void* library::sym(const char*) { return 0; } - inline void library::close() {} - #endif -}; - -#endif diff --git a/kaijuu/nall/dsp.hpp b/kaijuu/nall/dsp.hpp deleted file mode 100644 index a2400ec7..00000000 --- a/kaijuu/nall/dsp.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef NALL_DSP_HPP -#define NALL_DSP_HPP - -#include -#ifdef __SSE__ - #include -#endif - -#define NALL_DSP_INTERNAL_HPP -#include -#undef NALL_DSP_INTERNAL_HPP - -#endif diff --git a/kaijuu/nall/dsp/buffer.hpp b/kaijuu/nall/dsp/buffer.hpp deleted file mode 100644 index 4386d0e9..00000000 --- a/kaijuu/nall/dsp/buffer.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct Buffer { - double **sample; - uint16_t rdoffset; - uint16_t wroffset; - unsigned channels; - - void setChannels(unsigned channels) { - for(unsigned c = 0; c < this->channels; c++) { - if(sample[c]) delete[] sample[c]; - } - if(sample) delete[] sample; - - this->channels = channels; - if(channels == 0) return; - - sample = new double*[channels]; - for(unsigned c = 0; c < channels; c++) { - sample[c] = new double[65536](); - } - } - - inline double& read(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(rdoffset + offset)]; - } - - inline double& write(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(wroffset + offset)]; - } - - inline void clear() { - for(unsigned c = 0; c < channels; c++) { - for(unsigned n = 0; n < 65536; n++) { - sample[c][n] = 0; - } - } - rdoffset = 0; - wroffset = 0; - } - - Buffer() { - channels = 0; - } - - ~Buffer() { - setChannels(0); - } -}; - -#endif diff --git a/kaijuu/nall/dsp/core.hpp b/kaijuu/nall/dsp/core.hpp deleted file mode 100644 index a5b967b1..00000000 --- a/kaijuu/nall/dsp/core.hpp +++ /dev/null @@ -1,167 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include -#include - -namespace nall { - -//precision: can be float, double or long double -#define real float - -struct DSP; - -struct Resampler { - DSP &dsp; - real frequency; - - virtual void setFrequency() = 0; - virtual void clear() = 0; - virtual void sample() = 0; - Resampler(DSP &dsp) : dsp(dsp) {} -}; - -struct DSP { - enum class ResampleEngine : unsigned { - Nearest, - Linear, - Cosine, - Cubic, - Hermite, - Average, - Sinc, - }; - - inline void setChannels(unsigned channels); - inline void setPrecision(unsigned precision); - inline void setFrequency(real frequency); //inputFrequency - inline void setVolume(real volume); - inline void setBalance(real balance); - - inline void setResampler(ResampleEngine resamplingEngine); - inline void setResamplerFrequency(real frequency); //outputFrequency - - inline void sample(signed channel[]); - inline bool pending(); - inline void read(signed channel[]); - - inline void clear(); - inline DSP(); - inline ~DSP(); - -protected: - friend class ResampleNearest; - friend class ResampleLinear; - friend class ResampleCosine; - friend class ResampleCubic; - friend class ResampleAverage; - friend class ResampleHermite; - friend class ResampleSinc; - - struct Settings { - unsigned channels; - unsigned precision; - real frequency; - real volume; - real balance; - - //internal - real intensity; - real intensityInverse; - } settings; - - Resampler *resampler; - inline void write(real channel[]); - - #include "buffer.hpp" - Buffer buffer; - Buffer output; - - inline void adjustVolume(); - inline void adjustBalance(); - inline signed clamp(const unsigned bits, const signed x); -}; - -#include "resample/nearest.hpp" -#include "resample/linear.hpp" -#include "resample/cosine.hpp" -#include "resample/cubic.hpp" -#include "resample/hermite.hpp" -#include "resample/average.hpp" -#include "resample/sinc.hpp" -#include "settings.hpp" - -void DSP::sample(signed channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - buffer.write(c) = (real)channel[c] * settings.intensityInverse; - } - buffer.wroffset++; - resampler->sample(); -} - -bool DSP::pending() { - return output.rdoffset != output.wroffset; -} - -void DSP::read(signed channel[]) { - adjustVolume(); - adjustBalance(); - - for(unsigned c = 0; c < settings.channels; c++) { - channel[c] = clamp(settings.precision, output.read(c) * settings.intensity); - } - output.rdoffset++; -} - -void DSP::write(real channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - output.write(c) = channel[c]; - } - output.wroffset++; -} - -void DSP::adjustVolume() { - for(unsigned c = 0; c < settings.channels; c++) { - output.read(c) *= settings.volume; - } -} - -void DSP::adjustBalance() { - if(settings.channels != 2) return; //TODO: support > 2 channels - if(settings.balance < 0.0) output.read(1) *= 1.0 + settings.balance; - if(settings.balance > 0.0) output.read(0) *= 1.0 - settings.balance; -} - -signed DSP::clamp(const unsigned bits, const signed x) { - const signed b = 1U << (bits - 1); - const signed m = (1U << (bits - 1)) - 1; - return (x > m) ? m : (x < -b) ? -b : x; -} - -void DSP::clear() { - buffer.clear(); - output.clear(); - resampler->clear(); -} - -DSP::DSP() { - setResampler(ResampleEngine::Hermite); - setResamplerFrequency(44100.0); - - setChannels(2); - setPrecision(16); - setFrequency(44100.0); - setVolume(1.0); - setBalance(0.0); - - clear(); -} - -DSP::~DSP() { - if(resampler) delete resampler; -} - -#undef real - -} - -#endif diff --git a/kaijuu/nall/dsp/resample/average.hpp b/kaijuu/nall/dsp/resample/average.hpp deleted file mode 100644 index 867b13bf..00000000 --- a/kaijuu/nall/dsp/resample/average.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleAverage : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline void sampleLinear(); - ResampleAverage(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleAverage::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleAverage::clear() { - fraction = 0.0; -} - -void ResampleAverage::sample() { - //can only average if input frequency >= output frequency - if(step < 1.0) return sampleLinear(); - - fraction += 1.0; - - real scalar = 1.0; - if(fraction > step) scalar = 1.0 - (fraction - step); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) += dsp.buffer.read(c) * scalar; - } - - if(fraction >= step) { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) /= step; - } - dsp.output.wroffset++; - - fraction -= step; - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = dsp.buffer.read(c) * fraction; - } - } - - dsp.buffer.rdoffset++; -} - -void ResampleAverage::sampleLinear() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/cosine.hpp b/kaijuu/nall/dsp/resample/cosine.hpp deleted file mode 100644 index 3363d5f6..00000000 --- a/kaijuu/nall/dsp/resample/cosine.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCosine : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCosine(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCosine::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCosine::clear() { - fraction = 0.0; -} - -void ResampleCosine::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/cubic.hpp b/kaijuu/nall/dsp/resample/cubic.hpp deleted file mode 100644 index bc4cc955..00000000 --- a/kaijuu/nall/dsp/resample/cubic.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCubic : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCubic(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCubic::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCubic::clear() { - fraction = 0.0; -} - -void ResampleCubic::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - real mu = fraction; - - real A = d - c - a + b; - real B = a - b - A; - real C = c - a; - real D = b; - - channel[n] = A * (mu * 3) + B * (mu * 2) + C * mu + D; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/hermite.hpp b/kaijuu/nall/dsp/resample/hermite.hpp deleted file mode 100644 index 0cc9ba0e..00000000 --- a/kaijuu/nall/dsp/resample/hermite.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleHermite : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleHermite(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleHermite::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleHermite::clear() { - fraction = 0.0; -} - -void ResampleHermite::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - const real tension = 0.0; //-1 = low, 0 = normal, +1 = high - const real bias = 0.0; //-1 = left, 0 = even, +1 = right - - real mu1, mu2, mu3, m0, m1, a0, a1, a2, a3; - - mu1 = fraction; - mu2 = mu1 * mu1; - mu3 = mu2 * mu1; - - m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - a0 = +2 * mu3 - 3 * mu2 + 1; - a1 = mu3 - 2 * mu2 + mu1; - a2 = mu3 - mu2; - a3 = -2 * mu3 + 3 * mu2; - - channel[n] = (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c); - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/lib/sinc.hpp b/kaijuu/nall/dsp/resample/lib/sinc.hpp deleted file mode 100644 index 3e953679..00000000 --- a/kaijuu/nall/dsp/resample/lib/sinc.hpp +++ /dev/null @@ -1,600 +0,0 @@ -// If these types are changed to anything other than "float", you should comment out the SSE detection directives below -// so that the SSE code is not used. - -typedef float resample_coeff_t; // note: sizeof(resample_coeff_t) must be == to a power of 2, and not larger than 16 -typedef float resample_samp_t; - - -// ...but don't comment this single RESAMPLE_SSEREGPARM define out when disabling SSE. -#define RESAMPLE_SSEREGPARM - -#if defined(__SSE__) - #define SINCRESAMPLE_USE_SSE 1 - #ifndef __x86_64__ - #undef RESAMPLE_SSEREGPARM - #define RESAMPLE_SSEREGPARM __attribute__((sseregparm)) - #endif -#else - // TODO: altivec here -#endif - -namespace ResampleUtility -{ - inline void kaiser_window(double* io, int count, double beta); - inline void gen_sinc(double* out, int size, double cutoff, double kaiser); - inline void gen_sinc_os(double* out, int size, double cutoff, double kaiser); - inline void normalize(double* io, int size, double gain = 1.0); - - inline void* make_aligned(void* ptr, unsigned boundary); // boundary must be a power of 2 -} - -class SincResampleHR -{ - private: - - inline void Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count); - - unsigned ratio; - unsigned num_convolutions; - - resample_coeff_t *coeffs; - std::vector coeffs_mem; - - // second half of ringbuffer should be copy of first half. - resample_samp_t *rb; - std::vector rb_mem; - - signed rb_readpos; - signed rb_writepos; - signed rb_in; - signed rb_eff_size; - - friend class SincResample; -}; - -class SincResample -{ - public: - - enum - { - QUALITY_LOW = 0, - QUALITY_MEDIUM = 2, - QUALITY_HIGH = 4 - }; - - inline SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality = QUALITY_HIGH); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline void Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min); - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) RESAMPLE_SSEREGPARM; - - unsigned num_convolutions; - unsigned num_phases; - - unsigned step_int; - double step_fract; - - double input_pos_fract; - - - std::vector coeffs; // Pointers into coeff_mem. - std::vector coeff_mem; - - - std::vector rb; // second half should be copy of first half. - signed rb_readpos; - signed rb_writepos; - signed rb_in; - - bool hr_used; - SincResampleHR hr; -}; - - -// -// Code: -// -//#include "resample.hpp" - -#if 0 -namespace bit -{ - inline unsigned round(unsigned x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } -} -#endif - -void SincResampleHR::Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d) -{ - const unsigned align_boundary = 16; - std::vector coeffs_tmp; - double cutoff; // 1.0 = f/2 - - ratio = ratio_arg; - - //num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) + 1) &~ 1; // round up to be even - num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) | 1); - - cutoff = (1.0 / ratio) - (d / num_convolutions); - -//printf("%d %d %.20f\n", ratio, num_convolutions, cutoff); - assert(num_convolutions > ratio); - - - // Generate windowed sinc of POWER - coeffs_tmp.resize(num_convolutions); - //ResampleUtility::gen_sinc(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::gen_sinc_os(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeffs_tmp[0], num_convolutions); - - // Copy from coeffs_tmp to coeffs~ - // We multiply many coefficients at a time in the mac loop, so make sure the last few that don't really - // exist are allocated, zero'd mem. - - coeffs_mem.resize(((num_convolutions + 7) &~ 7) * sizeof(resample_coeff_t) + (align_boundary - 1)); - coeffs = (resample_coeff_t *)ResampleUtility::make_aligned(&coeffs_mem[0], align_boundary); - - - for(unsigned i = 0; i < num_convolutions; i++) - coeffs[i] = coeffs_tmp[i]; - - rb_eff_size = nall::bit::round(num_convolutions * 2) >> 1; - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; - - rb_mem.resize(rb_eff_size * 2 * sizeof(resample_samp_t) + (align_boundary - 1)); - rb = (resample_samp_t *)ResampleUtility::make_aligned(&rb_mem[0], align_boundary); -} - - -inline bool SincResampleHR::output_avail(void) -{ - return(rb_in >= (signed)num_convolutions); -} - -inline void SincResampleHR::write(resample_samp_t sample) -{ - assert(!output_avail()); - - rb[rb_writepos] = sample; - rb[rb_writepos + rb_eff_size] = sample; - rb_writepos = (rb_writepos + 1) & (rb_eff_size - 1); - rb_in++; -} - -resample_samp_t SincResampleHR::mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count) -{ -#if SINCRESAMPLE_USE_SSE - __m128 accum_veca[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - resample_samp_t accum; - - for(unsigned c = 0; c < count; c += 8) - { - for(unsigned i = 0; i < 2; i++) - { - __m128 co[2]; - __m128 w[2]; - - co[i] = _mm_load_ps(&coeff[c + i * 4]); - w[i] = _mm_load_ps(&wave[c + i * 4]); - - w[i] = _mm_mul_ps(w[i], co[i]); - - accum_veca[i] = _mm_add_ps(w[i], accum_veca[i]); - } - } - - __m128 accum_vec = _mm_add_ps(accum_veca[0], accum_veca[1]); //_mm_add_ps(_mm_add_ps(accum_veca[0], accum_veca[1]), _mm_add_ps(accum_veca[2], accum_veca[3])); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); - - return accum; -#else - resample_samp_t accum[4] = { 0, 0, 0, 0 }; - - for(unsigned c = 0; c < count; c+= 4) - { - accum[0] += wave[c + 0] * coeff[c + 0]; - accum[1] += wave[c + 1] * coeff[c + 1]; - accum[2] += wave[c + 2] * coeff[c + 2]; - accum[3] += wave[c + 3] * coeff[c + 3]; - } - - return (accum[0] + accum[1]) + (accum[2] + accum[3]); // don't mess with parentheses(assuming compiler doesn't already, which it may... - -#endif -} - - -resample_samp_t SincResampleHR::read(void) -{ - assert(output_avail()); - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[0], num_convolutions); - - rb_readpos = (rb_readpos + ratio) & (rb_eff_size - 1); - rb_in -= ratio; - - return ret; -} - - -SincResample::SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality) -{ - const struct - { - double beta; - double d; - unsigned pn_nume; - unsigned phases_min; - } qtab[5] = - { - { 5.658, 3.62, 4096, 4 }, - { 6.764, 4.32, 8192, 4 }, - { 7.865, 5.0, 16384, 8 }, - { 8.960, 5.7, 32768, 16 }, - { 10.056, 6.4, 65536, 32 } - }; - - // Sanity checks - assert(ceil(input_rate) > 0); - assert(ceil(output_rate) > 0); - assert(ceil(input_rate / output_rate) <= 1024); - assert(ceil(output_rate / input_rate) <= 1024); - - // The simplistic number-of-phases calculation code doesn't work well enough for when desired_bandwidth is close to 1.0 and when - // upsampling. - assert(desired_bandwidth >= 0.25 && desired_bandwidth < 0.96); - assert(quality >= 0 && quality <= 4); - - hr_used = false; - -#if 1 - // Round down to the nearest multiple of 4(so wave buffer remains aligned) - // It also adjusts the effective intermediate sampling rate up slightly, so that the upper frequencies below f/2 - // aren't overly attenuated so much. In the future, we might want to do an FFT or something to choose the intermediate rate more accurately - // to virtually eliminate over-attenuation. - unsigned ioratio_rd = (unsigned)floor(input_rate / (output_rate * (1.0 + (1.0 - desired_bandwidth) / 2) )) & ~3; - - if(ioratio_rd >= 8) - { - hr.Init(ioratio_rd, desired_bandwidth, qtab[quality].beta, qtab[quality].d); //10.056, 6.4); - hr_used = true; - - input_rate /= ioratio_rd; - } -#endif - - Init(input_rate, output_rate, desired_bandwidth, qtab[quality].beta, qtab[quality].d, qtab[quality].pn_nume, qtab[quality].phases_min); -} - -void SincResample::Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min) -{ - const unsigned max_mult_atatime = 8; // multiply "granularity". must be power of 2. - const unsigned max_mult_minus1 = (max_mult_atatime - 1); - const unsigned conv_alignment_bytes = 16; // must be power of 2 - const double input_to_output_ratio = input_rate / output_rate; - const double output_to_input_ratio = output_rate / input_rate; - double cutoff; // 1.0 = input_rate / 2 - std::vector coeff_init_buffer; - - // Round up num_convolutions to be even. - if(output_rate > input_rate) - num_convolutions = ((unsigned)ceil(d / (1.0 - desired_bandwidth)) + 1) & ~1; - else - num_convolutions = ((unsigned)ceil(d / (output_to_input_ratio * (1.0 - desired_bandwidth))) + 1) & ~1; - - if(output_rate > input_rate) // Upsampling - cutoff = desired_bandwidth; - else // Downsampling - cutoff = output_to_input_ratio * desired_bandwidth; - - // Round up to be even. - num_phases = (std::max(pn_nume / num_convolutions, phases_min) + 1) &~1; - - // Adjust cutoff to account for the multiple phases. - cutoff = cutoff / num_phases; - - assert((num_convolutions & 1) == 0); - assert((num_phases & 1) == 0); - -// fprintf(stderr, "num_convolutions=%u, num_phases=%u, total expected coeff byte size=%lu\n", num_convolutions, num_phases, -// (long)((num_phases + 2) * ((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * sizeof(float) + conv_alignment_bytes)); - - coeff_init_buffer.resize(num_phases * num_convolutions); - - coeffs.resize(num_phases + 1 + 1); - - coeff_mem.resize((num_phases + 1 + 1) * ((num_convolutions + max_mult_minus1) &~ max_mult_minus1) * sizeof(resample_coeff_t) + conv_alignment_bytes); - - // Assign aligned pointers into coeff_mem - { - resample_coeff_t *base_ptr = (resample_coeff_t *)ResampleUtility::make_aligned(&coeff_mem[0], conv_alignment_bytes); - - for(unsigned phase = 0; phase < (num_phases + 1 + 1); phase++) - { - coeffs[phase] = base_ptr + (((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * phase); - } - } - - ResampleUtility::gen_sinc(&coeff_init_buffer[0], num_phases * num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeff_init_buffer[0], num_phases * num_convolutions, num_phases); - - // Reorder coefficients to allow for more efficient convolution. - for(int phase = -1; phase < ((int)num_phases + 1); phase++) - { - for(int conv = 0; conv < (int)num_convolutions; conv++) - { - double coeff; - - if(phase == -1 && conv == 0) - coeff = 0; - else if(phase == (int)num_phases && conv == ((int)num_convolutions - 1)) - coeff = 0; - else - coeff = coeff_init_buffer[conv * num_phases + phase]; - - coeffs[phase + 1][conv] = coeff; - } - } - - // Free a bit of mem - coeff_init_buffer.resize(0); - - step_int = floor(input_to_output_ratio); - step_fract = input_to_output_ratio - step_int; - - input_pos_fract = 0; - - // Do NOT use rb.size() later in the code, since it'll include the padding. - // We should only need one "max_mult_minus1" here, not two, since it won't matter if it over-reads(due to doing "max_mult_atatime" multiplications at a time - // rather than just 1, in which case this over-read wouldn't happen), from the first half into the duplicated half, - // since those corresponding coefficients will be zero anyway; this is just to handle the case of reading off the end of the duplicated half to - // prevent illegal memory accesses. - rb.resize(num_convolutions * 2 + max_mult_minus1); - - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; -} - -resample_samp_t SincResample::mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) -{ - resample_samp_t accum = 0; -#if SINCRESAMPLE_USE_SSE - __m128 accum_vec_a[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - __m128 accum_vec_b[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - for(unsigned c = 0; c < count; c += 8) //8) //4) - { - __m128 coeff_a[2]; - __m128 coeff_b[2]; - __m128 w[2]; - __m128 result_a[2], result_b[2]; - - for(unsigned i = 0; i < 2; i++) - { - coeff_a[i] = _mm_load_ps(&coeffs_a[c + (i * 4)]); - coeff_b[i] = _mm_load_ps(&coeffs_b[c + (i * 4)]); - w[i] = _mm_loadu_ps(&wave[c + (i * 4)]); - - result_a[i] = _mm_mul_ps(coeff_a[i], w[i]); - result_b[i] = _mm_mul_ps(coeff_b[i], w[i]); - - accum_vec_a[i] = _mm_add_ps(result_a[i], accum_vec_a[i]); - accum_vec_b[i] = _mm_add_ps(result_b[i], accum_vec_b[i]); - } - } - - __m128 accum_vec, av_a, av_b; - __m128 mult_a_vec = _mm_set1_ps(1.0 - ffract); - __m128 mult_b_vec = _mm_set1_ps(ffract); - - av_a = _mm_mul_ps(mult_a_vec, /*accum_vec_a[0]);*/ _mm_add_ps(accum_vec_a[0], accum_vec_a[1])); - av_b = _mm_mul_ps(mult_b_vec, /*accum_vec_b[0]);*/ _mm_add_ps(accum_vec_b[0], accum_vec_b[1])); - - accum_vec = _mm_add_ps(av_a, av_b); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); -#else - resample_coeff_t mult_a = 1.0 - ffract; - resample_coeff_t mult_b = ffract; - - for(unsigned c = 0; c < count; c += 4) - { - accum += wave[c + 0] * (coeffs_a[c + 0] * mult_a + coeffs_b[c + 0] * mult_b); - accum += wave[c + 1] * (coeffs_a[c + 1] * mult_a + coeffs_b[c + 1] * mult_b); - accum += wave[c + 2] * (coeffs_a[c + 2] * mult_a + coeffs_b[c + 2] * mult_b); - accum += wave[c + 3] * (coeffs_a[c + 3] * mult_a + coeffs_b[c + 3] * mult_b); - } -#endif - - return accum; -} - -inline bool SincResample::output_avail(void) -{ - return(rb_in >= (int)num_convolutions); -} - -resample_samp_t SincResample::read(void) -{ - assert(output_avail()); - double phase = input_pos_fract * num_phases - 0.5; - signed phase_int = (signed)floor(phase); - double phase_fract = phase - phase_int; - unsigned phase_a = num_phases - 1 - phase_int; - unsigned phase_b = phase_a - 1; - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[phase_a + 1][0], &coeffs[phase_b + 1][0], phase_fract, num_convolutions); - - unsigned int_increment = step_int; - - input_pos_fract += step_fract; - int_increment += floor(input_pos_fract); - input_pos_fract -= floor(input_pos_fract); - - rb_readpos = (rb_readpos + int_increment) % num_convolutions; - rb_in -= int_increment; - - return ret; -} - -inline void SincResample::write(resample_samp_t sample) -{ - assert(!output_avail()); - - if(hr_used) - { - hr.write(sample); - - if(hr.output_avail()) - { - sample = hr.read(); - } - else - { - return; - } - } - - rb[rb_writepos + 0 * num_convolutions] = sample; - rb[rb_writepos + 1 * num_convolutions] = sample; - rb_writepos = (rb_writepos + 1) % num_convolutions; - rb_in++; -} - -void ResampleUtility::kaiser_window( double* io, int count, double beta) -{ - int const accuracy = 24; //16; //12; - - double* end = io + count; - - double beta2 = beta * beta * (double) -0.25; - double to_fract = beta2 / ((double) count * count); - double i = 0; - double rescale = 0; // Doesn't need an initializer, to shut up gcc - - for ( ; io < end; ++io, i += 1 ) - { - double x = i * i * to_fract - beta2; - double u = x; - double k = x + 1; - - double n = 2; - do - { - u *= x / (n * n); - n += 1; - k += u; - } - while ( k <= u * (1 << accuracy) ); - - if ( !i ) - rescale = 1 / k; // otherwise values get large - - *io *= k * rescale; - } -} - -void ResampleUtility::gen_sinc(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 0 ); // size must be even - - int const half_size = size / 2; - double* const mid = &out [half_size]; - - // Generate right half of sinc - for ( int i = 0; i < half_size; i++ ) - { - double angle = (i * 2 + 1) * (M_PI / 2); - mid [i] = sin( angle * cutoff ) / angle; - } - - kaiser_window( mid, half_size, kaiser ); - - // Mirror for left half - for ( int i = 0; i < half_size; i++ ) - out [i] = mid [half_size - 1 - i]; -} - -void ResampleUtility::gen_sinc_os(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 1); // size must be odd - - for(int i = 0; i < size; i++) - { - if(i == (size / 2)) - out[i] = 2 * M_PI * (cutoff / 2); //0.078478; //1.0; //sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - else - out[i] = sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - -// out[i] *= 0.3635819 - 0.4891775 * cos(2 * M_PI * i / (size - 1)) + 0.1365995 * cos(4 * M_PI * i / (size - 1)) - 0.0106411 * cos(6 * M_PI * i / (size - 1)); -//0.42 - 0.5 * cos(2 * M_PI * i / (size - 1)) + 0.08 * cos(4 * M_PI * i / (size - 1)); - -// printf("%d %f\n", i, out[i]); - } - - kaiser_window(&out[size / 2], size / 2 + 1, kaiser); - - // Mirror for left half - for ( int i = 0; i < size / 2; i++ ) - out [i] = out [size - 1 - i]; - -} - -void ResampleUtility::normalize(double* io, int size, double gain) -{ - double sum = 0; - for ( int i = 0; i < size; i++ ) - sum += io [i]; - - double scale = gain / sum; - for ( int i = 0; i < size; i++ ) - io [i] *= scale; -} - -void* ResampleUtility::make_aligned(void* ptr, unsigned boundary) -{ - unsigned char* null_ptr = (unsigned char *)NULL; - unsigned char* uc_ptr = (unsigned char *)ptr; - - uc_ptr += (boundary - ((uc_ptr - null_ptr) & (boundary - 1))) & (boundary - 1); - - //while((uc_ptr - null_ptr) & (boundary - 1)) - // uc_ptr++; - - //printf("%16llx %16llx\n", (unsigned long long)ptr, (unsigned long long)uc_ptr); - - assert((uc_ptr - (unsigned char *)ptr) < boundary && (uc_ptr >= (unsigned char *)ptr)); - - return uc_ptr; -} diff --git a/kaijuu/nall/dsp/resample/linear.hpp b/kaijuu/nall/dsp/resample/linear.hpp deleted file mode 100644 index 3c2dc9e6..00000000 --- a/kaijuu/nall/dsp/resample/linear.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleLinear : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleLinear(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleLinear::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleLinear::clear() { - fraction = 0.0; -} - -void ResampleLinear::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/nearest.hpp b/kaijuu/nall/dsp/resample/nearest.hpp deleted file mode 100644 index 14b401eb..00000000 --- a/kaijuu/nall/dsp/resample/nearest.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleNearest : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleNearest(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleNearest::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleNearest::clear() { - fraction = 0.0; -} - -void ResampleNearest::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = mu < 0.5 ? a : b; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/kaijuu/nall/dsp/resample/sinc.hpp b/kaijuu/nall/dsp/resample/sinc.hpp deleted file mode 100644 index a77a1eeb..00000000 --- a/kaijuu/nall/dsp/resample/sinc.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include "lib/sinc.hpp" - -struct ResampleSinc : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline ResampleSinc(DSP &dsp); - -private: - inline void remakeSinc(); - SincResample *sinc_resampler[8]; -}; - -void ResampleSinc::setFrequency() { - remakeSinc(); -} - -void ResampleSinc::clear() { - remakeSinc(); -} - -void ResampleSinc::sample() { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - sinc_resampler[c]->write(dsp.buffer.read(c)); - } - - if(sinc_resampler[0]->output_avail()) { - do { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = sinc_resampler[c]->read(); - } - dsp.output.wroffset++; - } while(sinc_resampler[0]->output_avail()); - } - - dsp.buffer.rdoffset++; -} - -ResampleSinc::ResampleSinc(DSP &dsp) : Resampler(dsp) { - for(unsigned n = 0; n < 8; n++) sinc_resampler[n] = 0; -} - -void ResampleSinc::remakeSinc() { - assert(dsp.settings.channels < 8); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - if(sinc_resampler[c]) delete sinc_resampler[c]; - sinc_resampler[c] = new SincResample(dsp.settings.frequency, frequency, 0.85, SincResample::QUALITY_HIGH); - } -} - -#endif diff --git a/kaijuu/nall/dsp/settings.hpp b/kaijuu/nall/dsp/settings.hpp deleted file mode 100644 index 3a8f24c6..00000000 --- a/kaijuu/nall/dsp/settings.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -void DSP::setChannels(unsigned channels) { - assert(channels > 0); - buffer.setChannels(channels); - output.setChannels(channels); - settings.channels = channels; -} - -void DSP::setPrecision(unsigned precision) { - settings.precision = precision; - settings.intensity = 1 << (settings.precision - 1); - settings.intensityInverse = 1.0 / settings.intensity; -} - -void DSP::setFrequency(real frequency) { - settings.frequency = frequency; - resampler->setFrequency(); -} - -void DSP::setVolume(real volume) { - settings.volume = volume; -} - -void DSP::setBalance(real balance) { - settings.balance = balance; -} - -void DSP::setResampler(ResampleEngine engine) { - if(resampler) delete resampler; - - switch(engine) { - case ResampleEngine::Nearest: resampler = new ResampleNearest(*this); return; - case ResampleEngine::Linear: resampler = new ResampleLinear (*this); return; - case ResampleEngine::Cosine: resampler = new ResampleCosine (*this); return; - case ResampleEngine::Cubic: resampler = new ResampleCubic (*this); return; - case ResampleEngine::Hermite: resampler = new ResampleHermite(*this); return; - case ResampleEngine::Average: resampler = new ResampleAverage(*this); return; - case ResampleEngine::Sinc: resampler = new ResampleSinc (*this); return; - } - - throw; -} - -void DSP::setResamplerFrequency(real frequency) { - resampler->frequency = frequency; - resampler->setFrequency(); -} - -#endif diff --git a/kaijuu/nall/emulation/famicom.hpp b/kaijuu/nall/emulation/famicom.hpp deleted file mode 100644 index 84275d69..00000000 --- a/kaijuu/nall/emulation/famicom.hpp +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef NALL_EMULATION_FAMICOM_HPP -#define NALL_EMULATION_FAMICOM_HPP - -#include -#include - -namespace nall { - -struct FamicomCartridge { - string markup; - inline FamicomCartridge(const uint8_t *data, unsigned size); - -//private: - unsigned mapper; - unsigned mirror; - unsigned prgrom; - unsigned prgram; - unsigned chrrom; - unsigned chrram; -}; - -FamicomCartridge::FamicomCartridge(const uint8_t *data, unsigned size) { - markup = ""; - if(size < 16) return; - if(data[0] != 'N') return; - if(data[1] != 'E') return; - if(data[2] != 'S') return; - if(data[3] != 26) return; - - markup.append("\n"); - - mapper = ((data[7] >> 4) << 4) | (data[6] >> 4); - mirror = ((data[6] & 0x08) >> 2) | (data[6] & 0x01); - prgrom = data[4] * 0x4000; - chrrom = data[5] * 0x2000; - prgram = 0u; - chrram = chrrom == 0u ? 8192u : 0u; - - markup.append("\n"); - - switch(mapper) { - default: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 1: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 2: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 3: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 4: - //MMC3 - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - //MMC6 - //markup.append(" \n"); - //markup.append(" \n"); - //prgram = 1024; - break; - - case 5: - markup.append(" \n"); - markup.append(" \n"); - prgram = 65536; - break; - - case 7: - markup.append(" \n"); - break; - - case 9: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 10: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 16: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 21: - case 23: - case 25: - //VRC4 - markup.append(" \n"); - markup.append(" \n"); - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 22: - //VRC2 - markup.append(" \n"); - markup.append(" \n"); - markup.append(" \n"); - markup.append(" \n"); - break; - - case 24: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 26: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 34: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 66: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 69: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 73: - markup.append(" \n"); - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - - case 75: - markup.append(" \n"); - markup.append(" \n"); - break; - - case 85: - markup.append(" \n"); - markup.append(" \n"); - prgram = 8192; - break; - } - - markup.append(" \n"); - if(prgrom) markup.append(" \n"); - if(prgram) markup.append(" \n"); - markup.append(" \n"); - - markup.append(" \n"); - if(chrrom) markup.append(" \n"); - if(chrram) markup.append(" \n"); - markup.append(" \n"); - - markup.append("\n"); - markup.transform("'", "\""); -} - -} - -#endif diff --git a/kaijuu/nall/emulation/game-boy-advance.hpp b/kaijuu/nall/emulation/game-boy-advance.hpp deleted file mode 100644 index e16d0949..00000000 --- a/kaijuu/nall/emulation/game-boy-advance.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef NALL_EMULATION_GAME_BOY_ADVANCE_HPP -#define NALL_EMULATION_GAME_BOY_ADVANCE_HPP - -#include -#include -#include - -namespace nall { - -struct GameBoyAdvanceCartridge { - string markup; - string identifiers; - inline GameBoyAdvanceCartridge(const uint8_t *data, unsigned size); -}; - -GameBoyAdvanceCartridge::GameBoyAdvanceCartridge(const uint8_t *data, unsigned size) { - struct Identifier { - string name; - unsigned size; - }; - vector idlist; - idlist.append({"SRAM_V", 6}); - idlist.append({"SRAM_F_V", 8}); - idlist.append({"EEPROM_V", 8}); - idlist.append({"FLASH_V", 7}); - idlist.append({"FLASH512_V", 10}); - idlist.append({"FLASH1M_V", 9}); - - lstring list; - for(auto &id : idlist) { - for(signed n = 0; n < size - 16; n++) { - if(!memcmp(data + n, (const char*)id.name, id.size)) { - const char *p = (const char*)data + n + id.size; - if(p[0] >= '0' && p[0] <= '9' - && p[1] >= '0' && p[1] <= '9' - && p[2] >= '0' && p[2] <= '9' - ) { - char text[16]; - memcpy(text, data + n, id.size + 3); - text[id.size + 3] = 0; - list.appendonce(text); - } - } - } - } - identifiers = list.concatenate(","); - - markup = ""; - - markup.append("\n"); - markup.append("\n"); - markup.append(" \n"); - if(0); - else if(identifiers.beginswith("SRAM_V" )) markup.append(" \n"); - else if(identifiers.beginswith("SRAM_F_V" )) markup.append(" \n"); - else if(identifiers.beginswith("EEPROM_V" )) markup.append(" \n"); - else if(identifiers.beginswith("FLASH_V" )) markup.append(" \n"); - else if(identifiers.beginswith("FLASH512_V")) markup.append(" \n"); - else if(identifiers.beginswith("FLASH1M_V" )) markup.append(" \n"); - if(identifiers.empty() == false) markup.append(" \n"); - - markup.append("\n"); - markup.transform("'", "\""); -} - -} - -#endif diff --git a/kaijuu/nall/emulation/game-boy.hpp b/kaijuu/nall/emulation/game-boy.hpp deleted file mode 100644 index ef1f3da9..00000000 --- a/kaijuu/nall/emulation/game-boy.hpp +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef NALL_EMULATION_GAME_BOY_HPP -#define NALL_EMULATION_GAME_BOY_HPP - -#include -#include - -namespace nall { - -struct GameBoyCartridge { - string markup; - inline GameBoyCartridge(uint8_t *data, unsigned size); - -//private: - struct Information { - string mapper; - bool ram; - bool battery; - bool rtc; - bool rumble; - - unsigned romsize; - unsigned ramsize; - - bool cgb; - bool cgbonly; - } info; -}; - -GameBoyCartridge::GameBoyCartridge(uint8_t *romdata, unsigned romsize) { - markup = ""; - if(romsize < 0x4000) return; - - info.mapper = "unknown"; - info.ram = false; - info.battery = false; - info.rtc = false; - info.rumble = false; - - info.romsize = 0; - info.ramsize = 0; - - unsigned base = romsize - 0x8000; - if(romdata[base + 0x0104] == 0xce && romdata[base + 0x0105] == 0xed - && romdata[base + 0x0106] == 0x66 && romdata[base + 0x0107] == 0x66 - && romdata[base + 0x0108] == 0xcc && romdata[base + 0x0109] == 0x0d - && romdata[base + 0x0147] >= 0x0b && romdata[base + 0x0147] <= 0x0d - ) { - //MMM01 stores header at bottom of image - //flip this around for consistency with all other mappers - uint8_t header[0x8000]; - memcpy(header, romdata + base, 0x8000); - memmove(romdata + 0x8000, romdata, romsize - 0x8000); - memcpy(romdata, header, 0x8000); - } - - info.cgb = (romdata[0x0143] & 0x80) == 0x80; - info.cgbonly = (romdata[0x0143] & 0xc0) == 0xc0; - - switch(romdata[0x0147]) { - case 0x00: info.mapper = "none"; break; - case 0x01: info.mapper = "MBC1"; break; - case 0x02: info.mapper = "MBC1"; info.ram = true; break; - case 0x03: info.mapper = "MBC1"; info.ram = true; info.battery = true; break; - case 0x05: info.mapper = "MBC2"; info.ram = true; break; - case 0x06: info.mapper = "MBC2"; info.ram = true; info.battery = true; break; - case 0x08: info.mapper = "none"; info.ram = true; break; - case 0x09: info.mapper = "MBC0"; info.ram = true; info.battery = true; break; - case 0x0b: info.mapper = "MMM01"; break; - case 0x0c: info.mapper = "MMM01"; info.ram = true; break; - case 0x0d: info.mapper = "MMM01"; info.ram = true; info.battery = true; break; - case 0x0f: info.mapper = "MBC3"; info.rtc = true; info.battery = true; break; - case 0x10: info.mapper = "MBC3"; info.rtc = true; info.ram = true; info.battery = true; break; - case 0x11: info.mapper = "MBC3"; break; - case 0x12: info.mapper = "MBC3"; info.ram = true; break; - case 0x13: info.mapper = "MBC3"; info.ram = true; info.battery = true; break; - case 0x19: info.mapper = "MBC5"; break; - case 0x1a: info.mapper = "MBC5"; info.ram = true; break; - case 0x1b: info.mapper = "MBC5"; info.ram = true; info.battery = true; break; - case 0x1c: info.mapper = "MBC5"; info.rumble = true; break; - case 0x1d: info.mapper = "MBC5"; info.rumble = true; info.ram = true; break; - case 0x1e: info.mapper = "MBC5"; info.rumble = true; info.ram = true; info.battery = true; break; - case 0xfc: break; //Pocket Camera - case 0xfd: break; //Bandai TAMA5 - case 0xfe: info.mapper = "HuC3"; break; - case 0xff: info.mapper = "HuC1"; info.ram = true; info.battery = true; break; - } - - switch(romdata[0x0148]) { default: - case 0x00: info.romsize = 2 * 16 * 1024; break; - case 0x01: info.romsize = 4 * 16 * 1024; break; - case 0x02: info.romsize = 8 * 16 * 1024; break; - case 0x03: info.romsize = 16 * 16 * 1024; break; - case 0x04: info.romsize = 32 * 16 * 1024; break; - case 0x05: info.romsize = 64 * 16 * 1024; break; - case 0x06: info.romsize = 128 * 16 * 1024; break; - case 0x07: info.romsize = 256 * 16 * 1024; break; - case 0x52: info.romsize = 72 * 16 * 1024; break; - case 0x53: info.romsize = 80 * 16 * 1024; break; - case 0x54: info.romsize = 96 * 16 * 1024; break; - } - - switch(romdata[0x0149]) { default: - case 0x00: info.ramsize = 0 * 1024; break; - case 0x01: info.ramsize = 2 * 1024; break; - case 0x02: info.ramsize = 8 * 1024; break; - case 0x03: info.ramsize = 32 * 1024; break; - } - - if(info.mapper == "MBC2") info.ramsize = 512; //512 x 4-bit - - markup = "\n"; - markup.append("\n"); - markup.append(" \n"); - markup.append(" \n"); - if(info.ramsize > 0) markup.append(" \n"); - markup.append("\n"); - markup.transform("'", "\""); -} - -} - -#endif diff --git a/kaijuu/nall/emulation/satellaview.hpp b/kaijuu/nall/emulation/satellaview.hpp deleted file mode 100644 index ddae080c..00000000 --- a/kaijuu/nall/emulation/satellaview.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NALL_EMULATION_SATELLAVIEW_HPP -#define NALL_EMULATION_SATELLAVIEW_HPP - -#include -#include - -namespace nall { - -struct SatellaviewCartridge { - string markup; - inline SatellaviewCartridge(const uint8_t *data, unsigned size); -}; - -SatellaviewCartridge::SatellaviewCartridge(const uint8_t *data, unsigned size) { - markup = ""; - - markup.append("\n"); - markup.append("\n"); - markup.append(" \n"); - markup.append("\n"); - markup.transform("'", "\""); -} - -} - -#endif diff --git a/kaijuu/nall/emulation/sufami-turbo.hpp b/kaijuu/nall/emulation/sufami-turbo.hpp deleted file mode 100644 index 0256360c..00000000 --- a/kaijuu/nall/emulation/sufami-turbo.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef NALL_EMULATION_SUFAMI_TURBO_HPP -#define NALL_EMULATION_SUFAMI_TURBO_HPP - -#include -#include - -namespace nall { - -struct SufamiTurboCartridge { - string markup; - inline SufamiTurboCartridge(const uint8_t *data, unsigned size); -}; - -SufamiTurboCartridge::SufamiTurboCartridge(const uint8_t *data, unsigned size) { - markup = ""; - - if(size < 0x20000) return; //too small to be a valid game? - if(memcmp(data, "BANDAI SFC-ADX", 14)) return; //missing required header? - unsigned romsize = data[0x36] * 0x20000; //128KB - unsigned ramsize = data[0x37] * 0x800; //2KB - bool linkable = data[0x35] != 0x00; //TODO: unconfirmed - - markup.append("\n"); - markup.append("\n"); - markup.append(" \n"); - markup.append(" \n"); - markup.append("\n"); - markup.transform("'", "\""); -} - -} - -#endif diff --git a/kaijuu/nall/emulation/super-famicom-usart.hpp b/kaijuu/nall/emulation/super-famicom-usart.hpp deleted file mode 100644 index 68dea605..00000000 --- a/kaijuu/nall/emulation/super-famicom-usart.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_EMULATION_SUPER_FAMICOM_USART_HPP -#define NALL_EMULATION_SUPER_FAMICOM_USART_HPP - -#include -#include -#include -#include - -#include -#include -#include - -#define usartproc dllexport - -static nall::function usart_quit; -static nall::function usart_usleep; -static nall::function usart_readable; -static nall::function usart_read; -static nall::function usart_writable; -static nall::function usart_write; - -extern "C" usartproc void usart_init( - nall::function quit, - nall::function usleep, - nall::function readable, - nall::function read, - nall::function writable, - nall::function write -) { - usart_quit = quit; - usart_usleep = usleep; - usart_readable = readable; - usart_read = read; - usart_writable = writable; - usart_write = write; -} - -extern "C" usartproc void usart_main(int, char**); - -// - -static nall::serial usart; -static bool usart_is_virtual = true; -static bool usart_sigint = false; - -static bool usart_virtual() { - return usart_is_virtual; -} - -// - -static bool usarthw_quit() { - return usart_sigint; -} - -static void usarthw_usleep(unsigned milliseconds) { - usleep(milliseconds); -} - -static bool usarthw_readable() { - return usart.readable(); -} - -static uint8_t usarthw_read() { - while(true) { - uint8_t buffer[1]; - signed length = usart.read((uint8_t*)&buffer, 1); - if(length > 0) return buffer[0]; - } -} - -static bool usarthw_writable() { - return usart.writable(); -} - -static void usarthw_write(uint8_t data) { - uint8_t buffer[1] = { data }; - usart.write((uint8_t*)&buffer, 1); -} - -static void sigint(int) { - signal(SIGINT, SIG_DFL); - usart_sigint = true; -} - -int main(int argc, char **argv) { - setpriority(PRIO_PROCESS, 0, -20); //requires superuser privileges; otherwise priority = +0 - signal(SIGINT, sigint); - - if(usart.open("/dev/ttyACM0", 57600, true) == false) { - printf("error: unable to open USART hardware device\n"); - return 0; - } - - usart_is_virtual = false; - usart_init(usarthw_quit, usarthw_usleep, usarthw_readable, usarthw_read, usarthw_writable, usarthw_write); - usart_main(argc, argv); - usart.close(); - - return 0; -} - -#endif diff --git a/kaijuu/nall/emulation/super-famicom.hpp b/kaijuu/nall/emulation/super-famicom.hpp deleted file mode 100644 index 597f9893..00000000 --- a/kaijuu/nall/emulation/super-famicom.hpp +++ /dev/null @@ -1,800 +0,0 @@ -#ifndef NALL_EMULATION_SUPER_FAMICOM_HPP -#define NALL_EMULATION_SUPER_FAMICOM_HPP - -#include -#include - -namespace nall { - -struct SuperFamicomCartridge { - string markup; - inline SuperFamicomCartridge(const uint8_t *data, unsigned size); - -//private: - inline void read_header(const uint8_t *data, unsigned size); - inline unsigned find_header(const uint8_t *data, unsigned size); - inline unsigned score_header(const uint8_t *data, unsigned size, unsigned addr); - - enum HeaderField { - CartName = 0x00, - Mapper = 0x15, - RomType = 0x16, - RomSize = 0x17, - RamSize = 0x18, - CartRegion = 0x19, - Company = 0x1a, - Version = 0x1b, - Complement = 0x1c, //inverse checksum - Checksum = 0x1e, - ResetVector = 0x3c, - }; - - enum Mode { - ModeNormal, - ModeBsxSlotted, - ModeBsx, - ModeSufamiTurbo, - ModeSuperGameBoy, - }; - - enum Type { - TypeNormal, - TypeBsxSlotted, - TypeBsxBios, - TypeBsx, - TypeSufamiTurboBios, - TypeSufamiTurbo, - TypeSuperGameBoy1Bios, - TypeSuperGameBoy2Bios, - TypeGameBoy, - TypeUnknown, - }; - - enum Region { - NTSC, - PAL, - }; - - enum MemoryMapper { - LoROM, - HiROM, - ExLoROM, - ExHiROM, - SuperFXROM, - SA1ROM, - SPC7110ROM, - BSCLoROM, - BSCHiROM, - BSXROM, - STROM, - }; - - enum DSP1MemoryMapper { - DSP1Unmapped, - DSP1LoROM1MB, - DSP1LoROM2MB, - DSP1HiROM, - }; - - bool loaded; //is a base cartridge inserted? - unsigned crc32; //crc32 of all cartridges (base+slot(s)) - unsigned rom_size; - unsigned ram_size; - - Mode mode; - Type type; - Region region; - MemoryMapper mapper; - DSP1MemoryMapper dsp1_mapper; - - bool has_bsx_slot; - bool has_superfx; - bool has_sa1; - bool has_srtc; - bool has_sdd1; - bool has_spc7110; - bool has_spc7110rtc; - bool has_cx4; - bool has_dsp1; - bool has_dsp2; - bool has_dsp3; - bool has_dsp4; - bool has_obc1; - bool has_st010; - bool has_st011; - bool has_st018; -}; - -SuperFamicomCartridge::SuperFamicomCartridge(const uint8_t *data, unsigned size) { - markup = ""; - if(size < 0x8000) return; - - read_header(data, size); - - markup = ""; - if(type == TypeGameBoy) return; - if(type == TypeBsx) return; - if(type == TypeSufamiTurbo) return; - - markup.append("\n"); - - const char *range = (rom_size > 0x200000) || (ram_size > 32 * 1024) ? "0000-7fff" : "0000-ffff"; - markup.append("\n"); - - if(type == TypeSuperGameBoy1Bios || type == TypeSuperGameBoy2Bios) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(has_cx4) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(has_spc7110) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(has_sdd1) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(mapper == LoROM) { - markup.append( - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - } - - else if(mapper == HiROM) { - markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - } - - else if(mapper == ExLoROM) { - markup.append( - " \n" - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - } - - else if(mapper == ExHiROM) { - markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - } - - else if(mapper == SuperFXROM) { - markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - markup.append( - " \n" - ); - } - - else if(mapper == SA1ROM) { - markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - if(ram_size > 0) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - markup.append( - " \n" - ); - } - - else if(mapper == BSCLoROM) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(mapper == BSCHiROM) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(mapper == BSXROM) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - else if(mapper == STROM) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_spc7110rtc) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_srtc) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_obc1) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_dsp1) { - //91e87d11e1c30d172556bed2211cce2efa94ba595f58c5d264809ef4d363a97b dsp1.rom - markup.append( - " \n" - " \n" - ); - if(dsp1_mapper == DSP1LoROM1MB) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - if(dsp1_mapper == DSP1LoROM2MB) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - if(dsp1_mapper == DSP1HiROM) markup.append( - " \n" - " \n" - " \n" - " \n" - ); - markup.append( - " \n" - ); - } - - if(has_dsp2) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_dsp3) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_dsp4) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_st010) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_st011) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - if(has_st018) markup.append( - " \n" - " \n" - " \n" - " \n" - " \n" - ); - - markup.append("\n"); - markup.transform("'", "\""); -} - -void SuperFamicomCartridge::read_header(const uint8_t *data, unsigned size) { - type = TypeUnknown; - mapper = LoROM; - dsp1_mapper = DSP1Unmapped; - region = NTSC; - rom_size = size; - ram_size = 0; - - has_bsx_slot = false; - has_superfx = false; - has_sa1 = false; - has_srtc = false; - has_sdd1 = false; - has_spc7110 = false; - has_spc7110rtc = false; - has_cx4 = false; - has_dsp1 = false; - has_dsp2 = false; - has_dsp3 = false; - has_dsp4 = false; - has_obc1 = false; - has_st010 = false; - has_st011 = false; - has_st018 = false; - - //===================== - //detect Game Boy carts - //===================== - - if(size >= 0x0140) { - if(data[0x0104] == 0xce && data[0x0105] == 0xed && data[0x0106] == 0x66 && data[0x0107] == 0x66 - && data[0x0108] == 0xcc && data[0x0109] == 0x0d && data[0x010a] == 0x00 && data[0x010b] == 0x0b) { - type = TypeGameBoy; - return; - } - } - - if(size < 32768) { - type = TypeUnknown; - return; - } - - const unsigned index = find_header(data, size); - const uint8_t mapperid = data[index + Mapper]; - const uint8_t rom_type = data[index + RomType]; - const uint8_t rom_size = data[index + RomSize]; - const uint8_t company = data[index + Company]; - const uint8_t regionid = data[index + CartRegion] & 0x7f; - - ram_size = 1024 << (data[index + RamSize] & 7); - if(ram_size == 1024) ram_size = 0; //no RAM present - - //0, 1, 13 = NTSC; 2 - 12 = PAL - region = (regionid <= 1 || regionid >= 13) ? NTSC : PAL; - - //======================= - //detect BS-X flash carts - //======================= - - if(data[index + 0x13] == 0x00 || data[index + 0x13] == 0xff) { - if(data[index + 0x14] == 0x00) { - const uint8_t n15 = data[index + 0x15]; - if(n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc) { - if(data[index + 0x1a] == 0x33 || data[index + 0x1a] == 0xff) { - type = TypeBsx; - mapper = BSXROM; - region = NTSC; //BS-X only released in Japan - return; - } - } - } - } - - //========================= - //detect Sufami Turbo carts - //========================= - - if(!memcmp(data, "BANDAI SFC-ADX", 14)) { - if(!memcmp(data + 16, "SFC-ADX BACKUP", 14)) { - type = TypeSufamiTurboBios; - } else { - type = TypeSufamiTurbo; - } - mapper = STROM; - region = NTSC; //Sufami Turbo only released in Japan - return; //RAM size handled outside this routine - } - - //========================== - //detect Super Game Boy BIOS - //========================== - - if(!memcmp(data + index, "Super GAMEBOY2", 14)) { - type = TypeSuperGameBoy2Bios; - return; - } - - if(!memcmp(data + index, "Super GAMEBOY", 13)) { - type = TypeSuperGameBoy1Bios; - return; - } - - //===================== - //detect standard carts - //===================== - - //detect presence of BS-X flash cartridge connector (reads extended header information) - if(data[index - 14] == 'Z') { - if(data[index - 11] == 'J') { - uint8_t n13 = data[index - 13]; - if((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9')) { - if(company == 0x33 || (data[index - 10] == 0x00 && data[index - 4] == 0x00)) { - has_bsx_slot = true; - } - } - } - } - - if(has_bsx_slot) { - if(!memcmp(data + index, "Satellaview BS-X ", 21)) { - //BS-X base cart - type = TypeBsxBios; - mapper = BSXROM; - region = NTSC; //BS-X only released in Japan - return; //RAM size handled internally by load_cart_bsx() -> BSXCart class - } else { - type = TypeBsxSlotted; - mapper = (index == 0x7fc0 ? BSCLoROM : BSCHiROM); - region = NTSC; //BS-X slotted cartridges only released in Japan - } - } else { - //standard cart - type = TypeNormal; - - if(index == 0x7fc0 && size >= 0x401000) { - mapper = ExLoROM; - } else if(index == 0x7fc0 && mapperid == 0x32) { - mapper = ExLoROM; - } else if(index == 0x7fc0) { - mapper = LoROM; - } else if(index == 0xffc0) { - mapper = HiROM; - } else { //index == 0x40ffc0 - mapper = ExHiROM; - } - } - - if(mapperid == 0x20 && (rom_type == 0x13 || rom_type == 0x14 || rom_type == 0x15 || rom_type == 0x1a)) { - has_superfx = true; - mapper = SuperFXROM; - ram_size = 1024 << (data[index - 3] & 7); - if(ram_size == 1024) ram_size = 0; - } - - if(mapperid == 0x23 && (rom_type == 0x32 || rom_type == 0x34 || rom_type == 0x35)) { - has_sa1 = true; - mapper = SA1ROM; - } - - if(mapperid == 0x35 && rom_type == 0x55) { - has_srtc = true; - } - - if(mapperid == 0x32 && (rom_type == 0x43 || rom_type == 0x45)) { - has_sdd1 = true; - } - - if(mapperid == 0x3a && (rom_type == 0xf5 || rom_type == 0xf9)) { - has_spc7110 = true; - has_spc7110rtc = (rom_type == 0xf9); - mapper = SPC7110ROM; - } - - if(mapperid == 0x20 && rom_type == 0xf3) { - has_cx4 = true; - } - - if((mapperid == 0x20 || mapperid == 0x21) && rom_type == 0x03) { - has_dsp1 = true; - } - - if(mapperid == 0x30 && rom_type == 0x05 && company != 0xb2) { - has_dsp1 = true; - } - - if(mapperid == 0x31 && (rom_type == 0x03 || rom_type == 0x05)) { - has_dsp1 = true; - } - - if(has_dsp1 == true) { - if((mapperid & 0x2f) == 0x20 && size <= 0x100000) { - dsp1_mapper = DSP1LoROM1MB; - } else if((mapperid & 0x2f) == 0x20) { - dsp1_mapper = DSP1LoROM2MB; - } else if((mapperid & 0x2f) == 0x21) { - dsp1_mapper = DSP1HiROM; - } - } - - if(mapperid == 0x20 && rom_type == 0x05) { - has_dsp2 = true; - } - - if(mapperid == 0x30 && rom_type == 0x05 && company == 0xb2) { - has_dsp3 = true; - } - - if(mapperid == 0x30 && rom_type == 0x03) { - has_dsp4 = true; - } - - if(mapperid == 0x30 && rom_type == 0x25) { - has_obc1 = true; - } - - if(mapperid == 0x30 && rom_type == 0xf6 && rom_size >= 10) { - has_st010 = true; - } - - if(mapperid == 0x30 && rom_type == 0xf6 && rom_size < 10) { - has_st011 = true; - } - - if(mapperid == 0x30 && rom_type == 0xf5) { - has_st018 = true; - } -} - -unsigned SuperFamicomCartridge::find_header(const uint8_t *data, unsigned size) { - unsigned score_lo = score_header(data, size, 0x007fc0); - unsigned score_hi = score_header(data, size, 0x00ffc0); - unsigned score_ex = score_header(data, size, 0x40ffc0); - if(score_ex) score_ex += 4; //favor ExHiROM on images > 32mbits - - if(score_lo >= score_hi && score_lo >= score_ex) { - return 0x007fc0; - } else if(score_hi >= score_ex) { - return 0x00ffc0; - } else { - return 0x40ffc0; - } -} - -unsigned SuperFamicomCartridge::score_header(const uint8_t *data, unsigned size, unsigned addr) { - if(size < addr + 64) return 0; //image too small to contain header at this location? - int score = 0; - - uint16_t resetvector = data[addr + ResetVector] | (data[addr + ResetVector + 1] << 8); - uint16_t checksum = data[addr + Checksum ] | (data[addr + Checksum + 1] << 8); - uint16_t complement = data[addr + Complement ] | (data[addr + Complement + 1] << 8); - - uint8_t resetop = data[(addr & ~0x7fff) | (resetvector & 0x7fff)]; //first opcode executed upon reset - uint8_t mapper = data[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 + complement) == 0xffff && (checksum != 0) && (complement != 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(data[addr + Company] == 0x33) score += 2; //0x33 indicates extended header - if(data[addr + RomType] < 0x08) score++; - if(data[addr + RomSize] < 0x10) score++; - if(data[addr + RamSize] < 0x08) score++; - if(data[addr + CartRegion] < 14) score++; - - if(score < 0) score = 0; - return score; -} - -} - -#endif diff --git a/kaijuu/nall/endian.hpp b/kaijuu/nall/endian.hpp deleted file mode 100644 index 1f834b5b..00000000 --- a/kaijuu/nall/endian.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_ENDIAN_HPP -#define NALL_ENDIAN_HPP - -#include - -#if defined(ENDIAN_LSB) - //little-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201 - #define order_lsb2(a,b) a,b - #define order_lsb3(a,b,c) a,b,c - #define order_lsb4(a,b,c,d) a,b,c,d - #define order_lsb5(a,b,c,d,e) a,b,c,d,e - #define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h - #define order_msb2(a,b) b,a - #define order_msb3(a,b,c) c,b,a - #define order_msb4(a,b,c,d) d,c,b,a - #define order_msb5(a,b,c,d,e) e,d,c,b,a - #define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a -#elif defined(ENDIAN_MSB) - //big-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304 - #define order_lsb2(a,b) b,a - #define order_lsb3(a,b,c) c,b,a - #define order_lsb4(a,b,c,d) d,c,b,a - #define order_lsb5(a,b,c,d,e) e,d,c,b,a - #define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a - #define order_msb2(a,b) a,b - #define order_msb3(a,b,c) a,b,c - #define order_msb4(a,b,c,d) a,b,c,d - #define order_msb5(a,b,c,d,e) a,b,c,d,e - #define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h -#else - #error "Unknown endian. Please specify in nall/intrinsics.hpp" -#endif - -#endif diff --git a/kaijuu/nall/file.hpp b/kaijuu/nall/file.hpp deleted file mode 100644 index 8a751041..00000000 --- a/kaijuu/nall/file.hpp +++ /dev/null @@ -1,322 +0,0 @@ -#ifndef NALL_FILE_HPP -#define NALL_FILE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - inline FILE* fopen_utf8(const string &utf8_filename, const char *mode) { - #if !defined(_WIN32) - return fopen(utf8_filename, mode); - #else - return _wfopen(utf16_t(utf8_filename), utf16_t(mode)); - #endif - } - - struct file { - enum class mode : unsigned { read, write, modify, append, readwrite = modify, writeread = append }; - enum class index : unsigned { absolute, relative }; - enum class time : unsigned { create, modify, access }; - - static bool copy(const string &sourcename, const string &targetname) { - file rd, wr; - if(rd.open(sourcename, mode::read) == false) return false; - if(wr.open(targetname, mode::write) == false) return false; - for(unsigned n = 0; n < rd.size(); n++) wr.write(rd.read()); - return true; - } - - static bool move(const string &sourcename, const string &targetname) { - #if !defined(_WIN32) - return rename(sourcename, targetname) == 0; - #else - return _wrename(utf16_t(sourcename), utf16_t(targetname)) == 0; - #endif - } - - static bool remove(const string &filename) { - return unlink(filename) == 0; - } - - static bool truncate(const string &filename, unsigned size) { - #if !defined(_WIN32) - return truncate(filename, size) == 0; - #else - bool result = false; - FILE *fp = fopen(filename, "rb+"); - if(fp) { - result = _chsize(fileno(fp), size) == 0; - fclose(fp); - } - return result; - #endif - } - - static vector read(const string &filename) { - vector memory; - file fp; - if(fp.open(filename, mode::read)) { - memory.resize(fp.size()); - fp.read(memory.data(), memory.size()); - } - return memory; - } - - static bool read(const string &filename, uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::read) == false) return false; - fp.read(data, size); - fp.close(); - return true; - } - - static bool write(const string &filename, const uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.write(data, size); - fp.close(); - return true; - } - - uint8_t read() { - if(!fp) return 0xff; //file not open - if(file_mode == mode::write) return 0xff; //reads not permitted - if(file_offset >= file_size) return 0xff; //cannot read past end of file - buffer_sync(); - return buffer[(file_offset++) & buffer_mask]; - } - - uintmax_t readl(unsigned length = 1) { - uintmax_t data = 0; - for(int i = 0; i < length; i++) { - data |= (uintmax_t)read() << (i << 3); - } - return data; - } - - uintmax_t readm(unsigned length = 1) { - uintmax_t data = 0; - while(length--) { - data <<= 8; - data |= read(); - } - return data; - } - - void read(uint8_t *buffer, unsigned length) { - while(length--) *buffer++ = read(); - } - - void write(uint8_t data) { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //writes not permitted - buffer_sync(); - buffer[(file_offset++) & buffer_mask] = data; - buffer_dirty = true; - if(file_offset > file_size) file_size = file_offset; - } - - void writel(uintmax_t data, unsigned length = 1) { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) { - for(int i = length - 1; i >= 0; i--) { - write(data >> (i << 3)); - } - } - - void write(const uint8_t *buffer, unsigned length) { - while(length--) write(*buffer++); - } - - template void print(Args... args) { - string data(args...); - const char *p = data; - while(*p) write(*p++); - } - - void flush() { - buffer_flush(); - fflush(fp); - } - - void seek(int offset, index index_ = index::absolute) { - if(!fp) return; //file not open - buffer_flush(); - - uintmax_t req_offset = file_offset; - switch(index_) { - case index::absolute: req_offset = offset; break; - case index::relative: req_offset += offset; break; - } - - if(req_offset < 0) req_offset = 0; //cannot seek before start of file - if(req_offset > file_size) { - if(file_mode == mode::read) { //cannot seek past end of file - req_offset = file_size; - } else { //pad file to requested location - file_offset = file_size; - while(file_size < req_offset) write(0x00); - } - } - - file_offset = req_offset; - } - - unsigned offset() const { - if(!fp) return 0; //file not open - return file_offset; - } - - unsigned size() const { - if(!fp) return 0; //file not open - return file_size; - } - - bool truncate(unsigned size) { - if(!fp) return false; //file not open - #if !defined(_WIN32) - return ftruncate(fileno(fp), size) == 0; - #else - return _chsize(fileno(fp), size) == 0; - #endif - } - - bool end() { - if(!fp) return true; //file not open - return file_offset >= file_size; - } - - static bool exists(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - return stat64(filename, &data) == 0; - #else - struct __stat64 data; - return _wstat64(utf16_t(filename), &data) == 0; - #endif - } - - static uintmax_t size(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - return S_ISREG(data.st_mode) ? data.st_size : 0u; - } - - static time_t timestamp(const string &filename, file::time mode = file::time::create) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - switch(mode) { default: - case file::time::create: return data.st_ctime; - case file::time::modify: return data.st_mtime; - case file::time::access: return data.st_atime; - } - } - - bool open() const { - return fp; - } - - bool open(const string &filename, mode mode_) { - if(fp) return false; - - switch(file_mode = mode_) { - #if !defined(_WIN32) - case mode::read: fp = fopen(filename, "rb" ); break; - case mode::write: fp = fopen(filename, "wb+"); break; //need read permission for buffering - case mode::readwrite: fp = fopen(filename, "rb+"); break; - case mode::writeread: fp = fopen(filename, "wb+"); break; - #else - case mode::read: fp = _wfopen(utf16_t(filename), L"rb" ); break; - case mode::write: fp = _wfopen(utf16_t(filename), L"wb+"); break; - case mode::readwrite: fp = _wfopen(utf16_t(filename), L"rb+"); break; - case mode::writeread: fp = _wfopen(utf16_t(filename), L"wb+"); break; - #endif - } - if(!fp) return false; - buffer_offset = -1; //invalidate buffer - file_offset = 0; - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - return true; - } - - void close() { - if(!fp) return; - buffer_flush(); - fclose(fp); - fp = 0; - } - - file() { - memset(buffer, 0, sizeof buffer); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - fp = 0; - file_offset = 0; - file_size = 0; - file_mode = mode::read; - } - - ~file() { - close(); - } - - file& operator=(const file&) = delete; - file(const file&) = delete; - - private: - enum { buffer_size = 1 << 12, buffer_mask = buffer_size - 1 }; - char buffer[buffer_size]; - int buffer_offset; - bool buffer_dirty; - FILE *fp; - unsigned file_offset; - unsigned file_size; - mode file_mode; - - void buffer_sync() { - if(!fp) return; //file not open - if(buffer_offset != (file_offset & ~buffer_mask)) { - buffer_flush(); - buffer_offset = file_offset & ~buffer_mask; - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fread(buffer, 1, length, fp); - } - } - - void buffer_flush() { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //buffer cannot be written to - if(buffer_offset < 0) return; //buffer unused - if(buffer_dirty == false) return; //buffer unmodified since read - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fwrite(buffer, 1, length, fp); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - } - }; -} - -#endif diff --git a/kaijuu/nall/filemap.hpp b/kaijuu/nall/filemap.hpp deleted file mode 100644 index f57d933c..00000000 --- a/kaijuu/nall/filemap.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifndef NALL_FILEMAP_HPP -#define NALL_FILEMAP_HPP - -#include -#include -#include - -#include -#include -#if defined(_WIN32) - #include -#else - #include - #include - #include - #include - #include -#endif - -namespace nall { - class filemap { - public: - enum class mode : unsigned { read, write, readwrite, writeread }; - - bool open() const { return p_open(); } - bool open(const char *filename, mode mode_) { return p_open(filename, mode_); } - void close() { return p_close(); } - unsigned size() const { return p_size; } - uint8_t* data() { return p_handle; } - const uint8_t* data() const { return p_handle; } - filemap() : p_size(0), p_handle(0) { p_ctor(); } - filemap(const char *filename, mode mode_) : p_size(0), p_handle(0) { p_ctor(); p_open(filename, mode_); } - ~filemap() { p_dtor(); } - - private: - unsigned p_size; - uint8_t *p_handle; - - #if defined(_WIN32) - //============= - //MapViewOfFile - //============= - - HANDLE p_filehandle, p_maphandle; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int desired_access, creation_disposition, flprotect, map_access; - - switch(mode_) { - default: return false; - case mode::read: - desired_access = GENERIC_READ; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READONLY; - map_access = FILE_MAP_READ; - break; - case mode::write: - //write access requires read access - desired_access = GENERIC_WRITE; - creation_disposition = CREATE_ALWAYS; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::readwrite: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::writeread: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = CREATE_NEW; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - } - - p_filehandle = CreateFileW(utf16_t(filename), desired_access, FILE_SHARE_READ, NULL, - creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL); - if(p_filehandle == INVALID_HANDLE_VALUE) return false; - - p_size = GetFileSize(p_filehandle, NULL); - - p_maphandle = CreateFileMapping(p_filehandle, NULL, flprotect, 0, p_size, NULL); - if(p_maphandle == INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - return false; - } - - p_handle = (uint8_t*)MapViewOfFile(p_maphandle, map_access, 0, 0, p_size); - return p_handle; - } - - void p_close() { - if(p_handle) { - UnmapViewOfFile(p_handle); - p_handle = 0; - } - - if(p_maphandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_maphandle); - p_maphandle = INVALID_HANDLE_VALUE; - } - - if(p_filehandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - } - } - - void p_ctor() { - p_filehandle = INVALID_HANDLE_VALUE; - p_maphandle = INVALID_HANDLE_VALUE; - } - - void p_dtor() { - close(); - } - - #else - //==== - //mmap - //==== - - int p_fd; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int open_flags, mmap_flags; - - switch(mode_) { - default: return false; - case mode::read: - open_flags = O_RDONLY; - mmap_flags = PROT_READ; - break; - case mode::write: - open_flags = O_RDWR | O_CREAT; //mmap() requires read access - mmap_flags = PROT_WRITE; - break; - case mode::readwrite: - open_flags = O_RDWR; - mmap_flags = PROT_READ | PROT_WRITE; - break; - case mode::writeread: - open_flags = O_RDWR | O_CREAT; - mmap_flags = PROT_READ | PROT_WRITE; - break; - } - - p_fd = ::open(filename, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); - if(p_fd < 0) return false; - - struct stat p_stat; - fstat(p_fd, &p_stat); - p_size = p_stat.st_size; - - p_handle = (uint8_t*)mmap(0, p_size, mmap_flags, MAP_SHARED, p_fd, 0); - if(p_handle == MAP_FAILED) { - p_handle = 0; - ::close(p_fd); - p_fd = -1; - return false; - } - - return p_handle; - } - - void p_close() { - if(p_handle) { - munmap(p_handle, p_size); - p_handle = 0; - } - - if(p_fd >= 0) { - ::close(p_fd); - p_fd = -1; - } - } - - void p_ctor() { - p_fd = -1; - } - - void p_dtor() { - p_close(); - } - - #endif - }; -} - -#endif diff --git a/kaijuu/nall/function.hpp b/kaijuu/nall/function.hpp deleted file mode 100644 index ca574b8c..00000000 --- a/kaijuu/nall/function.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef NALL_FUNCTION_HPP -#define NALL_FUNCTION_HPP - -namespace nall { - template class function; - - template class function { - struct container { - virtual R operator()(P... p) const = 0; - virtual container* copy() const = 0; - virtual ~container() {} - } *callback; - - struct global : container { - R (*function)(P...); - R operator()(P... p) const { return function(std::forward

(p)...); } - container* copy() const { return new global(function); } - global(R (*function)(P...)) : function(function) {} - }; - - template struct member : container { - R (C::*function)(P...); - C *object; - R operator()(P... p) const { return (object->*function)(std::forward

(p)...); } - container* copy() const { return new member(function, object); } - member(R (C::*function)(P...), C *object) : function(function), object(object) {} - }; - - template struct lambda : container { - mutable L object; - R operator()(P... p) const { return object(std::forward

(p)...); } - container* copy() const { return new lambda(object); } - lambda(const L& object) : object(object) {} - }; - - public: - operator bool() const { return callback; } - R operator()(P... p) const { return (*callback)(std::forward

(p)...); } - void reset() { if(callback) { delete callback; callback = nullptr; } } - - function& operator=(const function &source) { - if(this != &source) { - if(callback) { delete callback; callback = nullptr; } - if(source.callback) callback = source.callback->copy(); - } - return *this; - } - - function(const function &source) : callback(nullptr) { operator=(source); } - function() : callback(nullptr) {} - function(void *function) : callback(nullptr) { if(function) callback = new global((R (*)(P...))function); } - function(R (*function)(P...)) { callback = new global(function); } - template function(R (C::*function)(P...), C *object) { callback = new member(function, object); } - template function(R (C::*function)(P...) const, C *object) { callback = new member((R (C::*)(P...))function, object); } - template function(const L& object) { callback = new lambda(object); } - ~function() { if(callback) delete callback; } - }; -} - -#endif diff --git a/kaijuu/nall/gzip.hpp b/kaijuu/nall/gzip.hpp deleted file mode 100644 index a72a3faf..00000000 --- a/kaijuu/nall/gzip.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef NALL_GZIP_HPP -#define NALL_GZIP_HPP - -#include -#include - -namespace nall { - -struct gzip { - string filename; - uint8_t *data; - unsigned size; - - inline bool decompress(const string &filename); - inline bool decompress(const uint8_t *data, unsigned size); - - inline gzip(); - inline ~gzip(); -}; - -bool gzip::decompress(const string &filename) { - if(auto memory = file::read(filename)) { - return decompress(memory.data(), memory.size()); - } - return false; -} - -bool gzip::decompress(const uint8_t *data, unsigned size) { - if(size < 18) return false; - if(data[0] != 0x1f) return false; - if(data[1] != 0x8b) return false; - unsigned cm = data[2]; - unsigned flg = data[3]; - unsigned mtime = data[4]; - mtime |= data[5] << 8; - mtime |= data[6] << 16; - mtime |= data[7] << 24; - unsigned xfl = data[8]; - unsigned os = data[9]; - unsigned p = 10; - unsigned isize = data[size - 4]; - isize |= data[size - 3] << 8; - isize |= data[size - 2] << 16; - isize |= data[size - 1] << 24; - filename = ""; - - if(flg & 0x04) { //FEXTRA - unsigned xlen = data[p + 0]; - xlen |= data[p + 1] << 8; - p += 2 + xlen; - } - - if(flg & 0x08) { //FNAME - char buffer[PATH_MAX]; - for(unsigned n = 0; n < PATH_MAX; n++, p++) { - buffer[n] = data[p]; - if(data[p] == 0) break; - } - if(data[p++]) return false; - filename = buffer; - } - - if(flg & 0x10) { //FCOMMENT - while(data[p++]); - } - - if(flg & 0x02) { //FHCRC - p += 2; - } - - this->size = isize; - this->data = new uint8_t[this->size]; - return inflate(this->data, this->size, data + p, size - p - 8); -} - -gzip::gzip() : data(nullptr) { -} - -gzip::~gzip() { - if(data) delete[] data; -} - -} - -#endif diff --git a/kaijuu/nall/http.hpp b/kaijuu/nall/http.hpp deleted file mode 100644 index 48aeb097..00000000 --- a/kaijuu/nall/http.hpp +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef NALL_HTTP_HPP -#define NALL_HTTP_HPP - -#if !defined(_WIN32) - #include - #include - #include - #include -#else - #include - #include - #include -#endif - -#include -#include - -namespace nall { - -struct http { - string hostname; - addrinfo *serverinfo; - int serversocket; - string header; - - inline void download(const string &path, uint8_t *&data, unsigned &size) { - data = 0; - size = 0; - - send({ - "GET ", path, " HTTP/1.1\r\n" - "Host: ", hostname, "\r\n" - "Connection: close\r\n" - "\r\n" - }); - - header = downloadHeader(); - downloadContent(data, size); - } - - inline bool connect(string host, unsigned port) { - hostname = host; - - addrinfo hints; - memset(&hints, 0, sizeof(addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - - int status = getaddrinfo(hostname, string(port), &hints, &serverinfo); - if(status != 0) return false; - - serversocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); - if(serversocket == -1) return false; - - int result = ::connect(serversocket, serverinfo->ai_addr, serverinfo->ai_addrlen); - if(result == -1) return false; - - return true; - } - - inline bool send(const string &data) { - return send((const uint8_t*)(const char*)data, data.length()); - } - - inline bool send(const uint8_t *data, unsigned size) { - while(size) { - int length = ::send(serversocket, (const char*)data, size, 0); - if(length == -1) return false; - data += length; - size -= length; - } - return true; - } - - inline string downloadHeader() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n\r\n") == false); - return output; - } - - inline string downloadChunkLength() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n") == false); - return output; - } - - inline void downloadContent(uint8_t *&data, unsigned &size) { - unsigned capacity = 0; - - if(header.iposition("\r\nTransfer-Encoding: chunked\r\n")) { - while(true) { - unsigned length = hex(downloadChunkLength()); - if(length == 0) break; - capacity += length; - data = (uint8_t*)realloc(data, capacity); - - char buffer[length]; - while(length) { - int packetlength = recv(serversocket, buffer, length, 0); - if(packetlength <= 0) break; - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } - } else if(auto position = header.iposition("\r\nContent-Length: ")) { - unsigned length = decimal((const char*)header + position() + 18); - while(length) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, min(256, length), 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } else { - while(true) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, 256, 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - } - } - - data = (uint8_t*)realloc(data, capacity + 1); - data[capacity] = 0; - } - - inline void disconnect() { - close(serversocket); - freeaddrinfo(serverinfo); - serverinfo = 0; - serversocket = -1; - } - - #ifdef _WIN32 - inline int close(int sock) { - return closesocket(sock); - } - - inline http() { - int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) { - WSADATA wsaData; - if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - WSACleanup(); - return; - } - } else { - close(sock); - } - } - #endif -}; - -} - -#endif diff --git a/kaijuu/nall/image.hpp b/kaijuu/nall/image.hpp deleted file mode 100644 index 552a3e30..00000000 --- a/kaijuu/nall/image.hpp +++ /dev/null @@ -1,506 +0,0 @@ -#ifndef NALL_IMAGE_HPP -#define NALL_IMAGE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - -struct image { - uint8_t *data; - unsigned width; - unsigned height; - unsigned pitch; - - bool endian; //0 = little, 1 = big - unsigned depth; - unsigned stride; - - struct Channel { - uint64_t mask; - unsigned depth; - unsigned shift; - } alpha, red, green, blue; - - typedef double (*interpolation)(double, double, double, double, double); - static inline unsigned bitDepth(uint64_t color); - static inline unsigned bitShift(uint64_t color); - static inline uint64_t normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth); - - inline image& operator=(const image &source); - inline image& operator=(image &&source); - inline image(const image &source); - inline image(image &&source); - inline image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline image(const string &filename); - inline image(const uint8_t *data, unsigned size); - inline image(); - inline ~image(); - - inline uint64_t read(const uint8_t *data) const; - inline void write(uint8_t *data, uint64_t value) const; - - inline void free(); - inline bool empty() const; - inline void allocate(unsigned width, unsigned height); - inline void clear(uint64_t color); - inline bool load(const string &filename); -//inline bool loadBMP(const uint8_t *data, unsigned size); - inline bool loadPNG(const uint8_t *data, unsigned size); - inline void scale(unsigned width, unsigned height, interpolation op); - inline void transform(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline void alphaBlend(uint64_t alphaColor); - -protected: - inline uint64_t interpolate(double mu, const uint64_t *s, interpolation op); - inline void scaleX(unsigned width, interpolation op); - inline void scaleY(unsigned height, interpolation op); - inline bool loadBMP(const string &filename); - inline bool loadPNG(const string &filename); -}; - -//static - -unsigned image::bitDepth(uint64_t color) { - unsigned depth = 0; - if(color) while((color & 1) == 0) color >>= 1; - while((color & 1) == 1) { color >>= 1; depth++; } - return depth; -} - -unsigned image::bitShift(uint64_t color) { - unsigned shift = 0; - if(color) while((color & 1) == 0) { color >>= 1; shift++; } - return shift; -} - -uint64_t image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) { - while(sourceDepth < targetDepth) { - color = (color << sourceDepth) | color; - sourceDepth += sourceDepth; - } - if(targetDepth < sourceDepth) color >>= (sourceDepth - targetDepth); - return color; -} - -//public - -image& image::operator=(const image &source) { - free(); - - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = new uint8_t[width * height * stride]; - memcpy(data, source.data, width * height * stride); - return *this; -} - -image& image::operator=(image &&source) { - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = source.data; - source.data = nullptr; - return *this; -} - -image::image(const image &source) : data(nullptr) { - operator=(source); -} - -image::image(image &&source) : data(nullptr) { - operator=(std::forward(source)); -} - -image::image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = endian; - this->depth = depth; - this->stride = (depth / 8) + ((depth & 7) > 0); - - alpha.mask = alphaMask, red.mask = redMask, green.mask = greenMask, blue.mask = blueMask; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::image(const string &filename) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - load(filename); -} - -image::image(const uint8_t *data, unsigned size) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - loadPNG(data, size); -} - -image::image() : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::~image() { - free(); -} - -uint64_t image::read(const uint8_t *data) const { - uint64_t result = 0; - if(endian == 0) { - for(signed n = stride - 1; n >= 0; n--) result = (result << 8) | data[n]; - } else { - for(signed n = 0; n < stride; n++) result = (result << 8) | data[n]; - } - return result; -} - -void image::write(uint8_t *data, uint64_t value) const { - if(endian == 0) { - for(signed n = 0; n < stride; n++) { data[n] = value; value >>= 8; } - } else { - for(signed n = stride - 1; n >= 0; n--) { data[n] = value; value >>= 8; } - } -} - -void image::free() { - if(data) delete[] data; - data = nullptr; -} - -bool image::empty() const { - if(data == nullptr) return true; - if(width == 0 || height == 0) return true; - return false; -} - -void image::allocate(unsigned width, unsigned height) { - if(data != nullptr && this->width == width && this->height == height) return; - free(); - data = new uint8_t[width * height * stride](); - pitch = width * stride; - this->width = width; - this->height = height; -} - -void image::clear(uint64_t color) { - uint8_t *dp = data; - for(unsigned n = 0; n < width * height; n++) { - write(dp, color); - dp += stride; - } -} - -bool image::load(const string &filename) { - if(loadBMP(filename) == true) return true; - if(loadPNG(filename) == true) return true; - return false; -} - -void image::scale(unsigned outputWidth, unsigned outputHeight, interpolation op) { - if(width != outputWidth) scaleX(outputWidth, op); - if(height != outputHeight) scaleY(outputHeight, op); -} - -void image::transform(bool outputEndian, unsigned outputDepth, uint64_t outputAlphaMask, uint64_t outputRedMask, uint64_t outputGreenMask, uint64_t outputBlueMask) { - image output(outputEndian, outputDepth, outputAlphaMask, outputRedMask, outputGreenMask, outputBlueMask); - output.allocate(width, height); - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = output.data + output.pitch * y; - uint8_t *sp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(sp); - sp += stride; - - uint64_t a = (color & alpha.mask) >> alpha.shift; - uint64_t r = (color & red.mask) >> red.shift; - uint64_t g = (color & green.mask) >> green.shift; - uint64_t b = (color & blue.mask) >> blue.shift; - - a = normalize(a, alpha.depth, output.alpha.depth); - r = normalize(r, red.depth, output.red.depth); - g = normalize(g, green.depth, output.green.depth); - b = normalize(b, blue.depth, output.blue.depth); - - output.write(dp, (a << output.alpha.shift) | (r << output.red.shift) | (g << output.green.shift) | (b << output.blue.shift)); - dp += output.stride; - } - } - - operator=(std::move(output)); -} - -void image::alphaBlend(uint64_t alphaColor) { - uint64_t alphaR = (alphaColor & red.mask) >> red.shift; - uint64_t alphaG = (alphaColor & green.mask) >> green.shift; - uint64_t alphaB = (alphaColor & blue.mask) >> blue.shift; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(dp); - - uint64_t colorA = (color & alpha.mask) >> alpha.shift; - uint64_t colorR = (color & red.mask) >> red.shift; - uint64_t colorG = (color & green.mask) >> green.shift; - uint64_t colorB = (color & blue.mask) >> blue.shift; - double alphaScale = (double)colorA / (double)((1 << alpha.depth) - 1); - - colorA = (1 << alpha.depth) - 1; - colorR = (colorR * alphaScale) + (alphaR * (1.0 - alphaScale)); - colorG = (colorG * alphaScale) + (alphaG * (1.0 - alphaScale)); - colorB = (colorB * alphaScale) + (alphaB * (1.0 - alphaScale)); - - write(dp, (colorA << alpha.shift) | (colorR << red.shift) | (colorG << green.shift) | (colorB << blue.shift)); - dp += stride; - } - } -} - -//protected - -uint64_t image::interpolate(double mu, const uint64_t *s, double (*op)(double, double, double, double, double)) { - uint64_t aa = (s[0] & alpha.mask) >> alpha.shift, ar = (s[0] & red.mask) >> red.shift, - ag = (s[0] & green.mask) >> green.shift, ab = (s[0] & blue.mask) >> blue.shift; - uint64_t ba = (s[1] & alpha.mask) >> alpha.shift, br = (s[1] & red.mask) >> red.shift, - bg = (s[1] & green.mask) >> green.shift, bb = (s[1] & blue.mask) >> blue.shift; - uint64_t ca = (s[2] & alpha.mask) >> alpha.shift, cr = (s[2] & red.mask) >> red.shift, - cg = (s[2] & green.mask) >> green.shift, cb = (s[2] & blue.mask) >> blue.shift; - uint64_t da = (s[3] & alpha.mask) >> alpha.shift, dr = (s[3] & red.mask) >> red.shift, - dg = (s[3] & green.mask) >> green.shift, db = (s[3] & blue.mask) >> blue.shift; - - int64_t A = op(mu, aa, ba, ca, da); - int64_t R = op(mu, ar, br, cr, dr); - int64_t G = op(mu, ag, bg, cg, dg); - int64_t B = op(mu, ab, bb, cb, db); - - A = max(0, min(A, (1 << alpha.depth) - 1)); - R = max(0, min(R, (1 << red.depth) - 1)); - G = max(0, min(G, (1 << green.depth) - 1)); - B = max(0, min(B, (1 << blue.depth) - 1)); - - return (A << alpha.shift) | (R << red.shift) | (G << green.shift) | (B << blue.shift); -} - -void image::scaleX(unsigned outputWidth, interpolation op) { - uint8_t *outputData = new uint8_t[outputWidth * height * stride]; - unsigned outputPitch = outputWidth * stride; - double step = (double)width / (double)outputWidth; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = outputData + outputPitch * y; - uint8_t *sp = data + pitch * y; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; //B,C (0,1) = center of kernel { 0, 0, 1, 2 } - s[1] = s[0]; - s[2] = sp + stride < terminal ? read(sp += stride) : s[1]; - s[3] = sp + stride < terminal ? read(sp += stride) : s[2]; - - for(unsigned x = 0; x < width; x++) { - while(fraction <= 1.0) { - if(dp >= outputData + outputPitch * height) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += stride; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + stride < terminal) s[3] = read(sp += stride); - fraction -= 1.0; - } - } - - free(); - data = outputData; - width = outputWidth; - pitch = width * stride; -} - -void image::scaleY(unsigned outputHeight, interpolation op) { - uint8_t *outputData = new uint8_t[width * outputHeight * stride]; - double step = (double)height / (double)outputHeight; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned x = 0; x < width; x++) { - uint8_t *dp = outputData + stride * x; - uint8_t *sp = data + stride * x; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; - s[1] = s[0]; - s[2] = sp + pitch < terminal ? read(sp += pitch) : s[1]; - s[3] = sp + pitch < terminal ? read(sp += pitch) : s[2]; - - for(unsigned y = 0; y < height; y++) { - while(fraction <= 1.0) { - if(dp >= outputData + pitch * outputHeight) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += pitch; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + pitch < terminal) s[3] = read(sp += pitch); - fraction -= 1.0; - } - } - - free(); - data = outputData; - height = outputHeight; -} - -bool image::loadBMP(const string &filename) { - uint32_t *outputData; - unsigned outputWidth, outputHeight; - if(bmp::read(filename, outputData, outputWidth, outputHeight) == false) return false; - - allocate(outputWidth, outputHeight); - const uint32_t *sp = outputData; - uint8_t *dp = data; - - for(unsigned y = 0; y < outputHeight; y++) { - for(unsigned x = 0; x < outputWidth; x++) { - uint32_t color = *sp++; - uint64_t a = normalize((uint8_t)(color >> 24), 8, alpha.depth); - uint64_t r = normalize((uint8_t)(color >> 16), 8, red.depth); - uint64_t g = normalize((uint8_t)(color >> 8), 8, green.depth); - uint64_t b = normalize((uint8_t)(color >> 0), 8, blue.depth); - write(dp, (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift)); - dp += stride; - } - } - - delete[] outputData; - return true; -} - -bool image::loadPNG(const uint8_t *pngData, unsigned pngSize) { - png source; - if(source.decode(pngData, pngSize) == false) return false; - - allocate(source.info.width, source.info.height); - const uint8_t *sp = source.data; - uint8_t *dp = data; - - auto decode = [&]() -> uint64_t { - uint64_t p, r, g, b, a; - - switch(source.info.colorType) { - case 0: //L - r = g = b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 2: //R,G,B - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 3: //P - p = source.readbits(sp); - r = source.info.palette[p][0]; - g = source.info.palette[p][1]; - b = source.info.palette[p][2]; - a = (1 << source.info.bitDepth) - 1; - break; - case 4: //L,A - r = g = b = source.readbits(sp); - a = source.readbits(sp); - break; - case 6: //R,G,B,A - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = source.readbits(sp); - break; - } - - a = normalize(a, source.info.bitDepth, alpha.depth); - r = normalize(r, source.info.bitDepth, red.depth); - g = normalize(g, source.info.bitDepth, green.depth); - b = normalize(b, source.info.bitDepth, blue.depth); - - return (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift); - }; - - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - write(dp, decode()); - dp += stride; - } - } - - return true; -} - -bool image::loadPNG(const string &filename) { - filemap map; - if(map.open(filename, filemap::mode::read) == false) return false; - return loadPNG(map.data(), map.size()); -} - -} - -#endif diff --git a/kaijuu/nall/inflate.hpp b/kaijuu/nall/inflate.hpp deleted file mode 100644 index cbbf6d29..00000000 --- a/kaijuu/nall/inflate.hpp +++ /dev/null @@ -1,358 +0,0 @@ -#ifndef NALL_INFLATE_HPP -#define NALL_INFLATE_HPP - -#include - -namespace nall { - -namespace puff { - inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen - ); -} - -inline bool inflate( - uint8_t *target, unsigned targetLength, - const uint8_t *source, unsigned sourceLength -) { - unsigned long tl = targetLength, sl = sourceLength; - int result = puff::puff((unsigned char*)target, &tl, (unsigned char*)source, &sl); - return result == 0; -} - -namespace puff { - -//zlib/contrib/puff.c -//version 2.1* -//author: Mark Adler -//license: zlib -//ported by: byuu - -//* I have corrected a bug in fixed(), where it was accessing uninitialized -// memory: calling construct() with lencode prior to initializing lencode.count - -enum { - MAXBITS = 15, - MAXLCODES = 286, - MAXDCODES = 30, - FIXLCODES = 288, - MAXCODES = MAXLCODES + MAXDCODES, -}; - -struct state { - unsigned char *out; - unsigned long outlen; - unsigned long outcnt; - - unsigned char *in; - unsigned long inlen; - unsigned long incnt; - int bitbuf; - int bitcnt; - - jmp_buf env; -}; - -struct huffman { - short *count; - short *symbol; -}; - -inline int bits(state *s, int need) { - long val; - - val = s->bitbuf; - while(s->bitcnt < need) { - if(s->incnt == s->inlen) longjmp(s->env, 1); - val |= (long)(s->in[s->incnt++]) << s->bitcnt; - s->bitcnt += 8; - } - - s->bitbuf = (int)(val >> need); - s->bitcnt -= need; - - return (int)(val & ((1L << need) - 1)); -} - -inline int stored(state *s) { - unsigned len; - - s->bitbuf = 0; - s->bitcnt = 0; - - if(s->incnt + 4 > s->inlen) return 2; - len = s->in[s->incnt++]; - len |= s->in[s->incnt++] << 8; - if(s->in[s->incnt++] != (~len & 0xff) || - s->in[s->incnt++] != ((~len >> 8) & 0xff) - ) return 2; - - if(s->incnt + len > s->inlen) return 2; - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) s->out[s->outcnt++] = s->in[s->incnt++]; - } else { - s->outcnt += len; - s->incnt += len; - } - - return 0; -} - -inline int decode(state *s, huffman *h) { - int len, code, first, count, index, bitbuf, left; - short *next; - - bitbuf = s->bitbuf; - left = s->bitcnt; - code = first = index = 0; - len = 1; - next = h->count + 1; - while(true) { - while(left--) { - code |= bitbuf & 1; - bitbuf >>= 1; - count = *next++; - if(code - count < first) { - s->bitbuf = bitbuf; - s->bitcnt = (s->bitcnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS + 1) - len; - if(left == 0) break; - if(s->incnt == s->inlen) longjmp(s->env, 1); - bitbuf = s->in[s->incnt++]; - if(left > 8) left = 8; - } - - return -10; -} - -inline int construct(huffman *h, short *length, int n) { - int symbol, len, left; - short offs[MAXBITS + 1]; - - for(len = 0; len <= MAXBITS; len++) h->count[len] = 0; - for(symbol = 0; symbol < n; symbol++) h->count[length[symbol]]++; - if(h->count[0] == n) return 0; - - left = 1; - for(len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= h->count[len]; - if(left < 0) return left; - } - - offs[1] = 0; - for(len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; - - for(symbol = 0; symbol < n; symbol++) { - if(length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; - } - - return left; -} - -inline int codes(state *s, huffman *lencode, huffman *distcode) { - int symbol, len; - unsigned dist; - static const short lens[29] = { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 - }; - static const short lext[29] = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 - }; - static const short dists[30] = { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577 - }; - static const short dext[30] = { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13 - }; - - do { - symbol = decode(s, lencode); - if(symbol < 0) return symbol; - if(symbol < 256) { - if(s->out != 0) { - if(s->outcnt == s->outlen) return 1; - s->out[s->outcnt] = symbol; - } - s->outcnt++; - } else if(symbol > 256) { - symbol -= 257; - if(symbol >= 29) return -10; - len = lens[symbol] + bits(s, lext[symbol]); - - symbol = decode(s, distcode); - if(symbol < 0) return symbol; - dist = dists[symbol] + bits(s, dext[symbol]); - #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - if(dist > s->outcnt) return -11; - #endif - - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) { - s->out[s->outcnt] = - #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - dist > s->outcnt ? 0 : - #endif - s->out[s->outcnt - dist]; - s->outcnt++; - } - } else { - s->outcnt += len; - } - } - } while(symbol != 256); - - return 0; -} - -inline int fixed(state *s) { - static int virgin = 1; - static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; - static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - static huffman lencode, distcode; - - if(virgin) { - int symbol = 0; - short lengths[FIXLCODES]; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - for(; symbol < 144; symbol++) lengths[symbol] = 8; - for(; symbol < 256; symbol++) lengths[symbol] = 9; - for(; symbol < 280; symbol++) lengths[symbol] = 7; - for(; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; - construct(&lencode, lengths, FIXLCODES); - - for(symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; - construct(&distcode, lengths, MAXDCODES); - - virgin = 0; - } - - return codes(s, &lencode, &distcode); -} - -inline int dynamic(state *s) { - int nlen, ndist, ncode, index, err; - short lengths[MAXCODES]; - short lencnt[MAXBITS + 1], lensym[MAXLCODES]; - short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - huffman lencode, distcode; - static const short order[19] = { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 - }; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - nlen = bits(s, 5) + 257; - ndist = bits(s, 5) + 1; - ncode = bits(s, 4) + 4; - if(nlen > MAXLCODES || ndist > MAXDCODES) return -3; - - for(index = 0; index < ncode; index++) lengths[order[index]] = bits(s, 3); - for(; index < 19; index++) lengths[order[index]] = 0; - - err = construct(&lencode, lengths, 19); - if(err != 0) return -4; - - index = 0; - while(index < nlen + ndist) { - int symbol, len; - - symbol = decode(s, &lencode); - if(symbol < 16) { - lengths[index++] = symbol; - } else { - len = 0; - if(symbol == 16) { - if(index == 0) return -5; - len = lengths[index - 1]; - symbol = 3 + bits(s, 2); - } else if(symbol == 17) { - symbol = 3 + bits(s, 3); - } else { - symbol = 11 + bits(s, 7); - } - if(index + symbol > nlen + ndist) return -6; - while(symbol--) lengths[index++] = len; - } - } - - if(lengths[256] == 0) return -9; - - err = construct(&lencode, lengths, nlen); - if(err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) return -7; - - err = construct(&distcode, lengths + nlen, ndist); - if(err < 0 || (err > 0 && ndist - distcode.count[0] != 1)) return -8; - - return codes(s, &lencode, &distcode); -} - -inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen -) { - state s; - int last, type, err; - - s.out = dest; - s.outlen = *destlen; - s.outcnt = 0; - - s.in = source; - s.inlen = *sourcelen; - s.incnt = 0; - s.bitbuf = 0; - s.bitcnt = 0; - - if(setjmp(s.env) != 0) { - err = 2; - } else { - do { - last = bits(&s, 1); - type = bits(&s, 2); - err = type == 0 ? stored(&s) - : type == 1 ? fixed(&s) - : type == 2 ? dynamic(&s) - : -1; - if(err != 0) break; - } while(!last); - } - - if(err <= 0) { - *destlen = s.outcnt; - *sourcelen = s.incnt; - } - - return err; -} - -} - -} - -#endif diff --git a/kaijuu/nall/input.hpp b/kaijuu/nall/input.hpp deleted file mode 100644 index cd765393..00000000 --- a/kaijuu/nall/input.hpp +++ /dev/null @@ -1,386 +0,0 @@ -#ifndef NALL_INPUT_HPP -#define NALL_INPUT_HPP - -#include -#include -#include - -#include -#include - -namespace nall { - -struct Keyboard; -Keyboard& keyboard(unsigned = 0); - -static const char KeyboardScancodeName[][64] = { - "Escape", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", - "PrintScreen", "ScrollLock", "Pause", "Tilde", - "Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num0", - "Dash", "Equal", "Backspace", - "Insert", "Delete", "Home", "End", "PageUp", "PageDown", - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", - "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "LeftBracket", "RightBracket", "Backslash", "Semicolon", "Apostrophe", "Comma", "Period", "Slash", - "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9", "Keypad0", - "Point", "Enter", "Add", "Subtract", "Multiply", "Divide", - "NumLock", "CapsLock", - "Up", "Down", "Left", "Right", - "Tab", "Return", "Spacebar", "Menu", - "Shift", "Control", "Alt", "Super", -}; - -struct Keyboard { - const unsigned ID; - enum { Base = 1 }; - enum { Count = 8, Size = 128 }; - - enum Scancode { - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, Tilde, - Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9, Num0, - Dash, Equal, Backspace, - Insert, Delete, Home, End, PageUp, PageDown, - A, B, C, D, E, F, G, H, I, J, K, L, M, - N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - LeftBracket, RightBracket, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - Point, Enter, Add, Subtract, Multiply, Divide, - NumLock, CapsLock, - Up, Down, Left, Right, - Tab, Return, Spacebar, Menu, - Shift, Control, Alt, Super, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed keyDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return scancode - keyboard(i).key(Escape); - } - return -1; - } - - static signed modifierDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return scancode - keyboard(i).key(Shift); - } - return -1; - } - - static bool isAnyKey(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return true; - } - return false; - } - - static bool isAnyModifier(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "KB")) return 0; - s.ltrim("KB"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == KeyboardScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "KB", ID, "::", KeyboardScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t key(unsigned id) const { return Base + Size * ID + id; } - bool isKey(unsigned id) const { return id >= key(Escape) && id <= key(Menu); } - bool isModifier(unsigned id) const { return id >= key(Shift) && id <= key(Super); } - bool belongsTo(uint16_t scancode) const { return isKey(scancode) || isModifier(scancode); } - - Keyboard(unsigned ID_) : ID(ID_) {} -}; - -inline Keyboard& keyboard(unsigned id) { - static Keyboard kb0(0), kb1(1), kb2(2), kb3(3), kb4(4), kb5(5), kb6(6), kb7(7); - switch(id) { default: - case 0: return kb0; case 1: return kb1; case 2: return kb2; case 3: return kb3; - case 4: return kb4; case 5: return kb5; case 6: return kb6; case 7: return kb7; - } -} - -static const char MouseScancodeName[][64] = { - "Xaxis", "Yaxis", "Zaxis", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", -}; - -struct Mouse; -Mouse& mouse(unsigned = 0); - -struct Mouse { - const unsigned ID; - enum { Base = Keyboard::Base + Keyboard::Size * Keyboard::Count }; - enum { Count = 8, Size = 16 }; - enum { Axes = 3, Buttons = 8 }; - - enum Scancode { - Xaxis, Yaxis, Zaxis, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return scancode - mouse(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return scancode - mouse(i).button(0); - } - return -1; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "MS")) return 0; - s.ltrim("MS"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == MouseScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "MS", ID, "::", MouseScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Xaxis + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(2); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(7); } - bool belongsTo(uint16_t scancode) const { return isAxis(scancode) || isButton(scancode); } - - Mouse(unsigned ID_) : ID(ID_) {} -}; - -inline Mouse& mouse(unsigned id) { - static Mouse ms0(0), ms1(1), ms2(2), ms3(3), ms4(4), ms5(5), ms6(6), ms7(7); - switch(id) { default: - case 0: return ms0; case 1: return ms1; case 2: return ms2; case 3: return ms3; - case 4: return ms4; case 5: return ms5; case 6: return ms6; case 7: return ms7; - } -} - -static const char JoypadScancodeName[][64] = { - "Hat0", "Hat1", "Hat2", "Hat3", "Hat4", "Hat5", "Hat6", "Hat7", - "Axis0", "Axis1", "Axis2", "Axis3", "Axis4", "Axis5", "Axis6", "Axis7", - "Axis8", "Axis9", "Axis10", "Axis11", "Axis12", "Axis13", "Axis14", "Axis15", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", - "Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15", - "Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23", - "Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31", -}; - -struct Joypad; -Joypad& joypad(unsigned = 0); - -struct Joypad { - const unsigned ID; - enum { Base = Mouse::Base + Mouse::Size * Mouse::Count }; - enum { Count = 8, Size = 64 }; - enum { Hats = 8, Axes = 16, Buttons = 32 }; - - enum Scancode { - Hat0, Hat1, Hat2, Hat3, Hat4, Hat5, Hat6, Hat7, - Axis0, Axis1, Axis2, Axis3, Axis4, Axis5, Axis6, Axis7, - Axis8, Axis9, Axis10, Axis11, Axis12, Axis13, Axis14, Axis15, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Button8, Button9, Button10, Button11, Button12, Button13, Button14, Button15, - Button16, Button17, Button18, Button19, Button20, Button21, Button22, Button23, - Button24, Button25, Button26, Button27, Button28, Button29, Button30, Button31, - Limit, - }; - - enum Hat { HatCenter = 0, HatUp = 1, HatRight = 2, HatDown = 4, HatLeft = 8 }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed hatDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return scancode - joypad(i).hat(0); - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return scancode - joypad(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return scancode - joypad(i).button(0); - } - return -1; - } - - static bool isAnyHat(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return true; - } - return false; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "JP")) return 0; - s.ltrim("JP"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == JoypadScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - } - } - return { "JP", ID, "::", JoypadScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t hat(unsigned id) const { return Base + Size * ID + Hat0 + id; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Axis0 + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isHat(unsigned id) const { return id >= hat(0) && id <= hat(7); } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(15); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(31); } - bool belongsTo(uint16_t scancode) const { return isHat(scancode) || isAxis(scancode) || isButton(scancode); } - - Joypad(unsigned ID_) : ID(ID_) {} -}; - -inline Joypad& joypad(unsigned id) { - static Joypad jp0(0), jp1(1), jp2(2), jp3(3), jp4(4), jp5(5), jp6(6), jp7(7); - switch(id) { default: - case 0: return jp0; case 1: return jp1; case 2: return jp2; case 3: return jp3; - case 4: return jp4; case 5: return jp5; case 6: return jp6; case 7: return jp7; - } -} - -struct Scancode { - enum { None = 0, Limit = Joypad::Base + Joypad::Size * Joypad::Count }; - - static uint16_t decode(const char *name) { - uint16_t code; - code = Keyboard::decode(name); - if(code) return code; - code = Mouse::decode(name); - if(code) return code; - code = Joypad::decode(name); - if(code) return code; - return None; - } - - static string encode(uint16_t code) { - for(unsigned i = 0; i < Keyboard::Count; i++) { - if(keyboard(i).belongsTo(code)) return keyboard(i).encode(code); - } - for(unsigned i = 0; i < Mouse::Count; i++) { - if(mouse(i).belongsTo(code)) return mouse(i).encode(code); - } - for(unsigned i = 0; i < Joypad::Count; i++) { - if(joypad(i).belongsTo(code)) return joypad(i).encode(code); - } - return "None"; - } -}; - -} - -#endif diff --git a/kaijuu/nall/interpolation.hpp b/kaijuu/nall/interpolation.hpp deleted file mode 100644 index afc7108b..00000000 --- a/kaijuu/nall/interpolation.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NALL_INTERPOLATION_HPP -#define NALL_INTERPOLATION_HPP - -namespace nall { - -struct Interpolation { - static inline double Nearest(double mu, double a, double b, double c, double d) { - return (mu <= 0.5 ? b : c); - } - - static inline double Sublinear(double mu, double a, double b, double c, double d) { - mu = ((mu - 0.5) * 2.0) + 0.5; - if(mu < 0) mu = 0; - if(mu > 1) mu = 1; - return b * (1.0 - mu) + c * mu; - } - - static inline double Linear(double mu, double a, double b, double c, double d) { - return b * (1.0 - mu) + c * mu; - } - - static inline double Cosine(double mu, double a, double b, double c, double d) { - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - return b * (1.0 - mu) + c * mu; - } - - static inline double Cubic(double mu, double a, double b, double c, double d) { - double A = d - c - a + b; - double B = a - b - A; - double C = c - a; - double D = b; - return A * (mu * mu * mu) + B * (mu * mu) + C * mu + D; - } - - static inline double 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.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - 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); - } -}; - -} - -#endif diff --git a/kaijuu/nall/intrinsics.hpp b/kaijuu/nall/intrinsics.hpp deleted file mode 100644 index 413ef593..00000000 --- a/kaijuu/nall/intrinsics.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef NALL_INTRINSICS_HPP -#define NALL_INTRINSICS_HPP - -struct Intrinsics { - enum class Compiler : unsigned { GCC, VisualC, Unknown }; - enum class Platform : unsigned { X, OSX, Windows, Unknown }; - enum class Endian : unsigned { LSB, MSB, Unknown }; - - static inline Compiler compiler(); - static inline Platform platform(); - static inline Endian endian(); -}; - -/* Compiler detection */ - -#if defined(__GNUC__) - #define COMPILER_GCC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::GCC; } -#elif defined(_MSC_VER) - #define COMPILER_VISUALC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::VisualC; } -#else - #warning "unable to detect compiler" - #define COMPILER_UNKNOWN - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Unknown; } -#endif - -/* Platform detection */ - -#if defined(linux) || defined(__sun__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define PLATFORM_X - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::X; } -#elif defined(__APPLE__) - #define PLATFORM_OSX - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::OSX; } -#elif defined(_WIN32) - #define PLATFORM_WINDOWS - #define PLATFORM_WIN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; } -#else - #warning "unable to detect platform" - #define PLATFORM_UNKNOWN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Unknown; } -#endif - -/* Endian detection */ - -#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64) - #define ENDIAN_LSB - #define ARCH_LSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; } -#elif defined(__powerpc__) || defined(_M_PPC) || defined(__BIG_ENDIAN__) - #define ENDIAN_MSB - #define ARCH_MSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::MSB; } -#else - #warning "unable to detect endian" - #define ENDIAN_UNKNOWN - #define ARCH_UNKNOWN - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::Unknown; } -#endif - -#endif diff --git a/kaijuu/nall/invoke.hpp b/kaijuu/nall/invoke.hpp deleted file mode 100644 index 9dfb7d0b..00000000 --- a/kaijuu/nall/invoke.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef NALL_INVOKE_HPP -#define NALL_INVOKE_HPP - -//void invoke(const string &name, const string& args...); -//if a program is specified, it is executed with the arguments provided -//if a file is specified, the file is opened using the program associated with said file type -//if a folder is specified, the folder is opened using the associated file explorer -//if a URL is specified, the default web browser is opened and pointed at the URL requested -//path environment variable is always consulted -//execution is asynchronous (non-blocking); use system() for synchronous execution - -#include -#ifdef _WIN32 - #include -#endif - -namespace nall { - -#ifdef _WIN32 - -template -inline void invoke(const string &name, Args&&... args) { - lstring argl(std::forward(args)...); - for(auto &arg : argl) if(arg.position(" ")) arg = {"\"", arg, "\""}; - string arguments = argl.concatenate(" "); - ShellExecuteW(NULL, NULL, utf16_t(name), utf16_t(arguments), NULL, SW_SHOWNORMAL); -} - -#else - -template -inline void invoke(const string &name, Args&&... args) { - pid_t pid = fork(); - if(pid == 0) { - const char *argv[1 + sizeof...(args) + 1], **argp = argv; - lstring argl(std::forward(args)...); - *argp++ = (const char*)name; - for(auto &arg : argl) *argp++ = (const char*)arg; - *argp++ = nullptr; - - if(execvp(name, (char* const*)argv) < 0) { - execlp("xdg-open", "xdg-open", (const char*)name, nullptr); - } - exit(0); - } -} - -#endif - -} - -#endif diff --git a/kaijuu/nall/ips.hpp b/kaijuu/nall/ips.hpp deleted file mode 100644 index 473d74c5..00000000 --- a/kaijuu/nall/ips.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef NALL_IPS_HPP -#define NALL_IPS_HPP - -#include -#include -#include - -namespace nall { - -struct ips { - inline bool apply(); - inline void source(const uint8_t *data, unsigned size); - inline void modify(const uint8_t *data, unsigned size); - inline ips(); - inline ~ips(); - - uint8_t *data; - unsigned size; - const uint8_t *sourceData; - unsigned sourceSize; - const uint8_t *modifyData; - unsigned modifySize; -}; - -bool ips::apply() { - if(modifySize < 8) return false; - if(modifyData[0] != 'P') return false; - if(modifyData[1] != 'A') return false; - if(modifyData[2] != 'T') return false; - if(modifyData[3] != 'C') return false; - if(modifyData[4] != 'H') return false; - - if(data) delete[] data; - data = new uint8_t[16 * 1024 * 1024 + 65536](); //maximum size of IPS patch + single-tag padding - size = sourceSize; - memcpy(data, sourceData, sourceSize); - unsigned offset = 5; - - while(true) { - unsigned address, length; - - if(offset > modifySize - 3) break; - address = modifyData[offset++] << 16; - address |= modifyData[offset++] << 8; - address |= modifyData[offset++] << 0; - - if(address == 0x454f46) { //EOF - if(offset == modifySize) return true; - if(offset == modifySize - 3) { - size = modifyData[offset++] << 16; - size |= modifyData[offset++] << 8; - size |= modifyData[offset++] << 0; - return true; - } - } - - if(offset > modifySize - 2) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - - if(length) { //Copy - if(offset > modifySize - length) break; - while(length--) data[address++] = modifyData[offset++]; - } else { //RLE - if(offset > modifySize - 3) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - if(length == 0) break; //illegal - while(length--) data[address++] = modifyData[offset]; - offset++; - } - - size = max(size, address); - } - - delete[] data; - data = nullptr; - return false; -} - -void ips::source(const uint8_t *data, unsigned size) { - sourceData = data, sourceSize = size; -} - -void ips::modify(const uint8_t *data, unsigned size) { - modifyData = data, modifySize = size; -} - -ips::ips() : data(nullptr), sourceData(nullptr), modifyData(nullptr) { -} - -ips::~ips() { - if(data) delete[] data; - if(sourceData) delete[] sourceData; - if(modifyData) delete[] modifyData; -} - -} - -#endif diff --git a/kaijuu/nall/lzss.hpp b/kaijuu/nall/lzss.hpp deleted file mode 100644 index fb3e0ba6..00000000 --- a/kaijuu/nall/lzss.hpp +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef NALL_LZSS_HPP -#define NALL_LZSS_HPP - -#include -#include -#include -#include - -namespace nall { - -//19:5 pulldown -//8:1 marker: d7-d0 -//length: { 4 - 35 }, offset: { 1 - 0x80000 } -//4-byte file size header -//little-endian encoding -struct lzss { - inline void source(const uint8_t *data, unsigned size); - inline bool source(const string &filename); - inline unsigned size() const; - inline bool compress(const string &filename); - inline bool decompress(uint8_t *targetData, unsigned targetSize); - inline bool decompress(const string &filename); - -protected: - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - } *tree[65536]; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - -public: - inline lzss() : sourceData(nullptr), sourceSize(0) {} -}; - -void lzss::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -bool lzss::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - sourceData = sourceFile.data(); - sourceSize = sourceFile.size(); - return true; -} - -unsigned lzss::size() const { - unsigned size = 0; - if(sourceSize < 4) return size; - for(unsigned n = 0; n < 32; n += 8) size |= sourceData[n >> 3] << n; - return size; -} - -bool lzss::compress(const string &filename) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - - for(unsigned n = 0; n < 32; n += 8) targetFile.write(sourceSize >> n); - for(unsigned n = 0; n < 65536; n++) tree[n] = 0; - - uint8_t buffer[25]; - unsigned sourceOffset = 0; - - while(sourceOffset < sourceSize) { - uint8_t mask = 0x00; - unsigned bufferOffset = 1; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - uint16_t symbol = sourceData[sourceOffset + 0]; - if(sourceOffset < sourceSize - 1) symbol |= sourceData[sourceOffset + 1] << 8; - Node *node = tree[symbol]; - unsigned maxLength = 0, maxOffset = 0; - - while(node) { - if(node->offset < sourceOffset - 0x80000) { - //out-of-range: all subsequent nodes will also be, so free up their memory - if(node->next) { delete node->next; node->next = 0; } - break; - } - - unsigned length = 0, x = sourceOffset, y = node->offset; - while(length < 35 && x < sourceSize && sourceData[x++] == sourceData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset; - if(length == 35) break; - - node = node->next; - } - - //attach current symbol to top of tree for subsequent searches - node = new Node; - node->offset = sourceOffset; - node->next = tree[symbol]; - tree[symbol] = node; - - if(maxLength < 4) { - buffer[bufferOffset++] = sourceData[sourceOffset++]; - } else { - unsigned output = ((maxLength - 4) << 19) | (sourceOffset - 1 - maxOffset); - for(unsigned n = 0; n < 24; n += 8) buffer[bufferOffset++] = output >> n; - mask |= 0x80 >> iteration; - sourceOffset += maxLength; - } - } - - buffer[0] = mask; - targetFile.write(buffer, bufferOffset); - } - - sourceFile.close(); - targetFile.close(); - return true; -} - -bool lzss::decompress(uint8_t *targetData, unsigned targetSize) { - if(targetSize < size()) return false; - - unsigned sourceOffset = 4, targetOffset = 0; - while(sourceOffset < sourceSize) { - uint8_t mask = sourceData[sourceOffset++]; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - if((mask & (0x80 >> iteration)) == 0) { - targetData[targetOffset++] = sourceData[sourceOffset++]; - } else { - unsigned code = 0; - for(unsigned n = 0; n < 24; n += 8) code |= sourceData[sourceOffset++] << n; - unsigned length = (code >> 19) + 4; - unsigned offset = targetOffset - 1 - (code & 0x7ffff); - while(length--) targetData[targetOffset++] = targetData[offset++]; - } - } - } -} - -bool lzss::decompress(const string &filename) { - if(sourceSize < 4) return false; - unsigned targetSize = size(); - - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(targetSize); - fp.close(); - - filemap targetFile; - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - uint8_t *targetData = targetFile.data(); - - bool result = decompress(targetData, targetSize); - sourceFile.close(); - targetFile.close(); - return result; -} - -} - -#endif diff --git a/kaijuu/nall/map.hpp b/kaijuu/nall/map.hpp deleted file mode 100644 index 938f0c2d..00000000 --- a/kaijuu/nall/map.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef NALL_MAP_HPP -#define NALL_MAP_HPP - -#include - -namespace nall { - -template -struct map { - struct pair { - LHS name; - RHS data; - }; - - inline void reset() { - list.reset(); - } - - inline unsigned size() const { - return list.size(); - } - - //O(log n) find - inline optional find(const LHS &name) const { - signed first = 0, last = size() - 1; - while(first <= last) { - signed middle = (first + last) / 2; - if(name < list[middle].name) last = middle - 1; //search lower half - else if(list[middle].name < name) first = middle + 1; //search upper half - else return { true, (unsigned)middle }; //match found - } - return { false, 0u }; - } - - //O(n) insert + O(log n) find - inline RHS& insert(const LHS &name, const RHS &data) { - if(auto position = find(name)) { - list[position()].data = data; - return list[position()].data; - } - signed offset = size(); - for(unsigned n = 0; n < size(); n++) { - if(name < list[n].name) { offset = n; break; } - } - list.insert(offset, { name, data }); - return list[offset].data; - } - - //O(log n) find - inline void modify(const LHS &name, const RHS &data) { - if(auto position = find(name)) list[position()].data = data; - } - - //O(n) remove + O(log n) find - inline void remove(const LHS &name) { - if(auto position = find(name)) list.remove(position()); - } - - //O(log n) find - inline RHS& operator[](const LHS &name) { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline const RHS& operator[](const LHS &name) const { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline RHS& operator()(const LHS &name) { - if(auto position = find(name)) return list[position()].data; - return insert(name, RHS()); - } - - inline const RHS& operator()(const LHS &name, const RHS &data) const { - if(auto position = find(name)) return list[position()].data; - return data; - } - - inline pair* begin() { return list.begin(); } - inline pair* end() { return list.end(); } - inline const pair* begin() const { return list.begin(); } - inline const pair* end() const { return list.end(); } - -protected: - vector list; -}; - -template -struct bidirectional_map { - const map &lhs; - const map &rhs; - - inline void reset() { - llist.reset(); - rlist.reset(); - } - - inline unsigned size() const { - return llist.size(); - } - - inline void insert(const LHS &ldata, const RHS &rdata) { - llist.insert(ldata, rdata); - rlist.insert(rdata, ldata); - } - - inline bidirectional_map() : lhs(llist), rhs(rlist) {} - -protected: - map llist; - map rlist; -}; - -} - -#endif diff --git a/kaijuu/nall/mosaic.hpp b/kaijuu/nall/mosaic.hpp deleted file mode 100644 index 16fd0bfd..00000000 --- a/kaijuu/nall/mosaic.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef NALL_MOSAIC_HPP -#define NALL_MOSAIC_HPP - -#define NALL_MOSAIC_INTERNAL_HPP -#include -#include -#include -#undef NALL_MOSAIC_INTERNAL_HPP - -#endif diff --git a/kaijuu/nall/mosaic/bitstream.hpp b/kaijuu/nall/mosaic/bitstream.hpp deleted file mode 100644 index e2cb3bc5..00000000 --- a/kaijuu/nall/mosaic/bitstream.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct bitstream { - filemap fp; - uint8_t *data; - unsigned size; - bool readonly; - bool endian; - - inline bool read(uint64_t addr) const { - if(data == nullptr || (addr >> 3) >= size) return 0; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - return data[addr >> 3] & mask; - } - - inline void write(uint64_t addr, bool value) { - if(data == nullptr || readonly == true || (addr >> 3) >= size) return; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - if(value == 0) data[addr >> 3] &= ~mask; - if(value == 1) data[addr >> 3] |= mask; - } - - inline bool open(const string &filename) { - readonly = false; - if(fp.open(filename, filemap::mode::readwrite) == false) { - readonly = true; - if(fp.open(filename, filemap::mode::read) == false) { - return false; - } - } - data = fp.data(); - size = fp.size(); - return true; - } - - inline void close() { - fp.close(); - data = nullptr; - } - - inline bitstream() : data(nullptr), endian(1) { - } - - inline ~bitstream() { - close(); - } -}; - -} -} - -#endif diff --git a/kaijuu/nall/mosaic/context.hpp b/kaijuu/nall/mosaic/context.hpp deleted file mode 100644 index bc7a518a..00000000 --- a/kaijuu/nall/mosaic/context.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct context { - unsigned offset; - unsigned width; - unsigned height; - unsigned count; - - bool endian; //0 = lsb, 1 = msb - bool order; //0 = linear, 1 = planar - unsigned depth; //1 - 24bpp - - unsigned blockWidth; - unsigned blockHeight; - unsigned blockStride; - unsigned blockOffset; - vector block; - - unsigned tileWidth; - unsigned tileHeight; - unsigned tileStride; - unsigned tileOffset; - vector tile; - - unsigned mosaicWidth; - unsigned mosaicHeight; - unsigned mosaicStride; - unsigned mosaicOffset; - vector mosaic; - - unsigned paddingWidth; - unsigned paddingHeight; - unsigned paddingColor; - vector palette; - - inline unsigned objectWidth() const { return blockWidth * tileWidth * mosaicWidth + paddingWidth; } - inline unsigned objectHeight() const { return blockHeight * tileHeight * mosaicHeight + paddingHeight; } - inline unsigned objectSize() const { - unsigned size = blockStride * tileWidth * tileHeight * mosaicWidth * mosaicHeight - + blockOffset * tileHeight * mosaicWidth * mosaicHeight - + tileStride * mosaicWidth * mosaicHeight - + tileOffset * mosaicHeight; - return max(1u, size); - } - - inline unsigned eval(const string &expression) { - intmax_t result; - if(fixedpoint::eval(expression, result) == false) return 0u; - return result; - } - - inline void eval(vector &buffer, const string &expression_) { - string expression = expression_; - bool function = false; - for(auto &c : expression) { - if(c == '(') function = true; - if(c == ')') function = false; - if(c == ',' && function == true) c = ';'; - } - - lstring list = expression.split(","); - for(auto &item : list) { - item.trim(); - if(item.wildcard("f(?*) ?*")) { - item.ltrim<1>("f("); - lstring part = item.split<1>(") "); - lstring args = part[0].split<3>(";"); - for(auto &item : args) item.trim(); - - unsigned length = eval(args(0, "0")); - unsigned offset = eval(args(1, "0")); - unsigned stride = eval(args(2, "0")); - if(args.size() < 2) offset = buffer.size(); - if(args.size() < 3) stride = 1; - - for(unsigned n = 0; n < length; n++) { - string fn = part[1]; - fn.replace("n", decimal(n)); - fn.replace("o", decimal(offset)); - fn.replace("p", decimal(buffer.size())); - buffer.resize(offset + 1); - buffer[offset] = eval(fn); - offset += stride; - } - } else if(item.wildcard("base64*")) { - unsigned offset = 0; - item.ltrim<1>("base64"); - if(item.wildcard("(?*) *")) { - item.ltrim<1>("("); - lstring part = item.split<1>(") "); - offset = eval(part[0]); - item = part(1, ""); - } - item.trim(); - for(auto &c : item) { - if(c >= 'A' && c <= 'Z') buffer.append(offset + c - 'A' + 0); - if(c >= 'a' && c <= 'z') buffer.append(offset + c - 'a' + 26); - if(c >= '0' && c <= '9') buffer.append(offset + c - '0' + 52); - if(c == '-') buffer.append(offset + 62); - if(c == '_') buffer.append(offset + 63); - } - } else if(item.wildcard("file *")) { - item.ltrim<1>("file "); - item.trim(); - //... - } else if(item.empty() == false) { - buffer.append(eval(item)); - } - } - } - - inline void parse(const string &data) { - reset(); - - lstring lines = data.split("\n"); - for(auto &line : lines) { - lstring part = line.split<1>(":"); - if(part.size() != 2) continue; - part[0].trim(); - part[1].trim(); - - if(part[0] == "offset") offset = eval(part[1]); - if(part[0] == "width") width = eval(part[1]); - if(part[0] == "height") height = eval(part[1]); - if(part[0] == "count") count = eval(part[1]); - - if(part[0] == "endian") endian = eval(part[1]); - if(part[0] == "order") order = eval(part[1]); - if(part[0] == "depth") depth = eval(part[1]); - - if(part[0] == "blockWidth") blockWidth = eval(part[1]); - if(part[0] == "blockHeight") blockHeight = eval(part[1]); - if(part[0] == "blockStride") blockStride = eval(part[1]); - if(part[0] == "blockOffset") blockOffset = eval(part[1]); - if(part[0] == "block") eval(block, part[1]); - - if(part[0] == "tileWidth") tileWidth = eval(part[1]); - if(part[0] == "tileHeight") tileHeight = eval(part[1]); - if(part[0] == "tileStride") tileStride = eval(part[1]); - if(part[0] == "tileOffset") tileOffset = eval(part[1]); - if(part[0] == "tile") eval(tile, part[1]); - - if(part[0] == "mosaicWidth") mosaicWidth = eval(part[1]); - if(part[0] == "mosaicHeight") mosaicHeight = eval(part[1]); - if(part[0] == "mosaicStride") mosaicStride = eval(part[1]); - if(part[0] == "mosaicOffset") mosaicOffset = eval(part[1]); - if(part[0] == "mosaic") eval(mosaic, part[1]); - - if(part[0] == "paddingWidth") paddingWidth = eval(part[1]); - if(part[0] == "paddingHeight") paddingHeight = eval(part[1]); - if(part[0] == "paddingColor") paddingColor = eval(part[1]); - if(part[0] == "palette") eval(palette, part[1]); - } - - sanitize(); - } - - inline bool load(const string &filename) { - string filedata; - if(filedata.readfile(filename) == false) return false; - parse(filedata); - return true; - } - - inline void sanitize() { - if(depth < 1) depth = 1; - if(depth > 24) depth = 24; - - if(blockWidth < 1) blockWidth = 1; - if(blockHeight < 1) blockHeight = 1; - - if(tileWidth < 1) tileWidth = 1; - if(tileHeight < 1) tileHeight = 1; - - if(mosaicWidth < 1) mosaicWidth = 1; - if(mosaicHeight < 1) mosaicHeight = 1; - } - - inline void reset() { - offset = 0; - width = 0; - height = 0; - count = 0; - - endian = 1; - order = 0; - depth = 1; - - blockWidth = 1; - blockHeight = 1; - blockStride = 0; - blockOffset = 0; - block.reset(); - - tileWidth = 1; - tileHeight = 1; - tileStride = 0; - tileOffset = 0; - tile.reset(); - - mosaicWidth = 1; - mosaicHeight = 1; - mosaicStride = 0; - mosaicOffset = 0; - mosaic.reset(); - - paddingWidth = 0; - paddingHeight = 0; - paddingColor = 0x000000; - palette.reset(); - } - - inline context() { - reset(); - } -}; - -} -} - -#endif diff --git a/kaijuu/nall/mosaic/parser.hpp b/kaijuu/nall/mosaic/parser.hpp deleted file mode 100644 index b2c0b8ef..00000000 --- a/kaijuu/nall/mosaic/parser.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct parser { - image canvas; - - //export from bitstream to canvas - inline void load(bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - canvas.allocate(width, height); - canvas.clear(ctx.paddingColor); - parse(1, stream, offset, ctx, width, height); - } - - //import from canvas to bitstream - inline bool save(bitstream &stream, uint64_t offset, context &ctx) { - if(stream.readonly) return false; - parse(0, stream, offset, ctx, canvas.width, canvas.height); - return true; - } - - inline parser() : canvas(0, 32, 0u, 255u << 16, 255u << 8, 255u << 0) { - } - -private: - inline uint32_t read(unsigned x, unsigned y) const { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return 0u; - uint32_t *buffer = (uint32_t*)canvas.data; - return buffer[addr]; - } - - inline void write(unsigned x, unsigned y, uint32_t data) { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return; - uint32_t *buffer = (uint32_t*)canvas.data; - buffer[addr] = data; - } - - inline void parse(bool load, bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - stream.endian = ctx.endian; - unsigned canvasWidth = width / (ctx.mosaicWidth * ctx.tileWidth * ctx.blockWidth + ctx.paddingWidth); - unsigned canvasHeight = height / (ctx.mosaicHeight * ctx.tileHeight * ctx.blockHeight + ctx.paddingHeight); - unsigned bitsPerBlock = ctx.depth * ctx.blockWidth * ctx.blockHeight; - - unsigned objectOffset = 0; - for(unsigned objectY = 0; objectY < canvasHeight; objectY++) { - for(unsigned objectX = 0; objectX < canvasWidth; objectX++) { - if(objectOffset >= ctx.count && ctx.count > 0) break; - unsigned objectIX = objectX * ctx.objectWidth(); - unsigned objectIY = objectY * ctx.objectHeight(); - objectOffset++; - - unsigned mosaicOffset = 0; - for(unsigned mosaicY = 0; mosaicY < ctx.mosaicHeight; mosaicY++) { - for(unsigned mosaicX = 0; mosaicX < ctx.mosaicWidth; mosaicX++) { - unsigned mosaicData = ctx.mosaic(mosaicOffset, mosaicOffset); - unsigned mosaicIX = (mosaicData % ctx.mosaicWidth) * (ctx.tileWidth * ctx.blockWidth); - unsigned mosaicIY = (mosaicData / ctx.mosaicWidth) * (ctx.tileHeight * ctx.blockHeight); - mosaicOffset++; - - unsigned tileOffset = 0; - for(unsigned tileY = 0; tileY < ctx.tileHeight; tileY++) { - for(unsigned tileX = 0; tileX < ctx.tileWidth; tileX++) { - unsigned tileData = ctx.tile(tileOffset, tileOffset); - unsigned tileIX = (tileData % ctx.tileWidth) * ctx.blockWidth; - unsigned tileIY = (tileData / ctx.tileWidth) * ctx.blockHeight; - tileOffset++; - - unsigned blockOffset = 0; - for(unsigned blockY = 0; blockY < ctx.blockHeight; blockY++) { - for(unsigned blockX = 0; blockX < ctx.blockWidth; blockX++) { - if(load) { - unsigned palette = 0; - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - palette |= stream.read(offset + ctx.block(index, index)) << n; - } - - write( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY, - ctx.palette(palette, palette) - ); - } else /* save */ { - uint32_t palette = read( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY - ); - - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - stream.write(offset + ctx.block(index, index), palette & 1); - palette >>= 1; - } - } - } //blockX - } //blockY - - offset += ctx.blockStride; - } //tileX - - offset += ctx.blockOffset; - } //tileY - - offset += ctx.tileStride; - } //mosaicX - - offset += ctx.tileOffset; - } //mosaicY - - offset += ctx.mosaicStride; - } //objectX - - offset += ctx.mosaicOffset; - } //objectY - } -}; - -} -} - -#endif diff --git a/kaijuu/nall/nall.hpp b/kaijuu/nall/nall.hpp deleted file mode 100644 index 9a8f1dfa..00000000 --- a/kaijuu/nall/nall.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef NALL_HPP -#define NALL_HPP - -//include the most common nall headers with one statement -//does not include the most obscure components with high cost and low usage - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include - #include -#endif - -#if defined(PLATFORM_X) - #include -#endif - -#endif diff --git a/kaijuu/nall/platform.hpp b/kaijuu/nall/platform.hpp deleted file mode 100644 index a45a6723..00000000 --- a/kaijuu/nall/platform.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef NALL_PLATFORM_HPP -#define NALL_PLATFORM_HPP - -#if defined(_WIN32) - //minimum version needed for _wstat64, etc - #undef __MSVCRT_VERSION__ - #define __MSVCRT_VERSION__ 0x0601 - #include -#endif - -//========================= -//standard platform headers -//========================= - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#if defined(_WIN32) - #include - #include - #include - #include - #undef interface - #define dllexport __declspec(dllexport) -#else - #include - #include - #define dllexport -#endif - -//================== -//warning supression -//================== - -//Visual C++ -#if defined(_MSC_VER) - //disable libc "deprecation" warnings - #pragma warning(disable:4996) -#endif - -//================ -//POSIX compliance -//================ - -#if defined(_MSC_VER) - #define PATH_MAX _MAX_PATH - #define va_copy(dest, src) ((dest) = (src)) -#endif - -#if defined(_WIN32) - #define getcwd _getcwd - #define putenv _putenv - #define vsnprintf _vsnprintf - inline void usleep(unsigned milliseconds) { Sleep(milliseconds / 1000); } -#endif - -//================ -//inline expansion -//================ - -#if defined(__GNUC__) - #define noinline __attribute__((noinline)) - #define inline inline - #define alwaysinline inline __attribute__((always_inline)) -#elif defined(_MSC_VER) - #define noinline __declspec(noinline) - #define inline inline - #define alwaysinline inline __forceinline -#else - #define noinline - #define inline inline - #define alwaysinline inline -#endif - -#endif diff --git a/kaijuu/nall/png.hpp b/kaijuu/nall/png.hpp deleted file mode 100644 index f5ebaab4..00000000 --- a/kaijuu/nall/png.hpp +++ /dev/null @@ -1,337 +0,0 @@ -#ifndef NALL_PNG_HPP -#define NALL_PNG_HPP - -//PNG image decoder -//author: byuu - -#include -#include - -namespace nall { - -struct png { - //colorType: - //0 = L - //2 = R,G,B - //3 = P - //4 = L,A - //6 = R,G,B,A - struct Info { - unsigned width; - unsigned height; - unsigned bitDepth; - unsigned colorType; - unsigned compressionMethod; - unsigned filterType; - unsigned interlaceMethod; - - unsigned bytesPerPixel; - unsigned pitch; - - uint8_t palette[256][3]; - } info; - - uint8_t *data; - unsigned size; - - inline bool decode(const string &filename); - inline bool decode(const uint8_t *sourceData, unsigned sourceSize); - inline unsigned readbits(const uint8_t *&data); - unsigned bitpos; - - inline png(); - inline ~png(); - -protected: - enum class FourCC : unsigned { - IHDR = 0x49484452, - PLTE = 0x504c5445, - IDAT = 0x49444154, - IEND = 0x49454e44, - }; - - inline unsigned interlace(unsigned pass, unsigned index); - inline unsigned inflateSize(); - inline bool deinterlace(const uint8_t *&inputData, unsigned pass); - inline bool filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height); - inline unsigned read(const uint8_t *data, unsigned length); -}; - -bool png::decode(const string &filename) { - if(auto memory = file::read(filename)) { - return decode(memory.data(), memory.size()); - } - return false; -} - -bool png::decode(const uint8_t *sourceData, unsigned sourceSize) { - if(sourceSize < 8) return false; - if(read(sourceData + 0, 4) != 0x89504e47) return false; - if(read(sourceData + 4, 4) != 0x0d0a1a0a) return false; - - uint8_t *compressedData = 0; - unsigned compressedSize = 0; - - unsigned offset = 8; - while(offset < sourceSize) { - unsigned length = read(sourceData + offset + 0, 4); - unsigned fourCC = read(sourceData + offset + 4, 4); - unsigned checksum = read(sourceData + offset + 8 + length, 4); - - if(fourCC == (unsigned)FourCC::IHDR) { - info.width = read(sourceData + offset + 8, 4); - info.height = read(sourceData + offset + 12, 4); - info.bitDepth = read(sourceData + offset + 16, 1); - info.colorType = read(sourceData + offset + 17, 1); - info.compressionMethod = read(sourceData + offset + 18, 1); - info.filterType = read(sourceData + offset + 19, 1); - info.interlaceMethod = read(sourceData + offset + 20, 1); - - if(info.bitDepth == 0 || info.bitDepth > 16) return false; - if(info.bitDepth & (info.bitDepth - 1)) return false; //not a power of two - if(info.compressionMethod != 0) return false; - if(info.filterType != 0) return false; - if(info.interlaceMethod != 0 && info.interlaceMethod != 1) return false; - - switch(info.colorType) { - case 0: info.bytesPerPixel = info.bitDepth * 1; break; //L - case 2: info.bytesPerPixel = info.bitDepth * 3; break; //R,G,B - case 3: info.bytesPerPixel = info.bitDepth * 1; break; //P - case 4: info.bytesPerPixel = info.bitDepth * 2; break; //L,A - case 6: info.bytesPerPixel = info.bitDepth * 4; break; //R,G,B,A - default: return false; - } - - if(info.colorType == 2 || info.colorType == 4 || info.colorType == 6) - if(info.bitDepth != 8 && info.bitDepth != 16) return false; - if(info.colorType == 3 && info.bitDepth == 16) return false; - - info.bytesPerPixel = (info.bytesPerPixel + 7) / 8; - info.pitch = (int)info.width * info.bytesPerPixel; - } - - if(fourCC == (unsigned)FourCC::PLTE) { - if(length % 3) return false; - for(unsigned n = 0, p = offset + 8; n < length / 3; n++) { - info.palette[n][0] = sourceData[p++]; - info.palette[n][1] = sourceData[p++]; - info.palette[n][2] = sourceData[p++]; - } - } - - if(fourCC == (unsigned)FourCC::IDAT) { - compressedData = (uint8_t*)realloc(compressedData, compressedSize + length); - memcpy(compressedData + compressedSize, sourceData + offset + 8, length); - compressedSize += length; - } - - if(fourCC == (unsigned)FourCC::IEND) { - break; - } - - offset += 4 + 4 + length + 4; - } - - unsigned interlacedSize = inflateSize(); - uint8_t *interlacedData = new uint8_t[interlacedSize]; - - bool result = inflate(interlacedData, interlacedSize, compressedData + 2, compressedSize - 6); - delete[] compressedData; - - if(result == false) { - delete[] interlacedData; - return false; - } - - size = info.width * info.height * info.bytesPerPixel; - data = new uint8_t[size]; - - if(info.interlaceMethod == 0) { - if(filter(data, interlacedData, info.width, info.height) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } else { - const uint8_t *passData = interlacedData; - for(unsigned pass = 0; pass < 7; pass++) { - if(deinterlace(passData, pass) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } - } - - delete[] interlacedData; - return true; -} - -unsigned png::interlace(unsigned pass, unsigned index) { - static const unsigned data[7][4] = { - //x-distance, y-distance, x-origin, y-origin - { 8, 8, 0, 0 }, - { 8, 8, 4, 0 }, - { 4, 8, 0, 4 }, - { 4, 4, 2, 0 }, - { 2, 4, 0, 2 }, - { 2, 2, 1, 0 }, - { 1, 2, 0, 1 }, - }; - return data[pass][index]; -} - -unsigned png::inflateSize() { - if(info.interlaceMethod == 0) { - return info.width * info.height * info.bytesPerPixel + info.height; - } - - unsigned size = 0; - for(unsigned pass = 0; pass < 7; pass++) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) continue; - size += width * height * info.bytesPerPixel + height; - } - return size; -} - -bool png::deinterlace(const uint8_t *&inputData, unsigned pass) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) return true; - - unsigned outputSize = width * height * info.bytesPerPixel; - uint8_t *outputData = new uint8_t[outputSize]; - bool result = filter(outputData, inputData, width, height); - - const uint8_t *rd = outputData; - for(unsigned y = yo; y < info.height; y += yd) { - uint8_t *wr = data + y * info.pitch; - for(unsigned x = xo; x < info.width; x += xd) { - for(unsigned b = 0; b < info.bytesPerPixel; b++) { - wr[x * info.bytesPerPixel + b] = *rd++; - } - } - } - - inputData += outputSize + height; - delete[] outputData; - return result; -} - -bool png::filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height) { - uint8_t *wr = outputData; - const uint8_t *rd = inputData; - int bpp = info.bytesPerPixel, pitch = width * bpp; - for(int y = 0; y < height; y++) { - uint8_t filter = *rd++; - - switch(filter) { - case 0x00: //None - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x]; - } - break; - - case 0x01: //Subtract - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (x - bpp < 0 ? 0 : wr[x - bpp]); - } - break; - - case 0x02: //Above - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (y - 1 < 0 ? 0 : wr[x - pitch]); - } - break; - - case 0x03: //Average - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - - wr[x] = rd[x] + (uint8_t)((a + b) / 2); - } - break; - - case 0x04: //Paeth - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - short c = x - bpp < 0 || y - 1 < 0 ? 0 : wr[x - pitch - bpp]; - - short p = a + b - c; - short pa = p > a ? p - a : a - p; - short pb = p > b ? p - b : b - p; - short pc = p > c ? p - c : c - p; - - uint8_t paeth = (uint8_t)((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); - - wr[x] = rd[x] + paeth; - } - break; - - default: //Invalid - return false; - } - - rd += pitch; - wr += pitch; - } - - return true; -} - -unsigned png::read(const uint8_t *data, unsigned length) { - unsigned result = 0; - while(length--) result = (result << 8) | (*data++); - return result; -} - -unsigned png::readbits(const uint8_t *&data) { - unsigned result = 0; - switch(info.bitDepth) { - case 1: - result = (*data >> bitpos) & 1; - bitpos++; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 2: - result = (*data >> bitpos) & 3; - bitpos += 2; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 4: - result = (*data >> bitpos) & 15; - bitpos += 4; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 8: - result = *data++; - break; - case 16: - result = (data[0] << 8) | (data[1] << 0); - data += 2; - break; - } - return result; -} - -png::png() : data(nullptr) { - bitpos = 0; -} - -png::~png() { - if(data) delete[] data; -} - -} - -#endif diff --git a/kaijuu/nall/priority-queue.hpp b/kaijuu/nall/priority-queue.hpp deleted file mode 100644 index 1aedc6f1..00000000 --- a/kaijuu/nall/priority-queue.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef NALL_PRIORITY_QUEUE_HPP -#define NALL_PRIORITY_QUEUE_HPP - -#include -#include -#include -#include - -namespace nall { - template void priority_queue_nocallback(type_t) {} - - //priority queue implementation using binary min-heap array; - //does not require normalize() function. - //O(1) find (tick) - //O(log n) append (enqueue) - //O(log n) remove (dequeue) - template class priority_queue { - public: - inline void tick(unsigned ticks) { - basecounter += ticks; - while(heapsize && gte(basecounter, heap[0].counter)) callback(dequeue()); - } - - //counter is relative to current time (eg enqueue(64, ...) fires in 64 ticks); - //counter cannot exceed std::numeric_limits::max() >> 1. - void enqueue(unsigned counter, type_t event) { - unsigned child = heapsize++; - counter += basecounter; - - while(child) { - unsigned parent = (child - 1) >> 1; - if(gte(counter, heap[parent].counter)) break; - - heap[child].counter = heap[parent].counter; - heap[child].event = heap[parent].event; - child = parent; - } - - heap[child].counter = counter; - heap[child].event = event; - } - - type_t dequeue() { - type_t event(heap[0].event); - unsigned parent = 0; - unsigned counter = heap[--heapsize].counter; - - while(true) { - unsigned child = (parent << 1) + 1; - if(child >= heapsize) break; - if(child + 1 < heapsize && gte(heap[child].counter, heap[child + 1].counter)) child++; - if(gte(heap[child].counter, counter)) break; - - heap[parent].counter = heap[child].counter; - heap[parent].event = heap[child].event; - parent = child; - } - - heap[parent].counter = counter; - heap[parent].event = heap[heapsize].event; - return event; - } - - void reset() { - basecounter = 0; - heapsize = 0; - } - - void serialize(serializer &s) { - s.integer(basecounter); - s.integer(heapsize); - for(unsigned n = 0; n < heapcapacity; n++) { - s.integer(heap[n].counter); - s.integer(heap[n].event); - } - } - - priority_queue(unsigned size, function callback_ = &priority_queue_nocallback) - : callback(callback_) { - heap = new heap_t[size]; - heapcapacity = size; - reset(); - } - - ~priority_queue() { - delete[] heap; - } - - priority_queue& operator=(const priority_queue&) = delete; - priority_queue(const priority_queue&) = delete; - - private: - function callback; - unsigned basecounter; - unsigned heapsize; - unsigned heapcapacity; - struct heap_t { - unsigned counter; - type_t event; - } *heap; - - //return true if x is greater than or equal to y - inline bool gte(unsigned x, unsigned y) { - return x - y < (std::numeric_limits::max() >> 1); - } - }; -} - -#endif diff --git a/kaijuu/nall/property.hpp b/kaijuu/nall/property.hpp deleted file mode 100644 index 665afcad..00000000 --- a/kaijuu/nall/property.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef NALL_PROPERTY_HPP -#define NALL_PROPERTY_HPP - -//nall::property implements ownership semantics into container classes -//example: property::readonly implies that only owner has full -//access to type; and all other code has readonly access. -// -//this code relies on extended friend semantics from C++0x to work, as it -//declares a friend class via a template paramter. it also exploits a bug in -//G++ 4.x to work even in C++98 mode. -// -//if compiling elsewhere, simply remove the friend class and private semantics - -//property can be used either of two ways: -//struct foo { -// property::readonly x; -// property::readwrite y; -//}; -//-or- -//struct foo : property { -// readonly x; -// readwrite y; -//}; - -//return types are const T& (byref) instead of T (byval) to avoid major speed -//penalties for objects with expensive copy constructors - -//operator-> provides access to underlying object type: -//readonly foo; -//foo->bar(); -//... will call Object::bar(); - -//operator='s reference is constant so as to avoid leaking a reference handle -//that could bypass access restrictions - -//both constant and non-constant operators are provided, though it may be -//necessary to cast first, for instance: -//struct foo : property { readonly bar; } object; -//int main() { int value = const_cast(object); } - -//writeonly is useful for objects that have non-const reads, but const writes. -//however, to avoid leaking handles, the interface is very restricted. the only -//way to write is via operator=, which requires conversion via eg copy -//constructor. example: -//struct foo { -// foo(bool value) { ... } -//}; -//writeonly bar; -//bar = true; - -namespace nall { - template struct property { - template struct traits { typedef T type; }; - - template struct readonly { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - private: - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - friend class traits::type; - }; - - template struct writeonly { - void operator=(const T& value_) { value = value_; } - private: - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - T value; - friend class traits::type; - }; - - template struct readwrite { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - }; - }; -} - -#endif diff --git a/kaijuu/nall/public-cast.hpp b/kaijuu/nall/public-cast.hpp deleted file mode 100644 index 331800e1..00000000 --- a/kaijuu/nall/public-cast.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_PUBLIC_CAST_HPP -#define NALL_PUBLIC_CAST_HPP - -//this is a proof-of-concept-*only* C++ access-privilege elevation exploit. -//this code is 100% legal C++, per C++98 section 14.7.2 paragraph 8: -//"access checking rules do not apply to names in explicit instantiations." -//usage example: - -//struct N { typedef void (Class::*)(); }; -//template class public_cast; -//(class.*public_cast::value); - -//Class::Reference may be public, protected or private -//Class::Reference may be a function, object or variable - -namespace nall { - template struct public_cast; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value = public_cast::value = P; -} - -#endif diff --git a/kaijuu/nall/random.hpp b/kaijuu/nall/random.hpp deleted file mode 100644 index 409c4561..00000000 --- a/kaijuu/nall/random.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_RANDOM_HPP -#define NALL_RANDOM_HPP - -namespace nall { - //pseudo-random number generator - inline unsigned prng() { - static unsigned n = 0; - return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320); - } - - struct random_lfsr { - inline void seed(unsigned seed__) { - seed_ = seed__; - } - - inline unsigned operator()() { - return seed_ = (seed_ >> 1) ^ (((seed_ & 1) - 1) & 0xedb88320); - } - - random_lfsr() : seed_(0) { - } - - private: - unsigned seed_; - }; -} - -#endif diff --git a/kaijuu/nall/serial.hpp b/kaijuu/nall/serial.hpp deleted file mode 100644 index da87ae50..00000000 --- a/kaijuu/nall/serial.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef NALL_SERIAL_HPP -#define NALL_SERIAL_HPP - -#include -#include -#include -#include - -#include - -namespace nall { - struct serial { - bool readable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, &fdset, nullptr, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes read - int read(uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::read(port, (void*)data, length); - } - - bool writable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, nullptr, &fdset, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes written - int write(const uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::write(port, (void*)data, length); - } - - bool open(const char *portname, unsigned rate, bool flowcontrol) { - close(); - - port = ::open(portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); - if(port == -1) return false; - - if(ioctl(port, TIOCEXCL) == -1) { close(); return false; } - if(fcntl(port, F_SETFL, 0) == -1) { close(); return false; } - if(tcgetattr(port, &original_attr) == -1) { close(); return false; } - - termios attr = original_attr; - cfmakeraw(&attr); - cfsetspeed(&attr, rate); - - attr.c_lflag &=~ (ECHO | ECHONL | ISIG | ICANON | IEXTEN); - attr.c_iflag &=~ (BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY); - attr.c_iflag |= (IGNBRK | IGNPAR); - attr.c_oflag &=~ (OPOST); - attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB | CLOCAL); - attr.c_cflag |= (CS8 | CREAD); - if(flowcontrol == false) { - attr.c_cflag &= ~CRTSCTS; - } else { - attr.c_cflag |= CRTSCTS; - } - attr.c_cc[VTIME] = attr.c_cc[VMIN] = 0; - - if(tcsetattr(port, TCSANOW, &attr) == -1) { close(); return false; } - return port_open = true; - } - - void close() { - if(port != -1) { - tcdrain(port); - if(port_open == true) { - tcsetattr(port, TCSANOW, &original_attr); - port_open = false; - } - ::close(port); - port = -1; - } - } - - serial() { - port = -1; - port_open = false; - } - - ~serial() { - close(); - } - - private: - int port; - bool port_open; - termios original_attr; - }; -} - -#endif diff --git a/kaijuu/nall/serializer.hpp b/kaijuu/nall/serializer.hpp deleted file mode 100644 index fcb39456..00000000 --- a/kaijuu/nall/serializer.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef NALL_SERIALIZER_HPP -#define NALL_SERIALIZER_HPP - -#include -#include -#include -#include - -namespace nall { - //serializer: a class designed to save and restore the state of classes. - // - //benefits: - //- data() will be portable in size (it is not necessary to specify type sizes.) - //- data() will be portable in endianness (always stored internally as little-endian.) - //- one serialize function can both save and restore class states. - // - //caveats: - //- only plain-old-data can be stored. complex classes must provide serialize(serializer&); - //- floating-point usage is not portable across platforms - - class serializer { - public: - enum mode_t { Load, Save, Size }; - - mode_t mode() const { - return imode; - } - - const uint8_t* data() const { - return idata; - } - - unsigned size() const { - return isize; - } - - unsigned capacity() const { - return icapacity; - } - - template void floatingpoint(T &value) { - enum { size = sizeof(T) }; - //this is rather dangerous, and not cross-platform safe; - //but there is no standardized way to export FP-values - uint8_t *p = (uint8_t*)&value; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = p[n]; - } else if(imode == Load) { - for(unsigned n = 0; n < size; n++) p[n] = idata[isize++]; - } else { - isize += size; - } - } - - template void integer(T &value) { - enum { size = std::is_same::value ? 1 : sizeof(T) }; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = (uintmax_t)value >> (n << 3); - } else if(imode == Load) { - value = 0; - for(unsigned n = 0; n < size; n++) value |= (uintmax_t)idata[isize++] << (n << 3); - } else if(imode == Size) { - isize += size; - } - } - - template void array(T &array) { - enum { size = sizeof(T) / sizeof(typename std::remove_extent::type) }; - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - template void array(T array, unsigned size) { - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - //copy - serializer& operator=(const serializer &s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = new uint8_t[s.icapacity]; - isize = s.isize; - icapacity = s.icapacity; - - memcpy(idata, s.idata, s.icapacity); - return *this; - } - - serializer(const serializer &s) : idata(0) { - operator=(s); - } - - //move - serializer& operator=(serializer &&s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = s.idata; - isize = s.isize; - icapacity = s.icapacity; - - s.idata = 0; - return *this; - } - - serializer(serializer &&s) { - operator=(std::move(s)); - } - - //construction - serializer() { - imode = Size; - idata = 0; - isize = 0; - icapacity = 0; - } - - serializer(unsigned capacity) { - imode = Save; - idata = new uint8_t[capacity](); - isize = 0; - icapacity = capacity; - } - - serializer(const uint8_t *data, unsigned capacity) { - imode = Load; - idata = new uint8_t[capacity]; - isize = 0; - icapacity = capacity; - memcpy(idata, data, capacity); - } - - ~serializer() { - if(idata) delete[] idata; - } - - private: - mode_t imode; - uint8_t *idata; - unsigned isize; - unsigned icapacity; - }; - -}; - -#endif diff --git a/kaijuu/nall/set.hpp b/kaijuu/nall/set.hpp deleted file mode 100644 index c6d3d06e..00000000 --- a/kaijuu/nall/set.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef NALL_SET_HPP -#define NALL_SET_HPP - -//set -//* unordered -//* intended for unique items -//* dynamic growth -//* reference-based variant - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - -template struct set; - -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - T *pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } -}; - -//reference set -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - typedef typename std::remove_reference::type T; - T **pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - void reset() { - if(pool) free(pool); - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - if(size == poolsize) return; - pool = (T**)realloc(pool, sizeof(T*) * size); - poolsize = size; - objectsize = min(objectsize, size); - } - - void resize(unsigned size) { - if(size > poolsize) reserve(bit::round(size)); //amortize growth - objectsize = size; - } - - bool append(T& data) { - if(find(data)) return false; - unsigned offset = objectsize++; - if(offset >= poolsize) resize(offset + 1); - pool[offset] = &data; - return true; - } - - template - bool append(T& data, Args&&... args) { - bool result = append(data); - append(std::forward(args)...); - return result; - } - - bool remove(T& data) { - if(auto position = find(data)) { - for(signed i = position(); i < objectsize - 1; i++) pool[i] = pool[i + 1]; - resize(objectsize - 1); - return true; - } - return false; - } - - optional find(const T& data) { - for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return {true, n}; - return {false, 0u}; - } - - template set(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) { - construct(std::forward(args)...); - } - - ~set() { - reset(); - } - - set& operator=(const set &source) { - if(&source == this) return *this; - if(pool) free(pool); - objectsize = source.objectsize; - poolsize = source.poolsize; - pool = (T**)malloc(sizeof(T*) * poolsize); - memcpy(pool, source.pool, sizeof(T*) * objectsize); - return *this; - } - - set& operator=(const set &&source) { - if(&source == this) return *this; - if(pool) free(pool); - pool = source.pool; - poolsize = source.poolsize; - objectsize = source.objectsize; - source.pool = nullptr; - source.reset(); - return *this; - } - - T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return *pool[position]; - } - - struct iterator { - bool operator!=(const iterator &source) const { return position != source.position; } - T& operator*() { return source.operator[](position); } - iterator& operator++() { position++; return *this; } - iterator(const set &source, unsigned position) : source(source), position(position) {} - private: - const set &source; - unsigned position; - }; - - iterator begin() { return iterator(*this, 0); } - iterator end() { return iterator(*this, objectsize); } - const iterator begin() const { return iterator(*this, 0); } - const iterator end() const { return iterator(*this, objectsize); } - -private: - void construct() {} - void construct(const set &source) { operator=(source); } - void construct(const set &&source) { operator=(std::move(source)); } - template void construct(T& data, Args&&... args) { - append(data); - construct(std::forward(args)...); - } -}; - -} - -#endif diff --git a/kaijuu/nall/sha256.hpp b/kaijuu/nall/sha256.hpp deleted file mode 100644 index c63367a7..00000000 --- a/kaijuu/nall/sha256.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef NALL_SHA256_HPP -#define NALL_SHA256_HPP - -//author: vladitx - -#include - -namespace nall { - #define PTR(t, a) ((t*)(a)) - - #define SWAP32(x) ((uint32_t)( \ - (((uint32_t)(x) & 0x000000ff) << 24) | \ - (((uint32_t)(x) & 0x0000ff00) << 8) | \ - (((uint32_t)(x) & 0x00ff0000) >> 8) | \ - (((uint32_t)(x) & 0xff000000) >> 24) \ - )) - - #define ST32(a, d) *PTR(uint32_t, a) = (d) - #define ST32BE(a, d) ST32(a, SWAP32(d)) - - #define LD32(a) *PTR(uint32_t, a) - #define LD32BE(a) SWAP32(LD32(a)) - - #define LSL32(x, n) ((uint32_t)(x) << (n)) - #define LSR32(x, n) ((uint32_t)(x) >> (n)) - #define ROR32(x, n) (LSR32(x, n) | LSL32(x, 32 - (n))) - - //first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19 - static const uint32_t T_H[8] = { - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, - }; - - //first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311 - static const uint32_t T_K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, - }; - - struct sha256_ctx { - uint8_t in[64]; - unsigned inlen; - - uint32_t w[64]; - uint32_t h[8]; - uint64_t len; - }; - - inline void sha256_init(sha256_ctx *p) { - memset(p, 0, sizeof(sha256_ctx)); - memcpy(p->h, T_H, sizeof(T_H)); - } - - static void sha256_block(sha256_ctx *p) { - unsigned i; - uint32_t s0, s1; - uint32_t a, b, c, d, e, f, g, h; - uint32_t t1, t2, maj, ch; - - for(i = 0; i < 16; i++) p->w[i] = LD32BE(p->in + i * 4); - - for(i = 16; i < 64; i++) { - s0 = ROR32(p->w[i - 15], 7) ^ ROR32(p->w[i - 15], 18) ^ LSR32(p->w[i - 15], 3); - s1 = ROR32(p->w[i - 2], 17) ^ ROR32(p->w[i - 2], 19) ^ LSR32(p->w[i - 2], 10); - p->w[i] = p->w[i - 16] + s0 + p->w[i - 7] + s1; - } - - a = p->h[0]; b = p->h[1]; c = p->h[2]; d = p->h[3]; - e = p->h[4]; f = p->h[5]; g = p->h[6]; h = p->h[7]; - - for(i = 0; i < 64; i++) { - s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22); - maj = (a & b) ^ (a & c) ^ (b & c); - t2 = s0 + maj; - s1 = ROR32(e, 6) ^ ROR32(e, 11) ^ ROR32(e, 25); - ch = (e & f) ^ (~e & g); - t1 = h + s1 + ch + T_K[i] + p->w[i]; - - h = g; g = f; f = e; e = d + t1; - d = c; c = b; b = a; a = t1 + t2; - } - - p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d; - p->h[4] += e; p->h[5] += f; p->h[6] += g; p->h[7] += h; - - //next block - p->inlen = 0; - } - - inline void sha256_chunk(sha256_ctx *p, const uint8_t *s, unsigned len) { - unsigned l; - p->len += len; - - while(len) { - l = 64 - p->inlen; - l = (len < l) ? len : l; - - memcpy(p->in + p->inlen, s, l); - s += l; - p->inlen += l; - len -= l; - - if(p->inlen == 64) sha256_block(p); - } - } - - inline void sha256_final(sha256_ctx *p) { - uint64_t len; - p->in[p->inlen++] = 0x80; - - if(p->inlen > 56) { - memset(p->in + p->inlen, 0, 64 - p->inlen); - sha256_block(p); - } - - memset(p->in + p->inlen, 0, 56 - p->inlen); - - len = p->len << 3; - ST32BE(p->in + 56, len >> 32); - ST32BE(p->in + 60, len); - sha256_block(p); - } - - inline void sha256_hash(sha256_ctx *p, uint8_t *s) { - uint32_t *t = (uint32_t*)s; - for(unsigned i = 0; i < 8; i++) ST32BE(t++, p->h[i]); - } - - #undef PTR - #undef SWAP32 - #undef ST32 - #undef ST32BE - #undef LD32 - #undef LD32BE - #undef LSL32 - #undef LSR32 - #undef ROR32 -} - -#endif diff --git a/kaijuu/nall/sort.hpp b/kaijuu/nall/sort.hpp deleted file mode 100644 index 36d91865..00000000 --- a/kaijuu/nall/sort.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef NALL_SORT_HPP -#define NALL_SORT_HPP - -#include -#include - -//class: merge sort -//average: O(n log n) -//worst: O(n log n) -//memory: O(n) -//stack: O(log n) -//stable?: yes - -//note: merge sort was chosen over quick sort, because: -//* it is a stable sort -//* it lacks O(n^2) worst-case overhead - -#define NALL_SORT_INSERTION -//#define NALL_SORT_SELECTION - -namespace nall { - template - void sort(T list[], unsigned size, const Comparator &lessthan) { - if(size <= 1) return; //nothing to sort - - //use insertion sort to quickly sort smaller blocks - if(size < 64) { - #if defined(NALL_SORT_INSERTION) - for(signed i = 1, j; i < size; i++) { - T copy = std::move(list[i]); - for(j = i - 1; j >= 0; j--) { - if(lessthan(list[j], copy)) break; - list[j + 1] = std::move(list[j]); - } - list[j + 1] = std::move(copy); - } - #elif defined(NALL_SORT_SELECTION) - for(unsigned i = 0; i < size; i++) { - unsigned min = i; - for(unsigned j = i + 1; j < size; j++) { - if(lessthan(list[j], list[min])) min = j; - } - if(min != i) std::swap(list[i], list[min]); - } - #endif - return; - } - - //split list in half and recursively sort both - unsigned middle = size / 2; - sort(list, middle, lessthan); - sort(list + middle, size - middle, lessthan); - - //left and right are sorted here; perform merge sort - T *buffer = new T[size]; - unsigned offset = 0, left = 0, right = middle; - while(left < middle && right < size) { - if(lessthan(list[left], list[right])) { - buffer[offset++] = std::move(list[left++]); - } else { - buffer[offset++] = std::move(list[right++]); - } - } - while(left < middle) buffer[offset++] = std::move(list[left++]); - while(right < size) buffer[offset++] = std::move(list[right++]); - - for(unsigned i = 0; i < size; i++) list[i] = std::move(buffer[i]); - delete[] buffer; - } - - template - void sort(T list[], unsigned size) { - return sort(list, size, [](const T &l, const T &r) { return l < r; }); - } -} - -#endif diff --git a/kaijuu/nall/stdint.hpp b/kaijuu/nall/stdint.hpp deleted file mode 100644 index c63f5912..00000000 --- a/kaijuu/nall/stdint.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STDINT_HPP -#define NALL_STDINT_HPP - -#if defined(_MSC_VER) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef signed long long int64_t; - typedef int64_t intmax_t; - #if defined(_WIN64) - typedef int64_t intptr_t; - #else - typedef int32_t intptr_t; - #endif - - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; - typedef unsigned long long uint64_t; - typedef uint64_t uintmax_t; - #if defined(_WIN64) - typedef uint64_t uintptr_t; - #else - typedef uint32_t uintptr_t; - #endif -#else - #include -#endif - -namespace nall { - static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size"); - - static_assert(sizeof(uint8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(uint16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(uint32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(uint64_t) == 8, "int64_t is not of the correct size"); -} - -#endif diff --git a/kaijuu/nall/stream.hpp b/kaijuu/nall/stream.hpp deleted file mode 100644 index 586ccda7..00000000 --- a/kaijuu/nall/stream.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NALL_STREAM_HPP -#define NALL_STREAM_HPP - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define NALL_STREAM_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STREAM_INTERNAL_HPP - -#endif diff --git a/kaijuu/nall/stream/auto.hpp b/kaijuu/nall/stream/auto.hpp deleted file mode 100644 index d1b6e2ba..00000000 --- a/kaijuu/nall/stream/auto.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NALL_STREAM_AUTO_HPP -#define NALL_STREAM_AUTO_HPP - -namespace nall { - -#define autostream(...) (*makestream(__VA_ARGS__)) - -inline std::unique_ptr makestream(const string &path) { - if(path.ibeginswith("http://")) return std::unique_ptr(new httpstream(path, 80)); - if(path.iendswith(".gz")) return std::unique_ptr(new gzipstream(filestream{path})); - if(path.iendswith(".zip")) return std::unique_ptr(new zipstream(filestream{path})); - return std::unique_ptr(new mmapstream(path)); -} - -inline std::unique_ptr makestream(uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -inline std::unique_ptr makestream(const uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -} - -#endif diff --git a/kaijuu/nall/stream/file.hpp b/kaijuu/nall/stream/file.hpp deleted file mode 100644 index 878418cf..00000000 --- a/kaijuu/nall/stream/file.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_FILE_HPP -#define NALL_STREAM_FILE_HPP - -#include - -namespace nall { - -struct filestream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return false; } - - unsigned size() const { return pfile.size(); } - unsigned offset() const { return pfile.offset(); } - void seek(unsigned offset) const { pfile.seek(offset); } - - uint8_t read() const { return pfile.read(); } - void write(uint8_t data) const { pfile.write(data); } - - filestream(const string &filename) { - pfile.open(filename, file::mode::readwrite); - pwritable = pfile.open(); - if(!pwritable) pfile.open(filename, file::mode::read); - } - - filestream(const string &filename, file::mode mode) { - pfile.open(filename, mode); - pwritable = mode == file::mode::write || mode == file::mode::readwrite; - } - -private: - mutable file pfile; - bool pwritable; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/gzip.hpp b/kaijuu/nall/stream/gzip.hpp deleted file mode 100644 index 0c270a72..00000000 --- a/kaijuu/nall/stream/gzip.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NALL_STREAM_GZIP_HPP -#define NALL_STREAM_GZIP_HPP - -#include - -namespace nall { - -struct gzipstream : memorystream { - using stream::read; - using stream::write; - - gzipstream(const stream &stream) { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - gzip archive; - bool result = archive.decompress(data, size); - delete[] data; - if(result == false) return; - - psize = archive.size; - pdata = new uint8_t[psize]; - memcpy(pdata, archive.data, psize); - } - - ~gzipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/kaijuu/nall/stream/http.hpp b/kaijuu/nall/stream/http.hpp deleted file mode 100644 index 2f9e45dd..00000000 --- a/kaijuu/nall/stream/http.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef NALL_STREAM_HTTP_HPP -#define NALL_STREAM_HTTP_HPP - -#include - -namespace nall { - -struct httpstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return true; } - bool randomaccess() const { return true; } - - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - httpstream(const string &url, unsigned port) : pdata(nullptr), psize(0), poffset(0) { - string uri = url; - uri.ltrim<1>("http://"); - lstring part = uri.split<1>("/"); - part[1] = { "/", part[1] }; - - http connection; - if(connection.connect(part[0], port) == false) return; - connection.download(part[1], pdata, psize); - } - - ~httpstream() { - if(pdata) delete[] pdata; - } - -private: - mutable uint8_t *pdata; - mutable unsigned psize, poffset; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/memory.hpp b/kaijuu/nall/stream/memory.hpp deleted file mode 100644 index cf49b3b2..00000000 --- a/kaijuu/nall/stream/memory.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef NALL_STREAM_MEMORY_HPP -#define NALL_STREAM_MEMORY_HPP - -#include - -namespace nall { - -struct memorystream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t *data() const { return pdata; } - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - memorystream() : pdata(nullptr), psize(0), poffset(0), pwritable(true) {} - - memorystream(uint8_t *data, unsigned size) { - pdata = data, psize = size, poffset = 0; - pwritable = true; - } - - memorystream(const uint8_t *data, unsigned size) { - pdata = (uint8_t*)data, psize = size, poffset = 0; - pwritable = false; - } - -protected: - mutable uint8_t *pdata; - mutable unsigned psize, poffset, pwritable; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/mmap.hpp b/kaijuu/nall/stream/mmap.hpp deleted file mode 100644 index ce30f810..00000000 --- a/kaijuu/nall/stream/mmap.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_MMAP_HPP -#define NALL_STREAM_MMAP_HPP - -#include - -namespace nall { - -struct mmapstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - unsigned size() const { return pmmap.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - mmapstream(const string &filename) { - pmmap.open(filename, filemap::mode::readwrite); - pwritable = pmmap.open(); - if(!pwritable) pmmap.open(filename, filemap::mode::read); - pdata = pmmap.data(), poffset = 0; - } - -private: - mutable filemap pmmap; - mutable uint8_t *pdata; - mutable unsigned pwritable, poffset; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/stream.hpp b/kaijuu/nall/stream/stream.hpp deleted file mode 100644 index 9d937729..00000000 --- a/kaijuu/nall/stream/stream.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef NALL_STREAM_STREAM_HPP -#define NALL_STREAM_STREAM_HPP - -namespace nall { - -struct stream { - virtual bool seekable() const = 0; - virtual bool readable() const = 0; - virtual bool writable() const = 0; - virtual bool randomaccess() const = 0; - - virtual uint8_t* data() const { return nullptr; } - virtual unsigned size() const = 0; - virtual unsigned offset() const = 0; - virtual void seek(unsigned offset) const = 0; - - virtual uint8_t read() const = 0; - virtual void write(uint8_t data) const = 0; - - virtual uint8_t read(unsigned) const { return 0; } - virtual void write(unsigned, uint8_t) const {} - - operator bool() const { - return size(); - } - - bool empty() const { - return size() == 0; - } - - bool end() const { - return offset() >= size(); - } - - uintmax_t readl(unsigned length = 1) const { - uintmax_t data = 0, shift = 0; - while(length--) { data |= read() << shift; shift += 8; } - return data; - } - - uintmax_t readm(unsigned length = 1) const { - uintmax_t data = 0; - while(length--) data = (data << 8) | read(); - return data; - } - - void read(uint8_t *data, unsigned length) const { - while(length--) *data++ = read(); - } - - void writel(uintmax_t data, unsigned length = 1) const { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) const { - uintmax_t shift = 8 * length; - while(length--) { - shift -= 8; - write(data >> shift); - } - } - - void write(const uint8_t *data, unsigned length) const { - while(length--) write(*data++); - } - - struct byte { - operator uint8_t() const { return s.read(offset); } - byte& operator=(uint8_t data) { s.write(offset, data); return *this; } - byte(const stream &s, unsigned offset) : s(s), offset(offset) {} - - private: - const stream &s; - const unsigned offset; - }; - - byte operator[](unsigned offset) const { - return byte(*this, offset); - } - - stream() {} - virtual ~stream() {} - stream(const stream&) = delete; - stream& operator=(const stream&) = delete; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/vector.hpp b/kaijuu/nall/stream/vector.hpp deleted file mode 100644 index 59f36c02..00000000 --- a/kaijuu/nall/stream/vector.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef NALL_STREAM_VECTOR_HPP -#define NALL_STREAM_VECTOR_HPP - -#include -#include - -namespace nall { - -struct vectorstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t* data() const { return memory.data(); } - unsigned size() const { return memory.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return memory[poffset++]; } - void write(uint8_t data) const { memory[poffset++] = data; } - - uint8_t read(unsigned offset) const { return memory[offset]; } - void write(unsigned offset, uint8_t data) const { memory[offset] = data; } - - vectorstream(vector &memory) : memory(memory), poffset(0), pwritable(true) {} - vectorstream(const vector &memory) : memory((vector&)memory), poffset(0), pwritable(false) {} - -protected: - vector &memory; - mutable unsigned poffset, pwritable; -}; - -} - -#endif diff --git a/kaijuu/nall/stream/zip.hpp b/kaijuu/nall/stream/zip.hpp deleted file mode 100644 index 975cdeff..00000000 --- a/kaijuu/nall/stream/zip.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef NALL_STREAM_ZIP_HPP -#define NALL_STREAM_ZIP_HPP - -#include - -namespace nall { - -struct zipstream : memorystream { - using stream::read; - using stream::write; - - zipstream(const stream &stream, const string &filter = "*") { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - zip archive; - if(archive.open(data, size) == false) return; - delete[] data; - - for(auto &file : archive.file) { - if(file.name.wildcard(filter)) { - auto buffer = archive.extract(file); - psize = buffer.size(); - pdata = buffer.move(); - return; - } - } - } - - ~zipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/kaijuu/nall/string.hpp b/kaijuu/nall/string.hpp deleted file mode 100644 index 8c4f6b2c..00000000 --- a/kaijuu/nall/string.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef NALL_STRING_HPP -#define NALL_STRING_HPP - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define NALL_STRING_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STRING_INTERNAL_HPP - -#endif diff --git a/kaijuu/nall/string/base.hpp b/kaijuu/nall/string/base.hpp deleted file mode 100644 index f70c1247..00000000 --- a/kaijuu/nall/string/base.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - struct cstring; - struct string; - struct lstring; - template inline const char* to_string(T); - - struct cstring { - inline operator const char*() const; - inline unsigned length() const; - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline cstring& operator=(const char *data); - inline cstring(const char *data); - inline cstring(); - - protected: - const char *data; - }; - - struct string { - inline static string read(const string &filename); - - inline void reserve(unsigned); - inline bool empty() const; - - template inline string& assign(Args&&... args); - template inline string& append(Args&&... args); - - inline bool readfile(const string&); - - template inline string& replace(const char*, const char*); - template inline string& ireplace(const char*, const char*); - template inline string& qreplace(const char*, const char*); - template inline string& iqreplace(const char*, const char*); - - inline unsigned length() const; - inline unsigned capacity() const; - - template inline lstring split(const char*) const; - template inline lstring isplit(const char*) const; - template inline lstring qsplit(const char*) const; - template inline lstring iqsplit(const char*) const; - - inline bool equals(const char*) const; - inline bool iequals(const char*) const; - - inline bool wildcard(const char*) const; - inline bool iwildcard(const char*) const; - - inline bool beginswith(const char*) const; - inline bool ibeginswith(const char*) const; - inline bool endswith(const char*) const; - inline bool iendswith(const char*) const; - - inline string& lower(); - inline string& upper(); - inline string& qlower(); - inline string& qupper(); - inline string& transform(const char *before, const char *after); - - template inline string& ltrim(const char *key = " "); - template inline string& rtrim(const char *key = " "); - template inline string& trim(const char *key = " ", const char *rkey = 0); - - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline optional qposition(const char *key) const; - inline optional iqposition(const char *key) const; - - inline operator const char*() const; - inline char* operator()(); - inline char& operator[](int); - - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline bool operator< (const char*) const; - inline bool operator<=(const char*) const; - inline bool operator> (const char*) const; - inline bool operator>=(const char*) const; - - inline string& operator=(const string&); - inline string& operator=(string&&); - - template inline string(Args&&... args); - inline string(const string&); - inline string(string&&); - inline ~string(); - - inline char* begin() { return &data[0]; } - inline char* end() { return &data[length()]; } - inline const char* begin() const { return &data[0]; } - inline const char* end() const { return &data[length()]; } - - //internal functions - inline string& assign_(const char*); - inline string& append_(const char*); - - protected: - char *data; - unsigned size; - - template inline string& ureplace(const char*, const char*); - - #if defined(QSTRING_H) - public: - inline operator QString() const; - #endif - }; - - struct lstring : vector { - inline optional find(const char*) const; - inline string concatenate(const char*) const; - inline void append() {} - template inline void append(const string&, Args&&...); - - template inline lstring& split(const char*, const char*); - template inline lstring& isplit(const char*, const char*); - template inline lstring& qsplit(const char*, const char*); - template inline lstring& iqsplit(const char*, const char*); - - inline bool operator==(const lstring&) const; - inline bool operator!=(const lstring&) const; - - inline lstring& operator=(const lstring&); - inline lstring& operator=(lstring&); - inline lstring& operator=(lstring&&); - - template inline lstring(Args&&... args); - inline lstring(const lstring&); - inline lstring(lstring&); - inline lstring(lstring&&); - - protected: - template inline lstring& usplit(const char*, const char*); - }; - - //compare.hpp - inline char chrlower(char c); - inline char chrupper(char c); - inline int istrcmp(const char *str1, const char *str2); - inline bool strbegin(const char *str, const char *key); - inline bool istrbegin(const char *str, const char *key); - inline bool strend(const char *str, const char *key); - inline bool istrend(const char *str, const char *key); - - //convert.hpp - inline char* strlower(char *str); - inline char* strupper(char *str); - inline char* qstrlower(char *str); - inline char* qstrupper(char *str); - inline char* strtr(char *dest, const char *before, const char *after); - - //math.hpp - inline bool strint(const char *str, int &result); - inline bool strmath(const char *str, int &result); - - //platform.hpp - inline string activepath(); - inline string realpath(const string &name); - inline string userpath(); - inline string configpath(); - - //strm.hpp - inline unsigned strmcpy(char *target, const char *source, unsigned length); - inline unsigned strmcat(char *target, const char *source, unsigned length); - inline bool strccpy(char *target, const char *source, unsigned length); - inline bool strccat(char *target, const char *source, unsigned length); - inline void strpcpy(char *&target, const char *source, unsigned &length); - - //strpos.hpp - inline optional strpos(const char *str, const char *key); - inline optional istrpos(const char *str, const char *key); - inline optional qstrpos(const char *str, const char *key); - inline optional iqstrpos(const char *str, const char *key); - template inline optional ustrpos(const char *str, const char *key); - - //trim.hpp - template inline char* ltrim(char *str, const char *key = " "); - template inline char* rtrim(char *str, const char *key = " "); - template inline char* trim(char *str, const char *key = " ", const char *rkey = 0); - - //utility.hpp - template alwaysinline bool chrequal(char x, char y); - template alwaysinline bool quoteskip(T *&p); - template alwaysinline bool quotecopy(char *&t, T *&p); - inline string substr(const char *src, unsigned start = 0, unsigned length = ~0u); - inline string sha256(const uint8_t *data, unsigned size); - - inline char* integer(char *result, intmax_t value); - inline char* decimal(char *result, uintmax_t value); - - template inline string integer(intmax_t value); - template inline string linteger(intmax_t value); - template inline string decimal(uintmax_t value); - template inline string ldecimal(uintmax_t value); - template inline string hex(uintmax_t value); - template inline string binary(uintmax_t value); - inline unsigned fp(char *str, long double value); - inline string fp(long double value); - - //variadic.hpp - template inline void print(Args&&... args); - - //wildcard.hpp - inline bool wildcard(const char *str, const char *pattern); - inline bool iwildcard(const char *str, const char *pattern); -}; - -#endif diff --git a/kaijuu/nall/string/bml.hpp b/kaijuu/nall/string/bml.hpp deleted file mode 100644 index de1f07a0..00000000 --- a/kaijuu/nall/string/bml.hpp +++ /dev/null @@ -1,151 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BML v1.0 parser -//revision 0.05 - -namespace nall { -namespace BML { - -inline static string indent(const char *s, unsigned depth) { - vector output; - do { - for(unsigned n = 0; n < depth; n++) output.append('\t'); - do output.append(*s); while(*s && *s++ != '\n'); - } while(*s); - return output.data(); -} - -struct Node { - cstring name; - cstring value; - -private: - vector children; - - inline bool valid(char p) const { //A-Za-z0-9-. - return p - 'A' < 26u | p - 'a' < 26u | p - '0' < 10u | p - '-' < 2u; - } - - inline unsigned parseDepth(char *&p) { - while(*p == '\n' || *p == '#') { - while(*p != '\n') *p++ = 0; - *p++ = 0; //'\n' - } - unsigned depth = 0; - while(p[depth] == '\t') depth++; - return depth; - } - - inline void parseName(char *&p) { - if(valid(*p) == false) throw "Missing node name"; - name = p; - while(valid(*p)) p++; - } - - inline void parseValue(char *&p) { - char terminal = *p == ':' ? '\n' : ' '; //':' or '=' - *p++ = 0; - value = p; - while(*p && *p != terminal && *p != '\n') p++; - } - - inline void parseBlock(char *&p, unsigned depth) { - value = p; - char *w = p; - while(parseDepth(p) > depth) { - p += depth + 1; - while(*p && *p != '\n') *w++ = *p++; - if(*p && *p != '\n') throw "Multi-line value missing line feed"; - *w++ = *p; - } - *(w - 1) = 0; //'\n' - } - - inline void parseLine(char *&p) { - unsigned depth = parseDepth(p); - while(*p == '\t') p++; - - parseName(p); - bool multiLine = *p == '~'; - if(multiLine) *p++ = 0; - else if(*p == ':' || *p == '=') parseValue(p); - if(*p && *p != ' ' && *p != '\n') throw "Invalid character encountered"; - - while(*p == ' ') { - *p++ = 0; - Node node; - node.parseName(p); - if(*p == ':' || *p == '=') node.parseValue(p); - if(*p && *p != ' ' && *p != '\n') throw "Invalid character after node"; - if(*p == '\n') *p++ = 0; - children.append(node); - } - - if(multiLine) return parseBlock(p, depth); - - while(parseDepth(p) > depth) { - Node node; - node.parseLine(p); - children.append(node); - } - } - - inline void parse(char *&p) { - while(*p) { - Node node; - node.parseLine(p); - children.append(node); - } - } - -public: - inline Node& operator[](const char *name) { - for(auto &node : children) { - if(node.name == name) return node; - } - static Node node; - node.name = nullptr; - return node; - } - - inline bool exists() const { return name; } - unsigned size() const { return children.size(); } - Node* begin() { return children.begin(); } - Node* end() { return children.end(); } - const Node* begin() const { return children.begin(); } - const Node* end() const { return children.end(); } - inline Node() : name(""), value("") {} - friend class Document; -}; - -struct Document : Node { - cstring error; - - inline bool load(const char *document) { - if(document == nullptr) return false; - this->document = strdup(document); - char *p = this->document; - try { - this->error = nullptr; - parse(p); - } catch(const char *error) { - this->error = error; - free(this->document); - this->document = nullptr; - children.reset(); - return false; - } - return true; - } - - inline Document(const char *document = "") : document(nullptr), error(nullptr) { if(*document) load(document); } - inline ~Document() { if(document) free(document); } - -private: - char *document; -}; - -} -} - -#endif diff --git a/kaijuu/nall/string/bsv.hpp b/kaijuu/nall/string/bsv.hpp deleted file mode 100644 index d9415d53..00000000 --- a/kaijuu/nall/string/bsv.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BSV v1.0 parser -//revision 0.02 - -namespace nall { - -struct BSV { - static inline string decode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '}' ) return ""; - if(*input == '\r') return ""; - if(*input == '\n') return ""; - - //normal characters - if(*input != '{') { output[offset++] = *input++; continue; } - - //entities - if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; } - if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; } - if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; } - - //illegal entities - return ""; - } - output[offset] = 0; - return output; - } - - static inline string encode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '\r') return ""; - - if(*input == '\n') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'f'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '{') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '}') { - output[offset++] = '{'; - output[offset++] = 'r'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - output[offset++] = *input++; - } - output[offset] = 0; - return output; - } -}; - -} - -#endif diff --git a/kaijuu/nall/string/cast.hpp b/kaijuu/nall/string/cast.hpp deleted file mode 100644 index 7c7e276b..00000000 --- a/kaijuu/nall/string/cast.hpp +++ /dev/null @@ -1,185 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//convert any (supported) type to a const char* without constructing a new nall::string -//this is used inside istring(...) to build nall::string values -template struct stringify; - -// base types - -template<> struct stringify { - bool value; - operator const char*() const { return value ? "true" : "false"; } - stringify(bool value) : value(value) {} -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(char value) { integer(data, value); } -}; - -// signed integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed char value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed short value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed int value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long long value) { integer(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(int_t value) { integer(data, value); } -}; - -// unsigned integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned char value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned short value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned int value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long long value) { decimal(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(uint_t value) { decimal(data, value); } -}; - -// floating-point - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(float value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(double value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(long double value) { fp(data, value); } -}; - -// strings - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(char *value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const char *value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -#if defined(QSTRING_H) - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -string::operator QString() const { - return QString::fromUtf8(*this); -} - -#endif - -// - -template stringify make_string(T value) { - return stringify(std::forward(value)); -} - -} - -#endif diff --git a/kaijuu/nall/string/compare.hpp b/kaijuu/nall/string/compare.hpp deleted file mode 100644 index 941c8e67..00000000 --- a/kaijuu/nall/string/compare.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char chrlower(char c) { - return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; -} - -char chrupper(char c) { - return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; -} - -int istrcmp(const char *str1, const char *str2) { - while(*str1) { - if(chrlower(*str1) != chrlower(*str2)) break; - str1++, str2++; - } - return (int)chrlower(*str1) - (int)chrlower(*str2); -} - -bool strbegin(const char *str, const char *key) { - int i, ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str, key, ksl)); -} - -bool istrbegin(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = 0; i < ksl; i++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[i] && str[i]+0x20 != key[i])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[i] && str[i]-0x20 != key[i])return false; - } else { - if(str[i] != key[i])return false; - } - } - return true; -} - -bool strend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str + ssl - ksl, key, ksl)); -} - -bool istrend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = ssl - ksl, z = 0; i < ssl; i++, z++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[z] && str[i]+0x20 != key[z])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[z] && str[i]-0x20 != key[z])return false; - } else { - if(str[i] != key[z])return false; - } - } - return true; -} - -} - -#endif diff --git a/kaijuu/nall/string/convert.hpp b/kaijuu/nall/string/convert.hpp deleted file mode 100644 index f5a2a780..00000000 --- a/kaijuu/nall/string/convert.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char* strlower(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrlower(str[i]); - i++; - } - return str; -} - -char* strupper(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrupper(str[i]); - i++; - } - return str; -} - -char* qstrlower(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'A' && *s <= 'Z') *s += 0x20; - s++; - } -} - -char* qstrupper(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'a' && *s <= 'z') *s -= 0x20; - s++; - } -} - -char* strtr(char *dest, const char *before, const char *after) { - if(!dest || !before || !after) return dest; - int sl = strlen(dest), bsl = strlen(before), asl = strlen(after); - - if(bsl != asl || bsl == 0) return dest; //patterns must be the same length for 1:1 replace - for(unsigned i = 0; i < sl; i++) { - for(unsigned l = 0; l < bsl; l++) { - if(dest[i] == before[l]) { - dest[i] = after[l]; - break; - } - } - } - - return dest; -} - -} - -#endif diff --git a/kaijuu/nall/string/core.hpp b/kaijuu/nall/string/core.hpp deleted file mode 100644 index d5f75f3a..00000000 --- a/kaijuu/nall/string/core.hpp +++ /dev/null @@ -1,200 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -static void istring(string &output) { -} - -template -static void istring(string &output, const T &value, Args&&... args) { - output.append_(make_string(value)); - istring(output, std::forward(args)...); -} - -void string::reserve(unsigned size_) { - if(size_ > size) { - size = size_; - data = (char*)realloc(data, size + 1); - data[size] = 0; - } -} - -bool string::empty() const { - return !*data; -} - -template string& string::assign(Args&&... args) { - *data = 0; - istring(*this, std::forward(args)...); - return *this; -} - -template string& string::append(Args&&... args) { - istring(*this, std::forward(args)...); - return *this; -} - -string& string::assign_(const char *s) { - unsigned length = strlen(s); - reserve(length); - strcpy(data, s); - return *this; -} - -string& string::append_(const char *s) { - unsigned length = strlen(data) + strlen(s); - reserve(length); - strcat(data, s); - return *this; -} - -string::operator const char*() const { - return data; -} - -char* string::operator()() { - return data; -} - -char& string::operator[](int index) { - reserve(index); - return data[index]; -} - -bool string::operator==(const char *str) const { return strcmp(data, str) == 0; } -bool string::operator!=(const char *str) const { return strcmp(data, str) != 0; } -bool string::operator< (const char *str) const { return strcmp(data, str) < 0; } -bool string::operator<=(const char *str) const { return strcmp(data, str) <= 0; } -bool string::operator> (const char *str) const { return strcmp(data, str) > 0; } -bool string::operator>=(const char *str) const { return strcmp(data, str) >= 0; } - -string& string::operator=(const string &value) { - if(&value == this) return *this; - assign(value); - return *this; -} - -string& string::operator=(string &&source) { - if(&source == this) return *this; - if(data) free(data); - size = source.size; - data = source.data; - source.data = nullptr; - source.size = 0; - return *this; -} - -template string::string(Args&&... args) { - size = 64; - data = (char*)malloc(size + 1); - *data = 0; - istring(*this, std::forward(args)...); -} - -string::string(const string &value) { - if(&value == this) return; - size = strlen(value); - data = strdup(value); -} - -string::string(string &&source) { - if(&source == this) return; - size = source.size; - data = source.data; - source.data = nullptr; -} - -string::~string() { - if(data) free(data); -} - -bool string::readfile(const string &filename) { - assign(""); - - #if !defined(_WIN32) - FILE *fp = fopen(filename, "rb"); - #else - FILE *fp = _wfopen(utf16_t(filename), L"rb"); - #endif - if(!fp) return false; - - fseek(fp, 0, SEEK_END); - unsigned size = ftell(fp); - rewind(fp); - char *fdata = new char[size + 1]; - unsigned unused = fread(fdata, 1, size, fp); - fclose(fp); - fdata[size] = 0; - assign(fdata); - delete[] fdata; - - return true; -} - -optional lstring::find(const char *key) const { - for(unsigned i = 0; i < size(); i++) { - if(operator[](i) == key) return { true, i }; - } - return { false, 0 }; -} - -string lstring::concatenate(const char *separator) const { - string output; - for(unsigned i = 0; i < size(); i++) { - output.append(operator[](i), i < size() - 1 ? separator : ""); - } - return output; -} - -template void lstring::append(const string &data, Args&&... args) { - vector::append(data); - append(std::forward(args)...); -} - -bool lstring::operator==(const lstring &source) const { - if(this == &source) return true; - if(size() != source.size()) return false; - for(unsigned n = 0; n < size(); n++) { - if(operator[](n) != source[n]) return false; - } - return true; -} - -bool lstring::operator!=(const lstring &source) const { - return !operator==(source); -} - -lstring& lstring::operator=(const lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &&source) { - vector::operator=(std::move(source)); - return *this; -} - -template lstring::lstring(Args&&... args) { - append(std::forward(args)...); -} - -lstring::lstring(const lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &&source) { - vector::operator=(std::move(source)); -} - -} - -#endif diff --git a/kaijuu/nall/string/cstring.hpp b/kaijuu/nall/string/cstring.hpp deleted file mode 100644 index 13b508ff..00000000 --- a/kaijuu/nall/string/cstring.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//const string: -//bind a const char* pointer to an object that has various testing functionality; -//yet lacks the memory allocation and modification functionality of the string class - -namespace nall { - -cstring::operator const char*() const { return data; } -unsigned cstring::length() const { return strlen(data); } -bool cstring::operator==(const char *s) const { return !strcmp(data, s); } -bool cstring::operator!=(const char *s) const { return strcmp(data, s); } -optional cstring::position (const char *key) const { return strpos(data, key); } -optional cstring::iposition(const char *key) const { return istrpos(data, key); } -cstring& cstring::operator=(const char *data) { this->data = data; return *this; } -cstring::cstring(const char *data) : data(data) {} -cstring::cstring() : data("") {} - -} - -#endif diff --git a/kaijuu/nall/string/filename.hpp b/kaijuu/nall/string/filename.hpp deleted file mode 100644 index 19b5f117..00000000 --- a/kaijuu/nall/string/filename.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// "/foo/bar.c" -> "/foo/" -// "/foo/" -> "/foo/" -// "bar.c" -> "./" -inline string dir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - name[i + 1] = 0; - break; - } - if(i == 0) name = "./"; - } - return name; -} - -// "/foo/bar.c" -> "bar.c" -// "/foo/" -> "" -// "bar.c" -> "bar.c" -inline string notdir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - return (const char*)name + i + 1; - } - } - return name; -} - -// "/foo/bar/baz" -> "/foo/bar/" -// "/foo/bar/" -> "/foo/" -// "/foo/bar" -> "/foo/" -inline string parentdir(string name) { - unsigned length = name.length(), paths = 0, prev, last; - for(unsigned i = 0; i < length; i++) { - if(name[i] == '/' || name[i] == '\\') { - paths++; - prev = last; - last = i; - } - } - if(last + 1 == length) last = prev; //if name ends in slash; use previous slash - if(paths > 1) name[last + 1] = 0; - return name; -} - -// "/foo/bar.c" -> "/foo/bar" -inline string basename(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') break; //file has no extension - if(name[i] == '.') { - name[i] = 0; - break; - } - } - return name; -} - -// "/foo/bar.c" -> "c" -// "/foo/bar" -> "" -inline string extension(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') return ""; //file has no extension - if(name[i] == '.') { - return (const char*)name + i + 1; - } - } - return name; -} - -} - -#endif diff --git a/kaijuu/nall/string/math-fixed-point.hpp b/kaijuu/nall/string/math-fixed-point.hpp deleted file mode 100644 index a61b23f3..00000000 --- a/kaijuu/nall/string/math-fixed-point.hpp +++ /dev/null @@ -1,166 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace fixedpoint { - -static nall::function eval_fallback; - -static intmax_t eval_integer(const char *& s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - return value; - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static intmax_t eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - intmax_t value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 13); - else if(x == '~') value = ~eval(++s, 13); - else if(x == '+') value = +eval(++s, 13); - else if(x == '-') value = -eval(++s, 13); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 13) break; - if(x == '*') { value *= eval(++s, 13); continue; } - if(x == '/') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value /= result; continue; } - if(x == '%') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value %= result; continue; } - - if(depth >= 12) break; - if(x == '+') { value += eval(++s, 12); continue; } - if(x == '-') { value -= eval(++s, 12); continue; } - - if(depth >= 11) break; - if(x == '<' && y == '<') { value <<= eval(++++s, 11); continue; } - if(x == '>' && y == '>') { value >>= eval(++++s, 11); continue; } - - if(depth >= 10) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 10); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 10); continue; } - if(x == '<') { value = value < eval(++s, 10); continue; } - if(x == '>') { value = value > eval(++s, 10); continue; } - - if(depth >= 9) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 9); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 9); continue; } - - if(depth >= 8) break; - if(x == '&' && y != '&') { value = value & eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '^' && y != '^') { value = value ^ eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '|' && y != '|') { value = value | eval(++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - intmax_t lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - intmax_t rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, intmax_t &result) { - try { - result = eval(s); - return true; - } catch(const char*) { - result = 0; - return false; - } -} - -static intmax_t parse(const char *s) { - try { - intmax_t result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/kaijuu/nall/string/math-floating-point.hpp b/kaijuu/nall/string/math-floating-point.hpp deleted file mode 100644 index 43a2f0f4..00000000 --- a/kaijuu/nall/string/math-floating-point.hpp +++ /dev/null @@ -1,157 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace floatingpoint { - -static nall::function eval_fallback; - -static double eval_integer(const char *&s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, radix = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0' && y != '.') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - if(*s == '.') { s++; break; } - return value; - } - //floating-point - while(true) { - if(*s >= '0' && *s <= '9') { radix = radix * 10 + (*s++ - '0'); continue; } - return atof(nall::string{ nall::decimal(value), ".", nall::decimal(radix) }); - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static double eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - double value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 9); - else if(x == '+') value = +eval(++s, 9); - else if(x == '-') value = -eval(++s, 9); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 9) break; - if(x == '*') { value *= eval(++s, 9); continue; } - if(x == '/') { double result = eval(++s, 9); if(result == 0.0) throw "division by zero"; value /= result; continue; } - - if(depth >= 8) break; - if(x == '+') { value += eval(++s, 8); continue; } - if(x == '-') { value -= eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 7); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 7); continue; } - if(x == '<') { value = value < eval(++s, 7); continue; } - if(x == '>') { value = value > eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 6); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - double lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - double rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, double &result) { - try { - result = eval(s); - return true; - } catch(const char*e) { - result = 0; - return false; - } -} - -static double parse(const char *s) { - try { - double result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/kaijuu/nall/string/platform.hpp b/kaijuu/nall/string/platform.hpp deleted file mode 100644 index 469d79b3..00000000 --- a/kaijuu/nall/string/platform.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string activepath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - _wgetcwd(path, PATH_MAX); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - getcwd(path, PATH_MAX); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string realpath(const string &name) { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - if(::realpath(name, path)) result = path; - #endif - return result; -} - -string userpath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - struct passwd *userinfo = getpwuid(getuid()); - if(userinfo) strcpy(path, userinfo->pw_dir); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string configpath() { - #ifdef _WIN32 - return userpath(); - #else - return {userpath(), ".config/"}; - #endif -} - -} - -#endif diff --git a/kaijuu/nall/string/replace.hpp b/kaijuu/nall/string/replace.hpp deleted file mode 100644 index 2bd1412f..00000000 --- a/kaijuu/nall/string/replace.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -string& string::ureplace(const char *key, const char *token) { - if(!key || !*key) return *this; - enum : unsigned { limit = Limit ? Limit : ~0u }; - - const char *p = data; - unsigned counter = 0, keyLength = 0; - - while(*p) { - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter++; p += n; keyLength = n; break; } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - if(counter == 0) return *this; - if(Limit) counter = min(counter, Limit); - - char *t = data, *base; - unsigned tokenLength = strlen(token); - if(tokenLength > keyLength) { - t = base = strdup(data); - reserve((unsigned)(p - data) + ((tokenLength - keyLength) * counter)); - } - char *o = data; - - while(*t && counter) { - if(quotecopy(o, t)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter--; memcpy(o, token, tokenLength); t += keyLength; o += tokenLength; break; } - if(!chrequal(key[n], t[n])) { *o++ = *t++; break; } - } - } - do *o++ = *t; while(*t++); - if(tokenLength > keyLength) free(base); - - return *this; -} - -template string &string::replace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::ireplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::qreplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::iqreplace(const char *key, const char *token) { return ureplace(key, token); } - -}; - -#endif diff --git a/kaijuu/nall/string/split.hpp b/kaijuu/nall/string/split.hpp deleted file mode 100644 index bb12a91b..00000000 --- a/kaijuu/nall/string/split.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template lstring& lstring::usplit(const char *key, const char *base) { - reset(); - if(!key || !*key) return *this; - - const char *p = base; - - while(*p) { - if(Limit) if(size() >= Limit) break; - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { - append(substr(base, 0, p - base)); - p += n; - base = p; - break; - } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - - append(base); - return *this; -} - -template lstring& lstring::split(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::isplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::qsplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::iqsplit(const char *key, const char *src) { return usplit(key, src); } - -}; - -#endif diff --git a/kaijuu/nall/string/static.hpp b/kaijuu/nall/string/static.hpp deleted file mode 100644 index ca521cb0..00000000 --- a/kaijuu/nall/string/static.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string string::read(const string &filename) { - string data; - data.readfile(filename); - return data; -} - -} - -#endif diff --git a/kaijuu/nall/string/strm.hpp b/kaijuu/nall/string/strm.hpp deleted file mode 100644 index 21d05652..00000000 --- a/kaijuu/nall/string/strm.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// -//strmcpy, strmcat created by byuu -// - -//return = strlen(target) -unsigned strmcpy(char *target, const char *source, unsigned length) { - const char *origin = target; - if(length) { - while(*source && --length) *target++ = *source++; - *target = 0; - } - return target - origin; -} - -//return = strlen(target) -unsigned strmcat(char *target, const char *source, unsigned length) { - const char *origin = target; - while(*target && length) target++, length--; - return (target - origin) + strmcpy(target, source, length); -} - -//return = true when all of source was copied -bool strccpy(char *target, const char *source, unsigned length) { - return !source[strmcpy(target, source, length)]; -} - -//return = true when all of source was copied -bool strccat(char *target, const char *source, unsigned length) { - while(*target && length) target++, length--; - return !source[strmcpy(target, source, length)]; -} - -//return = reserved for future use -void strpcpy(char *&target, const char *source, unsigned &length) { - unsigned offset = strmcpy(target, source, length); - target += offset, length -= offset; -} - -} - -#endif diff --git a/kaijuu/nall/string/strpos.hpp b/kaijuu/nall/string/strpos.hpp deleted file mode 100644 index fe563a6c..00000000 --- a/kaijuu/nall/string/strpos.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//usage example: -//if(auto position = strpos(str, key)) print(position(), "\n"); -//prints position of key within str; but only if it is found - -namespace nall { - -template -optional ustrpos(const char *str, const char *key) { - const char *base = str; - - while(*str) { - if(quoteskip(str)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) return { true, (unsigned)(str - base) }; - if(str[n] == 0) return { false, 0 }; - if(!chrequal(str[n], key[n])) break; - } - str++; - } - - return { false, 0 }; -} - -optional strpos(const char *str, const char *key) { return ustrpos(str, key); } -optional istrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional qstrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional iqstrpos(const char *str, const char *key) { return ustrpos(str, key); } - -} - -#endif diff --git a/kaijuu/nall/string/trim.hpp b/kaijuu/nall/string/trim.hpp deleted file mode 100644 index ba049d71..00000000 --- a/kaijuu/nall/string/trim.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//limit defaults to zero, which will underflow on first compare; equivalent to no limit -template char* ltrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strbegin(str, key)) { - char *dest = str, *src = str + strlen(key); - while(true) { - *dest = *src++; - if(!*dest) break; - dest++; - } - if(--limit == 0) break; - } - return str; -} - -template char* rtrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strend(str, key)) { - str[strlen(str) - strlen(key)] = 0; - if(--limit == 0) break; - } - return str; -} - -template char* trim(char *str, const char *key, const char *rkey) { - if(rkey) return ltrim(rtrim(str, rkey), key); - return ltrim(rtrim(str, key), key); -} - -} - -#endif diff --git a/kaijuu/nall/string/utf8.hpp b/kaijuu/nall/string/utf8.hpp deleted file mode 100644 index 77397bf2..00000000 --- a/kaijuu/nall/string/utf8.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -struct UTF8 { - unsigned size; //size of encoded codepoint - uint64_t data; //encoded codepoint - unsigned codepoint; //decoded codepoint -}; - -inline UTF8 utf8_read(const char *s) { - UTF8 utf8; - - if((*s & 0xfe) == 0xfc) utf8.size = 6; - else if((*s & 0xfc) == 0xf8) utf8.size = 5; - else if((*s & 0xf8) == 0xf0) utf8.size = 4; - else if((*s & 0xf0) == 0xe0) utf8.size = 3; - else if((*s & 0xe0) == 0xc0) utf8.size = 2; - else utf8.size = 1; - - utf8.data = 0; - for(unsigned n = 0; n < utf8.size; n++) { - utf8.data = (utf8.data << 8) | (uint8_t)s[n]; - } - - static uint8_t mask[] = { 0, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; - utf8.codepoint = s[0] & mask[utf8.size]; - for(unsigned n = 1; n < utf8.size; n++) { - utf8.codepoint = (utf8.codepoint << 6) | (s[n] & 0x3f); - } - - return utf8; -} - -inline void utf8_write(char *s, const UTF8 &utf8) { - for(signed n = utf8.size - 1, shift = 0; n >= 0; n--, shift += 8) { - s[n] = utf8.data >> shift; - } -} - -} - -#endif diff --git a/kaijuu/nall/string/utility.hpp b/kaijuu/nall/string/utility.hpp deleted file mode 100644 index b2f93d2c..00000000 --- a/kaijuu/nall/string/utility.hpp +++ /dev/null @@ -1,283 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -bool chrequal(char x, char y) { - if(Insensitive) return chrlower(x) == chrlower(y); - return x == y; -} - -template -bool quoteskip(T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - while(*p && *p++ != x); - } - return true; -} - -template -bool quotecopy(char *&t, T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - *t++ = x; - while(*p && *p != x) *t++ = *p++; - *t++ = *p++; - } - return true; -} - -string substr(const char *src, unsigned start, unsigned length) { - string dest; - if(length == ~0u) { - //copy entire string - dest.reserve(strlen(src + start) + 1); - strcpy(dest(), src + start); - } else { - //copy partial string - dest.reserve(length + 1); - strmcpy(dest(), src + start, length + 1); - } - return dest; -} - -string sha256(const uint8_t *data, unsigned size) { - sha256_ctx sha; - uint8_t hash[32]; - sha256_init(&sha); - sha256_chunk(&sha, data, size); - sha256_final(&sha); - sha256_hash(&sha, hash); - string result; - for(auto &byte : hash) result.append(hex<2>(byte)); - return result; -} - -/* cast.hpp arithmetic -> string */ - -char* integer(char *result, intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size++] = negative ? '-' : '+'; - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -char* decimal(char *result, uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -/* general-purpose arithmetic -> string */ - -template string integer(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string linteger(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string decimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string ldecimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string hex(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value & 15; - buffer[size++] = n < 10 ? '0' + n : 'a' + n - 10; - value >>= 4; - } while(value); - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string binary(uintmax_t value) { - char buffer[256]; - unsigned size = 0; - - do { - unsigned n = value & 1; - buffer[size++] = '0' + n; - value >>= 1; - } while(value); - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -//using sprintf is certainly not the most ideal method to convert -//a double to a string ... but attempting to parse a double by -//hand, digit-by-digit, results in subtle rounding errors. -unsigned fp(char *str, long double value) { - char buffer[256]; - #ifdef _WIN32 - //Windows C-runtime does not support long double via sprintf() - sprintf(buffer, "%f", (double)value); - #else - sprintf(buffer, "%Lf", value); - #endif - - //remove excess 0's in fraction (2.500000 -> 2.5) - for(char *p = buffer; *p; p++) { - if(*p == '.') { - char *p = buffer + strlen(buffer) - 1; - while(*p == '0') { - if(*(p - 1) != '.') *p = 0; //... but not for eg 1.0 -> 1. - p--; - } - break; - } - } - - unsigned length = strlen(buffer); - if(str) strcpy(str, buffer); - return length + 1; -} - -string fp(long double value) { - string temp; - temp.reserve(fp(0, value)); - fp(temp(), value); - return temp; -} - -} - -#endif diff --git a/kaijuu/nall/string/variadic.hpp b/kaijuu/nall/string/variadic.hpp deleted file mode 100644 index c43bfe86..00000000 --- a/kaijuu/nall/string/variadic.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template inline void print(Args&&... args) { - printf("%s", (const char*)string(std::forward(args)...)); -} - -} - -#endif diff --git a/kaijuu/nall/string/wildcard.hpp b/kaijuu/nall/string/wildcard.hpp deleted file mode 100644 index 9d2359d5..00000000 --- a/kaijuu/nall/string/wildcard.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -bool wildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && *s != *p) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || *p == *s) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -bool iwildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && chrlower(*s) != chrlower(*p)) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || chrlower(*p) == chrlower(*s)) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(const char *s, const char *p) { - while(*s) { - if(*p == '*') { - while(*s) if(tokenize(s++, p + 1)) return true; - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(lstring &list, const char *s, const char *p) { - while(*s) { - if(*p == '*') { - const char *b = s; - while(*s) { - if(tokenize(list, s++, p + 1)) { - list.prepend(substr(b, 0, --s - b)); - return true; - } - } - list.prepend(b); - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') { list.prepend(s); p++; } - return !*p; -} - -} - -#endif diff --git a/kaijuu/nall/string/wrapper.hpp b/kaijuu/nall/string/wrapper.hpp deleted file mode 100644 index 9845e0b7..00000000 --- a/kaijuu/nall/string/wrapper.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -unsigned string::length() const { return strlen(data); } -unsigned string::capacity() const { return size; } - -template lstring string::split(const char *key) const { lstring result; result.split(key, data); return result; } -template lstring string::isplit(const char *key) const { lstring result; result.isplit(key, data); return result; } -template lstring string::qsplit(const char *key) const { lstring result; result.qsplit(key, data); return result; } -template lstring string::iqsplit(const char *key) const { lstring result; result.iqsplit(key, data); return result; } - -bool string::equals(const char *str) const { return !strcmp(data, str); } -bool string::iequals(const char *str) const { return !istrcmp(data, str); } - -bool string::wildcard(const char *str) const { return nall::wildcard(data, str); } -bool string::iwildcard(const char *str) const { return nall::iwildcard(data, str); } - -bool string::beginswith(const char *str) const { return strbegin(data, str); } -bool string::ibeginswith(const char *str) const { return istrbegin(data, str); } - -bool string::endswith(const char *str) const { return strend(data, str); } -bool string::iendswith(const char *str) const { return istrend(data, str); } - -string& string::lower() { nall::strlower(data); return *this; } -string& string::upper() { nall::strupper(data); return *this; } -string& string::qlower() { nall::qstrlower(data); return *this; } -string& string::qupper() { nall::qstrupper(data); return *this; } -string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } - -template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -template string& string::trim(const char *key, const char *rkey) { nall::trim (data, key, rkey); return *this; } - -optional string::position(const char *key) const { return strpos(data, key); } -optional string::iposition(const char *key) const { return istrpos(data, key); } -optional string::qposition(const char *key) const { return qstrpos(data, key); } -optional string::iqposition(const char *key) const { return iqstrpos(data, key); } - -} - -#endif diff --git a/kaijuu/nall/string/xml-legacy.hpp b/kaijuu/nall/string/xml-legacy.hpp deleted file mode 100644 index 069639b0..00000000 --- a/kaijuu/nall/string/xml-legacy.hpp +++ /dev/null @@ -1,265 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//XML v1.0 subset parser -//revision 0.05 - -namespace nall { - -struct xml_attribute { - string name; - string content; - virtual string parse() const; -}; - -struct xml_element : xml_attribute { - string parse() const; - linear_vector attribute; - linear_vector element; - -protected: - void parse_doctype(const char *&data); - bool parse_head(string data); - bool parse_body(const char *&data); - friend xml_element xml_parse(const char *data); -}; - -inline string xml_attribute::parse() const { - string data; - unsigned offset = 0; - - const char *source = content; - while(*source) { - if(*source == '&') { - if(strbegin(source, "<")) { data[offset++] = '<'; source += 4; continue; } - if(strbegin(source, ">")) { data[offset++] = '>'; source += 4; continue; } - if(strbegin(source, "&")) { data[offset++] = '&'; source += 5; continue; } - if(strbegin(source, "'")) { data[offset++] = '\''; source += 6; continue; } - if(strbegin(source, """)) { data[offset++] = '"'; source += 6; continue; } - } - - //reject illegal characters - if(*source == '&') return ""; - if(*source == '<') return ""; - if(*source == '>') return ""; - - data[offset++] = *source++; - } - - data[offset] = 0; - return data; -} - -inline string xml_element::parse() const { - string data; - unsigned offset = 0; - - const char *source = content; - while(*source) { - if(*source == '&') { - if(strbegin(source, "<")) { data[offset++] = '<'; source += 4; continue; } - if(strbegin(source, ">")) { data[offset++] = '>'; source += 4; continue; } - if(strbegin(source, "&")) { data[offset++] = '&'; source += 5; continue; } - if(strbegin(source, "'")) { data[offset++] = '\''; source += 6; continue; } - if(strbegin(source, """)) { data[offset++] = '"'; source += 6; continue; } - } - - if(strbegin(source, "")) { - source += pos() + 3; - continue; - } else { - return ""; - } - } - - if(strbegin(source, "")) { - if(pos() - 9 > 0) { - string cdata = substr(source, 9, pos() - 9); - data.append(cdata); - offset += strlen(cdata); - } - source += 9 + offset + 3; - continue; - } else { - return ""; - } - } - - //reject illegal characters - if(*source == '&') return ""; - if(*source == '<') return ""; - if(*source == '>') return ""; - - data[offset++] = *source++; - } - - data[offset] = 0; - return data; -} - -inline void xml_element::parse_doctype(const char *&data) { - name = "!DOCTYPE"; - const char *content_begin = data; - - signed counter = 0; - while(*data) { - char value = *data++; - if(value == '<') counter++; - if(value == '>') counter--; - if(counter < 0) { - content = substr(content_begin, 0, data - content_begin - 1); - return; - } - } - throw "..."; -} - -inline bool xml_element::parse_head(string data) { - data.qreplace("\t", " "); - data.qreplace("\r", " "); - data.qreplace("\n", " "); - while(qstrpos(data, " ")) data.qreplace(" ", " "); - data.qreplace(" =", "="); - data.qreplace("= ", "="); - data.rtrim(); - - lstring part; - part.qsplit(" ", data); - - name = part[0]; - if(name == "") throw "..."; - - for(unsigned i = 1; i < part.size(); i++) { - lstring side; - side.qsplit("=", part[i]); - if(side.size() != 2) throw "..."; - - xml_attribute attr; - attr.name = side[0]; - attr.content = side[1]; - if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim<1>("\""); - else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim<1>("'"); - else throw "..."; - attribute.append(attr); - } -} - -inline bool xml_element::parse_body(const char *&data) { - while(true) { - if(!*data) return false; - if(*data++ != '<') continue; - if(*data == '/') return false; - - if(strbegin(data, "!DOCTYPE") == true) { - parse_doctype(data); - return true; - } - - if(strbegin(data, "!--")) { - if(auto offset = strpos(data, "-->")) { - data += offset() + 3; - continue; - } else { - throw "..."; - } - } - - if(strbegin(data, "![CDATA[")) { - if(auto offset = strpos(data, "]]>")) { - data += offset() + 3; - continue; - } else { - throw "..."; - } - } - - auto offset = strpos(data, ">"); - if(!offset) throw "..."; - - string tag = substr(data, 0, offset()); - data += offset() + 1; - const char *content_begin = data; - - bool self_terminating = false; - - if(strend(tag, "?") == true) { - self_terminating = true; - tag.rtrim<1>("?"); - } else if(strend(tag, "/") == true) { - self_terminating = true; - tag.rtrim<1>("/"); - } - - parse_head(tag); - if(self_terminating) return true; - - while(*data) { - unsigned index = element.size(); - xml_element node; - if(node.parse_body(data) == false) { - if(*data == '/') { - signed length = data - content_begin - 1; - if(length > 0) content = substr(content_begin, 0, length); - - data++; - auto offset = strpos(data, ">"); - if(!offset) throw "..."; - - tag = substr(data, 0, offset()); - data += offset() + 1; - - tag.replace("\t", " "); - tag.replace("\r", " "); - tag.replace("\n", " "); - while(strpos(tag, " ")) tag.replace(" ", " "); - tag.rtrim(); - - if(name != tag) throw "..."; - return true; - } - } else { - element.append(node); - } - } - } -} - -//ensure there is only one root element -inline bool xml_validate(xml_element &document) { - unsigned root_counter = 0; - - for(unsigned i = 0; i < document.element.size(); i++) { - string &name = document.element[i].name; - if(strbegin(name, "?")) continue; - if(strbegin(name, "!")) continue; - if(++root_counter > 1) return false; - } - - return true; -} - -inline xml_element xml_parse(const char *data) { - xml_element self; - - try { - while(*data) { - xml_element node; - if(node.parse_body(data) == false) { - break; - } else { - self.element.append(node); - } - } - - if(xml_validate(self) == false) throw "..."; - return self; - } catch(const char*) { - xml_element empty; - return empty; - } -} - -} - -#endif diff --git a/kaijuu/nall/string/xml.hpp b/kaijuu/nall/string/xml.hpp deleted file mode 100644 index 937436c8..00000000 --- a/kaijuu/nall/string/xml.hpp +++ /dev/null @@ -1,250 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//XML v1.0 subset parser -//revision 0.01 - -namespace nall { -namespace XML { - -struct Node { - string name; - string data; - bool attribute; - vector children; - - inline bool exists() const { - return !name.empty(); - } - - inline bool isName(char c) const { - if(c >= 'A' && c <= 'Z') return true; - if(c >= 'a' && c <= 'z') return true; - if(c >= '0' && c <= '9') return true; - if(c == '.' || c == '_') return true; - if(c == '?') return true; - return false; - } - - inline bool isWhitespace(char c) const { - if(c == ' ' || c == '\t') return true; - if(c == '\r' || c == '\n') return true; - return false; - } - - //copy part of string from source document into target string; decode markup while copying - inline void copy(string &target, const char *source, unsigned length) { - target.reserve(length + 1); - - #if defined(NALL_XML_LITERAL) - memcpy(target(), source, length); - target[length] = 0; - return; - #endif - - char *output = target(); - while(length) { - if(*source == '&') { - if(!memcmp(source, "<", 4)) { *output++ = '<'; source += 4; length -= 4; continue; } - if(!memcmp(source, ">", 4)) { *output++ = '>'; source += 4; length -= 4; continue; } - if(!memcmp(source, "&", 5)) { *output++ = '&'; source += 5; length -= 5; continue; } - if(!memcmp(source, "'", 6)) { *output++ = '\''; source += 6; length -= 6; continue; } - if(!memcmp(source, """, 6)) { *output++ = '\"'; source += 6; length -= 6; continue; } - } - - if(attribute == false && source[0] == '<' && source[1] == '!') { - //comment - if(!memcmp(source, "", 3)) source++, length--; - source += 3, length -= 3; - continue; - } - - //CDATA - if(!memcmp(source, "", 3)) *output++ = *source++, length--; - source += 3, length -= 3; - continue; - } - } - - *output++ = *source++, length--; - } - *output = 0; - } - - inline bool parseExpression(const char *&p) { - if(*(p + 1) != '!') return false; - - //comment - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed comment"; - p += 3; - return true; - } - - //CDATA - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed CDATA"; - p += 3; - return true; - } - - //DOCTYPE - if(!memcmp(p, "') counter--; - } while(counter); - return true; - } - - return false; - } - - //returns true if tag closes itself (); false if not () - inline bool parseHead(const char *&p) { - //parse name - const char *nameStart = ++p; //skip '<' - while(isName(*p)) p++; - const char *nameEnd = p; - copy(name, nameStart, nameEnd - nameStart); - if(name.empty()) throw "missing element name"; - - //parse attributes - while(*p) { - while(isWhitespace(*p)) p++; - if(!*p) throw "unclosed attribute"; - if(*p == '?' || *p == '/' || *p == '>') break; - - //parse attribute name - Node *attribute = new Node; - children.append(attribute); - attribute->attribute = true; - - const char *nameStart = p; - while(isName(*p)) p++; - const char *nameEnd = p; - copy(attribute->name, nameStart, nameEnd - nameStart); - if(attribute->name.empty()) throw "missing attribute name"; - - //parse attribute data - if(*p++ != '=') throw "missing attribute value"; - char terminal = *p++; - if(terminal != '\'' && terminal != '\"') throw "attribute value not quoted"; - const char *dataStart = p; - while(*p && *p != terminal) p++; - if(!*p) throw "missing attribute data terminal"; - const char *dataEnd = p++; //skip closing terminal - - copy(attribute->data, dataStart, dataEnd - dataStart); - } - - //parse closure - if(*p == '?' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '/' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '>') { p += 1; return false; } - throw "invalid element tag"; - } - - //parse element and all of its child elements - inline void parseElement(const char *&p) { - Node *node = new Node; - children.append(node); - if(node->parseHead(p) == true) return; - node->parse(p); - } - - //return true if matches this node's name - inline bool parseClosureElement(const char *&p) { - if(p[0] != '<' || p[1] != '/') return false; - p += 2; - const char *nameStart = p; - while(*p && *p != '>') p++; - if(*p != '>') throw "unclosed closure element"; - const char *nameEnd = p++; - if(memcmp(name, nameStart, nameEnd - nameStart)) throw "closure element name mismatch"; - return true; - } - - //parse contents of an element - inline void parse(const char *&p) { - const char *dataStart = p, *dataEnd = p; - - while(*p) { - while(*p && *p != '<') p++; - if(!*p) break; - dataEnd = p; - if(parseClosureElement(p) == true) break; - if(parseExpression(p) == true) continue; - parseElement(p); - } - - copy(data, dataStart, dataEnd - dataStart); - } - - inline void reset() { - for(auto &child : children) delete child; - children.reset(); - } - - struct iterator { - inline bool operator!=(const iterator &source) const { return index != source.index; } - inline Node& operator*() { return *node.children[index]; } - inline iterator& operator++() { index++; return *this; } - inline iterator(const Node &node, unsigned index) : node(node), index(index) {} - private: - const Node &node; - unsigned index; - }; - - inline iterator begin() { return iterator(*this, 0); } - inline iterator end() { return iterator(*this, children.size()); } - inline const iterator begin() const { return iterator(*this, 0); } - inline const iterator end() const { return iterator(*this, children.size()); } - - inline Node& operator[](const char *name) { - for(auto &node : *this) { - if(node.name == name) return node; - } - static Node node; - return node; - } - - inline Node() : attribute(false) {} - inline ~Node() { reset(); } - - Node(const Node&) = delete; - Node& operator=(const Node&) = delete; -}; - -struct Document : Node { - string error; - - inline bool load(const char *document) { - if(document == nullptr) return false; - reset(); - try { - parse(document); - } catch(const char *error) { - reset(); - this->error = error; - return false; - } - return true; - } - - inline Document() {} - inline Document(const char *document) { load(document); } -}; - -} -} - -#endif diff --git a/kaijuu/nall/traits.hpp b/kaijuu/nall/traits.hpp deleted file mode 100644 index 6a140c2b..00000000 --- a/kaijuu/nall/traits.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef NALL_TRAITS_HPP -#define NALL_TRAITS_HPP - -#include - -namespace nall { - -template class has_default_constructor { - template class receive_size{}; - template static signed sfinae(receive_size*); - template static char sfinae(...); - -public: - enum : bool { value = sizeof(sfinae(0)) == sizeof(signed) }; -}; - -template struct enable_if { typedef T type; }; -template struct enable_if {}; - -template struct type_if { typedef T type; }; -template struct type_if { typedef F type; }; - -template struct static_and { enum { value = false }; }; -template<> struct static_and { enum { value = true }; }; - -template struct static_or { enum { value = false }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; - -} - -#endif diff --git a/kaijuu/nall/udl.hpp b/kaijuu/nall/udl.hpp deleted file mode 100644 index 30ceefb3..00000000 --- a/kaijuu/nall/udl.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_UDL_HPP -#define NALL_UDL_HPP - -//user-defined literals - -#include -#include - -namespace nall { - constexpr inline uintmax_t operator"" _b(const char *n) { return binary(n); } - - //convert to bytes - constexpr inline uintmax_t operator"" _kb(unsigned long long n) { return 1024 * n; } - constexpr inline uintmax_t operator"" _mb(unsigned long long n) { return 1024 * 1024 * n; } - constexpr inline uintmax_t operator"" _gb(unsigned long long n) { return 1024 * 1024 * 1024 * n; } - - //convert to bits - constexpr inline uintmax_t operator"" _kbit(unsigned long long n) { return 1024 * n / 8; } - constexpr inline uintmax_t operator"" _mbit(unsigned long long n) { return 1024 * 1024 * n / 8; } - constexpr inline uintmax_t operator"" _gbit(unsigned long long n) { return 1024 * 1024 * 1024 * n / 8; } - - //convert to hz - constexpr inline uintmax_t operator"" _khz(long double n) { return n * 1000; } - constexpr inline uintmax_t operator"" _mhz(long double n) { return n * 1000000; } - constexpr inline uintmax_t operator"" _ghz(long double n) { return n * 1000000000; } -} - -#endif diff --git a/kaijuu/nall/ups.hpp b/kaijuu/nall/ups.hpp deleted file mode 100644 index ffcdb2d7..00000000 --- a/kaijuu/nall/ups.hpp +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef NALL_UPS_HPP -#define NALL_UPS_HPP - -#include -#include -#include -#include - -namespace nall { - -struct ups { - enum class result : unsigned { - unknown, - success, - patch_unwritable, - patch_invalid, - source_invalid, - target_invalid, - target_too_small, - patch_checksum_invalid, - source_checksum_invalid, - target_checksum_invalid, - }; - - function progress; - - result create( - const uint8_t *sourcedata, unsigned sourcelength, - const uint8_t *targetdata, unsigned targetlength, - const char *patchfilename - ) { - source_data = (uint8_t*)sourcedata, target_data = (uint8_t*)targetdata; - source_length = sourcelength, target_length = targetlength; - source_offset = target_offset = 0; - source_checksum = target_checksum = patch_checksum = ~0; - - if(patch_file.open(patchfilename, file::mode::write) == false) return result::patch_unwritable; - - patch_write('U'); - patch_write('P'); - patch_write('S'); - patch_write('1'); - encode(source_length); - encode(target_length); - - unsigned output_length = source_length > target_length ? source_length : target_length; - unsigned relative = 0; - for(unsigned offset = 0; offset < output_length;) { - uint8_t x = source_read(); - uint8_t y = target_read(); - - if(x == y) { - offset++; - continue; - } - - encode(offset++ - relative); - patch_write(x ^ y); - - while(true) { - if(offset >= output_length) { - patch_write(0x00); - break; - } - - x = source_read(); - y = target_read(); - offset++; - patch_write(x ^ y); - if(x == y) break; - } - - relative = offset; - } - - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(source_checksum >> (i * 8)); - for(unsigned i = 0; i < 4; i++) patch_write(target_checksum >> (i * 8)); - uint32_t patch_result_checksum = ~patch_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(patch_result_checksum >> (i * 8)); - - patch_file.close(); - return result::success; - } - - result apply( - const uint8_t *patchdata, unsigned patchlength, - const uint8_t *sourcedata, unsigned sourcelength, - uint8_t *targetdata, unsigned &targetlength - ) { - patch_data = (uint8_t*)patchdata, source_data = (uint8_t*)sourcedata, target_data = targetdata; - patch_length = patchlength, source_length = sourcelength, target_length = targetlength; - patch_offset = source_offset = target_offset = 0; - patch_checksum = source_checksum = target_checksum = ~0; - - if(patch_length < 18) return result::patch_invalid; - if(patch_read() != 'U') return result::patch_invalid; - if(patch_read() != 'P') return result::patch_invalid; - if(patch_read() != 'S') return result::patch_invalid; - if(patch_read() != '1') return result::patch_invalid; - - unsigned source_read_length = decode(); - unsigned target_read_length = decode(); - - if(source_length != source_read_length && source_length != target_read_length) return result::source_invalid; - targetlength = (source_length == source_read_length ? target_read_length : source_read_length); - if(target_length < targetlength) return result::target_too_small; - target_length = targetlength; - - while(patch_offset < patch_length - 12) { - unsigned length = decode(); - while(length--) target_write(source_read()); - while(true) { - uint8_t patch_xor = patch_read(); - target_write(patch_xor ^ source_read()); - if(patch_xor == 0) break; - } - } - while(source_offset < source_length) target_write(source_read()); - while(target_offset < target_length) target_write(source_read()); - - uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0; - for(unsigned i = 0; i < 4; i++) source_read_checksum |= patch_read() << (i * 8); - for(unsigned i = 0; i < 4; i++) target_read_checksum |= patch_read() << (i * 8); - uint32_t patch_result_checksum = ~patch_checksum; - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_read_checksum |= patch_read() << (i * 8); - - if(patch_result_checksum != patch_read_checksum) return result::patch_invalid; - if(source_checksum == source_read_checksum && source_length == source_read_length) { - if(target_checksum == target_read_checksum && target_length == target_read_length) return result::success; - return result::target_invalid; - } else if(source_checksum == target_read_checksum && source_length == target_read_length) { - if(target_checksum == source_read_checksum && target_length == source_read_length) return result::success; - return result::target_invalid; - } else { - return result::source_invalid; - } - } - -private: - uint8_t *patch_data, *source_data, *target_data; - unsigned patch_length, source_length, target_length; - unsigned patch_offset, source_offset, target_offset; - unsigned patch_checksum, source_checksum, target_checksum; - file patch_file; - - uint8_t patch_read() { - if(patch_offset < patch_length) { - uint8_t n = patch_data[patch_offset++]; - patch_checksum = crc32_adjust(patch_checksum, n); - return n; - } - return 0x00; - } - - uint8_t source_read() { - if(source_offset < source_length) { - uint8_t n = source_data[source_offset++]; - source_checksum = crc32_adjust(source_checksum, n); - return n; - } - return 0x00; - } - - uint8_t target_read() { - uint8_t result = 0x00; - if(target_offset < target_length) { - result = target_data[target_offset]; - target_checksum = crc32_adjust(target_checksum, result); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - return result; - } - - void patch_write(uint8_t n) { - patch_file.write(n); - patch_checksum = crc32_adjust(patch_checksum, n); - } - - void target_write(uint8_t n) { - if(target_offset < target_length) { - target_data[target_offset] = n; - target_checksum = crc32_adjust(target_checksum, n); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - } - - void encode(uint64_t offset) { - while(true) { - uint64_t x = offset & 0x7f; - offset >>= 7; - if(offset == 0) { - patch_write(0x80 | x); - break; - } - patch_write(x); - offset--; - } - } - - uint64_t decode() { - uint64_t offset = 0, shift = 1; - while(true) { - uint8_t x = patch_read(); - offset += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - offset += shift; - } - return offset; - } -}; - -} - -#endif diff --git a/kaijuu/nall/utility.hpp b/kaijuu/nall/utility.hpp deleted file mode 100644 index b3c1e5aa..00000000 --- a/kaijuu/nall/utility.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_UTILITY_HPP -#define NALL_UTILITY_HPP - -#include -#include - -namespace nall { - template struct base_from_member { - T value; - base_from_member(T value_) : value(value_) {} - }; - - template class optional { - public: - bool valid; - T value; - public: - inline operator bool() const { return valid; } - inline const T& operator()() const { if(!valid) throw; return value; } - inline optional& operator=(const optional &source) { valid = source.valid; value = source.value; return *this; } - inline optional() : valid(false) {} - inline optional(bool valid, const T &value) : valid(valid), value(value) {} - }; - - template inline T* allocate(unsigned size, const T &value) { - T *array = new T[size]; - for(unsigned i = 0; i < size; i++) array[i] = value; - return array; - } -} - -#endif diff --git a/kaijuu/nall/varint.hpp b/kaijuu/nall/varint.hpp deleted file mode 100644 index 98e189db..00000000 --- a/kaijuu/nall/varint.hpp +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef NALL_VARINT_HPP -#define NALL_VARINT_HPP - -#include -#include - -namespace nall { - template struct uint_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = uclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = uclip(data - 1); return r; } - inline type_t operator ++() { return data = uclip(data + 1); } - inline type_t operator --() { return data = uclip(data - 1); } - inline type_t operator =(const type_t i) { return data = uclip(i); } - inline type_t operator |=(const type_t i) { return data = uclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = uclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = uclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = uclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = uclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = uclip(data + i); } - inline type_t operator -=(const type_t i) { return data = uclip(data - i); } - inline type_t operator *=(const type_t i) { return data = uclip(data * i); } - inline type_t operator /=(const type_t i) { return data = uclip(data / i); } - inline type_t operator %=(const type_t i) { return data = uclip(data % i); } - - inline uint_t() : data(0) {} - inline uint_t(const type_t i) : data(uclip(i)) {} - - template inline type_t operator=(const uint_t &i) { return data = uclip((type_t)i); } - template inline uint_t(const uint_t &i) : data(uclip(i)) {} - }; - - template struct int_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = sclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = sclip(data - 1); return r; } - inline type_t operator ++() { return data = sclip(data + 1); } - inline type_t operator --() { return data = sclip(data - 1); } - inline type_t operator =(const type_t i) { return data = sclip(i); } - inline type_t operator |=(const type_t i) { return data = sclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = sclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = sclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = sclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = sclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = sclip(data + i); } - inline type_t operator -=(const type_t i) { return data = sclip(data - i); } - inline type_t operator *=(const type_t i) { return data = sclip(data * i); } - inline type_t operator /=(const type_t i) { return data = sclip(data / i); } - inline type_t operator %=(const type_t i) { return data = sclip(data % i); } - - inline int_t() : data(0) {} - inline int_t(const type_t i) : data(sclip(i)) {} - - template inline type_t operator=(const int_t &i) { return data = sclip((type_t)i); } - template inline int_t(const int_t &i) : data(sclip(i)) {} - }; - - template struct varuint_t { - private: - type_t data; - type_t mask; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = (data + 1) & mask; return r; } - inline type_t operator --(int) { type_t r = data; data = (data - 1) & mask; return r; } - inline type_t operator ++() { return data = (data + 1) & mask; } - inline type_t operator --() { return data = (data - 1) & mask; } - inline type_t operator =(const type_t i) { return data = (i) & mask; } - inline type_t operator |=(const type_t i) { return data = (data | i) & mask; } - inline type_t operator ^=(const type_t i) { return data = (data ^ i) & mask; } - inline type_t operator &=(const type_t i) { return data = (data & i) & mask; } - inline type_t operator<<=(const type_t i) { return data = (data << i) & mask; } - inline type_t operator>>=(const type_t i) { return data = (data >> i) & mask; } - inline type_t operator +=(const type_t i) { return data = (data + i) & mask; } - inline type_t operator -=(const type_t i) { return data = (data - i) & mask; } - inline type_t operator *=(const type_t i) { return data = (data * i) & mask; } - inline type_t operator /=(const type_t i) { return data = (data / i) & mask; } - inline type_t operator %=(const type_t i) { return data = (data % i) & mask; } - - inline void bits(type_t bits) { mask = (1ull << (bits - 1)) + ((1ull << (bits - 1)) - 1); data &= mask; } - inline varuint_t() : data(0ull), mask((type_t)~0ull) {} - inline varuint_t(const type_t i) : data(i), mask((type_t)~0ull) {} - }; -} - -//typedefs - typedef nall::uint_t< 1> uint1_t; - typedef nall::uint_t< 2> uint2_t; - typedef nall::uint_t< 3> uint3_t; - typedef nall::uint_t< 4> uint4_t; - typedef nall::uint_t< 5> uint5_t; - typedef nall::uint_t< 6> uint6_t; - typedef nall::uint_t< 7> uint7_t; -//typedef nall::uint_t< 8> uint8_t; - - typedef nall::uint_t< 9> uint9_t; - typedef nall::uint_t<10> uint10_t; - typedef nall::uint_t<11> uint11_t; - typedef nall::uint_t<12> uint12_t; - typedef nall::uint_t<13> uint13_t; - typedef nall::uint_t<14> uint14_t; - typedef nall::uint_t<15> uint15_t; -//typedef nall::uint_t<16> uint16_t; - - typedef nall::uint_t<17> uint17_t; - typedef nall::uint_t<18> uint18_t; - typedef nall::uint_t<19> uint19_t; - typedef nall::uint_t<20> uint20_t; - typedef nall::uint_t<21> uint21_t; - typedef nall::uint_t<22> uint22_t; - typedef nall::uint_t<23> uint23_t; - typedef nall::uint_t<24> uint24_t; - typedef nall::uint_t<25> uint25_t; - typedef nall::uint_t<26> uint26_t; - typedef nall::uint_t<27> uint27_t; - typedef nall::uint_t<28> uint28_t; - typedef nall::uint_t<29> uint29_t; - typedef nall::uint_t<30> uint30_t; - typedef nall::uint_t<31> uint31_t; -//typedef nall::uint_t<32> uint32_t; - - typedef nall::int_t< 1> int1_t; - typedef nall::int_t< 2> int2_t; - typedef nall::int_t< 3> int3_t; - typedef nall::int_t< 4> int4_t; - typedef nall::int_t< 5> int5_t; - typedef nall::int_t< 6> int6_t; - typedef nall::int_t< 7> int7_t; -//typedef nall::int_t< 8> int8_t; - - typedef nall::int_t< 9> int9_t; - typedef nall::int_t<10> int10_t; - typedef nall::int_t<11> int11_t; - typedef nall::int_t<12> int12_t; - typedef nall::int_t<13> int13_t; - typedef nall::int_t<14> int14_t; - typedef nall::int_t<15> int15_t; -//typedef nall::int_t<16> int16_t; - - typedef nall::int_t<17> int17_t; - typedef nall::int_t<18> int18_t; - typedef nall::int_t<19> int19_t; - typedef nall::int_t<20> int20_t; - typedef nall::int_t<21> int21_t; - typedef nall::int_t<22> int22_t; - typedef nall::int_t<23> int23_t; - typedef nall::int_t<24> int24_t; - typedef nall::int_t<25> int25_t; - typedef nall::int_t<26> int26_t; - typedef nall::int_t<27> int27_t; - typedef nall::int_t<28> int28_t; - typedef nall::int_t<29> int29_t; - typedef nall::int_t<30> int30_t; - typedef nall::int_t<31> int31_t; -//typedef nall::int_t<32> int32_t; - -#endif diff --git a/kaijuu/nall/vector.hpp b/kaijuu/nall/vector.hpp deleted file mode 100644 index 13200ea6..00000000 --- a/kaijuu/nall/vector.hpp +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef NALL_VECTOR_HPP -#define NALL_VECTOR_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - template struct vector { - struct exception_out_of_bounds{}; - - protected: - T *pool; - unsigned poolsize; - unsigned objectsize; - - public: - operator bool() const { return pool; } - T* data() { return pool; } - - bool empty() const { return objectsize == 0; } - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - T* move() { - T *result = pool; - pool = nullptr; - poolsize = 0; - objectsize = 0; - return result; - } - - void reset() { - if(pool) { - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - } - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - size = bit::round(size); //amortize growth - T *copy = (T*)calloc(size, sizeof(T)); - for(unsigned n = 0; n < min(size, objectsize); n++) new(copy + n) T(pool[n]); - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - pool = copy; - poolsize = size; - objectsize = min(size, objectsize); - } - - //requires trivial constructor - void resize(unsigned size) { - if(size == objectsize) return; - if(size < objectsize) return reserve(size); - while(size > objectsize) append(T()); - } - - template - void append(const T& data, Args&&... args) { - append(data); - append(std::forward(args)...); - } - - void append(const T& data) { - if(objectsize + 1 > poolsize) reserve(objectsize + 1); - new(pool + objectsize++) T(data); - } - - bool appendonce(const T& data) { - if(find(data) == true) return false; - append(data); - return true; - } - - void insert(unsigned position, const T& data) { - append(data); - for(signed n = size() - 1; n > position; n--) pool[n] = pool[n - 1]; - pool[position] = data; - } - - void prepend(const T& data) { - insert(0, data); - } - - void remove(unsigned index = ~0u, unsigned count = 1) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - for(unsigned n = index; count + n < objectsize; n++) pool[n] = pool[count + n]; - objectsize = (count + index >= objectsize) ? index : objectsize - count; - } - - T take(unsigned index = ~0u) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - if(index >= objectsize) throw exception_out_of_bounds(); - T item = pool[index]; - remove(index); - return item; - } - - void reverse() { - unsigned pivot = size() / 2; - for(unsigned l = 0, r = size() - 1; l < pivot; l++, r--) { - std::swap(pool[l], pool[r]); - } - } - - void sort() { - nall::sort(pool, objectsize); - } - - template void sort(const Comparator &lessthan) { - nall::sort(pool, objectsize, lessthan); - } - - optional find(const T& data) { - for(unsigned n = 0; n < size(); n++) if(pool[n] == data) return { true, n }; - return { false, 0u }; - } - - T& first() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[0]; - } - - T& last() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[objectsize - 1]; - } - - //access - inline T& operator[](unsigned position) { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline const T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline T& operator()(unsigned position) { - if(position >= poolsize) reserve(position + 1); - while(position >= objectsize) append(T()); - return pool[position]; - } - - inline const T& operator()(unsigned position, const T& data) const { - if(position >= objectsize) return data; - return pool[position]; - } - - //iteration - T* begin() { return &pool[0]; } - T* end() { return &pool[objectsize]; } - const T* begin() const { return &pool[0]; } - const T* end() const { return &pool[objectsize]; } - - //copy - inline vector& operator=(const vector &source) { - reset(); - reserve(source.capacity()); - for(auto &data : source) append(data); - return *this; - } - - vector(const vector &source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(source); - } - - //move - inline vector& operator=(vector &&source) { - reset(); - pool = source.pool, poolsize = source.poolsize, objectsize = source.objectsize; - source.pool = nullptr, source.poolsize = 0, source.objectsize = 0; - return *this; - } - - vector(vector &&source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(std::move(source)); - } - - //construction - vector() : pool(nullptr), poolsize(0), objectsize(0) { - } - - vector(std::initializer_list list) : pool(nullptr), poolsize(0), objectsize(0) { - for(auto &data : list) append(data); - } - - ~vector() { - reset(); - } - }; -} - -#endif diff --git a/kaijuu/nall/windows/detour.hpp b/kaijuu/nall/windows/detour.hpp deleted file mode 100644 index e270f318..00000000 --- a/kaijuu/nall/windows/detour.hpp +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef NALL_WINDOWS_DETOUR_HPP -#define NALL_WINDOWS_DETOUR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -#define Copy 0 -#define RelNear 1 - -struct detour { - static bool insert(const string &moduleName, const string &functionName, void *&source, void *target); - static bool remove(const string &moduleName, const string &functionName, void *&source); - -protected: - static unsigned length(const uint8_t *function); - static unsigned mirror(uint8_t *target, const uint8_t *source); - - struct opcode { - uint16_t prefix; - unsigned length; - unsigned mode; - uint16_t modify; - }; - static opcode opcodes[]; -}; - -//TODO: -//* fs:, gs: should force another opcode copy -//* conditional branches within +5-byte range should fail -detour::opcode detour::opcodes[] = { - { 0x50, 1 }, //push eax - { 0x51, 1 }, //push ecx - { 0x52, 1 }, //push edx - { 0x53, 1 }, //push ebx - { 0x54, 1 }, //push esp - { 0x55, 1 }, //push ebp - { 0x56, 1 }, //push esi - { 0x57, 1 }, //push edi - { 0x58, 1 }, //pop eax - { 0x59, 1 }, //pop ecx - { 0x5a, 1 }, //pop edx - { 0x5b, 1 }, //pop ebx - { 0x5c, 1 }, //pop esp - { 0x5d, 1 }, //pop ebp - { 0x5e, 1 }, //pop esi - { 0x5f, 1 }, //pop edi - { 0x64, 1 }, //fs: - { 0x65, 1 }, //gs: - { 0x68, 5 }, //push dword - { 0x6a, 2 }, //push byte - { 0x74, 2, RelNear, 0x0f84 }, //je near -> je far - { 0x75, 2, RelNear, 0x0f85 }, //jne near -> jne far - { 0x89, 2 }, //mov reg,reg - { 0x8b, 2 }, //mov reg,reg - { 0x90, 1 }, //nop - { 0xa1, 5 }, //mov eax,[dword] - { 0xeb, 2, RelNear, 0xe9 }, //jmp near -> jmp far -}; - -bool detour::insert(const string &moduleName, const string &functionName, void *&source, void *target) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - unsigned sourceLength = detour::length(sourceData); - if(sourceLength < 5) { - //unable to clone enough bytes to insert hook - #if 1 - string output = { "detour::insert(", moduleName, "::", functionName, ") failed: " }; - for(unsigned n = 0; n < 16; n++) output.append(hex<2>(sourceData[n]), " "); - output.rtrim<1>(" "); - MessageBoxA(0, output, "nall::detour", MB_OK); - #endif - return false; - } - - uint8_t *mirrorData = new uint8_t[512](); - detour::mirror(mirrorData, sourceData); - - DWORD privileges; - VirtualProtect((void*)mirrorData, 512, PAGE_EXECUTE_READWRITE, &privileges); - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - uintmax_t address = (uintmax_t)target - ((uintmax_t)sourceData + 5); - sourceData[0] = 0xe9; //jmp target - sourceData[1] = address >> 0; - sourceData[2] = address >> 8; - sourceData[3] = address >> 16; - sourceData[4] = address >> 24; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)mirrorData; - return true; -} - -bool detour::remove(const string &moduleName, const string &functionName, void *&source) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - uint8_t *mirrorData = (uint8_t*)source; - if(mirrorData == sourceData) return false; //hook was never installed - - unsigned length = detour::length(256 + mirrorData); - if(length < 5) return false; - - DWORD privileges; - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - for(unsigned n = 0; n < length; n++) sourceData[n] = mirrorData[256 + n]; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)sourceData; - delete[] mirrorData; - return true; -} - -unsigned detour::length(const uint8_t *function) { - unsigned length = 0; - while(length < 5) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(function[length] == op.prefix) { - opcode = &op; - break; - } - } - if(opcode == 0) break; - length += opcode->length; - } - return length; -} - -unsigned detour::mirror(uint8_t *target, const uint8_t *source) { - const uint8_t *entryPoint = source; - for(unsigned n = 0; n < 256; n++) target[256 + n] = source[n]; - - unsigned size = detour::length(source); - while(size) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(*source == op.prefix) { - opcode = &op; - break; - } - } - - switch(opcode->mode) { - case Copy: - for(unsigned n = 0; n < opcode->length; n++) *target++ = *source++; - break; - case RelNear: { - source++; - uintmax_t sourceAddress = (uintmax_t)source + 1 + (int8_t)*source; - *target++ = opcode->modify; - if(opcode->modify >> 8) *target++ = opcode->modify >> 8; - uintmax_t targetAddress = (uintmax_t)target + 4; - uintmax_t address = sourceAddress - targetAddress; - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - source += 2; - } break; - } - - size -= opcode->length; - } - - uintmax_t address = (entryPoint + detour::length(entryPoint)) - (target + 5); - *target++ = 0xe9; //jmp entryPoint - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - - return source - entryPoint; -} - -#undef Implied -#undef RelNear - -} - -#endif diff --git a/kaijuu/nall/windows/guid.hpp b/kaijuu/nall/windows/guid.hpp deleted file mode 100644 index 386cfc75..00000000 --- a/kaijuu/nall/windows/guid.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NALL_WINDOWS_GUID_HPP -#define NALL_WINDOWS_GUID_HPP - -#include -#include - -namespace nall { - -//generate unique GUID -inline string guid() { - random_lfsr lfsr; - lfsr.seed(time(0)); - for(unsigned n = 0; n < 256; n++) lfsr(); - - string output; - for(unsigned n = 0; n < 4; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 6; n++) output.append(hex<2>(lfsr())); - return {"{", output, "}"}; -} - -} - -#endif diff --git a/kaijuu/nall/windows/launcher.hpp b/kaijuu/nall/windows/launcher.hpp deleted file mode 100644 index 914683ec..00000000 --- a/kaijuu/nall/windows/launcher.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef NALL_WINDOWS_LAUNCHER_HPP -#define NALL_WINDOWS_LAUNCHER_HPP - -namespace nall { - -//launch a new process and inject specified DLL into it - -bool launch(const char *applicationName, const char *libraryName, uint32_t entryPoint) { - //if a launcher does not send at least one message, a wait cursor will appear - PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0); - MSG msg; - GetMessage(&msg, 0, 0, 0); - - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - memset(&si, 0, sizeof(STARTUPINFOW)); - BOOL result = CreateProcessW( - utf16_t(applicationName), GetCommandLineW(), NULL, NULL, TRUE, - DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, //do not break if application creates its own processes - NULL, NULL, &si, &pi - ); - if(result == false) return false; - - uint8_t entryData[1024], entryHook[1024] = { - 0x68, 0x00, 0x00, 0x00, 0x00, //push libraryName - 0xb8, 0x00, 0x00, 0x00, 0x00, //mov eax,LoadLibraryW - 0xff, 0xd0, //call eax - 0xcd, 0x03, //int 3 - }; - - entryHook[1] = (uint8_t)((entryPoint + 14) >> 0); - entryHook[2] = (uint8_t)((entryPoint + 14) >> 8); - entryHook[3] = (uint8_t)((entryPoint + 14) >> 16); - entryHook[4] = (uint8_t)((entryPoint + 14) >> 24); - - uint32_t pLoadLibraryW = (uint32_t)GetProcAddress(GetModuleHandleW(L"kernel32"), "LoadLibraryW"); - entryHook[6] = pLoadLibraryW >> 0; - entryHook[7] = pLoadLibraryW >> 8; - entryHook[8] = pLoadLibraryW >> 16; - entryHook[9] = pLoadLibraryW >> 24; - - utf16_t buffer = utf16_t(libraryName); - memcpy(entryHook + 14, buffer, 2 * wcslen(buffer) + 2); - - while(true) { - DEBUG_EVENT event; - WaitForDebugEvent(&event, INFINITE); - - if(event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break; - - if(event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) { - if(event.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) { - if(event.u.Exception.ExceptionRecord.ExceptionAddress == (void*)(entryPoint + 14 - 1)) { - HANDLE hProcess = OpenProcess(0, FALSE, event.dwProcessId); - HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, event.dwThreadId); - - CONTEXT context; - context.ContextFlags = CONTEXT_FULL; - GetThreadContext(hThread, &context); - - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - context.Eip = entryPoint; - SetThreadContext(hThread, &context); - - CloseHandle(hThread); - CloseHandle(hProcess); - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); - continue; - } - - if(event.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) { - ReadProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryHook, sizeof entryHook, NULL); - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - } - - return true; -} - -} - -#endif diff --git a/kaijuu/nall/windows/registry.hpp b/kaijuu/nall/windows/registry.hpp deleted file mode 100644 index 0774e04a..00000000 --- a/kaijuu/nall/windows/registry.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef NALL_WINDOWS_REGISTRY_HPP -#define NALL_WINDOWS_REGISTRY_HPP - -#include -#include - -#include -#ifndef KEY_WOW64_64KEY - #define KEY_WOW64_64KEY 0x0100 -#endif -#ifndef KEY_WOW64_32KEY - #define KEY_WOW64_32KEY 0x0200 -#endif - -#ifndef NWR_FLAGS - #define NWR_FLAGS KEY_WOW64_64KEY -#endif - -#ifndef NWR_SIZE - #define NWR_SIZE 4096 -#endif - -namespace nall { - -struct registry { - static bool exists(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return true; - } - return false; - } - - static string read(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return (const char*)utf8_t(data); - } - return ""; - } - - static void write(const string &name, const string &data = "") { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(), path; - DWORD disposition; - for(unsigned n = 0; n < part.size(); n++) { - path.append(part[n]); - if(RegCreateKeyExW(rootKey, utf16_t(path), 0, NULL, 0, NWR_FLAGS | KEY_ALL_ACCESS, NULL, &handle, &disposition) == ERROR_SUCCESS) { - if(n == part.size() - 1) { - RegSetValueExW(handle, utf16_t(node), 0, REG_SZ, (BYTE*)(wchar_t*)utf16_t(data), (data.length() + 1) * sizeof(wchar_t)); - } - RegCloseKey(handle); - } - path.append("\\"); - } - } - - static bool remove(const string &name) { - lstring part = name.split("/"); - HKEY rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(node.empty()) return SHDeleteKeyW(rootKey, utf16_t(path)) == ERROR_SUCCESS; - return SHDeleteValueW(rootKey, utf16_t(path), utf16_t(node)) == ERROR_SUCCESS; - } - - static lstring contents(const string &name) { - lstring part = name.split("/"), result; - HKEY handle, rootKey = root(part.take(0)); - part.remove(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD folders, nodes; - RegQueryInfoKey(handle, NULL, NULL, NULL, &folders, NULL, NULL, &nodes, NULL, NULL, NULL, NULL); - for(unsigned n = 0; n < folders; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumKeyEx(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append({(const char*)utf8_t(name), "/"}); - } - for(unsigned n = 0; n < nodes; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumValueW(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append((const char*)utf8_t(name)); - } - RegCloseKey(handle); - } - return result; - } - -private: - static HKEY root(const string &name) { - if(name == "HKCR") return HKEY_CLASSES_ROOT; - if(name == "HKCC") return HKEY_CURRENT_CONFIG; - if(name == "HKCU") return HKEY_CURRENT_USER; - if(name == "HKLM") return HKEY_LOCAL_MACHINE; - if(name == "HKU" ) return HKEY_USERS; - return NULL; - } -}; - -} - -#endif diff --git a/kaijuu/nall/windows/utf8.hpp b/kaijuu/nall/windows/utf8.hpp deleted file mode 100644 index b1374943..00000000 --- a/kaijuu/nall/windows/utf8.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef NALL_UTF8_HPP -#define NALL_UTF8_HPP - -//UTF-8 <> UTF-16 conversion -//used only for Win32; Linux, etc use UTF-8 internally - -#if defined(_WIN32) - -#undef UNICODE -#undef _WIN32_WINNT -#undef NOMINMAX -#define UNICODE -#define _WIN32_WINNT 0x0501 -#define NOMINMAX -#include -#include -#undef interface - -namespace nall { - //UTF-8 to UTF-16 - class utf16_t { - public: - operator wchar_t*() { - return buffer; - } - - operator const wchar_t*() const { - return buffer; - } - - utf16_t(const char *s = "") { - if(!s) s = ""; - unsigned length = MultiByteToWideChar(CP_UTF8, 0, s, -1, 0, 0); - buffer = new wchar_t[length + 1](); - MultiByteToWideChar(CP_UTF8, 0, s, -1, buffer, length); - } - - ~utf16_t() { - delete[] buffer; - } - - private: - wchar_t *buffer; - }; - - //UTF-16 to UTF-8 - class utf8_t { - public: - operator char*() { - return buffer; - } - - operator const char*() const { - return buffer; - } - - utf8_t(const wchar_t *s = L"") { - if(!s) s = L""; - unsigned length = WideCharToMultiByte(CP_UTF8, 0, s, -1, 0, 0, (const char*)0, (BOOL*)0); - buffer = new char[length + 1](); - WideCharToMultiByte(CP_UTF8, 0, s, -1, buffer, length, (const char*)0, (BOOL*)0); - } - - ~utf8_t() { - delete[] buffer; - } - - utf8_t(const utf8_t&) = delete; - utf8_t& operator=(const utf8_t&) = delete; - - private: - char *buffer; - }; - - inline void utf8_args(int &argc, char **&argv) { - wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = new char*[argc]; - for(unsigned i = 0; i < argc; i++) { - argv[i] = new char[_MAX_PATH]; - strcpy(argv[i], nall::utf8_t(wargv[i])); - } - } -} - -#endif //if defined(_WIN32) - -#endif diff --git a/kaijuu/nall/xorg/guard.hpp b/kaijuu/nall/xorg/guard.hpp deleted file mode 100644 index a1282683..00000000 --- a/kaijuu/nall/xorg/guard.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NALL_XORG_GUARD_HPP -#define NALL_XORG_GUARD_HPP - -#define None -#undef XlibNone -#define XlibNone 0L -#define Button1 XlibButton1 -#define Button2 XlibButton2 -#define Button3 XlibButton3 -#define Button4 XlibButton4 -#define Button5 XlibButton5 -#define Display XlibDisplay -#define Screen XlibScreen -#define Window XlibWindow - -#else -#undef NALL_XORG_GUARD_HPP - -#undef None -#undef Button1 -#undef Button2 -#undef Button3 -#undef Button4 -#undef Button5 -#undef Display -#undef Screen -#undef Window - -#endif diff --git a/kaijuu/nall/xorg/xorg.hpp b/kaijuu/nall/xorg/xorg.hpp deleted file mode 100644 index bcf48b46..00000000 --- a/kaijuu/nall/xorg/xorg.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef NALL_XORG_XORG_HPP -#define NALL_XORG_XORG_HPP - -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/kaijuu/nall/zip.hpp b/kaijuu/nall/zip.hpp deleted file mode 100644 index 779b067e..00000000 --- a/kaijuu/nall/zip.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_UNZIP_HPP -#define NALL_UNZIP_HPP - -#include -#include -#include -#include - -namespace nall { - -struct zip { - struct File { - string name; - const uint8_t *data; - unsigned size; - unsigned csize; - unsigned cmode; //0 = uncompressed, 8 = deflate - unsigned crc32; - }; - - inline bool open(const string &filename) { - close(); - if(fm.open(filename, filemap::mode::read) == false) return false; - if(open(fm.data(), fm.size()) == false) { - fm.close(); - return false; - } - return true; - } - - inline bool open(const uint8_t *data, unsigned size) { - if(size < 22) return false; - - filedata = data; - filesize = size; - - file.reset(); - - const uint8_t *footer = data + size - 22; - while(true) { - if(footer <= data + 22) return false; - if(read(footer, 4) == 0x06054b50) { - unsigned commentlength = read(footer + 20, 2); - if(footer + 22 + commentlength == data + size) break; - } - footer--; - } - const uint8_t *directory = data + read(footer + 16, 4); - - while(true) { - unsigned signature = read(directory + 0, 4); - if(signature != 0x02014b50) break; - - File file; - file.cmode = read(directory + 10, 2); - file.crc32 = read(directory + 16, 4); - file.csize = read(directory + 20, 4); - file.size = read(directory + 24, 4); - - unsigned namelength = read(directory + 28, 2); - unsigned extralength = read(directory + 30, 2); - unsigned commentlength = read(directory + 32, 2); - - char *filename = new char[namelength + 1]; - memcpy(filename, directory + 46, namelength); - filename[namelength] = 0; - file.name = filename; - delete[] filename; - - unsigned offset = read(directory + 42, 4); - unsigned offsetNL = read(data + offset + 26, 2); - unsigned offsetEL = read(data + offset + 28, 2); - file.data = data + offset + 30 + offsetNL + offsetEL; - - directory += 46 + namelength + extralength + commentlength; - - this->file.append(file); - } - - return true; - } - - inline vector extract(File &file) { - vector buffer; - - if(file.cmode == 0) { - buffer.resize(file.size); - memcpy(buffer.data(), file.data, file.size); - } - - if(file.cmode == 8) { - buffer.resize(file.size); - if(inflate(buffer.data(), buffer.size(), file.data, file.csize) == false) { - buffer.reset(); - } - } - - return buffer; - } - - inline void close() { - if(fm.open()) fm.close(); - } - - ~zip() { - close(); - } - -protected: - filemap fm; - const uint8_t *filedata; - unsigned filesize; - - unsigned read(const uint8_t *data, unsigned size) { - unsigned result = 0, shift = 0; - while(size--) { result |= *data++ << shift; shift += 8; } - return result; - } - -public: - vector file; -}; - -} - -#endif diff --git a/kaijuu/phoenix/Makefile b/kaijuu/phoenix/Makefile deleted file mode 100644 index d1c9d981..00000000 --- a/kaijuu/phoenix/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -ifeq ($(platform),x) - ifeq ($(phoenix),) - phoenix := gtk - endif - - ifeq ($(phoenix),gtk) - phoenixflags := -DPHOENIX_GTK `pkg-config --cflags gtk+-2.0` - phoenixlink := `pkg-config --libs gtk+-2.0` - endif - - ifeq ($(phoenix),qt) - phoenixflags := -DPHOENIX_QT `pkg-config --cflags QtCore QtGui` - phoenixlink := `pkg-config --libs QtCore QtGui` - endif -else ifeq ($(platform),win) - phoenixflags := -DPHOENIX_WINDOWS - phoenixlink := -lkernel32 -luser32 -lgdi32 -ladvapi32 -lole32 -lcomctl32 -lcomdlg32 -lshlwapi -else - phoenixflags := -DPHOENIX_REFERENCE - phoenixlink := -endif diff --git a/kaijuu/phoenix/core/core.cpp b/kaijuu/phoenix/core/core.cpp deleted file mode 100644 index a6a1ce38..00000000 --- a/kaijuu/phoenix/core/core.cpp +++ /dev/null @@ -1,1326 +0,0 @@ -#include "state.hpp" -#include "layout/fixed-layout.cpp" -#include "layout/horizontal-layout.cpp" -#include "layout/vertical-layout.cpp" - -#if defined(PHOENIX_WINDOWS) - #include "../windows/platform.cpp" -#elif defined(PHOENIX_QT) - #include "../qt/platform.cpp" -#elif defined(PHOENIX_GTK) - #include "../gtk/platform.cpp" -#elif defined(PHOENIX_REFERENCE) - #include "../reference/platform.cpp" -#endif - -static bool OS_quit = false; - -//Color -//===== - -uint32_t Color::rgb() const { - return (255 << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -uint32_t Color::rgba() const { - return (alpha << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -//Geometry -//======== - -Position Geometry::position() const { - return { x, y }; -} - -Size Geometry::size() const { - return { width, height }; -} - -string Geometry::text() const { - return { x, ",", y, ",", width, ",", height }; -} - -Geometry::Geometry(const string &text) { - lstring part = text.split(","); - x = integer(part(0, "256")); - y = integer(part(1, "256")); - width = decimal(part(2, "256")); - height = decimal(part(3, "256")); -} - -//Font -//==== - -Geometry Font::geometry(const string &text) { - return pFont::geometry(description, text); -} - -Font::Font(const string &description): -description(description) { -} - -//Desktop -//======= - -Size Desktop::size() { - return pDesktop::size(); -} - -Geometry Desktop::workspace() { - return pDesktop::workspace(); -} - -//Keyboard -//======== - -bool Keyboard::pressed(Keyboard::Scancode scancode) { - return pKeyboard::pressed(scancode); -} - -bool Keyboard::released(Keyboard::Scancode scancode) { - return !pressed(scancode); -} - -vector Keyboard::state() { - return pKeyboard::state(); -} - -//Mouse -//===== - -Position Mouse::position() { - return pMouse::position(); -} - -bool Mouse::pressed(Mouse::Button button) { - return pMouse::pressed(button); -} - -bool Mouse::released(Mouse::Button button) { - return !pressed(button); -} - -//DialogWindow -//============ - -string DialogWindow::fileOpen_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileOpen(parent, path, filter); -} - -string DialogWindow::fileSave_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileSave(parent, path, filter); -} - -string DialogWindow::folderSelect(Window &parent, const string &path) { - return pDialogWindow::folderSelect(parent, path); -} - -//MessageWindow -//============= - -MessageWindow::Response MessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::information(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::question(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::warning(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::critical(parent, text, buttons); -} - -//Object -//====== - -Object::Object(pObject &p): -p(p) { - OS::initialize(); - p.constructor(); -} - -Object::~Object() { - p.destructor(); - delete &p; -} - -//OS -//== - -void OS::main() { - return pOS::main(); -} - -bool OS::pendingEvents() { - return pOS::pendingEvents(); -} - -void OS::processEvents() { - return pOS::processEvents(); -} - -void OS::quit() { - OS_quit = true; - return pOS::quit(); -} - -void OS::initialize() { - static bool initialized = false; - if(initialized == false) { - initialized = true; - return pOS::initialize(); - } -} - -//Timer -//===== - -void Timer::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Timer::setInterval(unsigned milliseconds) { - state.milliseconds = milliseconds; - return p.setInterval(milliseconds); -} - -Timer::Timer(): -state(*new State), -base_from_member(*new pTimer(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Timer::~Timer() { - p.destructor(); - delete &state; -} - -//Window -//====== - -Window& Window::none() { - return pWindow::none(); -} - -void Window::append_(Layout &layout) { - if(state.layout.append(layout)) { - ((Sizable&)layout).state.window = this; - ((Sizable&)layout).state.layout = 0; - p.append(layout); - layout.synchronizeLayout(); - } -} - -void Window::append_(Menu &menu) { - if(state.menu.append(menu)) { - ((Action&)menu).state.window = this; - p.append(menu); - } -} - -void Window::append_(Widget &widget) { - if(state.widget.append(widget)) { - ((Sizable&)widget).state.window = this; - p.append(widget); - } -} - -Color Window::backgroundColor() { - return p.backgroundColor(); -} - -Geometry Window::frameGeometry() { - Geometry geometry = p.geometry(); - Geometry margin = p.frameMargin(); - return { - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height - }; -} - -Geometry Window::frameMargin() { - return p.frameMargin(); -} - -bool Window::focused() { - return p.focused(); -} - -bool Window::fullScreen() { - return state.fullScreen; -} - -Geometry Window::geometry() { - return p.geometry(); -} - -void Window::ignore() { - state.ignore = true; -} - -void Window::remove_(Layout &layout) { - if(state.layout.remove(layout)) { - p.remove(layout); - ((Sizable&)layout).state.window = 0; - } -} - -void Window::remove_(Menu &menu) { - if(state.menu.remove(menu)) { - p.remove(menu); - ((Action&)menu).state.window = 0; - } -} - -void Window::remove_(Widget &widget) { - if(state.widget.remove(widget)) { - p.remove(widget); - ((Sizable&)widget).state.window = 0; - } -} - -void Window::setBackgroundColor(const Color &color) { - state.backgroundColorOverride = true; - state.backgroundColor = color; - return p.setBackgroundColor(color); -} - -void Window::setFrameGeometry(const Geometry &geometry) { - Geometry margin = p.frameMargin(); - return setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width - margin.width, geometry.height - margin.height - }); -} - -void Window::setFocused() { - return p.setFocused(); -} - -void Window::setFullScreen(bool fullScreen) { - state.fullScreen = fullScreen; - return p.setFullScreen(fullScreen); -} - -void Window::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Window::setMenuFont(const string &font) { - state.menuFont = font; - return p.setMenuFont(font); -} - -void Window::setMenuVisible(bool visible) { - state.menuVisible = visible; - return p.setMenuVisible(visible); -} - -void Window::setModal(bool modal) { - state.modal = modal; - return p.setModal(modal); -} - -void Window::setResizable(bool resizable) { - state.resizable = resizable; - return p.setResizable(resizable); -} - -void Window::setStatusFont(const string &font) { - state.statusFont = font; - return p.setStatusFont(font); -} - -void Window::setStatusText(const string &text) { - state.statusText = text; - return p.setStatusText(text); -} - -void Window::setStatusVisible(bool visible) { - state.statusVisible = visible; - return p.setStatusVisible(visible); -} - -void Window::setTitle(const string &text) { - state.title = text; - return p.setTitle(text); -} - -void Window::setVisible(bool visible) { - state.visible = visible; - synchronizeLayout(); - return p.setVisible(visible); -} - -void Window::setWidgetFont(const string &font) { - state.widgetFont = font; - return p.setWidgetFont(font); -} - -string Window::statusText() { - return state.statusText; -} - -void Window::synchronizeLayout() { - if(visible() && OS_quit == false) setGeometry(geometry()); -} - -bool Window::visible() { - return state.visible; -} - -Window::Window(): -state(*new State), -base_from_member(*new pWindow(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Window::~Window() { - p.destructor(); - delete &state; -} - -//Action -//====== - -bool Action::enabled() { - return state.enabled; -} - -void Action::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Action::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Action::visible() { - return state.visible; -} - -Action::Action(pAction &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Action::~Action() { - p.destructor(); - delete &state; -} - -//Menu -//==== - -void Menu::append(const set &list) { - for(auto &action : list) { - if(state.action.append(action)) { - action.state.menu = this; - p.append(action); - } - } -} - -void Menu::remove(const set &list) { - for(auto &action : list) { - if(state.action.remove(action)) { - action.state.menu = 0; - return p.remove(action); - } - } -} - -void Menu::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Menu::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Menu::Menu(): -state(*new State), -base_from_member(*new pMenu(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Menu::~Menu() { - p.destructor(); - delete &state; -} - -//Separator -//========= - -Separator::Separator(): -base_from_member(*new pSeparator(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Separator::~Separator() { - p.destructor(); -} - -//Item -//==== - -void Item::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Item::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Item::Item(): -state(*new State), -base_from_member(*new pItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Item::~Item() { - p.destructor(); - delete &state; -} - -//CheckItem -//========= - -bool CheckItem::checked() { - return p.checked(); -} - -void CheckItem::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckItem::CheckItem(): -state(*new State), -base_from_member(*new pCheckItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckItem::~CheckItem() { - p.destructor(); - delete &state; -} - -//RadioItem -//========= - -void RadioItem::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioItem::checked() { - return p.checked(); -} - -void RadioItem::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string RadioItem::text() { - return state.text; -} - -RadioItem::RadioItem(): -state(*new State), -base_from_member(*new pRadioItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioItem::~RadioItem() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//Sizable -//======= - -Layout* Sizable::layout() { - return state.layout; -} - -Window* Sizable::window() { - if(state.layout) return state.layout->window(); - return state.window; -} - -Sizable::Sizable(pSizable &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Sizable::~Sizable() { - if(layout()) layout()->remove(*this); - p.destructor(); - delete &state; -} - -//Layout -//====== - -void Layout::append(Sizable &sizable) { - sizable.state.layout = this; - sizable.state.window = 0; - - if(dynamic_cast(&sizable)) { - Layout &layout = (Layout&)sizable; - layout.synchronizeLayout(); - } - - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->append(widget); - } -} - -void Layout::remove(Sizable &sizable) { - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->remove(widget); - } - - sizable.state.layout = 0; - sizable.state.window = 0; -} - -Layout::Layout(): -state(*new State), -base_from_member(*new pLayout(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { -} - -Layout::Layout(pLayout &p): -state(*new State), -base_from_member(p), -Sizable(p), -p(p) { -} - -Layout::~Layout() { - if(layout()) layout()->remove(*this); - else if(window()) window()->remove(*this); - p.destructor(); - delete &state; -} - -//Widget -//====== - -bool Widget::enabled() { - return state.enabled; -} - -string Widget::font() { - return state.font; -} - -Geometry Widget::geometry() { - return state.geometry; -} - -Geometry Widget::minimumGeometry() { - return p.minimumGeometry(); -} - -void Widget::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Widget::setFocused() { - return p.setFocused(); -} - -void Widget::setFont(const string &font) { - state.font = font; - return p.setFont(font); -} - -void Widget::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Widget::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Widget::visible() { - return state.visible; -} - -Widget::Widget(): -state(*new State), -base_from_member(*new pWidget(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { - state.abstract = true; - p.constructor(); -} - -Widget::Widget(pWidget &p): -state(*new State), -base_from_member(p), -Sizable(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Widget::~Widget() { - p.destructor(); - delete &state; -} - -//Button -//====== - -void Button::setImage(const image &image, Orientation orientation) { - state.image = image; - state.orientation = orientation; - return p.setImage(image, orientation); -} - -void Button::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Button::Button(): -state(*new State), -base_from_member(*new pButton(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Button::~Button() { - p.destructor(); - delete &state; -} - -//Canvas -//====== - -uint32_t* Canvas::data() { - return state.data; -} - -bool Canvas::setImage(const nall::image &image) { - if(image.data == nullptr || image.width == 0 || image.height == 0) return false; - state.width = image.width; - state.height = image.height; - setSize({ state.width, state.height }); - memcpy(state.data, image.data, state.width * state.height * sizeof(uint32_t)); - return true; -} - -void Canvas::setSize(const Size &size) { - state.width = size.width; - state.height = size.height; - delete[] state.data; - state.data = new uint32_t[size.width * size.height]; - return p.setSize(size); -} - -Size Canvas::size() { - return { state.width, state.height }; -} - -void Canvas::update() { - return p.update(); -} - -Canvas::Canvas(): -state(*new State), -base_from_member(*new pCanvas(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - state.data = new uint32_t[state.width * state.height]; - p.constructor(); -} - -Canvas::~Canvas() { - p.destructor(); - delete[] state.data; - delete &state; -} - -//CheckBox -//======== - -bool CheckBox::checked() { - return p.checked(); -} - -void CheckBox::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckBox::CheckBox(): -state(*new State), -base_from_member(*new pCheckBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckBox::~CheckBox() { - p.destructor(); - delete &state; -} - -//ComboBox -//======== - -void ComboBox::append_(const lstring &list) { - for(auto &text : list) { - state.text.append(text); - p.append(text); - } -} - -void ComboBox::modify(unsigned row, const string &text) { - state.text(row) = text; - p.modify(row, text); -} - -void ComboBox::remove(unsigned row) { - state.text.remove(row); - p.remove(row); -} - -void ComboBox::reset() { - state.selection = 0; - state.text.reset(); - return p.reset(); -} - -unsigned ComboBox::selection() { - return p.selection(); -} - -void ComboBox::setSelection(unsigned row) { - state.selection = row; - return p.setSelection(row); -} - -string ComboBox::text() { - return state.text(selection()); -} - -string ComboBox::text(unsigned row) { - return state.text(row); -} - -ComboBox::ComboBox(): -state(*new State), -base_from_member(*new pComboBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ComboBox::~ComboBox() { - p.destructor(); - delete &state; -} - -//HexEdit -//======= - -void HexEdit::setColumns(unsigned columns) { - state.columns = columns; - return p.setColumns(columns); -} - -void HexEdit::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HexEdit::setOffset(unsigned offset) { - state.offset = offset; - return p.setOffset(offset); -} - -void HexEdit::setRows(unsigned rows) { - state.rows = rows; - return p.setRows(rows); -} - -void HexEdit::update() { - return p.update(); -} - -HexEdit::HexEdit(): -state(*new State), -base_from_member(*new pHexEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HexEdit::~HexEdit() { - p.destructor(); - delete &state; -} - -//HorizontalScrollBar -//=================== - -unsigned HorizontalScrollBar::length() { - return state.length; -} - -unsigned HorizontalScrollBar::position() { - return p.position(); -} - -void HorizontalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalScrollBar::HorizontalScrollBar(): -state(*new State), -base_from_member(*new pHorizontalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalScrollBar::~HorizontalScrollBar() { - p.destructor(); - delete &state; -} - -//HorizontalSlider -//================ - -unsigned HorizontalSlider::length() { - return state.length; -} - -unsigned HorizontalSlider::position() { - return p.position(); -} - -void HorizontalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalSlider::HorizontalSlider(): -state(*new State), -base_from_member(*new pHorizontalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalSlider::~HorizontalSlider() { - p.destructor(); - delete &state; -} - -//Label -//===== - -void Label::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Label::Label(): -state(*new State), -base_from_member(*new pLabel(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Label::~Label() { - p.destructor(); - delete &state; -} - -//LineEdit -//======== - -void LineEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void LineEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string LineEdit::text() { - return p.text(); -} - -LineEdit::LineEdit(): -state(*new State), -base_from_member(*new pLineEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -LineEdit::~LineEdit() { - p.destructor(); - delete &state; -} - -//ListView -//======== - -void ListView::append_(const lstring &text) { - state.checked.append(false); - state.text.append(text); - return p.append(text); -} - -void ListView::autoSizeColumns() { - return p.autoSizeColumns(); -} - -bool ListView::checked(unsigned row) { - return p.checked(row); -} - -void ListView::modify_(unsigned row, const lstring &text) { - state.text[row] = text; - return p.modify(row, text); -} - -void ListView::remove(unsigned row) { - state.text.remove(row); - state.image.remove(row); - return p.remove(row); -} - -void ListView::reset() { - state.checked.reset(); - state.image.reset(); - state.text.reset(); - return p.reset(); -} - -bool ListView::selected() { - return p.selected(); -} - -unsigned ListView::selection() { - return p.selection(); -} - -void ListView::setCheckable(bool checkable) { - state.checkable = checkable; - return p.setCheckable(checkable); -} - -void ListView::setChecked(unsigned row, bool checked) { - state.checked[row] = checked; - return p.setChecked(row, checked); -} - -void ListView::setHeaderText_(const lstring &text) { - state.headerText = text; - return p.setHeaderText(text); -} - -void ListView::setHeaderVisible(bool visible) { - state.headerVisible = visible; - return p.setHeaderVisible(visible); -} - -void ListView::setImage(unsigned row, unsigned column, const nall::image &image) { - state.image(row)(column) = image; - return p.setImage(row, column, image); -} - -void ListView::setSelected(bool selected) { - state.selected = selected; - return p.setSelected(selected); -} - -void ListView::setSelection(unsigned row) { - state.selected = true; - state.selection = row; - return p.setSelection(row); -} - -ListView::ListView(): -state(*new State), -base_from_member(*new pListView(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ListView::~ListView() { - p.destructor(); - delete &state; -} - -//ProgressBar -//=========== - -void ProgressBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -ProgressBar::ProgressBar(): -state(*new State), -base_from_member(*new pProgressBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ProgressBar::~ProgressBar() { - p.destructor(); - delete &state; -} - -//RadioBox -//======== - -void RadioBox::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioBox::checked() { - return p.checked(); -} - -void RadioBox::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -RadioBox::RadioBox(): -state(*new State), -base_from_member(*new pRadioBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioBox::~RadioBox() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//TextEdit -//======== - -void TextEdit::setCursorPosition(unsigned position) { - state.cursorPosition = position; - return p.setCursorPosition(position); -} - -void TextEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void TextEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -void TextEdit::setWordWrap(bool wordWrap) { - state.wordWrap = wordWrap; - return p.setWordWrap(wordWrap); -} - -string TextEdit::text() { - return p.text(); -} - -TextEdit::TextEdit(): -state(*new State), -base_from_member(*new pTextEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -TextEdit::~TextEdit() { - p.destructor(); - delete &state; -} - -//VerticalScrollBar -//================= - -unsigned VerticalScrollBar::length() { - return state.length; -} - -unsigned VerticalScrollBar::position() { - return p.position(); -} - -void VerticalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalScrollBar::VerticalScrollBar(): -state(*new State), -base_from_member(*new pVerticalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalScrollBar::~VerticalScrollBar() { - p.destructor(); - delete &state; -} - -//VerticalSlider -//============== - -unsigned VerticalSlider::length() { - return state.length; -} - -unsigned VerticalSlider::position() { - return p.position(); -} - -void VerticalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalSlider::VerticalSlider(): -state(*new State), -base_from_member(*new pVerticalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalSlider::~VerticalSlider() { - p.destructor(); - delete &state; -} - -//Viewport -//======== - -uintptr_t Viewport::handle() { - return p.handle(); -} - -Viewport::Viewport(): -base_from_member(*new pViewport(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Viewport::~Viewport() { - p.destructor(); -} diff --git a/kaijuu/phoenix/core/core.hpp b/kaijuu/phoenix/core/core.hpp deleted file mode 100644 index 1e88ca5d..00000000 --- a/kaijuu/phoenix/core/core.hpp +++ /dev/null @@ -1,612 +0,0 @@ -struct Font; -struct Window; -struct Menu; -struct Sizable; -struct Layout; -struct Widget; - -struct pFont; -struct pObject; -struct pOS; -struct pTimer; -struct pWindow; -struct pAction; -struct pMenu; -struct pSeparator; -struct pItem; -struct pCheckItem; -struct pRadioItem; -struct pSizable; -struct pLayout; -struct pWidget; -struct pButton; -struct pCanvas; -struct pCheckBox; -struct pComboBox; -struct pHexEdit; -struct pHorizontalScrollBar; -struct pHorizontalSlider; -struct pLabel; -struct pLineEdit; -struct pListView; -struct pProgressBar; -struct pRadioBox; -struct pTextEdit; -struct pVerticalScrollBar; -struct pVerticalSlider; -struct pViewport; - -enum : unsigned { - MaximumSize = ~0u, - MinimumSize = 0u, -}; - -struct Color { - uint8_t red, green, blue, alpha; - uint32_t rgb() const; - uint32_t rgba() const; - inline Color() : red(0), green(0), blue(0), alpha(255) {} - inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) : red(red), green(green), blue(blue), alpha(alpha) {} -}; - -struct Position { - signed x, y; - inline Position() : x(0), y(0) {} - template inline Position(X x, Y y) : x(x), y(y) {} -}; - -struct Size { - unsigned width, height; - inline Size() : width(0), height(0) {} - template inline Size(W width, H height) : width(width), height(height) {} -}; - -struct Geometry { - signed x, y; - unsigned width, height; - Position position() const; - Size size() const; - nall::string text() const; - inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(const Position& position, const Size& size) : x(position.x), y(position.y), width(size.width), height(size.height) {} - template inline Geometry(X x, Y y, W width, H height) : x(x), y(y), width(width), height(height) {} - Geometry(const nall::string &text); -}; - -enum class Orientation : unsigned { Horizontal, Vertical }; - -struct Font { - nall::string description; - Geometry geometry(const nall::string &text); - Font(const nall::string &description = ""); -}; - -struct Desktop { - static Size size(); - static Geometry workspace(); - Desktop() = delete; -}; - -struct Keyboard { - #include "keyboard.hpp" - static bool pressed(Scancode scancode); - static bool released(Scancode scancode); - static nall::vector state(); - Keyboard() = delete; -}; - -struct Mouse { - enum class Button : unsigned { Left, Middle, Right }; - static Position position(); - static bool pressed(Button); - static bool released(Button); - Mouse() = delete; -}; - -struct DialogWindow { - template static nall::string fileOpen(Window &parent, const nall::string &path, const Args&... args) { return fileOpen_(parent, path, { args... }); } - template static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); } - static nall::string folderSelect(Window &parent, const nall::string &path); - DialogWindow() = delete; - -private: - static nall::string fileOpen_(Window &parent, const nall::string &path, const nall::lstring& filter); - static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter); -}; - -struct MessageWindow { - enum class Buttons : unsigned { - Ok, - OkCancel, - YesNo, - }; - - enum class Response : unsigned { - Ok, - Cancel, - Yes, - No, - }; - - static Response information(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response question(Window &parent, const nall::string &text, Buttons = Buttons::YesNo); - static Response warning(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - MessageWindow() = delete; -}; - -struct Object { - Object(pObject &p); - Object& operator=(const Object&) = delete; - Object(const Object&) = delete; - virtual ~Object(); - pObject &p; -}; - -struct OS : Object { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - OS(); - static void initialize(); -}; - -struct Timer : private nall::base_from_member, Object { - nall::function onTimeout; - - void setEnabled(bool enabled = true); - void setInterval(unsigned milliseconds); - - Timer(); - ~Timer(); - struct State; - State &state; - pTimer &p; -}; - -struct Window : private nall::base_from_member, Object { - nall::function onClose; - nall::function onKeyPress; - nall::function onKeyRelease; - nall::function onMove; - nall::function onSize; - - static Window& none(); - - inline void append() {} - inline void remove() {} - template void append(T &arg, Args&... args) { append_(arg); append(args...); } - template void remove(T &arg, Args&... args) { remove_(arg); remove(args...); } - - void append_(Layout &layout); - void append_(Menu &menu); - void append_(Widget &widget); - Color backgroundColor(); - Geometry frameGeometry(); - Geometry frameMargin(); - bool focused(); - bool fullScreen(); - Geometry geometry(); - void ignore(); - void remove_(Layout &layout); - void remove_(Menu &menu); - void remove_(Widget &widget); - void setBackgroundColor(const Color &color); - void setFrameGeometry(const Geometry &geometry); - void setFocused(); - void setFullScreen(bool fullScreen = true); - void setGeometry(const Geometry &geometry); - void setMenuFont(const nall::string &font); - void setMenuVisible(bool visible = true); - void setModal(bool modal = true); - void setResizable(bool resizable = true); - void setStatusFont(const nall::string &font); - void setStatusText(const nall::string &text); - void setStatusVisible(bool visible = true); - void setTitle(const nall::string &text); - void setVisible(bool visible = true); - void setWidgetFont(const nall::string &font); - nall::string statusText(); - void synchronizeLayout(); - bool visible(); - - Window(); - ~Window(); - struct State; - State &state; - pWindow &p; -}; - -struct Action : Object { - bool enabled(); - void setEnabled(bool enabled = true); - void setVisible(bool visible = true); - bool visible(); - - Action(pAction &p); - ~Action(); - struct State; - State &state; - pAction &p; -}; - -struct Menu : private nall::base_from_member, Action { - template void append(Args&... args) { append({args...}); } - template void remove(Args&... args) { remove({args...}); } - - void append(const nall::set &list); - void remove(const nall::set &list); - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Menu(); - ~Menu(); - struct State; - State &state; - pMenu &p; -}; - -struct Separator : private nall::base_from_member, Action { - Separator(); - ~Separator(); - pSeparator &p; -}; - -struct Item : private nall::base_from_member, Action { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Item(); - ~Item(); - struct State; - State &state; - pItem &p; -}; - -struct CheckItem : private nall::base_from_member, Action { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckItem(); - ~CheckItem(); - struct State; - State &state; - pCheckItem &p; -}; - -struct RadioItem : private nall::base_from_member, Action { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - nall::string text(); - - RadioItem(); - ~RadioItem(); - struct State; - State &state; - pRadioItem &p; -}; - -struct Sizable : Object { - virtual bool enabled() = 0; - Layout* layout(); - virtual Geometry minimumGeometry() = 0; - virtual void setEnabled(bool enabled = true) = 0; - virtual void setGeometry(const Geometry &geometry) = 0; - virtual void setVisible(bool visible = true) = 0; - virtual bool visible() = 0; - Window* window(); - - Sizable(pSizable &p); - ~Sizable(); - struct State; - State &state; - pSizable &p; -}; - -struct Layout : private nall::base_from_member, Sizable { - virtual void append(Sizable &sizable); - virtual void remove(Sizable &sizable); - virtual void reset() {} - virtual void synchronizeLayout() = 0; - - Layout(); - Layout(pLayout &p); - ~Layout(); - struct State; - State &state; - pLayout &p; -}; - -struct Widget : private nall::base_from_member, Sizable { - bool enabled(); - nall::string font(); - Geometry geometry(); - Geometry minimumGeometry(); - void setEnabled(bool enabled = true); - void setFocused(); - void setFont(const nall::string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - bool visible(); - - Widget(); - Widget(pWidget &p); - ~Widget(); - struct State; - State &state; - pWidget &p; -}; - -struct Button : private nall::base_from_member, Widget { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}, Orientation = Orientation::Horizontal); - void setText(const nall::string &text); - - Button(); - ~Button(); - struct State; - State &state; - pButton &p; -}; - -struct Canvas : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uint32_t* data(); - bool setImage(const nall::image &image); - void setSize(const Size &size); - Size size(); - void update(); - - Canvas(); - ~Canvas(); - struct State; - State &state; - pCanvas &p; -}; - -struct CheckBox : private nall::base_from_member, Widget { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckBox(); - ~CheckBox(); - struct State; - State &state; - pCheckBox &p; -}; - -struct ComboBox : private nall::base_from_member, Widget { - nall::function onChange; - - template void append(const Args&... args) { append_({args...}); } - - void append_(const nall::lstring &list); - void modify(unsigned row, const nall::string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - nall::string text(); - nall::string text(unsigned row); - - ComboBox(); - ~ComboBox(); - struct State; - State &state; - pComboBox &p; -}; - -struct HexEdit : private nall::base_from_member, Widget { - nall::function onRead; - nall::function onWrite; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - HexEdit(); - ~HexEdit(); - struct State; - State &state; - pHexEdit &p; -}; - -struct HorizontalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalScrollBar(); - ~HorizontalScrollBar(); - struct State; - State &state; - pHorizontalScrollBar &p; -}; - -struct HorizontalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalSlider(); - ~HorizontalSlider(); - struct State; - State &state; - pHorizontalSlider &p; -}; - -struct Label : private nall::base_from_member, Widget { - void setText(const nall::string &text); - - Label(); - ~Label(); - struct State; - State &state; - pLabel &p; -}; - -struct LineEdit : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - - void setEditable(bool editable = true); - void setText(const nall::string &text); - nall::string text(); - - LineEdit(); - ~LineEdit(); - struct State; - State &state; - pLineEdit &p; -}; - -struct ListView : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - nall::function onToggle; - - template void append(const Args&... args) { append_({args...}); } - template void modify(unsigned row, const Args&... args) { modify_(row, {args...}); } - template void setHeaderText(const Args&... args) { setHeaderText_({args...}); } - - void append_(const nall::lstring &list); - void autoSizeColumns(); - bool checked(unsigned row); - void modify_(unsigned row, const nall::lstring &list); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable = true); - void setChecked(unsigned row, bool checked = true); - void setHeaderText_(const nall::lstring &list); - void setHeaderVisible(bool visible = true); - void setImage(unsigned row, unsigned column, const nall::image &image = nall::image{}); - void setSelected(bool selected = true); - void setSelection(unsigned row); - - ListView(); - ~ListView(); - struct State; - State &state; - pListView &p; -}; - -struct ProgressBar : private nall::base_from_member, Widget { - void setPosition(unsigned position); - - ProgressBar(); - ~ProgressBar(); - struct State; - State &state; - pProgressBar &p; -}; - -struct RadioBox : private nall::base_from_member, Widget { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - - RadioBox(); - ~RadioBox(); - struct State; - State &state; - pRadioBox &p; -}; - -struct TextEdit : private nall::base_from_member, Widget { - nall::function onChange; - - void setCursorPosition(unsigned position); - void setEditable(bool editable = true); - void setText(const nall::string &text); - void setWordWrap(bool wordWrap = true); - nall::string text(); - - TextEdit(); - ~TextEdit(); - struct State; - State &state; - pTextEdit &p; -}; - -struct VerticalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalScrollBar(); - ~VerticalScrollBar(); - struct State; - State &state; - pVerticalScrollBar &p; -}; - -struct VerticalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalSlider(); - ~VerticalSlider(); - struct State; - State &state; - pVerticalSlider &p; -}; - -struct Viewport : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uintptr_t handle(); - - Viewport(); - ~Viewport(); - pViewport &p; -}; - -#include "layout/fixed-layout.hpp" -#include "layout/horizontal-layout.hpp" -#include "layout/vertical-layout.hpp" diff --git a/kaijuu/phoenix/core/keyboard.hpp b/kaijuu/phoenix/core/keyboard.hpp deleted file mode 100644 index ed04ec05..00000000 --- a/kaijuu/phoenix/core/keyboard.hpp +++ /dev/null @@ -1,45 +0,0 @@ -//each code refers to a physical key -//names are taken assuming: NumLock on, CapsLock off, Shift off -//layout uses US-104 keyboard -enum class Scancode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - - Limit, -}; - -//each enum refers to a translated scancode (eg Shift+1 = !) -enum class Keycode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, SysRq, ScrollLock, Pause, Break, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - Tilde, Exclamation, At, Pound, Dollar, Percent, Power, Ampersand, Asterisk, ParenthesisLeft, ParenthesisRight, Underscore, Plus, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - BraceLeft, BraceRight, Pipe, Colon, Quote, CaretLeft, CaretRight, Question, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - KeypadInsert, KeypadDelete, KeypadHome, KeypadEnd, KeypadPageUp, KeypadPageDown, KeypadUp, KeypadDown, KeypadLeft, KeypadRight, KeypadCenter, - - Limit, -}; diff --git a/kaijuu/phoenix/core/layout/fixed-layout.cpp b/kaijuu/phoenix/core/layout/fixed-layout.cpp deleted file mode 100644 index 71ff3dac..00000000 --- a/kaijuu/phoenix/core/layout/fixed-layout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -void FixedLayout::append(Sizable &sizable, const Geometry &geometry) { - children.append({ &sizable, geometry }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void FixedLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool FixedLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry FixedLayout::minimumGeometry() { - unsigned width = MinimumSize, height = MinimumSize; - for(auto &child : children) { - width = max(width, child.sizable->minimumGeometry().width); - height = max(height, child.sizable->minimumGeometry().height); - } - return { 0, 0, width, height }; -} - -void FixedLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void FixedLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void FixedLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void FixedLayout::setGeometry(const Geometry &geometry) { -} - -void FixedLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void FixedLayout::synchronizeLayout() { - for(auto &child : children) { - Layout::append(*child.sizable); - child.sizable->setGeometry(child.geometry); - } -} - -bool FixedLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -FixedLayout::FixedLayout() { - state.enabled = true; - state.visible = true; -} - -FixedLayout::~FixedLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/kaijuu/phoenix/core/layout/fixed-layout.hpp b/kaijuu/phoenix/core/layout/fixed-layout.hpp deleted file mode 100644 index a67f2185..00000000 --- a/kaijuu/phoenix/core/layout/fixed-layout.hpp +++ /dev/null @@ -1,27 +0,0 @@ -struct FixedLayout : Layout { - void append(Sizable &sizable, const Geometry &geometry); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - FixedLayout(); - ~FixedLayout(); - -//private: - struct State { - bool enabled; - bool visible; - } state; - - struct Children { - Sizable *sizable; - Geometry geometry; - }; - nall::vector children; -}; diff --git a/kaijuu/phoenix/core/layout/horizontal-layout.cpp b/kaijuu/phoenix/core/layout/horizontal-layout.cpp deleted file mode 100644 index a1146038..00000000 --- a/kaijuu/phoenix/core/layout/horizontal-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void HorizontalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void HorizontalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool HorizontalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry HorizontalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - width += child.spacing; - if(child.width == MinimumSize || child.width == MaximumSize) { - width += child.sizable->minimumGeometry().width; - continue; - } - width += child.width; - } - - for(auto &child : children) { - if(child.height == MinimumSize || child.height == MaximumSize) { - height = max(height, child.sizable->minimumGeometry().height); - continue; - } - height = max(height, child.height); - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void HorizontalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void HorizontalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void HorizontalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void HorizontalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void HorizontalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumWidth = 0, maximumWidthCounter = 0; - for(auto &child : children) { - if(child.width == MaximumSize) maximumWidthCounter++; - if(child.width != MaximumSize) minimumWidth += child.width; - minimumWidth += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = (geometry.width - minimumWidth) / maximumWidthCounter; - if(child.height == MaximumSize) child.height = geometry.height; - } - - unsigned maximumHeight = 0; - for(auto &child : children) maximumHeight = max(maximumHeight, child.height); - - for(auto &child : children) { - unsigned pivot = (maximumHeight - child.height) * state.alignment; - Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.x += child.width + child.spacing; - geometry.width -= child.width + child.spacing; - } -} - -void HorizontalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void HorizontalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void HorizontalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool HorizontalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -HorizontalLayout::HorizontalLayout() { - state.alignment = 0.5; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -HorizontalLayout::~HorizontalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/kaijuu/phoenix/core/layout/horizontal-layout.hpp b/kaijuu/phoenix/core/layout/horizontal-layout.hpp deleted file mode 100644 index 96d4f101..00000000 --- a/kaijuu/phoenix/core/layout/horizontal-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct HorizontalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - HorizontalLayout(); - ~HorizontalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/kaijuu/phoenix/core/layout/vertical-layout.cpp b/kaijuu/phoenix/core/layout/vertical-layout.cpp deleted file mode 100644 index 4fd6315b..00000000 --- a/kaijuu/phoenix/core/layout/vertical-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void VerticalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void VerticalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool VerticalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry VerticalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - if(child.width == MinimumSize || child.width == MaximumSize) { - width = max(width, child.sizable->minimumGeometry().width); - continue; - } - width = max(width, child.width); - } - - for(auto &child : children) { - height += child.spacing; - if(child.height == MinimumSize || child.height == MaximumSize) { - height += child.sizable->minimumGeometry().height; - continue; - } - height += child.height; - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void VerticalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void VerticalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void VerticalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void VerticalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void VerticalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumHeight = 0, maximumHeightCounter = 0; - for(auto &child : children) { - if(child.height == MaximumSize) maximumHeightCounter++; - if(child.height != MaximumSize) minimumHeight += child.height; - minimumHeight += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = geometry.width; - if(child.height == MaximumSize) child.height = (geometry.height - minimumHeight) / maximumHeightCounter; - } - - unsigned maximumWidth = 0; - for(auto &child : children) maximumWidth = max(maximumWidth, child.width); - - for(auto &child : children) { - unsigned pivot = (maximumWidth - child.width) * state.alignment; - Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.y += child.height + child.spacing; - geometry.height -= child.height + child.spacing; - } -} - -void VerticalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void VerticalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void VerticalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool VerticalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -VerticalLayout::VerticalLayout() { - state.alignment = 0.0; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -VerticalLayout::~VerticalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/kaijuu/phoenix/core/layout/vertical-layout.hpp b/kaijuu/phoenix/core/layout/vertical-layout.hpp deleted file mode 100644 index 8273dbe2..00000000 --- a/kaijuu/phoenix/core/layout/vertical-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct VerticalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - VerticalLayout(); - ~VerticalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/kaijuu/phoenix/core/state.hpp b/kaijuu/phoenix/core/state.hpp deleted file mode 100644 index 2d46ca2f..00000000 --- a/kaijuu/phoenix/core/state.hpp +++ /dev/null @@ -1,278 +0,0 @@ -struct Timer::State { - bool enabled; - unsigned milliseconds; - - State() { - enabled = false; - milliseconds = 0; - } -}; - -struct Window::State { - bool backgroundColorOverride; - Color backgroundColor; - bool fullScreen; - Geometry geometry; - bool ignore; - set layout; - set menu; - string menuFont; - bool menuVisible; - bool modal; - bool resizable; - string statusFont; - string statusText; - bool statusVisible; - string title; - bool visible; - set widget; - string widgetFont; - - State() { - backgroundColorOverride = false; - backgroundColor = {0, 0, 0, 255}; - fullScreen = false; - geometry = {128, 128, 256, 256}; - ignore = false; - menuVisible = false; - modal = false; - resizable = true; - statusVisible = false; - visible = false; - } -}; - -struct Action::State { - bool enabled; - Menu *menu; - bool visible; - Window *window; - - State() { - enabled = true; - menu = 0; - visible = true; - window = 0; - } -}; - -struct Menu::State { - set action; - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Item::State { - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct CheckItem::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct RadioItem::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct Sizable::State { - Layout *layout; - Window *window; - - State() { - layout = 0; - window = 0; - } -}; - -struct Layout::State { - State() { - } -}; - -struct Widget::State { - bool abstract; - bool enabled; - string font; - Geometry geometry; - bool visible; - - State() { - abstract = false; - enabled = true; - geometry = {0, 0, 0, 0}; - visible = true; - } -}; - -struct Button::State { - nall::image image; - Orientation orientation; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Canvas::State { - uint32_t *data; - unsigned width; - unsigned height; - - State() { - data = nullptr; - width = 256; - height = 256; - } -}; - -struct CheckBox::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct ComboBox::State { - unsigned selection; - vector text; - - State() { - selection = 0; - } -}; - -struct HexEdit::State { - unsigned columns; - unsigned length; - unsigned offset; - unsigned rows; - - State() { - columns = 16; - length = 0; - offset = 0; - rows = 16; - } -}; - -struct HorizontalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct HorizontalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct Label::State { - string text; -}; - -struct LineEdit::State { - bool editable; - string text; - - State() { - editable = true; - } -}; - -struct ListView::State { - bool checkable; - vector checked; - lstring headerText; - bool headerVisible; - vector> image; - bool selected; - unsigned selection; - vector text; - - State() { - checkable = false; - headerVisible = false; - selected = false; - selection = 0; - } -}; - -struct ProgressBar::State { - unsigned position; - - State() { - position = 0; - } -}; - -struct RadioBox::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct TextEdit::State { - unsigned cursorPosition; - bool editable; - string text; - bool wordWrap; - - State() { - cursorPosition = 0; - editable = true; - wordWrap = true; - } -}; - -struct VerticalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct VerticalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; diff --git a/kaijuu/phoenix/gtk/action/action.cpp b/kaijuu/phoenix/gtk/action/action.cpp deleted file mode 100644 index 950259de..00000000 --- a/kaijuu/phoenix/gtk/action/action.cpp +++ /dev/null @@ -1,27 +0,0 @@ -void pAction::setEnabled(bool enabled) { - gtk_widget_set_sensitive(widget, enabled); -} - -void pAction::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); -} - -void pAction::constructor() { -} - -void pAction::orphan() { -} - -//GTK+ uses _ for mnemonics, __ for _ -//transform so that & is used for mnemonics, && for & -string pAction::mnemonic(string text) { - text.transform("&_", "\x01\x02"); - text.replace("\x01\x01", "&"); - text.transform("\x01", "_"); - text.replace("\x02", "__"); - return text; -} - -void pAction::setFont(const string &font) { - pFont::setFont(widget, font); -} diff --git a/kaijuu/phoenix/gtk/action/check-item.cpp b/kaijuu/phoenix/gtk/action/check-item.cpp deleted file mode 100644 index 2cc182a6..00000000 --- a/kaijuu/phoenix/gtk/action/check-item.cpp +++ /dev/null @@ -1,33 +0,0 @@ -static void CheckItem_toggle(CheckItem *self) { - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pCheckItem::setChecked(bool checked) { - locked = true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked); - locked = false; -} - -void pCheckItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pCheckItem::constructor() { - widget = gtk_check_menu_item_new_with_mnemonic(""); - setChecked(checkItem.state.checked); - setText(checkItem.state.text); - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_toggle), (gpointer)&checkItem); -} - -void pCheckItem::destructor() { - gtk_widget_destroy(widget); -} - -void pCheckItem::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/action/item.cpp b/kaijuu/phoenix/gtk/action/item.cpp deleted file mode 100644 index afab955e..00000000 --- a/kaijuu/phoenix/gtk/action/item.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static void Item_activate(Item *self) { - if(self->onActivate) self->onActivate(); -} - -void pItem::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pItem::constructor() { - widget = gtk_image_menu_item_new_with_mnemonic(""); - g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_activate), (gpointer)&item); - setText(item.state.text); -} - -void pItem::destructor() { - gtk_widget_destroy(widget); -} - -void pItem::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/action/menu.cpp b/kaijuu/phoenix/gtk/action/menu.cpp deleted file mode 100644 index 92252085..00000000 --- a/kaijuu/phoenix/gtk/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - action.state.window = this->action.state.window; - - gtk_menu_shell_append(GTK_MENU_SHELL(gtkMenu), action.p.widget); - if(action.state.window && action.state.window->state.menuFont != "") { - action.p.setFont(action.state.window->state.menuFont); - } - gtk_widget_show(action.p.widget); -} - -void pMenu::remove(Action &action) { - action.p.orphan(); - action.state.window = 0; -} - -void pMenu::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pMenu::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pMenu::constructor() { - gtkMenu = gtk_menu_new(); - widget = gtk_image_menu_item_new_with_mnemonic(""); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), gtkMenu); - setText(menu.state.text); -} - -void pMenu::destructor() { - gtk_widget_destroy(gtkMenu); - gtk_widget_destroy(widget); -} - -void pMenu::orphan() { - for(auto &action : menu.state.action) action.p.orphan(); - destructor(); - constructor(); - for(auto &action : menu.state.action) append(action); -} - -void pMenu::setFont(const string &font) { - pAction::setFont(font); - for(auto &item : menu.state.action) item.p.setFont(font); -} diff --git a/kaijuu/phoenix/gtk/action/radio-item.cpp b/kaijuu/phoenix/gtk/action/radio-item.cpp deleted file mode 100644 index a599d70b..00000000 --- a/kaijuu/phoenix/gtk/action/radio-item.cpp +++ /dev/null @@ -1,48 +0,0 @@ -static void RadioItem_activate(RadioItem *self) { - for(auto &item : self->state.group) item.state.checked = (&item == self); - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true); - locked = false; -} - -void pRadioItem::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget)); - if(currentGroup != gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[n].p.widget))) { - gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(group[n].p.widget), currentGroup); - } - } -} - -void pRadioItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pRadioItem::constructor() { - widget = gtk_radio_menu_item_new_with_mnemonic(0, ""); - setGroup(radioItem.state.group); - setText(radioItem.state.text); - for(auto &item : radioItem.state.group) { - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), item.state.checked); - } - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_activate), (gpointer)&radioItem); -} - -void pRadioItem::destructor() { - gtk_widget_destroy(widget); -} - -void pRadioItem::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/action/separator.cpp b/kaijuu/phoenix/gtk/action/separator.cpp deleted file mode 100644 index 8b7a1a6b..00000000 --- a/kaijuu/phoenix/gtk/action/separator.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pSeparator::constructor() { - widget = gtk_separator_menu_item_new(); -} - -void pSeparator::destructor() { - gtk_widget_destroy(widget); -} - -void pSeparator::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/desktop.cpp b/kaijuu/phoenix/gtk/desktop.cpp deleted file mode 100644 index 2b1801ad..00000000 --- a/kaijuu/phoenix/gtk/desktop.cpp +++ /dev/null @@ -1,36 +0,0 @@ -Size pDesktop::size() { - return { - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} - -Geometry pDesktop::workspace() { - XlibDisplay *display = XOpenDisplay(0); - int screen = DefaultScreen(display); - - static Atom atom = XlibNone; - if(atom == XlibNone) atom = XInternAtom(display, "_NET_WORKAREA", True); - - int format; - unsigned char *data = 0; - unsigned long items, after; - Atom returnAtom; - - int result = XGetWindowProperty( - display, RootWindow(display, screen), atom, 0, 4, False, XA_CARDINAL, &returnAtom, &format, &items, &after, &data - ); - - XCloseDisplay(display); - - if(result == Success && returnAtom == XA_CARDINAL && format == 32 && items == 4) { - unsigned long *workarea = (unsigned long*)data; - return { (signed)workarea[0], (signed)workarea[1], (unsigned)workarea[2], (unsigned)workarea[3] }; - } - - return { - 0, 0, - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} diff --git a/kaijuu/phoenix/gtk/dialog-window.cpp b/kaijuu/phoenix/gtk/dialog-window.cpp deleted file mode 100644 index eb04bd64..00000000 --- a/kaijuu/phoenix/gtk/dialog-window.cpp +++ /dev/null @@ -1,69 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - save == 0 ? "Load File" : "Save File", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - save == 0 ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - for(auto &filterItem : filter) { - GtkFileFilter *gtkFilter = gtk_file_filter_new(); - gtk_file_filter_set_name(gtkFilter, filterItem); - lstring part; - part.split("(", filterItem); - part[1].rtrim<1>(")"); - lstring list; - list.split(",", part[1]); - for(auto &pattern : list) gtk_file_filter_add_pattern(gtkFilter, pattern); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), gtkFilter); - } - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(0, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(1, parent, path, filter); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - "Select Folder", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - if(name == "") return ""; - if(name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/kaijuu/phoenix/gtk/font.cpp b/kaijuu/phoenix/gtk/font.cpp deleted file mode 100644 index cb6889d1..00000000 --- a/kaijuu/phoenix/gtk/font.cpp +++ /dev/null @@ -1,58 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - PangoFontDescription *font = create(description); - Geometry geometry = pFont::geometry(font, text); - free(font); - return geometry; -} - -PangoFontDescription* pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - PangoFontDescription *font = pango_font_description_new(); - pango_font_description_set_family(font, family); - pango_font_description_set_size(font, size * PANGO_SCALE); - pango_font_description_set_weight(font, !bold ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD); - pango_font_description_set_style(font, !italic ? PANGO_STYLE_NORMAL : PANGO_STYLE_OBLIQUE); - return font; -} - -void pFont::free(PangoFontDescription *font) { - pango_font_description_free(font); -} - -Geometry pFont::geometry(PangoFontDescription *font, const string &text) { - PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); - PangoLayout *layout = pango_layout_new(context); - pango_layout_set_font_description(layout, font); - pango_layout_set_text(layout, text, -1); - int width = 0, height = 0; - pango_layout_get_pixel_size(layout, &width, &height); - g_object_unref((gpointer)layout); - return { 0, 0, width, height }; -} - -void pFont::setFont(GtkWidget *widget, const string &font) { - auto gtkFont = pFont::create(font); - pFont::setFont(widget, (gpointer)gtkFont); - pFont::free(gtkFont); -} - -void pFont::setFont(GtkWidget *widget, gpointer font) { - if(font == 0) return; - gtk_widget_modify_font(widget, (PangoFontDescription*)font); - if(GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)pFont::setFont, font); - } -} diff --git a/kaijuu/phoenix/gtk/keyboard.cpp b/kaijuu/phoenix/gtk/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/kaijuu/phoenix/gtk/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/kaijuu/phoenix/gtk/message-window.cpp b/kaijuu/phoenix/gtk/message-window.cpp deleted file mode 100644 index 7cd2172a..00000000 --- a/kaijuu/phoenix/gtk/message-window.cpp +++ /dev/null @@ -1,61 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, gint response) { - if(response == GTK_RESPONSE_OK) return MessageWindow::Response::Ok; - if(response == GTK_RESPONSE_CANCEL) return MessageWindow::Response::Cancel; - if(response == GTK_RESPONSE_YES) return MessageWindow::Response::Yes; - if(response == GTK_RESPONSE_NO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} diff --git a/kaijuu/phoenix/gtk/mouse.cpp b/kaijuu/phoenix/gtk/mouse.cpp deleted file mode 100644 index e00f7ff7..00000000 --- a/kaijuu/phoenix/gtk/mouse.cpp +++ /dev/null @@ -1,20 +0,0 @@ -Position pMouse::position() { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - return { rootx, rooty }; -} - -bool pMouse::pressed(Mouse::Button button) { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - switch(button) { - case Mouse::Button::Left: return mask & Button1Mask; - case Mouse::Button::Middle: return mask & Button2Mask; - case Mouse::Button::Right: return mask & Button3Mask; - } - return false; -} diff --git a/kaijuu/phoenix/gtk/platform.cpp b/kaijuu/phoenix/gtk/platform.cpp deleted file mode 100644 index c6650dbb..00000000 --- a/kaijuu/phoenix/gtk/platform.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; -Font pOS::defaultFont; - -void pOS::main() { - gtk_main(); -} - -bool pOS::pendingEvents() { - return gtk_events_pending(); -} - -void pOS::processEvents() { - while(pendingEvents()) gtk_main_iteration_do(false); -} - -void pOS::quit() { - gtk_main_quit(); -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - int argc = 1; - char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - gtk_init(&argc, &argvp); - - gtk_rc_parse_string(R"( - style "phoenix-gtk" - { - GtkWindow::resize-grip-width = 0 - GtkWindow::resize-grip-height = 0 - GtkTreeView::vertical-separator = 0 - GtkComboBox::appears-as-list = 1 - } - class "GtkWindow" style "phoenix-gtk" - class "GtkTreeView" style "phoenix-gtk" - # class "GtkComboBox" style "phoenix-gtk" - )"); - - pKeyboard::initialize(); -} diff --git a/kaijuu/phoenix/gtk/platform.hpp b/kaijuu/phoenix/gtk/platform.hpp deleted file mode 100644 index 344e8239..00000000 --- a/kaijuu/phoenix/gtk/platform.hpp +++ /dev/null @@ -1,501 +0,0 @@ -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - unsigned windowBackgroundColor; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static PangoFontDescription* create(const string &description); - static void free(PangoFontDescription *font); - static Geometry geometry(PangoFontDescription *font, const string &text); - static void setFont(GtkWidget *widget, const string &font); - static void setFont(GtkWidget *widget, gpointer font); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - static Font defaultFont; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - GtkWidget *widget; - GtkWidget *menuContainer; - GtkWidget *formContainer; - GtkWidget *statusContainer; - GtkWidget *menu; - GtkWidget *status; - GtkAllocation lastAllocation; - bool onSizePending; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - unsigned menuHeight(); - unsigned statusHeight(); -}; - -struct pAction : public pObject { - Action &action; - GtkWidget *widget; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - virtual void orphan(); - string mnemonic(string text); - virtual void setFont(const string &font); -}; - -struct pMenu : public pAction { - Menu &menu; - GtkWidget *gtkMenu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); - void orphan(); - void setFont(const string &font); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - GtkWidget *gtkWidget; - - bool enabled(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - virtual void setFocused(); - virtual void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public pWidget { - Button &button; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - cairo_surface_t *surface; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - unsigned itemCounter; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - GtkWidget *container; - GtkWidget *subWidget; - GtkWidget *scrollBar; - GtkTextBuffer *textBuffer; - GtkTextMark *textCursor; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - unsigned cursorPosition(); - bool keyPress(unsigned scancode); - void scroll(unsigned position); - void setCursorPosition(unsigned position); - void setScroll(); - void updateScroll(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - GtkWidget *subWidget; - GtkListStore *store; - struct GtkColumn { - GtkTreeViewColumn *column; - GtkCellRenderer *checkbox, *icon, *text; - GtkWidget *label; - }; - vector column; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - void setFocused(); - void setFont(const string &font); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - GtkWidget *subWidget; - GtkTextBuffer *textBuffer; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/kaijuu/phoenix/gtk/settings.cpp b/kaijuu/phoenix/gtk/settings.cpp deleted file mode 100644 index aeb28bba..00000000 --- a/kaijuu/phoenix/gtk/settings.cpp +++ /dev/null @@ -1,25 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/gtk.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("gtk.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); - append(windowBackgroundColor = 0xedeceb, "windowBackgroundColor"); -} diff --git a/kaijuu/phoenix/gtk/timer.cpp b/kaijuu/phoenix/gtk/timer.cpp deleted file mode 100644 index d04183f8..00000000 --- a/kaijuu/phoenix/gtk/timer.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static guint Timer_trigger(pTimer *self) { - //timer may have been disabled prior to triggering, so check state - if(self->timer.state.enabled) { - if(self->timer.onTimeout) self->timer.onTimeout(); - } - //callback may have disabled timer, so check state again - if(self->timer.state.enabled) { - g_timeout_add(self->timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)self); - } - //kill this timer instance (it is spawned above if needed again) - return false; -} - -void pTimer::setEnabled(bool enabled) { - if(enabled) { - g_timeout_add(timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)this); - } -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/kaijuu/phoenix/gtk/utility.cpp b/kaijuu/phoenix/gtk/utility.cpp deleted file mode 100644 index 29e87bb8..00000000 --- a/kaijuu/phoenix/gtk/utility.cpp +++ /dev/null @@ -1,200 +0,0 @@ -static GdkPixbuf* CreatePixbuf(const nall::image &image, bool scale = false) { - nall::image gdkImage = image; - gdkImage.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); - if(scale) gdkImage.scale(15, 15, Interpolation::Linear); - - GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, gdkImage.width, gdkImage.height); - memcpy(gdk_pixbuf_get_pixels(pixbuf), gdkImage.data, gdkImage.width * gdkImage.height * 4); - - return pixbuf; -} - -static GtkImage* CreateImage(const nall::image &image, bool scale = false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, scale); - GtkImage *gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); - return gtkImage; -} - -static Keyboard::Keycode Keysym(unsigned keysym) { - switch(keysym) { - case GDK_Escape: return Keyboard::Keycode::Escape; - case GDK_F1: return Keyboard::Keycode::F1; - case GDK_F2: return Keyboard::Keycode::F2; - case GDK_F3: return Keyboard::Keycode::F3; - case GDK_F4: return Keyboard::Keycode::F4; - case GDK_F5: return Keyboard::Keycode::F5; - case GDK_F6: return Keyboard::Keycode::F6; - case GDK_F7: return Keyboard::Keycode::F7; - case GDK_F8: return Keyboard::Keycode::F8; - case GDK_F9: return Keyboard::Keycode::F9; - case GDK_F10: return Keyboard::Keycode::F10; - case GDK_F11: return Keyboard::Keycode::F11; - case GDK_F12: return Keyboard::Keycode::F12; - - case GDK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case GDK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case GDK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case GDK_Insert: return Keyboard::Keycode::Insert; - case GDK_Delete: return Keyboard::Keycode::Delete; - case GDK_Home: return Keyboard::Keycode::Home; - case GDK_End: return Keyboard::Keycode::End; - case GDK_Prior: return Keyboard::Keycode::PageUp; - case GDK_Next: return Keyboard::Keycode::PageDown; - - case GDK_Up: return Keyboard::Keycode::Up; - case GDK_Down: return Keyboard::Keycode::Down; - case GDK_Left: return Keyboard::Keycode::Left; - case GDK_Right: return Keyboard::Keycode::Right; - - case GDK_grave: return Keyboard::Keycode::Grave; - case GDK_1: return Keyboard::Keycode::Number1; - case GDK_2: return Keyboard::Keycode::Number2; - case GDK_3: return Keyboard::Keycode::Number3; - case GDK_4: return Keyboard::Keycode::Number4; - case GDK_5: return Keyboard::Keycode::Number5; - case GDK_6: return Keyboard::Keycode::Number6; - case GDK_7: return Keyboard::Keycode::Number7; - case GDK_8: return Keyboard::Keycode::Number8; - case GDK_9: return Keyboard::Keycode::Number9; - case GDK_0: return Keyboard::Keycode::Number0; - case GDK_minus: return Keyboard::Keycode::Minus; - case GDK_equal: return Keyboard::Keycode::Equal; - case GDK_BackSpace: return Keyboard::Keycode::Backspace; - - case GDK_asciitilde: return Keyboard::Keycode::Tilde; - case GDK_exclam: return Keyboard::Keycode::Exclamation; - case GDK_at: return Keyboard::Keycode::At; - case GDK_numbersign: return Keyboard::Keycode::Pound; - case GDK_dollar: return Keyboard::Keycode::Dollar; - case GDK_percent: return Keyboard::Keycode::Percent; - case GDK_asciicircum: return Keyboard::Keycode::Power; - case GDK_ampersand: return Keyboard::Keycode::Ampersand; - case GDK_asterisk: return Keyboard::Keycode::Asterisk; - case GDK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case GDK_parenright: return Keyboard::Keycode::ParenthesisRight; - case GDK_underscore: return Keyboard::Keycode::Underscore; - case GDK_plus: return Keyboard::Keycode::Plus; - - case GDK_bracketleft: return Keyboard::Keycode::BracketLeft; - case GDK_bracketright: return Keyboard::Keycode::BracketRight; - case GDK_backslash: return Keyboard::Keycode::Backslash; - case GDK_semicolon: return Keyboard::Keycode::Semicolon; - case GDK_apostrophe: return Keyboard::Keycode::Apostrophe; - case GDK_comma: return Keyboard::Keycode::Comma; - case GDK_period: return Keyboard::Keycode::Period; - case GDK_slash: return Keyboard::Keycode::Slash; - - case GDK_braceleft: return Keyboard::Keycode::BraceLeft; - case GDK_braceright: return Keyboard::Keycode::BraceRight; - case GDK_bar: return Keyboard::Keycode::Pipe; - case GDK_colon: return Keyboard::Keycode::Colon; - case GDK_quotedbl: return Keyboard::Keycode::Quote; - case GDK_less: return Keyboard::Keycode::CaretLeft; - case GDK_greater: return Keyboard::Keycode::CaretRight; - case GDK_question: return Keyboard::Keycode::Question; - - case GDK_Tab: return Keyboard::Keycode::Tab; - case GDK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case GDK_Return: return Keyboard::Keycode::Return; - case GDK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case GDK_Shift_R: return Keyboard::Keycode::ShiftRight; - case GDK_Control_L: return Keyboard::Keycode::ControlLeft; - case GDK_Control_R: return Keyboard::Keycode::ControlRight; - case GDK_Super_L: return Keyboard::Keycode::SuperLeft; - case GDK_Super_R: return Keyboard::Keycode::SuperRight; - case GDK_Alt_L: return Keyboard::Keycode::AltLeft; - case GDK_Alt_R: return Keyboard::Keycode::AltRight; - case GDK_space: return Keyboard::Keycode::Space; - case GDK_Menu: return Keyboard::Keycode::Menu; - - case GDK_A: return Keyboard::Keycode::A; - case GDK_B: return Keyboard::Keycode::B; - case GDK_C: return Keyboard::Keycode::C; - case GDK_D: return Keyboard::Keycode::D; - case GDK_E: return Keyboard::Keycode::E; - case GDK_F: return Keyboard::Keycode::F; - case GDK_G: return Keyboard::Keycode::G; - case GDK_H: return Keyboard::Keycode::H; - case GDK_I: return Keyboard::Keycode::I; - case GDK_J: return Keyboard::Keycode::J; - case GDK_K: return Keyboard::Keycode::K; - case GDK_L: return Keyboard::Keycode::L; - case GDK_M: return Keyboard::Keycode::M; - case GDK_N: return Keyboard::Keycode::N; - case GDK_O: return Keyboard::Keycode::O; - case GDK_P: return Keyboard::Keycode::P; - case GDK_Q: return Keyboard::Keycode::Q; - case GDK_R: return Keyboard::Keycode::R; - case GDK_S: return Keyboard::Keycode::S; - case GDK_T: return Keyboard::Keycode::T; - case GDK_U: return Keyboard::Keycode::U; - case GDK_V: return Keyboard::Keycode::V; - case GDK_W: return Keyboard::Keycode::W; - case GDK_X: return Keyboard::Keycode::X; - case GDK_Y: return Keyboard::Keycode::Y; - case GDK_Z: return Keyboard::Keycode::Z; - - case GDK_a: return Keyboard::Keycode::a; - case GDK_b: return Keyboard::Keycode::b; - case GDK_c: return Keyboard::Keycode::c; - case GDK_d: return Keyboard::Keycode::d; - case GDK_e: return Keyboard::Keycode::e; - case GDK_f: return Keyboard::Keycode::f; - case GDK_g: return Keyboard::Keycode::g; - case GDK_h: return Keyboard::Keycode::h; - case GDK_i: return Keyboard::Keycode::i; - case GDK_j: return Keyboard::Keycode::j; - case GDK_k: return Keyboard::Keycode::k; - case GDK_l: return Keyboard::Keycode::l; - case GDK_m: return Keyboard::Keycode::m; - case GDK_n: return Keyboard::Keycode::n; - case GDK_o: return Keyboard::Keycode::o; - case GDK_p: return Keyboard::Keycode::p; - case GDK_q: return Keyboard::Keycode::q; - case GDK_r: return Keyboard::Keycode::r; - case GDK_s: return Keyboard::Keycode::s; - case GDK_t: return Keyboard::Keycode::t; - case GDK_u: return Keyboard::Keycode::u; - case GDK_v: return Keyboard::Keycode::v; - case GDK_w: return Keyboard::Keycode::w; - case GDK_x: return Keyboard::Keycode::x; - case GDK_y: return Keyboard::Keycode::y; - case GDK_z: return Keyboard::Keycode::z; - - case GDK_Num_Lock: return Keyboard::Keycode::NumLock; - case GDK_KP_Divide: return Keyboard::Keycode::Divide; - case GDK_KP_Multiply: return Keyboard::Keycode::Multiply; - case GDK_KP_Subtract: return Keyboard::Keycode::Subtract; - case GDK_KP_Add: return Keyboard::Keycode::Add; - case GDK_KP_Enter: return Keyboard::Keycode::Enter; - case GDK_KP_Decimal: return Keyboard::Keycode::Point; - - case GDK_KP_1: return Keyboard::Keycode::Keypad1; - case GDK_KP_2: return Keyboard::Keycode::Keypad2; - case GDK_KP_3: return Keyboard::Keycode::Keypad3; - case GDK_KP_4: return Keyboard::Keycode::Keypad4; - case GDK_KP_5: return Keyboard::Keycode::Keypad5; - case GDK_KP_6: return Keyboard::Keycode::Keypad6; - case GDK_KP_7: return Keyboard::Keycode::Keypad7; - case GDK_KP_8: return Keyboard::Keycode::Keypad8; - case GDK_KP_9: return Keyboard::Keycode::Keypad9; - case GDK_KP_0: return Keyboard::Keycode::Keypad0; - - case GDK_KP_Home: return Keyboard::Keycode::KeypadHome; - case GDK_KP_End: return Keyboard::Keycode::KeypadEnd; - case GDK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case GDK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case GDK_KP_Up: return Keyboard::Keycode::KeypadUp; - case GDK_KP_Down: return Keyboard::Keycode::KeypadDown; - case GDK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case GDK_KP_Right: return Keyboard::Keycode::KeypadRight; - case GDK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case GDK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case GDK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/kaijuu/phoenix/gtk/widget/button.cpp b/kaijuu/phoenix/gtk/widget/button.cpp deleted file mode 100644 index 6f646a25..00000000 --- a/kaijuu/phoenix/gtk/widget/button.cpp +++ /dev/null @@ -1,53 +0,0 @@ -static void Button_activate(Button *self) { - if(self->onActivate) self->onActivate(); -} - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 24, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image); - gtk_button_set_image(GTK_BUTTON(gtkWidget), (GtkWidget*)gtkImage); - } else { - gtk_button_set_image(GTK_BUTTON(gtkWidget), nullptr); - } - switch(orientation) { - case Orientation::Horizontal: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_LEFT); break; - case Orientation::Vertical: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_TOP); break; - } -} - -void pButton::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); - setFont(widget.state.font); -} - -void pButton::constructor() { - gtkWidget = gtk_button_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_activate), (gpointer)&button); - - setText(button.state.text); -} - -void pButton::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/canvas.cpp b/kaijuu/phoenix/gtk/widget/canvas.cpp deleted file mode 100644 index 9d17dc82..00000000 --- a/kaijuu/phoenix/gtk/widget/canvas.cpp +++ /dev/null @@ -1,70 +0,0 @@ -static gboolean Canvas_expose(GtkWidget *widget, GdkEvent *event, pCanvas *self) { - cairo_t *context = gdk_cairo_create(gtk_widget_get_window(widget)); - cairo_set_source_surface(context, self->surface, 0, 0); - cairo_paint(context); - cairo_destroy(context); - return true; -} - -static gboolean Canvas_mouseLeave(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseLeave) self->canvas.onMouseLeave(); - return true; -} - -static gboolean Canvas_mouseMove(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseMove) self->canvas.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Canvas_mousePress(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMousePress) switch(event->button) { - case 1: self->canvas.onMousePress(Mouse::Button::Left); break; - case 2: self->canvas.onMousePress(Mouse::Button::Middle); break; - case 3: self->canvas.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Canvas_mouseRelease(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseRelease) switch(event->button) { - case 1: self->canvas.onMouseRelease(Mouse::Button::Left); break; - case 2: self->canvas.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->canvas.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -void pCanvas::setSize(const Size &size) { - cairo_surface_destroy(surface); - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); -} - -void pCanvas::update() { - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - if(gtk_widget_get_realized(gtkWidget) == false) return; - gdk_window_invalidate_rect(gtk_widget_get_window(gtkWidget), 0, true); -} - -void pCanvas::constructor() { - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - gtkWidget = gtk_drawing_area_new(); - gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Canvas_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Canvas_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Canvas_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Canvas_mouseMove), (gpointer)this); -} - -void pCanvas::destructor() { - gtk_widget_destroy(gtkWidget); - cairo_surface_destroy(surface); -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/check-box.cpp b/kaijuu/phoenix/gtk/widget/check-box.cpp deleted file mode 100644 index b6493f32..00000000 --- a/kaijuu/phoenix/gtk/widget/check-box.cpp +++ /dev/null @@ -1,40 +0,0 @@ -static void CheckBox_toggle(CheckBox *self) { - self->state.checked = self->checked(); - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, checkBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pCheckBox::constructor() { - gtkWidget = gtk_check_button_new_with_label(""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_toggle), (gpointer)&checkBox); - - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/combo-box.cpp b/kaijuu/phoenix/gtk/widget/combo-box.cpp deleted file mode 100644 index 648d587f..00000000 --- a/kaijuu/phoenix/gtk/widget/combo-box.cpp +++ /dev/null @@ -1,73 +0,0 @@ -static void ComboBox_change(ComboBox *self) { - if(self->p.locked == false) { - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -void pComboBox::append(const string &text) { - gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text); - if(itemCounter++ == 0) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &item : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(widget.state.font, item).width); - - Geometry geometry = pFont::geometry(widget.state.font, " "); - return { 0, 0, maximumWidth + 44, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkWidget), row, text); - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - if(position == row) gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), 0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(gtkWidget)))); - itemCounter = 0; - locked = false; -} - -unsigned pComboBox::selection() { - return gtk_combo_box_get_active(GTK_COMBO_BOX(gtkWidget)); -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), row); - locked = false; -} - -void pComboBox::constructor() { - itemCounter = 0; - gtkWidget = gtk_combo_box_new_text(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox); - - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(comboBox.state.selection); -} - -void pComboBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/hex-edit.cpp b/kaijuu/phoenix/gtk/widget/hex-edit.cpp deleted file mode 100644 index 9c0dbdef..00000000 --- a/kaijuu/phoenix/gtk/widget/hex-edit.cpp +++ /dev/null @@ -1,264 +0,0 @@ -static bool HexEdit_keyPress(GtkWidget *widget, GdkEventKey *event, HexEdit *self) { - return self->p.keyPress(event->keyval); -} - -static bool HexEdit_scroll(GtkRange *range, GtkScrollType scroll, gdouble value, HexEdit *self) { - self->p.scroll((unsigned)value); - return false; -} - -void pHexEdit::setColumns(unsigned columns) { - setScroll(); - update(); -} - -void pHexEdit::setLength(unsigned length) { - setScroll(); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - setScroll(); - updateScroll(); - update(); -} - -void pHexEdit::setRows(unsigned rows) { - setScroll(); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - gtk_text_buffer_set_text(textBuffer, "", -1); - return; - } - - unsigned position = cursorPosition(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - gtk_text_buffer_set_text(textBuffer, output, -1); - if(position == 0) position = 10; //start at first position where hex values can be entered - setCursorPosition(position); -} - -void pHexEdit::constructor() { - gtkWidget = gtk_hbox_new(false, 0); - - container = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(container), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(container), GTK_SHADOW_ETCHED_IN); - - subWidget = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), false); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_NONE); - gtk_container_add(GTK_CONTAINER(container), subWidget); - g_signal_connect(G_OBJECT(subWidget), "key-press-event", G_CALLBACK(HexEdit_keyPress), (gpointer)&hexEdit); - - scrollBar = gtk_vscrollbar_new((GtkAdjustment*)0); - gtk_range_set_range(GTK_RANGE(scrollBar), 0, 255); - gtk_range_set_increments(GTK_RANGE(scrollBar), 1, 16); - gtk_widget_set_sensitive(scrollBar, false); - g_signal_connect(G_OBJECT(scrollBar), "change-value", G_CALLBACK(HexEdit_scroll), (gpointer)&hexEdit); - - gtk_box_pack_start(GTK_BOX(gtkWidget), container, true, true, 0); - gtk_box_pack_start(GTK_BOX(gtkWidget), scrollBar, false, false, 1); - - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - textCursor = gtk_text_buffer_get_mark(textBuffer, "insert"); - - gtk_widget_show(scrollBar); - gtk_widget_show(subWidget); - gtk_widget_show(container); - - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - gtk_widget_destroy(scrollBar); - gtk_widget_destroy(subWidget); - gtk_widget_destroy(container); - gtk_widget_destroy(gtkWidget); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -unsigned pHexEdit::cursorPosition() { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - return gtk_text_iter_get_offset(&iter); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = cursorPosition(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - if(scancode == GDK_Home) { - setCursorPosition(cursorY * lineWidth + 10); - return true; - } - - if(scancode == GDK_End) { - setCursorPosition(cursorY * lineWidth + 10 + (hexEdit.state.columns * 3 - 1)); - return true; - } - - if(scancode == GDK_Up) { - if(cursorY != 0) return false; - - signed newOffset = hexEdit.state.offset - hexEdit.state.columns; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Down) { - if(cursorY != hexEdit.state.rows - 1) return false; - - signed newOffset = hexEdit.state.offset + hexEdit.state.columns; - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Page_Up) { - signed newOffset = hexEdit.state.offset - hexEdit.state.columns * hexEdit.state.rows; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - } else { - hexEdit.setOffset(0); - } - update(); - return true; - } - - if(scancode == GDK_Page_Down) { - signed newOffset = hexEdit.state.offset + hexEdit.state.columns * hexEdit.state.rows; - for(unsigned n = 0; n < hexEdit.state.rows; n++) { - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - break; - } - newOffset -= hexEdit.state.columns; - } - return true; - } - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; //not a valid hex value - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - setCursorPosition(position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} - -void pHexEdit::scroll(unsigned position) { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(position >= rows) position = rows - 1; - hexEdit.setOffset(position * hexEdit.state.columns); -} - -void pHexEdit::setCursorPosition(unsigned position) { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - - //GTK+ will throw many errors to the terminal if you set iterator past end of buffer - GtkTextIter endIter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - unsigned endPosition = gtk_text_iter_get_offset(&iter); - - gtk_text_iter_set_offset(&iter, min(position, endPosition)); - gtk_text_buffer_place_cursor(textBuffer, &iter); -} - -void pHexEdit::setScroll() { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(rows) rows--; - if(rows) { - gtk_range_set_range(GTK_RANGE(scrollBar), 0, rows); - gtk_widget_set_sensitive(scrollBar, true); - } else { - gtk_widget_set_sensitive(scrollBar, false); - } -} - -void pHexEdit::updateScroll() { - unsigned row = hexEdit.state.offset / hexEdit.state.columns; - gtk_range_set_value(GTK_RANGE(scrollBar), row); -} diff --git a/kaijuu/phoenix/gtk/widget/horizontal-scroll-bar.cpp b/kaijuu/phoenix/gtk/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 0d765e92..00000000 --- a/kaijuu/phoenix/gtk/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void HorizontalScrollBar_change(HorizontalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalScrollBar::constructor() { - gtkWidget = gtk_hscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar); - - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/horizontal-slider.cpp b/kaijuu/phoenix/gtk/widget/horizontal-slider.cpp deleted file mode 100644 index 2d19bae6..00000000 --- a/kaijuu/phoenix/gtk/widget/horizontal-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void HorizontalSlider_change(HorizontalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalSlider::constructor() { - gtkWidget = gtk_hscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider); - - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/label.cpp b/kaijuu/phoenix/gtk/widget/label.cpp deleted file mode 100644 index 8b5cec4f..00000000 --- a/kaijuu/phoenix/gtk/widget/label.cpp +++ /dev/null @@ -1,24 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - gtk_label_set_text(GTK_LABEL(gtkWidget), text); -} - -void pLabel::constructor() { - gtkWidget = gtk_label_new(""); - gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5); - - setText(label.state.text); -} - -void pLabel::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/line-edit.cpp b/kaijuu/phoenix/gtk/widget/line-edit.cpp deleted file mode 100644 index 8dbe9ef4..00000000 --- a/kaijuu/phoenix/gtk/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -static void LineEdit_activate(LineEdit *self) { - if(self->onActivate) self->onActivate(); -} - -static void LineEdit_change(LineEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, lineEdit.state.text); - return { 0, 0, geometry.width + 10, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - gtk_editable_set_editable(GTK_EDITABLE(gtkWidget), editable); -} - -void pLineEdit::setText(const string &text) { - locked = true; - gtk_entry_set_text(GTK_ENTRY(gtkWidget), text); - locked = false; -} - -string pLineEdit::text() { - return gtk_entry_get_text(GTK_ENTRY(gtkWidget)); -} - -void pLineEdit::constructor() { - gtkWidget = gtk_entry_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit); - - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/list-view.cpp b/kaijuu/phoenix/gtk/widget/list-view.cpp deleted file mode 100644 index 5572c1f7..00000000 --- a/kaijuu/phoenix/gtk/widget/list-view.cpp +++ /dev/null @@ -1,217 +0,0 @@ -static void ListView_activate(ListView *self) { - if(self->onActivate) self->onActivate(); -} - -static void ListView_change(ListView *self) { - if(self->state.selected == false || self->state.selection != self->selection()) { - self->state.selected = true; - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -static void ListView_toggle(GtkCellRendererToggle *cell, gchar *path, ListView *self) { - unsigned row = decimal(path); - self->setChecked(row, !self->checked(row)); - if(self->onToggle) self->onToggle(row); -} - -void pListView::append(const lstring &text) { - GtkTreeIter iter; - gtk_list_store_append(store, &iter); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::autoSizeColumns() { - gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget)); -} - -bool pListView::checked(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - bool state; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return false; - gtk_tree_model_get(model, &iter, 0, &state, -1); - return state; -} - -void pListView::modify(unsigned row, const lstring &text) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::remove(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_remove(store, &iter); -} - -void pListView::reset() { - listView.state.selected = false; - listView.state.selection = 0; - gtk_list_store_clear(GTK_LIST_STORE(store)); - gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store)); - //reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty - gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); - gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); -} - -bool pListView::selected() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - return gtk_tree_selection_get_selected(selection, 0, 0); -} - -unsigned pListView::selection() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - if(gtk_tree_selection_get_selected(selection, 0, &iter) == false) return listView.state.selection; - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - unsigned row = decimal(path); - g_free(path); - return row; -} - -void pListView::setCheckable(bool checkable) { - gtk_cell_renderer_set_visible(column(0).checkbox, checkable); -} - -void pListView::setChecked(unsigned row, bool checked) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, checked, -1); -} - -void pListView::setHeaderText(const lstring &text) { - destructor(); - constructor(); -} - -void pListView::setHeaderVisible(bool visible) { - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - if(image.empty() == false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, true); - gtk_list_store_set(store, &iter, 1 + column * 2, pixbuf, -1); - } else { - gtk_list_store_set(store, &iter, 1 + column * 2, nullptr, -1); - } -} - -void pListView::setSelected(bool selected) { - if(selected == false) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - } else { - setSelection(listView.state.selection); - } -} - -void pListView::setSelection(unsigned row) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - GtkTreeIter iter; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return; - gtk_tree_selection_select_iter(selection, &iter); - - //scroll window to selected item - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - GtkTreePath *treePath = gtk_tree_path_new_from_string(path); - gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(subWidget), treePath, nullptr, true, 0.5, 0.0); - gtk_tree_path_free(treePath); - g_free(path); -} - -void pListView::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - - lstring headerText = listView.state.headerText; - if(headerText.size() == 0) headerText.append(""); //ListView must have at least one column - - column.reset(); - vector gtype; - for(auto &text : headerText) { - GtkColumn cell; - cell.label = gtk_label_new(text); - cell.column = gtk_tree_view_column_new(); - gtk_tree_view_column_set_resizable(cell.column, true); - gtk_tree_view_column_set_title(cell.column, ""); - - if(column.size() == 0) { //first column checkbox - cell.checkbox = gtk_cell_renderer_toggle_new(); - gtk_tree_view_column_pack_start(cell.column, cell.checkbox, false); - gtk_tree_view_column_set_attributes(cell.column, cell.checkbox, "active", gtype.size(), nullptr); - gtype.append(G_TYPE_BOOLEAN); - g_signal_connect(cell.checkbox, "toggled", G_CALLBACK(ListView_toggle), (gpointer)&listView); - } - - cell.icon = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(cell.column, cell.icon, false); - gtk_tree_view_column_set_attributes(cell.column, cell.icon, "pixbuf", gtype.size(), nullptr); - gtype.append(GDK_TYPE_PIXBUF); - - cell.text = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(cell.column, cell.text, false); - gtk_tree_view_column_set_attributes(cell.column, cell.text, "text", gtype.size(), nullptr); - gtype.append(G_TYPE_STRING); - - column.append(cell); - } - - store = gtk_list_store_newv(gtype.size(), gtype.data()); - subWidget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - g_object_unref(G_OBJECT(store)); - - for(auto &cell : column) { - gtk_tree_view_column_set_widget(GTK_TREE_VIEW_COLUMN(cell.column), cell.label); - gtk_tree_view_append_column(GTK_TREE_VIEW(subWidget), cell.column); - gtk_widget_show(cell.label); - } - - gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(subWidget), headerText.size() >= 2); //two or more columns + checkbox column - gtk_tree_view_set_search_column(GTK_TREE_VIEW(subWidget), 2); - - g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView); - g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView); - - gtk_widget_show(subWidget); - - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setFocused() { - gtk_widget_grab_focus(subWidget); -} - -void pListView::setFont(const string &font) { - pFont::setFont(gtkWidget, font); - for(auto &cell : column) pFont::setFont(cell.label, font); -} diff --git a/kaijuu/phoenix/gtk/widget/progress-bar.cpp b/kaijuu/phoenix/gtk/widget/progress-bar.cpp deleted file mode 100644 index 972170b8..00000000 --- a/kaijuu/phoenix/gtk/widget/progress-bar.cpp +++ /dev/null @@ -1,23 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - position = position <= 100 ? position : 0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (double)position / 100.0); -} - -void pProgressBar::constructor() { - gtkWidget = gtk_progress_bar_new(); - - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/radio-box.cpp b/kaijuu/phoenix/gtk/widget/radio-box.cpp deleted file mode 100644 index 36aff3fa..00000000 --- a/kaijuu/phoenix/gtk/widget/radio-box.cpp +++ /dev/null @@ -1,50 +0,0 @@ -static void RadioBox_activate(RadioBox *self) { - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, radioBox.state.text); -//Font &font = pWidget::font(); -//Geometry geometry = font.geometry(radioBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), true); - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(group[0].p.gtkWidget)); - if(currentGroup != gtk_radio_button_get_group(GTK_RADIO_BUTTON(gtkWidget))) { - gtk_radio_button_set_group(GTK_RADIO_BUTTON(gtkWidget), currentGroup); - } - } -} - -void pRadioBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pRadioBox::constructor() { - gtkWidget = gtk_radio_button_new_with_label(0, ""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_activate), (gpointer)&radioBox); - - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/text-edit.cpp b/kaijuu/phoenix/gtk/widget/text-edit.cpp deleted file mode 100644 index 08812fb3..00000000 --- a/kaijuu/phoenix/gtk/widget/text-edit.cpp +++ /dev/null @@ -1,66 +0,0 @@ -static void TextEdit_change(TextEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -void pTextEdit::setCursorPosition(unsigned position) { - GtkTextMark *mark = gtk_text_buffer_get_mark(textBuffer, "insert"); - GtkTextIter iter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter))); - gtk_text_buffer_place_cursor(textBuffer, &iter); - gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(subWidget), mark); -} - -void pTextEdit::setEditable(bool editable) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable); -} - -void pTextEdit::setText(const string &text) { - locked = true; - gtk_text_buffer_set_text(textBuffer, text, -1); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), - wordWrap ? GTK_POLICY_NEVER : GTK_POLICY_ALWAYS, - GTK_POLICY_ALWAYS); -} - -string pTextEdit::text() { - GtkTextIter start, end; - gtk_text_buffer_get_start_iter(textBuffer, &start); - gtk_text_buffer_get_end_iter(textBuffer, &end); - char *temp = gtk_text_buffer_get_text(textBuffer, &start, &end, true); - string text = temp; - g_free(temp); - return text; -} - -void pTextEdit::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - subWidget = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_WORD_CHAR); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit); - gtk_widget_show(subWidget); - - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/vertical-scroll-bar.cpp b/kaijuu/phoenix/gtk/widget/vertical-scroll-bar.cpp deleted file mode 100644 index e3bde589..00000000 --- a/kaijuu/phoenix/gtk/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void VerticalScrollBar_change(VerticalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pVerticalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalScrollBar::constructor() { - gtkWidget = gtk_vscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalScrollBar_change), (gpointer)&verticalScrollBar); - - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/vertical-slider.cpp b/kaijuu/phoenix/gtk/widget/vertical-slider.cpp deleted file mode 100644 index 3c68489e..00000000 --- a/kaijuu/phoenix/gtk/widget/vertical-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void VerticalSlider_change(VerticalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalSlider::constructor() { - gtkWidget = gtk_vscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider); - - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/viewport.cpp b/kaijuu/phoenix/gtk/widget/viewport.cpp deleted file mode 100644 index e842a2e5..00000000 --- a/kaijuu/phoenix/gtk/widget/viewport.cpp +++ /dev/null @@ -1,58 +0,0 @@ -static gboolean Viewport_mouseLeave(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseLeave) self->viewport.onMouseLeave(); - return true; -} - -static gboolean Viewport_mouseMove(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseMove) self->viewport.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Viewport_mousePress(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMousePress) switch(event->button) { - case 1: self->viewport.onMousePress(Mouse::Button::Left); break; - case 2: self->viewport.onMousePress(Mouse::Button::Middle); break; - case 3: self->viewport.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Viewport_mouseRelease(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseRelease) switch(event->button) { - case 1: self->viewport.onMouseRelease(Mouse::Button::Left); break; - case 2: self->viewport.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->viewport.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -uintptr_t pViewport::handle() { - return GDK_WINDOW_XID(gtk_widget_get_window(gtkWidget)); -} - -void pViewport::constructor() { - gtkWidget = gtk_drawing_area_new(); -//gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Viewport_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Viewport_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Viewport_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Viewport_mouseMove), (gpointer)this); - - GdkColor color; - color.pixel = 0; - color.red = 0; - color.green = 0; - color.blue = 0; - gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color); -} - -void pViewport::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/widget/widget.cpp b/kaijuu/phoenix/gtk/widget/widget.cpp deleted file mode 100644 index dceb8266..00000000 --- a/kaijuu/phoenix/gtk/widget/widget.cpp +++ /dev/null @@ -1,47 +0,0 @@ -Geometry pWidget::minimumGeometry() { - return { 0, 0, 0, 0 }; -} - -bool pWidget::enabled() { - return gtk_widget_get_sensitive(gtkWidget); -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - gtk_widget_set_sensitive(gtkWidget, enabled); -} - -void pWidget::setFocused() { - gtk_widget_grab_focus(gtkWidget); -} - -void pWidget::setFont(const string &font) { - pFont::setFont(gtkWidget, font); -} - -void pWidget::setGeometry(const Geometry &geometry) { - if(sizable.window() && sizable.window()->visible()) gtk_fixed_move(GTK_FIXED(sizable.window()->p.formContainer), gtkWidget, geometry.x, geometry.y); - unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width; - unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height; - gtk_widget_set_size_request(gtkWidget, width, height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - gtk_widget_set_visible(gtkWidget, visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) gtkWidget = gtk_label_new(""); -} - -void pWidget::destructor() { - if(widget.state.abstract) gtk_widget_destroy(gtkWidget); -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/gtk/window.cpp b/kaijuu/phoenix/gtk/window.cpp deleted file mode 100644 index ae1521a3..00000000 --- a/kaijuu/phoenix/gtk/window.cpp +++ /dev/null @@ -1,352 +0,0 @@ -static gint Window_close(GtkWidget *widget, GdkEvent *event, Window *window) { - window->state.ignore = false; - if(window->onClose) window->onClose(); - if(window->state.ignore == false) window->setVisible(false); - return true; -} - -static gboolean Window_expose(GtkWidget *widget, GdkEvent *event, Window *window) { - if(window->state.backgroundColorOverride == false) return false; - cairo_t *context = gdk_cairo_create(widget->window); - - Color color = window->backgroundColor(); - double red = (double)color.red / 255.0; - double green = (double)color.green / 255.0; - double blue = (double)color.blue / 255.0; - double alpha = (double)color.alpha / 255.0; - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - cairo_set_source_rgba(context, red, green, blue, alpha); - } else { - cairo_set_source_rgb(context, red, green, blue); - } - - cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); - cairo_paint(context); - cairo_destroy(context); - - return false; -} - -static gboolean Window_configure(GtkWidget *widget, GdkEvent *event, Window *window) { - if(gtk_widget_get_realized(window->p.widget) == false) return false; - GdkWindow *gdkWindow = gtk_widget_get_window(widget); - - GdkRectangle border, client; - gdk_window_get_frame_extents(gdkWindow, &border); - gdk_window_get_geometry(gdkWindow, 0, 0, &client.width, &client.height, 0); - gdk_window_get_origin(gdkWindow, &client.x, &client.y); - - if(window->state.fullScreen == false) { - //update geometry settings - settings->frameGeometryX = client.x - border.x; - settings->frameGeometryY = client.y - border.y; - settings->frameGeometryWidth = border.width - client.width; - settings->frameGeometryHeight = border.height - client.height; - if(window->state.backgroundColorOverride == false) { - GdkColor color = widget->style->bg[GTK_STATE_NORMAL]; - settings->windowBackgroundColor - = ((uint8_t)(color.red >> 8) << 16) - + ((uint8_t)(color.green >> 8) << 8) - + ((uint8_t)(color.blue >> 8) << 0); - } - settings->save(); - } - - Geometry geometry = { - client.x, - client.y + window->p.menuHeight(), - client.width, - client.height - window->p.menuHeight() - window->p.statusHeight() - }; - - //move - if(geometry.x != window->state.geometry.x || geometry.y != window->state.geometry.y) { - if(window->state.fullScreen == false) { - window->state.geometry.x = geometry.x; - window->state.geometry.y = geometry.y; - } - if(window->p.locked == false && window->onMove) window->onMove(); - } - - //size - if(geometry.width != window->state.geometry.width || geometry.height != window->state.geometry.height) { - window->p.onSizePending = true; - } - - return false; -} - -static gboolean Window_keyPressEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyPress) window->onKeyPress(key); - return false; -} - -static gboolean Window_keyReleaseEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyRelease) window->onKeyRelease(key); - return false; -} - -static void Window_sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, Window *window) { - //size-allocate sent from gtk_fixed_move(); detect if layout unchanged and return - if(allocation->width == window->p.lastAllocation.width - && allocation->height == window->p.lastAllocation.height) return; - - window->state.geometry.width = allocation->width; - window->state.geometry.height = allocation->height; - - for(auto &layout : window->state.layout) { - Geometry geometry = window->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(window->p.onSizePending && window->p.locked == false && window->onSize) { - window->p.onSizePending = false; - window->onSize(); - } - - window->p.lastAllocation = *allocation; -} - -static void Window_sizeRequest(GtkWidget *widget, GtkRequisition *requisition, Window *window) { - requisition->width = window->state.geometry.width; - requisition->height = window->state.geometry.height; -} - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = this->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), menu.p.widget); - gtk_widget_show(menu.p.widget); -} - -void pWindow::append(Widget &widget) { - ((Sizable&)widget).state.window = &window; - gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - return { - (uint8_t)(settings->windowBackgroundColor >> 16), - (uint8_t)(settings->windowBackgroundColor >> 8), - (uint8_t)(settings->windowBackgroundColor >> 0), - 255 - }; -} - -Geometry pWindow::frameMargin() { - if(window.state.fullScreen) return { - 0, - menuHeight(), - 0, - menuHeight() + statusHeight() - }; - - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight(), - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight() + statusHeight() - }; -} - -bool pWindow::focused() { - return gtk_window_is_active(GTK_WINDOW(widget)); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen == true) return { - 0, - menuHeight(), - Desktop::size().width, - Desktop::size().height - menuHeight() - statusHeight() - }; - - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - menu.p.orphan(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - GdkColor gdkColor; - gdkColor.pixel = (color.red << 16) | (color.green << 8) | (color.blue << 0); - gdkColor.red = (color.red << 8) | (color.red << 0); - gdkColor.green = (color.green << 8) | (color.green << 0); - gdkColor.blue = (color.blue << 8) | (color.blue << 0); - gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &gdkColor); -} - -void pWindow::setFocused() { - gtk_window_present(GTK_WINDOW(widget)); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - gtk_window_unfullscreen(GTK_WINDOW(widget)); - } else { - gtk_window_fullscreen(GTK_WINDOW(widget)); - } -} - -void pWindow::setGeometry(const Geometry &geometry) { - Geometry margin = frameMargin(); - gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y); - - GdkGeometry geom; - geom.min_width = window.state.resizable ? 1 : window.state.geometry.width; - geom.min_height = window.state.resizable ? 1 : window.state.geometry.height; - gtk_window_set_geometry_hints(GTK_WINDOW(widget), GTK_WIDGET(widget), &geom, GDK_HINT_MIN_SIZE); - -//gtk_window_set_policy(GTK_WINDOW(widget), true, true, false); - gtk_widget_set_size_request(formContainer, geometry.width, geometry.height); - gtk_window_resize(GTK_WINDOW(widget), geometry.width, geometry.height + menuHeight() + statusHeight()); -} - -void pWindow::setMenuFont(const string &font) { - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - gtk_widget_set_visible(menu, visible); -} - -void pWindow::setModal(bool modal) { - gtk_window_set_modal(GTK_WINDOW(widget), modal); -} - -void pWindow::setResizable(bool resizable) { - gtk_window_set_resizable(GTK_WINDOW(widget), resizable); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable); -} - -void pWindow::setStatusFont(const string &font) { - pFont::setFont(status, font); -} - -void pWindow::setStatusText(const string &text) { - gtk_statusbar_pop(GTK_STATUSBAR(status), 1); - gtk_statusbar_push(GTK_STATUSBAR(status), 1, text); -} - -void pWindow::setStatusVisible(bool visible) { - gtk_widget_set_visible(status, visible); -} - -void pWindow::setTitle(const string &text) { - gtk_window_set_title(GTK_WINDOW(widget), text); -} - -void pWindow::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); - if(visible) { - if(gtk_widget_get_visible(menu)) { - GtkAllocation allocation; - gtk_widget_get_allocation(menu, &allocation); - settings->menuGeometryHeight = allocation.height; - } - - if(gtk_widget_get_visible(status)) { - GtkAllocation allocation; - gtk_widget_get_allocation(status, &allocation); - settings->statusGeometryHeight = allocation.height; - } - } -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(item.state.font == "") item.setFont(font); - } -} - -void pWindow::constructor() { - lastAllocation.width = 0; - lastAllocation.height = 0; - onSizePending = false; - - widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - gtk_widget_set_colormap(widget, gdk_screen_get_rgba_colormap(gdk_screen_get_default())); - } else { - gtk_widget_set_colormap(widget, gdk_screen_get_rgb_colormap(gdk_screen_get_default())); - } - - gtk_window_set_resizable(GTK_WINDOW(widget), true); - #if GTK_MAJOR_VERSION >= 3 - gtk_window_set_has_resize_grip(GTK_WINDOW(widget), false); - #endif - - gtk_widget_set_app_paintable(widget, true); - gtk_widget_add_events(widget, GDK_CONFIGURE); - - menuContainer = gtk_vbox_new(false, 0); - gtk_container_add(GTK_CONTAINER(widget), menuContainer); - gtk_widget_show(menuContainer); - - menu = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), menu, false, false, 0); - - formContainer = gtk_fixed_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), formContainer, true, true, 0); - gtk_widget_show(formContainer); - - statusContainer = gtk_event_box_new(); - status = gtk_statusbar_new(); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), true); - gtk_container_add(GTK_CONTAINER(statusContainer), status); - gtk_box_pack_start(GTK_BOX(menuContainer), statusContainer, false, false, 0); - gtk_widget_show(statusContainer); - - setTitle(""); - setResizable(window.state.resizable); - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); - - g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "expose-event", G_CALLBACK(Window_expose), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - - g_signal_connect(G_OBJECT(formContainer), "size-allocate", G_CALLBACK(Window_sizeAllocate), (gpointer)&window); - g_signal_connect(G_OBJECT(formContainer), "size-request", G_CALLBACK(Window_sizeRequest), (gpointer)&window); -} - -unsigned pWindow::menuHeight() { - return window.state.menuVisible ? settings->menuGeometryHeight : 0; -} - -unsigned pWindow::statusHeight() { - return window.state.statusVisible ? settings->statusGeometryHeight : 0; -} diff --git a/kaijuu/phoenix/phoenix.cpp b/kaijuu/phoenix/phoenix.cpp deleted file mode 100644 index eaa66b97..00000000 --- a/kaijuu/phoenix/phoenix.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef PHOENIX_CPP -#define PHOENIX_CPP - -#if defined(PHOENIX_WINDOWS) - #define UNICODE - #define WINVER 0x0501 - #define _WIN32_WINNT 0x0501 - #define _WIN32_IE 0x0600 - #define __MSVCRT_VERSION__ 0x0601 - #define NOMINMAX - - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_QT) - #include - #include - #include - #define XK_MISCELLANY - #define XK_LATIN1 - #include - #include - #undef XK_MISCELLANY - #undef XK_LATIN1 - #include -#elif defined(PHOENIX_GTK) - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_REFERENCE) -#else - #error "phoenix: unrecognized target" -#endif - -#include "phoenix.hpp" -using namespace nall; - -namespace phoenix { - #include "core/core.cpp" -} - -#endif diff --git a/kaijuu/phoenix/phoenix.hpp b/kaijuu/phoenix/phoenix.hpp deleted file mode 100644 index 8a6129c4..00000000 --- a/kaijuu/phoenix/phoenix.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PHOENIX_HPP -#define PHOENIX_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace phoenix { - #include "core/core.hpp" -} - -#endif diff --git a/kaijuu/phoenix/qt/action/action.cpp b/kaijuu/phoenix/qt/action/action.cpp deleted file mode 100644 index 62efaa2a..00000000 --- a/kaijuu/phoenix/qt/action/action.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setEnabled(enabled); - } -} - -void pAction::setFont(const string &font) { - QFont qtFont = pFont::create(font); - - if(dynamic_cast(&action)) { - ((Menu&)action).p.setFont(font); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setFont(qtFont); - } -} - -void pAction::setVisible(bool visible) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->menuAction()->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setVisible(visible); - } -} - -void pAction::constructor() { -} - -void pAction::destructor() { -} diff --git a/kaijuu/phoenix/qt/action/check-item.cpp b/kaijuu/phoenix/qt/action/check-item.cpp deleted file mode 100644 index ef451e73..00000000 --- a/kaijuu/phoenix/qt/action/check-item.cpp +++ /dev/null @@ -1,27 +0,0 @@ -bool pCheckItem::checked() { - return qtAction->isChecked(); -} - -void pCheckItem::setChecked(bool checked) { - qtAction->setChecked(checked); -} - -void pCheckItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pCheckItem::constructor() { - qtAction = new QAction(0); - qtAction->setCheckable(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onToggle())); -} - -void pCheckItem::destructor() { - if(action.state.menu) action.state.menu->remove(checkItem); - delete qtAction; -} - -void pCheckItem::onToggle() { - checkItem.state.checked = checked(); - if(checkItem.onToggle) checkItem.onToggle(); -} diff --git a/kaijuu/phoenix/qt/action/item.cpp b/kaijuu/phoenix/qt/action/item.cpp deleted file mode 100644 index 7f142289..00000000 --- a/kaijuu/phoenix/qt/action/item.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pItem::setImage(const image &image) { - qtAction->setIcon(CreateIcon(image)); -} - -void pItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pItem::constructor() { - qtAction = new QAction(0); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pItem::destructor() { - if(action.state.menu) action.state.menu->remove(item); - delete qtAction; -} - -void pItem::onActivate() { - if(item.onActivate) item.onActivate(); -} diff --git a/kaijuu/phoenix/qt/action/menu.cpp b/kaijuu/phoenix/qt/action/menu.cpp deleted file mode 100644 index 43d89a1e..00000000 --- a/kaijuu/phoenix/qt/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - if(dynamic_cast(&action)) { - qtMenu->addMenu(((Menu&)action).p.qtMenu); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((RadioItem&)action).p.qtAction); - } -} - -void pMenu::remove(Action &action) { - if(dynamic_cast(&action)) { - //QMenu::removeMenu() does not exist - qtMenu->clear(); - for(auto &action : menu.state.action) append(action); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } -} - -void pMenu::setFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : menu.state.action) item.p.setFont(font); -} - -void pMenu::setImage(const image &image) { - qtMenu->setIcon(CreateIcon(image)); -} - -void pMenu::setText(const string &text) { - qtMenu->setTitle(QString::fromUtf8(text)); -} - -void pMenu::constructor() { - qtMenu = new QMenu; -} - -void pMenu::destructor() { - if(action.state.menu) action.state.menu->remove(menu); - delete qtMenu; -} diff --git a/kaijuu/phoenix/qt/action/radio-item.cpp b/kaijuu/phoenix/qt/action/radio-item.cpp deleted file mode 100644 index 66cf6c6a..00000000 --- a/kaijuu/phoenix/qt/action/radio-item.cpp +++ /dev/null @@ -1,41 +0,0 @@ -bool pRadioItem::checked() { - return qtAction->isChecked(); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) { - bool checkState = item.p.qtAction == qtAction; - item.state.checked = checkState; - item.p.qtAction->setChecked(checkState); - } - locked = false; -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pRadioItem::constructor() { - qtAction = new QAction(0); - qtGroup = new QActionGroup(0); - qtAction->setCheckable(true); - qtAction->setActionGroup(qtGroup); - qtAction->setChecked(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pRadioItem::destructor() { - if(action.state.menu) action.state.menu->remove(radioItem); - delete qtAction; -} - -void pRadioItem::onActivate() { - if(radioItem.state.checked == false) { - setChecked(); - if(locked == false && radioItem.onActivate) radioItem.onActivate(); - } -} diff --git a/kaijuu/phoenix/qt/action/separator.cpp b/kaijuu/phoenix/qt/action/separator.cpp deleted file mode 100644 index 95e66b6c..00000000 --- a/kaijuu/phoenix/qt/action/separator.cpp +++ /dev/null @@ -1,9 +0,0 @@ -void pSeparator::constructor() { - qtAction = new QAction(0); - qtAction->setSeparator(true); -} - -void pSeparator::destructor() { - if(action.state.menu) action.state.menu->remove(separator); - delete qtAction; -} diff --git a/kaijuu/phoenix/qt/desktop.cpp b/kaijuu/phoenix/qt/desktop.cpp deleted file mode 100644 index 554106b5..00000000 --- a/kaijuu/phoenix/qt/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - QRect rect = QApplication::desktop()->screenGeometry(); - return { rect.width(), rect.height() }; -} - -Geometry pDesktop::workspace() { - QRect rect = QApplication::desktop()->availableGeometry(); - return { rect.x(), rect.y(), rect.width(), rect.height() }; -} diff --git a/kaijuu/phoenix/qt/dialog-window.cpp b/kaijuu/phoenix/qt/dialog-window.cpp deleted file mode 100644 index 680a6e2e..00000000 --- a/kaijuu/phoenix/qt/dialog-window.cpp +++ /dev/null @@ -1,57 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getOpenFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Open File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getSaveFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Save File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - QString directory = QFileDialog::getExistingDirectory( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Select Directory", - QString::fromUtf8(path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks - ); - string name = directory.toUtf8().constData(); - if(name != "" && name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/kaijuu/phoenix/qt/font.cpp b/kaijuu/phoenix/qt/font.cpp deleted file mode 100644 index bb3261cd..00000000 --- a/kaijuu/phoenix/qt/font.cpp +++ /dev/null @@ -1,40 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return pFont::geometry(pFont::create(description), text); -} - -QFont pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - QFont qtFont; - qtFont.setFamily(family); - qtFont.setPointSize(size); - if(bold) qtFont.setBold(true); - if(italic) qtFont.setItalic(true); - return qtFont; -} - -Geometry pFont::geometry(const QFont &qtFont, const string &text) { - QFontMetrics metrics(qtFont); - - lstring lines; - lines.split("\n", text); - - unsigned maxWidth = 0; - for(auto &line : lines) { - maxWidth = max(maxWidth, metrics.width(line)); - } - - return { 0, 0, maxWidth, metrics.height() * lines.size() }; -} diff --git a/kaijuu/phoenix/qt/keyboard.cpp b/kaijuu/phoenix/qt/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/kaijuu/phoenix/qt/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/kaijuu/phoenix/qt/message-window.cpp b/kaijuu/phoenix/qt/message-window.cpp deleted file mode 100644 index 7bceba0f..00000000 --- a/kaijuu/phoenix/qt/message-window.cpp +++ /dev/null @@ -1,47 +0,0 @@ -static QMessageBox::StandardButtons MessageWindow_buttons(MessageWindow::Buttons buttons) { - QMessageBox::StandardButtons standardButtons = QMessageBox::NoButton; - if(buttons == MessageWindow::Buttons::Ok) standardButtons = QMessageBox::Ok; - if(buttons == MessageWindow::Buttons::OkCancel) standardButtons = QMessageBox::Ok | QMessageBox::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) standardButtons = QMessageBox::Yes | QMessageBox::No; - return standardButtons; -} - -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, QMessageBox::StandardButton response) { - if(response == QMessageBox::Ok) return MessageWindow::Response::Ok; - if(response == QMessageBox::Cancel) return MessageWindow::Response::Cancel; - if(response == QMessageBox::Yes) return MessageWindow::Response::Yes; - if(response == QMessageBox::No) return MessageWindow::Response::No; - - //MessageWindow was closed via window manager, rather than by a button; assume a cancel/no response - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::information(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::question(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::warning(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::critical(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} diff --git a/kaijuu/phoenix/qt/mouse.cpp b/kaijuu/phoenix/qt/mouse.cpp deleted file mode 100644 index 4ea06cc9..00000000 --- a/kaijuu/phoenix/qt/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - QPoint point = QCursor::pos(); - return { point.x(), point.y() }; -} - -bool pMouse::pressed(Mouse::Button button) { - Qt::MouseButtons buttons = QApplication::mouseButtons(); - switch(button) { - case Mouse::Button::Left: return buttons & Qt::LeftButton; - case Mouse::Button::Middle: return buttons & Qt::MidButton; - case Mouse::Button::Right: return buttons & Qt::RightButton; - } - return false; -} diff --git a/kaijuu/phoenix/qt/platform.cpp b/kaijuu/phoenix/qt/platform.cpp deleted file mode 100644 index 86f659c8..00000000 --- a/kaijuu/phoenix/qt/platform.cpp +++ /dev/null @@ -1,91 +0,0 @@ -//Qt 4.8.0 and earlier improperly define the QLOCATION macro -//in C++11, it is detected as a malformed user-defined literal -//below is a workaround to fix compilation errors caused by this -#undef QLOCATION -#define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__) - -#include "platform.moc.hpp" -#include "platform.moc" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; - -void pOS::main() { - QApplication::exec(); -} - -bool pOS::pendingEvents() { - return QApplication::hasPendingEvents(); -} - -void pOS::processEvents() { - while(pendingEvents()) QApplication::processEvents(); -} - -void pOS::quit() { - QApplication::quit(); - //note: QApplication cannot be deleted; or libQtGui will crash - qtApplication = 0; -} - -void pOS::syncX() { - for(unsigned n = 0; n < 8; n++) { - QApplication::syncX(); - OS::processEvents(); - usleep(2000); - } -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - static int argc = 1; - static char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - - qtApplication = new QApplication(argc, argvp); - - pKeyboard::initialize(); -} diff --git a/kaijuu/phoenix/qt/platform.moc b/kaijuu/phoenix/qt/platform.moc deleted file mode 100644 index 3b2db923..00000000 --- a/kaijuu/phoenix/qt/platform.moc +++ /dev/null @@ -1,1105 +0,0 @@ -/**************************************************************************** -** Meta object code from reading C++ file 'platform.moc.hpp' -** -** Created: Sun Jul 22 02:20:29 2012 -** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - -#if !defined(Q_MOC_OUTPUT_REVISION) -#error "The header file 'platform.moc.hpp' doesn't include ." -#elif Q_MOC_OUTPUT_REVISION != 62 -#error "This file was generated using the moc from 4.6.3. It" -#error "cannot be used with the include files from this version of Qt." -#error "(The moc has changed too much.)" -#endif - -QT_BEGIN_MOC_NAMESPACE -static const uint qt_meta_data_pTimer[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 8, 7, 7, 7, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTimer[] = { - "pTimer\0\0onTimeout()\0" -}; - -const QMetaObject pTimer::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTimer, - qt_meta_data_pTimer, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTimer::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTimer::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTimer::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTimer)) - return static_cast(const_cast< pTimer*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pTimer*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTimer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onTimeout(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pWindow[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pWindow[] = { - "pWindow\0" -}; - -const QMetaObject pWindow::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pWindow, - qt_meta_data_pWindow, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pWindow::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pWindow::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pWindow::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pWindow)) - return static_cast(const_cast< pWindow*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pWindow*>(this)); - return QObject::qt_metacast(_clname); -} - -int pWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 7, 6, 6, 6, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pItem[] = { - "pItem\0\0onActivate()\0" -}; - -const QMetaObject pItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pItem, - qt_meta_data_pItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pItem)) - return static_cast(const_cast< pItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCheckItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckItem[] = { - "pCheckItem\0\0onToggle()\0" -}; - -const QMetaObject pCheckItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckItem, - qt_meta_data_pCheckItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckItem)) - return static_cast(const_cast< pCheckItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pCheckItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pRadioItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioItem[] = { - "pRadioItem\0\0onActivate()\0" -}; - -const QMetaObject pRadioItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioItem, - qt_meta_data_pRadioItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioItem)) - return static_cast(const_cast< pRadioItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pRadioItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pButton[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 9, 8, 8, 8, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pButton[] = { - "pButton\0\0onActivate()\0" -}; - -const QMetaObject pButton::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pButton, - qt_meta_data_pButton, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pButton::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pButton::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pButton::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pButton)) - return static_cast(const_cast< pButton*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pButton*>(this)); - return QObject::qt_metacast(_clname); -} - -int pButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCanvas[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pCanvas[] = { - "pCanvas\0" -}; - -const QMetaObject pCanvas::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCanvas, - qt_meta_data_pCanvas, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCanvas::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCanvas::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCanvas::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCanvas)) - return static_cast(const_cast< pCanvas*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCanvas*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCanvas::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pCheckBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckBox[] = { - "pCheckBox\0\0onToggle()\0" -}; - -const QMetaObject pCheckBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckBox, - qt_meta_data_pCheckBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckBox)) - return static_cast(const_cast< pCheckBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCheckBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pComboBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pComboBox[] = { - "pComboBox\0\0onChange()\0" -}; - -const QMetaObject pComboBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pComboBox, - qt_meta_data_pComboBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pComboBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pComboBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pComboBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pComboBox)) - return static_cast(const_cast< pComboBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pComboBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHexEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 10, 9, 9, 9, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHexEdit[] = { - "pHexEdit\0\0onScroll()\0" -}; - -const QMetaObject pHexEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHexEdit, - qt_meta_data_pHexEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHexEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHexEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHexEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHexEdit)) - return static_cast(const_cast< pHexEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHexEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHexEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onScroll(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 22, 21, 21, 21, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalScrollBar[] = { - "pHorizontalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pHorizontalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalScrollBar, - qt_meta_data_pHorizontalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalScrollBar)) - return static_cast(const_cast< pHorizontalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 19, 18, 18, 18, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalSlider[] = { - "pHorizontalSlider\0\0onChange()\0" -}; - -const QMetaObject pHorizontalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalSlider, - qt_meta_data_pHorizontalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalSlider)) - return static_cast(const_cast< pHorizontalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pLineEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 2, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 24, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pLineEdit[] = { - "pLineEdit\0\0onActivate()\0onChange()\0" -}; - -const QMetaObject pLineEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pLineEdit, - qt_meta_data_pLineEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pLineEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pLineEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pLineEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pLineEdit)) - return static_cast(const_cast< pLineEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pLineEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange(); break; - default: ; - } - _id -= 2; - } - return _id; -} -static const uint qt_meta_data_pListView[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 3, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 29, 24, 10, 10, 0x0a, - 56, 24, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pListView[] = { - "pListView\0\0onActivate()\0item\0" - "onChange(QTreeWidgetItem*)\0" - "onToggle(QTreeWidgetItem*)\0" -}; - -const QMetaObject pListView::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pListView, - qt_meta_data_pListView, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pListView::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pListView::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pListView::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pListView)) - return static_cast(const_cast< pListView*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pListView*>(this)); - return QObject::qt_metacast(_clname); -} - -int pListView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - case 2: onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - default: ; - } - _id -= 3; - } - return _id; -} -static const uint qt_meta_data_pRadioBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioBox[] = { - "pRadioBox\0\0onActivate()\0" -}; - -const QMetaObject pRadioBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioBox, - qt_meta_data_pRadioBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioBox)) - return static_cast(const_cast< pRadioBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pRadioBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pTextEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTextEdit[] = { - "pTextEdit\0\0onChange()\0" -}; - -const QMetaObject pTextEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTextEdit, - qt_meta_data_pTextEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTextEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTextEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTextEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTextEdit)) - return static_cast(const_cast< pTextEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pTextEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTextEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 20, 19, 19, 19, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalScrollBar[] = { - "pVerticalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pVerticalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalScrollBar, - qt_meta_data_pVerticalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalScrollBar)) - return static_cast(const_cast< pVerticalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 17, 16, 16, 16, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalSlider[] = { - "pVerticalSlider\0\0onChange()\0" -}; - -const QMetaObject pVerticalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalSlider, - qt_meta_data_pVerticalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalSlider)) - return static_cast(const_cast< pVerticalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -QT_END_MOC_NAMESPACE diff --git a/kaijuu/phoenix/qt/platform.moc.hpp b/kaijuu/phoenix/qt/platform.moc.hpp deleted file mode 100644 index 9e75fdc8..00000000 --- a/kaijuu/phoenix/qt/platform.moc.hpp +++ /dev/null @@ -1,633 +0,0 @@ -static QApplication *qtApplication = nullptr; - -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static QFont create(const string &description); - static Geometry geometry(const QFont &qtFont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); - static void syncX(); -}; - -struct pTimer : public QObject, public pObject { - Q_OBJECT - -public: - Timer &timer; - QTimer *qtTimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); - void destructor(); - -public slots: - void onTimeout(); -}; - -struct pWindow : public QObject, public pObject { - Q_OBJECT - -public: - Window &window; - struct QtWindow : public QWidget { - pWindow &self; - void closeEvent(QCloseEvent*); - void keyPressEvent(QKeyEvent*); - void keyReleaseEvent(QKeyEvent*); - void moveEvent(QMoveEvent*); - void resizeEvent(QResizeEvent*); - QSize sizeHint() const; - QtWindow(pWindow &self) : self(self) {} - } *qtWindow; - QVBoxLayout *qtLayout; - QMenuBar *qtMenu; - QStatusBar *qtStatus; - QWidget *qtContainer; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - Geometry frameMargin(); - bool focused(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateFrameGeometry(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setFont(const string &font); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - void destructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - QMenu *qtMenu; - - void append(Action &action); - void remove(Action &action); - void setFont(const string &font); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - QAction *qtAction; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public QObject, public pAction { - Q_OBJECT - -public: - Item &item; - QAction *qtAction; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pCheckItem : public QObject, public pAction { - Q_OBJECT - -public: - CheckItem &checkItem; - QAction *qtAction; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - -public slots: - void onToggle(); -}; - -struct pRadioItem : public QObject, public pAction { - Q_OBJECT - -public: - RadioItem &radioItem; - QAction *qtAction; - QActionGroup *qtGroup; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} - - void constructor() {} - void destructor() {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} - - void constructor() {} - void destructor() {} -}; - -struct pWidget : public pSizable { - Widget &widget; - QWidget *qtWidget; - - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void synchronizeState(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public QObject, public pWidget { - Q_OBJECT - -public: - Button &button; - QToolButton *qtButton; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pCanvas : public QObject, public pWidget { - Q_OBJECT - -public: - Canvas &canvas; - QImage *qtImage; - struct QtCanvas : public QWidget { - pCanvas &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - void paintEvent(QPaintEvent*); - QtCanvas(pCanvas &self); - } *qtCanvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: -}; - -struct pCheckBox : public QObject, public pWidget { - Q_OBJECT - -public: - CheckBox &checkBox; - QCheckBox *qtCheckBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onToggle(); -}; - -struct pComboBox : public QObject, public pWidget { - Q_OBJECT - -public: - ComboBox &comboBox; - QComboBox *qtComboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHexEdit : public QObject, public pWidget { - Q_OBJECT - -public: - HexEdit &hexEdit; - struct QtHexEdit : public QTextEdit { - pHexEdit &self; - void keyPressEvent(QKeyEvent*); - void keyPressEventAcknowledge(QKeyEvent*); - QtHexEdit(pHexEdit &self) : self(self) {} - } *qtHexEdit; - QHBoxLayout *qtLayout; - QScrollBar *qtScroll; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - void keyPressEvent(QKeyEvent*); - -public slots: - void onScroll(); -}; - -struct pHorizontalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalScrollBar &horizontalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHorizontalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalSlider &horizontalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pLabel : public pWidget { - Label &label; - QLabel *qtLabel; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public QObject, public pWidget { - Q_OBJECT - -public: - LineEdit &lineEdit; - QLineEdit *qtLineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(); -}; - -struct pListView : public QObject, public pWidget { - Q_OBJECT - -public: - ListView &listView; - QTreeWidget *qtListView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(QTreeWidgetItem *item); - void onToggle(QTreeWidgetItem *item); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - QProgressBar *qtProgressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public QObject, public pWidget { - Q_OBJECT - -public: - RadioBox &radioBox; - QRadioButton *qtRadioBox; - QButtonGroup *qtGroup; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pTextEdit : public QObject, public pWidget { - Q_OBJECT - -public: - TextEdit &textEdit; - QTextEdit *qtTextEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalScrollBar &verticalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalSlider &verticalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - struct QtViewport : public QWidget { - pViewport &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - QtViewport(pViewport &self); - } *qtViewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/kaijuu/phoenix/qt/settings.cpp b/kaijuu/phoenix/qt/settings.cpp deleted file mode 100644 index 90d3a76e..00000000 --- a/kaijuu/phoenix/qt/settings.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/qt.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("qt.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); -} diff --git a/kaijuu/phoenix/qt/timer.cpp b/kaijuu/phoenix/qt/timer.cpp deleted file mode 100644 index 61f00ba8..00000000 --- a/kaijuu/phoenix/qt/timer.cpp +++ /dev/null @@ -1,25 +0,0 @@ -void pTimer::setEnabled(bool enabled) { - if(enabled) { - qtTimer->start(); - } else { - qtTimer->stop(); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - qtTimer->setInterval(milliseconds); -} - -void pTimer::constructor() { - qtTimer = new QTimer; - qtTimer->setInterval(0); - connect(qtTimer, SIGNAL(timeout()), SLOT(onTimeout())); -} - -void pTimer::destructor() { - delete qtTimer; -} - -void pTimer::onTimeout() { - if(timer.onTimeout) timer.onTimeout(); -} diff --git a/kaijuu/phoenix/qt/utility.cpp b/kaijuu/phoenix/qt/utility.cpp deleted file mode 100644 index 400df0a2..00000000 --- a/kaijuu/phoenix/qt/utility.cpp +++ /dev/null @@ -1,190 +0,0 @@ -static QIcon CreateIcon(const nall::image &image, bool scale = false) { - nall::image qtBuffer = image; - qtBuffer.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - if(scale) qtBuffer.scale(16, 16, Interpolation::Linear); - QImage qtImage(qtBuffer.data, qtBuffer.width, qtBuffer.height, QImage::Format_ARGB32); - return QIcon(QPixmap::fromImage(qtImage)); -} - -static Keyboard::Keycode Keysym(int keysym) { - switch(keysym) { - case XK_Escape: return Keyboard::Keycode::Escape; - case XK_F1: return Keyboard::Keycode::F1; - case XK_F2: return Keyboard::Keycode::F2; - case XK_F3: return Keyboard::Keycode::F3; - case XK_F4: return Keyboard::Keycode::F4; - case XK_F5: return Keyboard::Keycode::F5; - case XK_F6: return Keyboard::Keycode::F6; - case XK_F7: return Keyboard::Keycode::F7; - case XK_F8: return Keyboard::Keycode::F8; - case XK_F9: return Keyboard::Keycode::F9; - case XK_F10: return Keyboard::Keycode::F10; - case XK_F11: return Keyboard::Keycode::F11; - case XK_F12: return Keyboard::Keycode::F12; - - case XK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case XK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case XK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case XK_Insert: return Keyboard::Keycode::Insert; - case XK_Delete: return Keyboard::Keycode::Delete; - case XK_Home: return Keyboard::Keycode::Home; - case XK_End: return Keyboard::Keycode::End; - case XK_Prior: return Keyboard::Keycode::PageUp; - case XK_Next: return Keyboard::Keycode::PageDown; - - case XK_Up: return Keyboard::Keycode::Up; - case XK_Down: return Keyboard::Keycode::Down; - case XK_Left: return Keyboard::Keycode::Left; - case XK_Right: return Keyboard::Keycode::Right; - - case XK_grave: return Keyboard::Keycode::Grave; - case XK_1: return Keyboard::Keycode::Number1; - case XK_2: return Keyboard::Keycode::Number2; - case XK_3: return Keyboard::Keycode::Number3; - case XK_4: return Keyboard::Keycode::Number4; - case XK_5: return Keyboard::Keycode::Number5; - case XK_6: return Keyboard::Keycode::Number6; - case XK_7: return Keyboard::Keycode::Number7; - case XK_8: return Keyboard::Keycode::Number8; - case XK_9: return Keyboard::Keycode::Number9; - case XK_0: return Keyboard::Keycode::Number0; - case XK_minus: return Keyboard::Keycode::Minus; - case XK_equal: return Keyboard::Keycode::Equal; - case XK_BackSpace: return Keyboard::Keycode::Backspace; - - case XK_asciitilde: return Keyboard::Keycode::Tilde; - case XK_exclam: return Keyboard::Keycode::Exclamation; - case XK_at: return Keyboard::Keycode::At; - case XK_numbersign: return Keyboard::Keycode::Pound; - case XK_dollar: return Keyboard::Keycode::Dollar; - case XK_percent: return Keyboard::Keycode::Percent; - case XK_asciicircum: return Keyboard::Keycode::Power; - case XK_ampersand: return Keyboard::Keycode::Ampersand; - case XK_asterisk: return Keyboard::Keycode::Asterisk; - case XK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case XK_parenright: return Keyboard::Keycode::ParenthesisRight; - case XK_underscore: return Keyboard::Keycode::Underscore; - case XK_plus: return Keyboard::Keycode::Plus; - - case XK_bracketleft: return Keyboard::Keycode::BracketLeft; - case XK_bracketright: return Keyboard::Keycode::BracketRight; - case XK_backslash: return Keyboard::Keycode::Backslash; - case XK_semicolon: return Keyboard::Keycode::Semicolon; - case XK_apostrophe: return Keyboard::Keycode::Apostrophe; - case XK_comma: return Keyboard::Keycode::Comma; - case XK_period: return Keyboard::Keycode::Period; - case XK_slash: return Keyboard::Keycode::Slash; - - case XK_braceleft: return Keyboard::Keycode::BraceLeft; - case XK_braceright: return Keyboard::Keycode::BraceRight; - case XK_bar: return Keyboard::Keycode::Pipe; - case XK_colon: return Keyboard::Keycode::Colon; - case XK_quotedbl: return Keyboard::Keycode::Quote; - case XK_less: return Keyboard::Keycode::CaretLeft; - case XK_greater: return Keyboard::Keycode::CaretRight; - case XK_question: return Keyboard::Keycode::Question; - - case XK_Tab: return Keyboard::Keycode::Tab; - case XK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case XK_Return: return Keyboard::Keycode::Return; - case XK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case XK_Shift_R: return Keyboard::Keycode::ShiftRight; - case XK_Control_L: return Keyboard::Keycode::ControlLeft; - case XK_Control_R: return Keyboard::Keycode::ControlRight; - case XK_Super_L: return Keyboard::Keycode::SuperLeft; - case XK_Super_R: return Keyboard::Keycode::SuperRight; - case XK_Alt_L: return Keyboard::Keycode::AltLeft; - case XK_Alt_R: return Keyboard::Keycode::AltRight; - case XK_space: return Keyboard::Keycode::Space; - case XK_Menu: return Keyboard::Keycode::Menu; - - case XK_A: return Keyboard::Keycode::A; - case XK_B: return Keyboard::Keycode::B; - case XK_C: return Keyboard::Keycode::C; - case XK_D: return Keyboard::Keycode::D; - case XK_E: return Keyboard::Keycode::E; - case XK_F: return Keyboard::Keycode::F; - case XK_G: return Keyboard::Keycode::G; - case XK_H: return Keyboard::Keycode::H; - case XK_I: return Keyboard::Keycode::I; - case XK_J: return Keyboard::Keycode::J; - case XK_K: return Keyboard::Keycode::K; - case XK_L: return Keyboard::Keycode::L; - case XK_M: return Keyboard::Keycode::M; - case XK_N: return Keyboard::Keycode::N; - case XK_O: return Keyboard::Keycode::O; - case XK_P: return Keyboard::Keycode::P; - case XK_Q: return Keyboard::Keycode::Q; - case XK_R: return Keyboard::Keycode::R; - case XK_S: return Keyboard::Keycode::S; - case XK_T: return Keyboard::Keycode::T; - case XK_U: return Keyboard::Keycode::U; - case XK_V: return Keyboard::Keycode::V; - case XK_W: return Keyboard::Keycode::W; - case XK_X: return Keyboard::Keycode::X; - case XK_Y: return Keyboard::Keycode::Y; - case XK_Z: return Keyboard::Keycode::Z; - - case XK_a: return Keyboard::Keycode::a; - case XK_b: return Keyboard::Keycode::b; - case XK_c: return Keyboard::Keycode::c; - case XK_d: return Keyboard::Keycode::d; - case XK_e: return Keyboard::Keycode::e; - case XK_f: return Keyboard::Keycode::f; - case XK_g: return Keyboard::Keycode::g; - case XK_h: return Keyboard::Keycode::h; - case XK_i: return Keyboard::Keycode::i; - case XK_j: return Keyboard::Keycode::j; - case XK_k: return Keyboard::Keycode::k; - case XK_l: return Keyboard::Keycode::l; - case XK_m: return Keyboard::Keycode::m; - case XK_n: return Keyboard::Keycode::n; - case XK_o: return Keyboard::Keycode::o; - case XK_p: return Keyboard::Keycode::p; - case XK_q: return Keyboard::Keycode::q; - case XK_r: return Keyboard::Keycode::r; - case XK_s: return Keyboard::Keycode::s; - case XK_t: return Keyboard::Keycode::t; - case XK_u: return Keyboard::Keycode::u; - case XK_v: return Keyboard::Keycode::v; - case XK_w: return Keyboard::Keycode::w; - case XK_x: return Keyboard::Keycode::x; - case XK_y: return Keyboard::Keycode::y; - case XK_z: return Keyboard::Keycode::z; - - case XK_Num_Lock: return Keyboard::Keycode::NumLock; - case XK_KP_Divide: return Keyboard::Keycode::Divide; - case XK_KP_Multiply: return Keyboard::Keycode::Multiply; - case XK_KP_Subtract: return Keyboard::Keycode::Subtract; - case XK_KP_Add: return Keyboard::Keycode::Add; - case XK_KP_Enter: return Keyboard::Keycode::Enter; - case XK_KP_Decimal: return Keyboard::Keycode::Point; - - case XK_KP_1: return Keyboard::Keycode::Keypad1; - case XK_KP_2: return Keyboard::Keycode::Keypad2; - case XK_KP_3: return Keyboard::Keycode::Keypad3; - case XK_KP_4: return Keyboard::Keycode::Keypad4; - case XK_KP_5: return Keyboard::Keycode::Keypad5; - case XK_KP_6: return Keyboard::Keycode::Keypad6; - case XK_KP_7: return Keyboard::Keycode::Keypad7; - case XK_KP_8: return Keyboard::Keycode::Keypad8; - case XK_KP_9: return Keyboard::Keycode::Keypad9; - case XK_KP_0: return Keyboard::Keycode::Keypad0; - - case XK_KP_Home: return Keyboard::Keycode::KeypadHome; - case XK_KP_End: return Keyboard::Keycode::KeypadEnd; - case XK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case XK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case XK_KP_Up: return Keyboard::Keycode::KeypadUp; - case XK_KP_Down: return Keyboard::Keycode::KeypadDown; - case XK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case XK_KP_Right: return Keyboard::Keycode::KeypadRight; - case XK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case XK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case XK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/kaijuu/phoenix/qt/widget/button.cpp b/kaijuu/phoenix/qt/widget/button.cpp deleted file mode 100644 index 0e1522b3..00000000 --- a/kaijuu/phoenix/qt/widget/button.cpp +++ /dev/null @@ -1,52 +0,0 @@ -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - qtButton->setIconSize(QSize(image.width, image.height)); - qtButton->setIcon(CreateIcon(image)); - qtButton->setStyleSheet("text-align: top;"); - switch(orientation) { - case Orientation::Horizontal: qtButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; - case Orientation::Vertical: qtButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; - } -} - -void pButton::setText(const string &text) { - qtButton->setText(QString::fromUtf8(text)); -} - -void pButton::constructor() { - qtWidget = qtButton = new QToolButton; - qtButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - connect(qtButton, SIGNAL(released()), SLOT(onActivate())); - - pWidget::synchronizeState(); - setText(button.state.text); -} - -void pButton::destructor() { - delete qtButton; - qtWidget = qtButton = 0; -} - -void pButton::orphan() { - destructor(); - constructor(); -} - -void pButton::onActivate() { - if(button.onActivate) button.onActivate(); -} diff --git a/kaijuu/phoenix/qt/widget/canvas.cpp b/kaijuu/phoenix/qt/widget/canvas.cpp deleted file mode 100644 index 245c1e9f..00000000 --- a/kaijuu/phoenix/qt/widget/canvas.cpp +++ /dev/null @@ -1,73 +0,0 @@ -void pCanvas::setSize(const Size &size) { - delete qtImage; - qtImage = new QImage(size.width, size.height, QImage::Format_ARGB32); -} - -void pCanvas::update() { - uint32_t *dp = (uint32_t*)qtImage->bits(), *sp = (uint32_t*)canvas.state.data; - for(unsigned n = 0; n < canvas.state.width * canvas.state.height; n++) *dp++ = 0xff000000 | *sp++; - qtCanvas->update(); -} - -void pCanvas::constructor() { - qtWidget = qtCanvas = new QtCanvas(*this); - qtCanvas->setMouseTracking(true); - qtImage = new QImage(canvas.state.width, canvas.state.height, QImage::Format_ARGB32); - memcpy(qtImage->bits(), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - - pWidget::synchronizeState(); - update(); -} - -void pCanvas::destructor() { - delete qtCanvas; - delete qtImage; - qtWidget = qtCanvas = 0; - qtImage = 0; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::QtCanvas::leaveEvent(QEvent *event) { - if(self.canvas.onMouseLeave) self.canvas.onMouseLeave(); -} - -void pCanvas::QtCanvas::mouseMoveEvent(QMouseEvent *event) { - if(self.canvas.onMouseMove) self.canvas.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pCanvas::QtCanvas::mousePressEvent(QMouseEvent *event) { - if(self.canvas.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMousePress(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::mouseReleaseEvent(QMouseEvent *event) { - if(self.canvas.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMouseRelease(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::paintEvent(QPaintEvent *event) { - QPainter painter(self.qtCanvas); - painter.drawImage(0, 0, *self.qtImage); - -//this will scale the source image to fit the target widget size (nearest-neighbor): -//painter.drawImage( -// QRect(0, 0, geometry().width(), geometry().height()), -// *self.qtImage, -// QRect(0, 0, self.canvas.state.width, self.canvas.state.height) -//); -} - -pCanvas::QtCanvas::QtCanvas(pCanvas &self) : self(self) { -} diff --git a/kaijuu/phoenix/qt/widget/check-box.cpp b/kaijuu/phoenix/qt/widget/check-box.cpp deleted file mode 100644 index c45bb326..00000000 --- a/kaijuu/phoenix/qt/widget/check-box.cpp +++ /dev/null @@ -1,42 +0,0 @@ -bool pCheckBox::checked() { - return qtCheckBox->isChecked(); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), checkBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - qtCheckBox->setChecked(checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - qtCheckBox->setText(QString::fromUtf8(text)); -} - -void pCheckBox::constructor() { - qtWidget = qtCheckBox = new QCheckBox; - connect(qtCheckBox, SIGNAL(stateChanged(int)), SLOT(onToggle())); - - pWidget::synchronizeState(); - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - delete qtCheckBox; - qtWidget = qtCheckBox = 0; -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} - -void pCheckBox::onToggle() { - checkBox.state.checked = checked(); - if(locked == false && checkBox.onToggle) checkBox.onToggle(); -} diff --git a/kaijuu/phoenix/qt/widget/combo-box.cpp b/kaijuu/phoenix/qt/widget/combo-box.cpp deleted file mode 100644 index 1dfa609d..00000000 --- a/kaijuu/phoenix/qt/widget/combo-box.cpp +++ /dev/null @@ -1,68 +0,0 @@ -void pComboBox::append(const string &text) { - locked = true; - qtComboBox->addItem(QString::fromUtf8(text)); - locked = false; -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(qtWidget->font(), text).width); - Geometry geometry = pFont::geometry(qtWidget->font(), " "); - return { 0, 0, maximumWidth + 32, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - qtComboBox->setItemText(row, text); -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - qtComboBox->removeItem(row); - if(position == row) qtComboBox->setCurrentIndex(0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - while(qtComboBox->count()) qtComboBox->removeItem(0); - locked = false; -} - -unsigned pComboBox::selection() { - signed index = qtComboBox->currentIndex(); - return index >= 0 ? index : 0; -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - qtComboBox->setCurrentIndex(row); - locked = false; -} - -void pComboBox::constructor() { - qtWidget = qtComboBox = new QComboBox; - connect(qtComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - unsigned selection = comboBox.state.selection; - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(selection); -} - -void pComboBox::destructor() { - delete qtComboBox; - qtWidget = qtComboBox = 0; -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::onChange() { - comboBox.state.selection = selection(); - if(locked == false && comboBox.onChange) comboBox.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/hex-edit.cpp b/kaijuu/phoenix/qt/widget/hex-edit.cpp deleted file mode 100644 index fdeebe4a..00000000 --- a/kaijuu/phoenix/qt/widget/hex-edit.cpp +++ /dev/null @@ -1,191 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - //add one if last row is not equal to column length (eg only part of the row is present) - bool indivisible = hexEdit.state.columns == 0 || (hexEdit.state.length % hexEdit.state.columns) != 0; - qtScroll->setRange(0, hexEdit.state.length / hexEdit.state.columns + indivisible - hexEdit.state.rows); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - locked = true; - qtScroll->setSliderPosition(hexEdit.state.offset / hexEdit.state.columns); - locked = false; - update(); -} - -void pHexEdit::setRows(unsigned rows) { - qtScroll->setPageStep(hexEdit.state.rows); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - qtHexEdit->setPlainText(""); - return; - } - - unsigned cursorPosition = qtHexEdit->textCursor().position(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - qtHexEdit->setPlainText(QString::fromUtf8(output)); - QTextCursor cursor = qtHexEdit->textCursor(); - cursor.setPosition(cursorPosition); - qtHexEdit->setTextCursor(cursor); -} - -void pHexEdit::constructor() { - qtWidget = qtHexEdit = new QtHexEdit(*this); - - qtHexEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - qtHexEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - qtLayout = new QHBoxLayout; - qtLayout->setAlignment(Qt::AlignRight); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtHexEdit->setLayout(qtLayout); - - qtScroll = new QScrollBar(Qt::Vertical); - qtScroll->setSingleStep(1); - qtLayout->addWidget(qtScroll); - - connect(qtScroll, SIGNAL(actionTriggered(int)), SLOT(onScroll())); - - pWidget::synchronizeState(); - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - delete qtScroll; - delete qtLayout; - delete qtHexEdit; - qtWidget = qtHexEdit = 0; - qtLayout = 0; - qtScroll = 0; -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -void pHexEdit::keyPressEvent(QKeyEvent *event) { - if(!hexEdit.onRead) return; - - QTextCursor cursor = qtHexEdit->textCursor(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = cursor.position() / lineWidth; - unsigned cursorX = cursor.position() % lineWidth; - - unsigned nibble; - switch(event->key()) { - case Qt::Key_0: nibble = 0; break; - case Qt::Key_1: nibble = 1; break; - case Qt::Key_2: nibble = 2; break; - case Qt::Key_3: nibble = 3; break; - case Qt::Key_4: nibble = 4; break; - case Qt::Key_5: nibble = 5; break; - case Qt::Key_6: nibble = 6; break; - case Qt::Key_7: nibble = 7; break; - case Qt::Key_8: nibble = 8; break; - case Qt::Key_9: nibble = 9; break; - case Qt::Key_A: nibble = 10; break; - case Qt::Key_B: nibble = 11; break; - case Qt::Key_C: nibble = 12; break; - case Qt::Key_D: nibble = 13; break; - case Qt::Key_E: nibble = 14; break; - case Qt::Key_F: nibble = 15; break; - default: { - //allow navigation keys to move cursor, but block text input - qtHexEdit->setTextInteractionFlags(Qt::TextInteractionFlags( - Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse - )); - qtHexEdit->keyPressEventAcknowledge(event); - qtHexEdit->setTextInteractionFlags(Qt::TextEditorInteraction); - return; - } - } - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return; //do not edit past end of file - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (nibble << 0); - } else { - data = (data & 0x0f) | (nibble << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - unsigned step = 1; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) step = 2; - cursor.setPosition(cursor.position() + step); - qtHexEdit->setTextCursor(cursor); - - //refresh output to reflect modified data - update(); - } - } - } -} - -void pHexEdit::onScroll() { - if(locked) return; - unsigned offset = qtScroll->sliderPosition(); - hexEdit.state.offset = offset * hexEdit.state.columns; - update(); -} - -void pHexEdit::QtHexEdit::keyPressEvent(QKeyEvent *event) { - self.keyPressEvent(event); -} - -void pHexEdit::QtHexEdit::keyPressEventAcknowledge(QKeyEvent *event) { - QTextEdit::keyPressEvent(event); -} diff --git a/kaijuu/phoenix/qt/widget/horizontal-scroll-bar.cpp b/kaijuu/phoenix/qt/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 6127c301..00000000 --- a/kaijuu/phoenix/qt/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 15 }; -} - -unsigned pHorizontalScrollBar::position() { - return qtScrollBar->value(); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pHorizontalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Horizontal); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pHorizontalScrollBar::onChange() { - horizontalScrollBar.state.position = position(); - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/horizontal-slider.cpp b/kaijuu/phoenix/qt/widget/horizontal-slider.cpp deleted file mode 100644 index 5401aae1..00000000 --- a/kaijuu/phoenix/qt/widget/horizontal-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return qtSlider->value(); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pHorizontalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Horizontal); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} - -void pHorizontalSlider::onChange() { - horizontalSlider.state.position = position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/label.cpp b/kaijuu/phoenix/qt/widget/label.cpp deleted file mode 100644 index 8dd86eb6..00000000 --- a/kaijuu/phoenix/qt/widget/label.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - qtLabel->setText(QString::fromUtf8(text)); -} - -void pLabel::constructor() { - qtWidget = qtLabel = new QLabel; - - pWidget::synchronizeState(); - setText(label.state.text); -} - -void pLabel::destructor() { - delete qtLabel; - qtWidget = qtLabel = 0; -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/qt/widget/line-edit.cpp b/kaijuu/phoenix/qt/widget/line-edit.cpp deleted file mode 100644 index a13f3b81..00000000 --- a/kaijuu/phoenix/qt/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 12 }; -} - -void pLineEdit::setEditable(bool editable) { - qtLineEdit->setReadOnly(!editable); -} - -void pLineEdit::setText(const string &text) { - qtLineEdit->setText(QString::fromUtf8(text)); -} - -string pLineEdit::text() { - return qtLineEdit->text().toUtf8().constData(); -} - -void pLineEdit::constructor() { - qtWidget = qtLineEdit = new QLineEdit; - connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate())); - connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - delete qtLineEdit; - qtWidget = qtLineEdit = 0; -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} - -void pLineEdit::onActivate() { - if(lineEdit.onActivate) lineEdit.onActivate(); -} - -void pLineEdit::onChange() { - lineEdit.state.text = text(); - if(lineEdit.onChange) lineEdit.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/list-view.cpp b/kaijuu/phoenix/qt/widget/list-view.cpp deleted file mode 100644 index a81c092d..00000000 --- a/kaijuu/phoenix/qt/widget/list-view.cpp +++ /dev/null @@ -1,164 +0,0 @@ -void pListView::append(const lstring &text) { - locked = true; - auto items = qtListView->findItems("", Qt::MatchContains); - QTreeWidgetItem *item = new QTreeWidgetItem(qtListView); - - item->setData(0, Qt::UserRole, (unsigned)items.size()); - if(listView.state.checkable) item->setCheckState(0, Qt::Unchecked); - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::autoSizeColumns() { - for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n); -} - -bool pListView::checked(unsigned row) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - return item ? item->checkState(0) == Qt::Checked : false; -} - -void pListView::modify(unsigned row, const lstring &text) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::remove(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - delete item; - locked = false; -} - -void pListView::reset() { - qtListView->clear(); -} - -bool pListView::selected() { - QTreeWidgetItem *item = qtListView->currentItem(); - return (item && item->isSelected() == true); -} - -unsigned pListView::selection() { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item == 0) return 0; - return item->data(0, Qt::UserRole).toUInt(); -} - -void pListView::setCheckable(bool checkable) { - if(checkable) { - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) items[n]->setCheckState(0, Qt::Unchecked); - } -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) item->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); - locked = false; -} - -void pListView::setHeaderText(const lstring &text) { - QStringList labels; - for(auto &column : text) labels << QString::fromUtf8(column); - - qtListView->setColumnCount(text.size()); - qtListView->setAlternatingRowColors(text.size() >= 2); - qtListView->setHeaderLabels(labels); - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - qtListView->setHeaderHidden(!visible); - autoSizeColumns(); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) { - if(image.empty() == 0) item->setIcon(column, CreateIcon(image)); - if(image.empty() == 1) item->setIcon(column, QIcon()); - } -} - -void pListView::setSelected(bool selected) { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(selected); -} - -void pListView::setSelection(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(false); - qtListView->setCurrentItem(0); - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) { - if(items[n]->data(0, Qt::UserRole).toUInt() == row) { - qtListView->setCurrentItem(items[n]); - break; - } - } - locked = false; -} - -void pListView::constructor() { - qtWidget = qtListView = new QTreeWidget; - qtListView->setAllColumnsShowFocus(true); - qtListView->setRootIsDecorated(false); - - connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate())); - connect(qtListView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(onChange(QTreeWidgetItem*))); - connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*))); - - pWidget::synchronizeState(); - setCheckable(listView.state.checkable); - setHeaderText(listView.state.headerText.size() ? listView.state.headerText : lstring{ " " }); - setHeaderVisible(listView.state.headerVisible); - for(auto &row : listView.state.text) append(row); - if(listView.state.checkable) { - for(unsigned n = 0; n < listView.state.checked.size(); n++) { - setChecked(n, listView.state.checked[n]); - } - } - setSelected(listView.state.selected); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - delete qtListView; - qtWidget = qtListView = 0; -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::onActivate() { - if(locked == false && listView.onActivate) listView.onActivate(); -} - -void pListView::onChange(QTreeWidgetItem *item) { - //Qt bug workaround: clicking items with mouse does not mark items as selected - if(item) item->setSelected(true); - listView.state.selected = selected(); - if(listView.state.selected) listView.state.selection = selection(); - if(locked == false && listView.onChange) listView.onChange(); -} - -void pListView::onToggle(QTreeWidgetItem *item) { - unsigned row = item->data(0, Qt::UserRole).toUInt(); - bool checkState = checked(row); - listView.state.checked[row] = checkState; - if(locked == false && listView.onToggle) listView.onToggle(row); -} diff --git a/kaijuu/phoenix/qt/widget/progress-bar.cpp b/kaijuu/phoenix/qt/widget/progress-bar.cpp deleted file mode 100644 index 8178bb66..00000000 --- a/kaijuu/phoenix/qt/widget/progress-bar.cpp +++ /dev/null @@ -1,26 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - qtProgressBar->setValue(position); -} - -void pProgressBar::constructor() { - qtWidget = qtProgressBar = new QProgressBar; - qtProgressBar->setRange(0, 100); - qtProgressBar->setTextVisible(false); - - pWidget::synchronizeState(); - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - delete qtProgressBar; - qtWidget = qtProgressBar = 0; -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/qt/widget/radio-box.cpp b/kaijuu/phoenix/qt/widget/radio-box.cpp deleted file mode 100644 index bf640fd2..00000000 --- a/kaijuu/phoenix/qt/widget/radio-box.cpp +++ /dev/null @@ -1,64 +0,0 @@ -bool pRadioBox::checked() { - return qtRadioBox->isChecked(); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), radioBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pRadioBox::setChecked() { - locked = true; - for(auto &item : radioBox.state.group) { - bool checkState = item.p.qtRadioBox == qtRadioBox; - item.state.checked = checkState; - item.p.qtRadioBox->setChecked(checkState); - } - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - locked = true; - if(qtGroup) { - delete qtGroup; - qtGroup = 0; - } - if(group.size() > 0 && qtRadioBox == group[0].p.qtRadioBox) { - qtGroup = new QButtonGroup; - for(auto &item : group) qtGroup->addButton(item.p.qtRadioBox); - setChecked(); - } - locked = false; -} - -void pRadioBox::setText(const string &text) { - qtRadioBox->setText(QString::fromUtf8(text)); -} - -void pRadioBox::constructor() { - qtWidget = qtRadioBox = new QRadioButton; - qtGroup = new QButtonGroup; - qtGroup->addButton(qtRadioBox); - qtRadioBox->setChecked(true); - connect(qtRadioBox, SIGNAL(toggled(bool)), SLOT(onActivate())); - - pWidget::synchronizeState(); - setGroup(radioBox.state.group); - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - delete qtGroup; - delete qtRadioBox; - qtWidget = qtRadioBox = 0; - qtGroup = 0; -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} - -void pRadioBox::onActivate() { - if(locked == false && checked() && radioBox.onActivate) radioBox.onActivate(); -} diff --git a/kaijuu/phoenix/qt/widget/text-edit.cpp b/kaijuu/phoenix/qt/widget/text-edit.cpp deleted file mode 100644 index 8cdbe573..00000000 --- a/kaijuu/phoenix/qt/widget/text-edit.cpp +++ /dev/null @@ -1,50 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - QTextCursor cursor = qtTextEdit->textCursor(); - unsigned lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData()); - cursor.setPosition(min(position, lastCharacter)); - qtTextEdit->setTextCursor(cursor); -} - -void pTextEdit::setEditable(bool editable) { - qtTextEdit->setReadOnly(!editable); -} - -void pTextEdit::setText(const string &text) { - qtTextEdit->setPlainText(QString::fromUtf8(text)); -} - -void pTextEdit::setWordWrap(bool wordWrap) { - qtTextEdit->setWordWrapMode(wordWrap ? QTextOption::WordWrap : QTextOption::NoWrap); - qtTextEdit->setHorizontalScrollBarPolicy(wordWrap ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn); - qtTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); -} - -string pTextEdit::text() { - return qtTextEdit->toPlainText().toUtf8().constData(); -} - -void pTextEdit::constructor() { - qtWidget = qtTextEdit = new QTextEdit; - connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - if(sizable.state.layout) sizable.state.layout->remove(textEdit); - delete qtTextEdit; - qtWidget = qtTextEdit = 0; -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} - -void pTextEdit::onChange() { - textEdit.state.text = text(); - if(textEdit.onChange) textEdit.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/vertical-scroll-bar.cpp b/kaijuu/phoenix/qt/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 74d68ca6..00000000 --- a/kaijuu/phoenix/qt/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 15, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return qtScrollBar->value(); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pVerticalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Vertical); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pVerticalScrollBar::onChange() { - verticalScrollBar.state.position = position(); - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/vertical-slider.cpp b/kaijuu/phoenix/qt/widget/vertical-slider.cpp deleted file mode 100644 index 500adb07..00000000 --- a/kaijuu/phoenix/qt/widget/vertical-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return qtSlider->value(); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pVerticalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Vertical); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} - -void pVerticalSlider::onChange() { - verticalSlider.state.position = position(); - if(verticalSlider.onChange) verticalSlider.onChange(); -} diff --git a/kaijuu/phoenix/qt/widget/viewport.cpp b/kaijuu/phoenix/qt/widget/viewport.cpp deleted file mode 100644 index 1b67d776..00000000 --- a/kaijuu/phoenix/qt/widget/viewport.cpp +++ /dev/null @@ -1,51 +0,0 @@ -uintptr_t pViewport::handle() { - return (uintptr_t)qtViewport->winId(); -} - -void pViewport::constructor() { - qtWidget = qtViewport = new QtViewport(*this); - qtViewport->setMouseTracking(true); - qtViewport->setAttribute(Qt::WA_PaintOnScreen, true); - qtViewport->setStyleSheet("background: #000000"); - - pWidget::synchronizeState(); -} - -void pViewport::destructor() { - delete qtViewport; - qtWidget = qtViewport = nullptr; -} - -void pViewport::orphan() { - destructor(); - constructor(); -} - -void pViewport::QtViewport::leaveEvent(QEvent *event) { - if(self.viewport.onMouseLeave) self.viewport.onMouseLeave(); -} - -void pViewport::QtViewport::mouseMoveEvent(QMouseEvent *event) { - if(self.viewport.onMouseMove) self.viewport.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pViewport::QtViewport::mousePressEvent(QMouseEvent *event) { - if(self.viewport.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMousePress(Mouse::Button::Right); break; - } -} - -void pViewport::QtViewport::mouseReleaseEvent(QMouseEvent *event) { - if(self.viewport.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMouseRelease(Mouse::Button::Right); break; - } -} - -pViewport::QtViewport::QtViewport(pViewport &self) : self(self) { -} diff --git a/kaijuu/phoenix/qt/widget/widget.cpp b/kaijuu/phoenix/qt/widget/widget.cpp deleted file mode 100644 index 0bc4901c..00000000 --- a/kaijuu/phoenix/qt/widget/widget.cpp +++ /dev/null @@ -1,52 +0,0 @@ -Geometry pWidget::minimumGeometry() { - return { 0, 0, 0, 0 }; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - qtWidget->setEnabled(enabled); -} - -void pWidget::setFocused() { - qtWidget->setFocus(Qt::OtherFocusReason); -} - -void pWidget::setFont(const string &font) { - qtWidget->setFont(pFont::create(font)); -} - -void pWidget::setGeometry(const Geometry &geometry) { - qtWidget->setGeometry(geometry.x, geometry.y, geometry.width, geometry.height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout == 0) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - qtWidget->setVisible(visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) qtWidget = new QWidget; -} - -//pWidget::constructor() called before p{Derived}::constructor(); ergo qtWidget is not yet valid -//pWidget::synchronizeState() is called to finish construction of p{Derived}::constructor() -void pWidget::synchronizeState() { - setEnabled(widget.state.enabled); - setFont(widget.state.font); -//setVisible(widget.state.visible); -} - -void pWidget::destructor() { - if(widget.state.abstract) { - delete qtWidget; - qtWidget = 0; - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/qt/window.cpp b/kaijuu/phoenix/qt/window.cpp deleted file mode 100644 index c6cb35d6..00000000 --- a/kaijuu/phoenix/qt/window.cpp +++ /dev/null @@ -1,288 +0,0 @@ -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = window.state.geometry; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - qtMenu->addMenu(menu.p.qtMenu); -} - -void pWindow::append(Widget &widget) { - if(widget.state.font == "") { - if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - } - widget.p.qtWidget->setParent(qtContainer); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - QColor color = qtWindow->palette().color(QPalette::ColorRole::Window); - return { (uint8_t)color.red(), (uint8_t)color.green(), (uint8_t)color.blue(), (uint8_t)color.alpha() }; -} - -Geometry pWindow::frameMargin() { - unsigned menuHeight = window.state.menuVisible ? settings->menuGeometryHeight : 0; - unsigned statusHeight = window.state.statusVisible ? settings->statusGeometryHeight : 0; - if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight }; - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight, - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight + statusHeight - }; -} - -bool pWindow::focused() { - return qtWindow->isActiveWindow() && !qtWindow->isMinimized(); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen) { - unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; - unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; - return { 0, menuHeight, Desktop::size().width, Desktop::size().height - menuHeight - statusHeight }; - } - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - //QMenuBar::removeMenu() does not exist - qtMenu->clear(); - for(auto &menu : window.state.menu) append(menu); -} - -void pWindow::remove(Widget &widget) { - //bugfix: orphan() destroys and recreates widgets (to disassociate them from their parent); - //attempting to create widget again after QApplication::quit() crashes libQtGui - if(qtApplication) widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - QPalette palette; - palette.setColor(QPalette::Window, QColor(color.red, color.green, color.blue, color.alpha)); - qtContainer->setPalette(palette); - qtContainer->setAutoFillBackground(true); - qtWindow->setAttribute(Qt::WA_TranslucentBackground, color.alpha != 255); -} - -void pWindow::setFocused() { - qtWindow->raise(); - qtWindow->activateWindow(); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - setResizable(window.state.resizable); - qtWindow->showNormal(); - qtWindow->adjustSize(); - } else { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setFixedSize(Desktop::size().width - frameMargin().width, Desktop::size().height - frameMargin().height); - qtWindow->showFullScreen(); - } -} - -void pWindow::setGeometry(const Geometry &geometry_) { - locked = true; - OS::processEvents(); - QApplication::syncX(); - Geometry geometry = geometry_, margin = frameMargin(); - - setResizable(window.state.resizable); - qtWindow->move(geometry.x - frameMargin().x, geometry.y - frameMargin().y); - //qtWindow->adjustSize() fails if larger than 2/3rds screen size - qtWindow->resize(qtWindow->sizeHint()); - qtWindow->setMinimumSize(1, 1); - qtContainer->setMinimumSize(1, 1); - - for(auto &layout : window.state.layout) { - geometry = geometry_; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - qtMenu->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setModal(bool modal) { - qtWindow->setWindowModality(modal ? Qt::ApplicationModal : Qt::NonModal); -} - -void pWindow::setResizable(bool resizable) { - if(resizable) { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setMinimumSize(window.state.geometry.width, window.state.geometry.height); - } else { - qtLayout->setSizeConstraint(QLayout::SetFixedSize); - qtContainer->setFixedSize(window.state.geometry.width, window.state.geometry.height); - } - qtStatus->setSizeGripEnabled(resizable); -} - -void pWindow::setStatusFont(const string &font) { - qtStatus->setFont(pFont::create(font)); -} - -void pWindow::setStatusText(const string &text) { - qtStatus->showMessage(QString::fromUtf8(text), 0); -} - -void pWindow::setStatusVisible(bool visible) { - qtStatus->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setTitle(const string &text) { - qtWindow->setWindowTitle(QString::fromUtf8(text)); -} - -void pWindow::setVisible(bool visible) { - locked = true; - qtWindow->setVisible(visible); - if(visible) { - updateFrameGeometry(); - setGeometry(window.state.geometry); - } - locked = false; -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(!item.state.font) item.setFont(font); - } -} - -void pWindow::constructor() { - qtWindow = new QtWindow(*this); - qtWindow->setWindowTitle(" "); - - qtLayout = new QVBoxLayout(qtWindow); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtWindow->setLayout(qtLayout); - - qtMenu = new QMenuBar(qtWindow); - qtMenu->setVisible(false); - qtLayout->addWidget(qtMenu); - - qtContainer = new QWidget(qtWindow); - qtContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - qtContainer->setVisible(true); - qtLayout->addWidget(qtContainer); - - qtStatus = new QStatusBar(qtWindow); - qtStatus->setSizeGripEnabled(true); - qtStatus->setVisible(false); - qtLayout->addWidget(qtStatus); - - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); -} - -void pWindow::destructor() { - delete qtStatus; - delete qtContainer; - delete qtMenu; - delete qtLayout; - delete qtWindow; -} - -void pWindow::updateFrameGeometry() { - pOS::syncX(); - QRect border = qtWindow->frameGeometry(); - QRect client = qtWindow->geometry(); - - settings->frameGeometryX = client.x() - border.x(); - settings->frameGeometryY = client.y() - border.y(); - settings->frameGeometryWidth = border.width() - client.width(); - settings->frameGeometryHeight = border.height() - client.height(); - - if(window.state.menuVisible) { - pOS::syncX(); - settings->menuGeometryHeight = qtMenu->height(); - } - - if(window.state.statusVisible) { - pOS::syncX(); - settings->statusGeometryHeight = qtStatus->height(); - } - - settings->save(); -} - -void pWindow::QtWindow::closeEvent(QCloseEvent *event) { - self.window.state.ignore = false; - event->ignore(); - if(self.window.onClose) self.window.onClose(); - if(self.window.state.ignore == false) hide(); -} - -void pWindow::QtWindow::moveEvent(QMoveEvent *event) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.x += event->pos().x() - event->oldPos().x(); - self.window.state.geometry.y += event->pos().y() - event->oldPos().y(); - } - - if(self.locked == false) { - if(self.window.onMove) self.window.onMove(); - } -} - -void pWindow::QtWindow::keyPressEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym); -} - -void pWindow::QtWindow::keyReleaseEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym); -} - -void pWindow::QtWindow::resizeEvent(QResizeEvent*) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.width = self.qtContainer->geometry().width(); - self.window.state.geometry.height = self.qtContainer->geometry().height(); - } - - for(auto &layout : self.window.state.layout) { - Geometry geometry = self.geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(self.locked == false) { - if(self.window.onSize) self.window.onSize(); - } -} - -QSize pWindow::QtWindow::sizeHint() const { - unsigned width = self.window.state.geometry.width; - unsigned height = self.window.state.geometry.height; - if(self.window.state.menuVisible) height += settings->menuGeometryHeight; - if(self.window.state.statusVisible) height += settings->statusGeometryHeight; - return QSize(width, height); -} diff --git a/kaijuu/phoenix/reference/action/action.cpp b/kaijuu/phoenix/reference/action/action.cpp deleted file mode 100644 index 0bc6bc3f..00000000 --- a/kaijuu/phoenix/reference/action/action.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pAction::setEnabled(bool enabled) { -} - -void pAction::setVisible(bool visible) { -} - -void pAction::constructor() { -} diff --git a/kaijuu/phoenix/reference/action/check-item.cpp b/kaijuu/phoenix/reference/action/check-item.cpp deleted file mode 100644 index 26970fc8..00000000 --- a/kaijuu/phoenix/reference/action/check-item.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pCheckItem::checked() { - return false; -} - -void pCheckItem::setChecked(bool checked) { -} - -void pCheckItem::setText(const string &text) { -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { -} diff --git a/kaijuu/phoenix/reference/action/item.cpp b/kaijuu/phoenix/reference/action/item.cpp deleted file mode 100644 index 438ed32f..00000000 --- a/kaijuu/phoenix/reference/action/item.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pItem::setImage(const image &image) { -} - -void pItem::setText(const string &text) { -} - -void pItem::constructor() { -} - -void pItem::destructor() { -} diff --git a/kaijuu/phoenix/reference/action/menu.cpp b/kaijuu/phoenix/reference/action/menu.cpp deleted file mode 100644 index 4f0a65a8..00000000 --- a/kaijuu/phoenix/reference/action/menu.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pMenu::append(Action &action) { -} - -void pMenu::remove(Action &action) { -} - -void pMenu::setImage(const image &image) { -} - -void pMenu::setText(const string &text) { -} - -void pMenu::constructor() { -} - -void pMenu::destructor() { -} diff --git a/kaijuu/phoenix/reference/action/radio-item.cpp b/kaijuu/phoenix/reference/action/radio-item.cpp deleted file mode 100644 index e87a4deb..00000000 --- a/kaijuu/phoenix/reference/action/radio-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pRadioItem::checked() { - return false; -} - -void pRadioItem::setChecked() { -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { -} diff --git a/kaijuu/phoenix/reference/action/separator.cpp b/kaijuu/phoenix/reference/action/separator.cpp deleted file mode 100644 index 24a45c04..00000000 --- a/kaijuu/phoenix/reference/action/separator.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { -} diff --git a/kaijuu/phoenix/reference/desktop.cpp b/kaijuu/phoenix/reference/desktop.cpp deleted file mode 100644 index a96eb1f0..00000000 --- a/kaijuu/phoenix/reference/desktop.cpp +++ /dev/null @@ -1,8 +0,0 @@ -Size pDesktop::size() { - return { 0, 0 }; -} - -Geometry pDesktop::workspace() { - return { 0, 0, 0, 0 }; -} - diff --git a/kaijuu/phoenix/reference/dialog-window.cpp b/kaijuu/phoenix/reference/dialog-window.cpp deleted file mode 100644 index c7d089ae..00000000 --- a/kaijuu/phoenix/reference/dialog-window.cpp +++ /dev/null @@ -1,11 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - return ""; -} diff --git a/kaijuu/phoenix/reference/font.cpp b/kaijuu/phoenix/reference/font.cpp deleted file mode 100644 index bfda5c06..00000000 --- a/kaijuu/phoenix/reference/font.cpp +++ /dev/null @@ -1,3 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return { 0, 0, 0, 0 }; -} diff --git a/kaijuu/phoenix/reference/keyboard.cpp b/kaijuu/phoenix/reference/keyboard.cpp deleted file mode 100644 index 40b3a1a7..00000000 --- a/kaijuu/phoenix/reference/keyboard.cpp +++ /dev/null @@ -1,10 +0,0 @@ -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return false; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - return output; -} diff --git a/kaijuu/phoenix/reference/message-window.cpp b/kaijuu/phoenix/reference/message-window.cpp deleted file mode 100644 index 84a287f5..00000000 --- a/kaijuu/phoenix/reference/message-window.cpp +++ /dev/null @@ -1,15 +0,0 @@ -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} diff --git a/kaijuu/phoenix/reference/mouse.cpp b/kaijuu/phoenix/reference/mouse.cpp deleted file mode 100644 index f103a15a..00000000 --- a/kaijuu/phoenix/reference/mouse.cpp +++ /dev/null @@ -1,7 +0,0 @@ -Position pMouse::position() { - return { 0, 0 }; -} - -bool pMouse::pressed(Mouse::Button button) { - return false; -} diff --git a/kaijuu/phoenix/reference/platform.cpp b/kaijuu/phoenix/reference/platform.cpp deleted file mode 100644 index e64f7eab..00000000 --- a/kaijuu/phoenix/reference/platform.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "platform.hpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -void pOS::main() { -} - -bool pOS::pendingEvents() { - return false; -} - -void pOS::processEvents() { -} - -void pOS::quit() { -} - -void pOS::initialize() { -} diff --git a/kaijuu/phoenix/reference/platform.hpp b/kaijuu/phoenix/reference/platform.hpp deleted file mode 100644 index 5ffb5b60..00000000 --- a/kaijuu/phoenix/reference/platform.hpp +++ /dev/null @@ -1,381 +0,0 @@ -struct pFont; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(locked) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - - bool enabled(); - Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); -}; - -struct pButton : public pWidget { - Button &button; - - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); -}; - -struct pLabel : public pWidget { - Label &label; - - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); -}; - -struct pListView : public pWidget { - ListView &listView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); -}; diff --git a/kaijuu/phoenix/reference/timer.cpp b/kaijuu/phoenix/reference/timer.cpp deleted file mode 100644 index 6cbe571a..00000000 --- a/kaijuu/phoenix/reference/timer.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pTimer::setEnabled(bool enabled) { -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/button.cpp b/kaijuu/phoenix/reference/widget/button.cpp deleted file mode 100644 index fc06c371..00000000 --- a/kaijuu/phoenix/reference/widget/button.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pButton::setImage(const image &image, Orientation orientation) { -} - -void pButton::setText(const string &text) { -} - -void pButton::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/canvas.cpp b/kaijuu/phoenix/reference/widget/canvas.cpp deleted file mode 100644 index 953cfa77..00000000 --- a/kaijuu/phoenix/reference/widget/canvas.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pCanvas::setSize(const Size &size) { -} - -void pCanvas::update() { -} - -void pCanvas::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/check-box.cpp b/kaijuu/phoenix/reference/widget/check-box.cpp deleted file mode 100644 index c5aec216..00000000 --- a/kaijuu/phoenix/reference/widget/check-box.cpp +++ /dev/null @@ -1,12 +0,0 @@ -bool pCheckBox::checked() { - return false; -} - -void pCheckBox::setChecked(bool checked) { -} - -void pCheckBox::setText(const string &text) { -} - -void pCheckBox::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/combo-box.cpp b/kaijuu/phoenix/reference/widget/combo-box.cpp deleted file mode 100644 index 297d7369..00000000 --- a/kaijuu/phoenix/reference/widget/combo-box.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pComboBox::append(const string &text) { -} - -void pComboBox::modify(unsigned row, const string &text) { -} - -void pComboBox::remove(unsigned row) { -} - -void pComboBox::reset() { -} - -unsigned pComboBox::selection() { - return 0; -} - -void pComboBox::setSelection(unsigned row) { -} - -void pComboBox::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/hex-edit.cpp b/kaijuu/phoenix/reference/widget/hex-edit.cpp deleted file mode 100644 index 40bf9f5d..00000000 --- a/kaijuu/phoenix/reference/widget/hex-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { -} - -void pHexEdit::setLength(unsigned length) { -} - -void pHexEdit::setOffset(unsigned offset) { -} - -void pHexEdit::setRows(unsigned rows) { -} - -void pHexEdit::update() { -} - -void pHexEdit::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/horizontal-scroll-bar.cpp b/kaijuu/phoenix/reference/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 352b3393..00000000 --- a/kaijuu/phoenix/reference/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalScrollBar::position() { - return 0; -} - -void pHorizontalScrollBar::setLength(unsigned length) { -} - -void pHorizontalScrollBar::setPosition(unsigned position) { -} - -void pHorizontalScrollBar::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/horizontal-slider.cpp b/kaijuu/phoenix/reference/widget/horizontal-slider.cpp deleted file mode 100644 index 0a4a8392..00000000 --- a/kaijuu/phoenix/reference/widget/horizontal-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalSlider::position() { - return 0; -} - -void pHorizontalSlider::setLength(unsigned length) { -} - -void pHorizontalSlider::setPosition(unsigned position) { -} - -void pHorizontalSlider::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/label.cpp b/kaijuu/phoenix/reference/widget/label.cpp deleted file mode 100644 index 25600d2a..00000000 --- a/kaijuu/phoenix/reference/widget/label.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pLabel::setText(const string &text) { -} - -void pLabel::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/line-edit.cpp b/kaijuu/phoenix/reference/widget/line-edit.cpp deleted file mode 100644 index 96b9ac6c..00000000 --- a/kaijuu/phoenix/reference/widget/line-edit.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pLineEdit::setEditable(bool editable) { -} - -void pLineEdit::setText(const string &text) { -} - -string pLineEdit::text() { -} - -void pLineEdit::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/list-view.cpp b/kaijuu/phoenix/reference/widget/list-view.cpp deleted file mode 100644 index 6e90e0a3..00000000 --- a/kaijuu/phoenix/reference/widget/list-view.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pListView::append(const lstring &text) { -} - -void pListView::autoSizeColumns() { -} - -bool pListView::checked(unsigned row) { -} - -void pListView::modify(unsigned row, const lstring &text) { -} - -void pListView::remove(unsigned row) { -} - -void pListView::reset() { -} - -bool pListView::selected() { - return false; -} - -unsigned pListView::selection() { - return 0; -} - -void pListView::setCheckable(bool checkable) { -} - -void pListView::setChecked(unsigned row, bool checked) { -} - -void pListView::setHeaderText(const lstring &text) { -} - -void pListView::setHeaderVisible(bool visible) { -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { -} - -void pListView::setSelected(bool selected) { -} - -void pListView::setSelection(unsigned row) { -} - -void pListView::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/progress-bar.cpp b/kaijuu/phoenix/reference/widget/progress-bar.cpp deleted file mode 100644 index b4905a85..00000000 --- a/kaijuu/phoenix/reference/widget/progress-bar.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pProgressBar::setPosition(unsigned position) { -} - -void pProgressBar::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/radio-box.cpp b/kaijuu/phoenix/reference/widget/radio-box.cpp deleted file mode 100644 index f6aebcbe..00000000 --- a/kaijuu/phoenix/reference/widget/radio-box.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pRadioBox::checked() { - return false; -} - -void pRadioBox::setChecked() { -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { -} - -void pRadioBox::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/text-edit.cpp b/kaijuu/phoenix/reference/widget/text-edit.cpp deleted file mode 100644 index 74121b2d..00000000 --- a/kaijuu/phoenix/reference/widget/text-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { -} - -void pTextEdit::setEditable(bool editable) { -} - -void pTextEdit::setText(const string &text) { -} - -void pTextEdit::setWordWrap(bool wordWrap) { -} - -string pTextEdit::text() { -} - -void pTextEdit::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/vertical-scroll-bar.cpp b/kaijuu/phoenix/reference/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 26795248..00000000 --- a/kaijuu/phoenix/reference/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalScrollBar::position() { - return 0; -} - -void pVerticalScrollBar::setLength(unsigned length) { -} - -void pVerticalScrollBar::setPosition(unsigned position) { -} - -void pVerticalScrollBar::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/vertical-slider.cpp b/kaijuu/phoenix/reference/widget/vertical-slider.cpp deleted file mode 100644 index a6d8ae00..00000000 --- a/kaijuu/phoenix/reference/widget/vertical-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalSlider::position() { - return 0; -} - -void pVerticalSlider::setLength(unsigned length) { -} - -void pVerticalSlider::setPosition(unsigned position) { -} - -void pVerticalSlider::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/viewport.cpp b/kaijuu/phoenix/reference/widget/viewport.cpp deleted file mode 100644 index 9d398438..00000000 --- a/kaijuu/phoenix/reference/widget/viewport.cpp +++ /dev/null @@ -1,6 +0,0 @@ -uintptr_t pViewport::handle() { - return 0; -} - -void pViewport::constructor() { -} diff --git a/kaijuu/phoenix/reference/widget/widget.cpp b/kaijuu/phoenix/reference/widget/widget.cpp deleted file mode 100644 index 49a6c79e..00000000 --- a/kaijuu/phoenix/reference/widget/widget.cpp +++ /dev/null @@ -1,25 +0,0 @@ -bool pWidget::enabled() { - return false; -} - -Geometry pWidget::minimumGeometry() { - return { 0, 0, 0, 0 }; -} - -void pWidget::setEnabled(bool enabled) { -} - -void pWidget::setFocused() { -} - -void pWidget::setFont(const string &font) { -} - -void pWidget::setGeometry(const Geometry &geometry) { -} - -void pWidget::setVisible(bool visible) { -} - -void pWidget::constructor() { -} diff --git a/kaijuu/phoenix/reference/window.cpp b/kaijuu/phoenix/reference/window.cpp deleted file mode 100644 index 128a9c2d..00000000 --- a/kaijuu/phoenix/reference/window.cpp +++ /dev/null @@ -1,78 +0,0 @@ -void pWindow::append(Layout &layout) { -} - -void pWindow::append(Menu &menu) { -} - -void pWindow::append(Widget &widget) { -} - -Color pWindow::backgroundColor() { - return {0, 0, 0, 255}; -} - -bool pWindow::focused() { - return false; -} - -Geometry pWindow::frameMargin() { - return {0, 0, 0, 0}; -} - -Geometry pWindow::geometry() { - return {0, 0, 0, 0}; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { -} - -void pWindow::remove(Widget &widget) { -} - -void pWindow::setBackgroundColor(const Color &color) { -} - -void pWindow::setFocused() { -} - -void pWindow::setFullScreen(bool fullScreen) { -} - -void pWindow::setGeometry(const Geometry &geometry) { -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { -} - -void pWindow::setModal(bool modal) { -} - -void pWindow::setResizable(bool resizable) { -} - -void pWindow::setStatusFont(const string &font) { -} - -void pWindow::setStatusText(const string &text) { -} - -void pWindow::setStatusVisible(bool visible) { -} - -void pWindow::setTitle(const string &text) { -} - -void pWindow::setVisible(bool visible) { -} - -void pWindow::setWidgetFont(const string &font) { -} - -void pWindow::constructor() { -} diff --git a/kaijuu/phoenix/sync.sh b/kaijuu/phoenix/sync.sh deleted file mode 100644 index 40ee3d98..00000000 --- a/kaijuu/phoenix/sync.sh +++ /dev/null @@ -1,9 +0,0 @@ -synchronize() { - if [ -d ../"$1" ]; then - test -d "$1" && rm -r "$1" - cp -r ../"$1" ./"$1" - fi -} - -synchronize "nall" -rm -r nall/test diff --git a/kaijuu/phoenix/windows/action/action.cpp b/kaijuu/phoenix/windows/action/action.cpp deleted file mode 100644 index b80208d1..00000000 --- a/kaijuu/phoenix/windows/action/action.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::setVisible(bool visible) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::constructor() { - parentMenu = 0; - parentWindow = 0; -} diff --git a/kaijuu/phoenix/windows/action/check-item.cpp b/kaijuu/phoenix/windows/action/check-item.cpp deleted file mode 100644 index 195deabd..00000000 --- a/kaijuu/phoenix/windows/action/check-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pCheckItem::checked() { - return checkItem.state.checked; -} - -void pCheckItem::setChecked(bool checked) { - if(parentMenu) CheckMenuItem(parentMenu->p.hmenu, id, checked ? MF_CHECKED : MF_UNCHECKED); -} - -void pCheckItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { - if(parentMenu) parentMenu->remove(checkItem); -} diff --git a/kaijuu/phoenix/windows/action/item.cpp b/kaijuu/phoenix/windows/action/item.cpp deleted file mode 100644 index 2804bfcb..00000000 --- a/kaijuu/phoenix/windows/action/item.cpp +++ /dev/null @@ -1,29 +0,0 @@ -void pItem::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::constructor() { - createBitmap(); -} - -void pItem::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) parentMenu->remove(item); -} - -void pItem::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(item.state.image.width && item.state.image.height) { - nall::image nallImage = item.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} diff --git a/kaijuu/phoenix/windows/action/menu.cpp b/kaijuu/phoenix/windows/action/menu.cpp deleted file mode 100644 index 5d9da04e..00000000 --- a/kaijuu/phoenix/windows/action/menu.cpp +++ /dev/null @@ -1,109 +0,0 @@ -void pMenu::append(Action &action) { - action.p.parentMenu = &menu; - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::remove(Action &action) { - if(parentWindow) parentWindow->p.updateMenu(); - action.p.parentMenu = 0; -} - -void pMenu::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::constructor() { - hmenu = 0; - createBitmap(); -} - -void pMenu::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) { - parentMenu->remove(menu); - } else if(parentWindow) { - //belongs to window's main menubar - parentWindow->remove(menu); - } -} - -void pMenu::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(menu.state.image.width && menu.state.image.height) { - nall::image nallImage = menu.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} - -//Windows actions lack the ability to toggle visibility. -//To support this, menus must be destroyed and recreated when toggling any action's visibility. -void pMenu::update(Window &parentWindow, Menu *parentMenu) { - this->parentMenu = parentMenu; - this->parentWindow = &parentWindow; - - if(hmenu) DestroyMenu(hmenu); - hmenu = CreatePopupMenu(); - - for(auto &action : menu.state.action) { - action.p.parentMenu = &menu; - action.p.parentWindow = &parentWindow; - - unsigned enabled = action.state.enabled ? 0 : MF_GRAYED; - if(dynamic_cast(&action)) { - Menu &item = (Menu&)action; - if(action.state.visible) { - item.p.update(parentWindow, &menu); - AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, (UINT_PTR)item.p.hmenu, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - Separator &item = (Separator&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L""); - } - } else if(dynamic_cast(&action)) { - Item &item = (Item&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, item.p.id, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - CheckItem &item = (CheckItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } else if(dynamic_cast(&action)) { - RadioItem &item = (RadioItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } - } -} diff --git a/kaijuu/phoenix/windows/action/radio-item.cpp b/kaijuu/phoenix/windows/action/radio-item.cpp deleted file mode 100644 index 6b4f3a31..00000000 --- a/kaijuu/phoenix/windows/action/radio-item.cpp +++ /dev/null @@ -1,26 +0,0 @@ -bool pRadioItem::checked() { - return radioItem.state.checked; -} - -void pRadioItem::setChecked() { - for(auto &item : radioItem.state.group) { - //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi - //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) - //to check id, we use: lo == hi == id (only ID, but in range) - if(item.p.parentMenu) CheckMenuRadioItem(item.p.parentMenu->p.hmenu, item.p.id, item.p.id, item.p.id + (id != item.p.id), MF_BYCOMMAND); - } -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { - if(parentMenu) parentMenu->remove(radioItem); -} diff --git a/kaijuu/phoenix/windows/action/separator.cpp b/kaijuu/phoenix/windows/action/separator.cpp deleted file mode 100644 index fac38eca..00000000 --- a/kaijuu/phoenix/windows/action/separator.cpp +++ /dev/null @@ -1,6 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { - if(parentMenu) parentMenu->remove(separator); -} diff --git a/kaijuu/phoenix/windows/desktop.cpp b/kaijuu/phoenix/windows/desktop.cpp deleted file mode 100644 index 956ba521..00000000 --- a/kaijuu/phoenix/windows/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - return { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) }; -} - -Geometry pDesktop::workspace() { - RECT rc; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top }; -} diff --git a/kaijuu/phoenix/windows/dialog-window.cpp b/kaijuu/phoenix/windows/dialog-window.cpp deleted file mode 100644 index 3005c020..00000000 --- a/kaijuu/phoenix/windows/dialog-window.cpp +++ /dev/null @@ -1,88 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string dir = path; - dir.replace("/", "\\"); - - string filterList; - for(auto &filterItem : filter) { - lstring part; - part.split("(", filterItem); - if(part.size() != 2) continue; - part[1].rtrim<1>(")"); - part[1].replace(" ", ""); - part[1].transform(",", ";"); - filterList.append(string(filterItem, "\t", part[1], "\t")); - } - - utf16_t wfilter(filterList); - utf16_t wdir(dir); - wchar_t wfilename[PATH_MAX + 1] = L""; - - wchar_t *p = wfilter; - while(*p != L'\0') { - if(*p == L'\t') *p = L'\0'; - p++; - } - - if(path.empty() == false) { - //clear COMDLG32 MRU (most recently used) file list - //this is required in order for lpstrInitialDir to be honored in Windows 7 and above - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/LastVisitedPidlMRU/"); - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/OpenSavePidlMRU/"); - } - - OPENFILENAME ofn; - memset(&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - ofn.lpstrFilter = wfilter; - ofn.lpstrInitialDir = wdir; - ofn.lpstrFile = wfilename; - ofn.nMaxFile = PATH_MAX; - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - ofn.lpstrDefExt = L""; - - bool result = (save == false ? GetOpenFileName(&ofn) : GetSaveFileName(&ofn)); - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - name.transform("\\", "/"); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(false, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(true, parent, path, filter); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - wchar_t wfilename[PATH_MAX + 1] = L""; - BROWSEINFO bi; - bi.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - bi.pidlRoot = NULL; - bi.pszDisplayName = wfilename; - bi.lpszTitle = L""; - bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS; - bi.lpfn = NULL; - bi.lParam = 0; - bi.iImage = 0; - bool result = false; - LPITEMIDLIST pidl = SHBrowseForFolder(&bi); - if(pidl) { - if(SHGetPathFromIDList(pidl, wfilename)) { - result = true; - IMalloc *imalloc = 0; - if(SUCCEEDED(SHGetMalloc(&imalloc))) { - imalloc->Free(pidl); - imalloc->Release(); - } - } - } - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - if(name == "") return ""; - name.transform("\\", "/"); - if(name.endswith("/") == false) name.append("/"); - return name; -} \ No newline at end of file diff --git a/kaijuu/phoenix/windows/font.cpp b/kaijuu/phoenix/windows/font.cpp deleted file mode 100644 index de42f24d..00000000 --- a/kaijuu/phoenix/windows/font.cpp +++ /dev/null @@ -1,44 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - HFONT hfont = pFont::create(description); - Geometry geometry = pFont::geometry(hfont, text); - pFont::free(hfont); - return geometry; -} - -HFONT pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - return CreateFont( - -(size * 96.0 / 72.0 + 0.5), - 0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, 0, 0, 0, 0, 0, 0, 0, - utf16_t(family) - ); -} - -void pFont::free(HFONT hfont) { - DeleteObject(hfont); -} - -Geometry pFont::geometry(HFONT hfont, const string &text_) { - //temporary fix: empty text string returns height of zero; bad for eg Button height - string text = (text_ == "" ? " " : text_); - - HDC hdc = GetDC(0); - SelectObject(hdc, hfont); - RECT rc = { 0, 0, 0, 0 }; - DrawText(hdc, utf16_t(text), -1, &rc, DT_CALCRECT); - ReleaseDC(0, hdc); - return { 0, 0, rc.right, rc.bottom }; -} diff --git a/kaijuu/phoenix/windows/keyboard.cpp b/kaijuu/phoenix/windows/keyboard.cpp deleted file mode 100644 index 1edffcb3..00000000 --- a/kaijuu/phoenix/windows/keyboard.cpp +++ /dev/null @@ -1,137 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, keysym); - }; - - append(Keyboard::Scancode::Escape, VK_ESCAPE); - append(Keyboard::Scancode::F1, VK_F1); - append(Keyboard::Scancode::F2, VK_F2); - append(Keyboard::Scancode::F3, VK_F3); - append(Keyboard::Scancode::F4, VK_F4); - append(Keyboard::Scancode::F5, VK_F5); - append(Keyboard::Scancode::F6, VK_F6); - append(Keyboard::Scancode::F7, VK_F7); - append(Keyboard::Scancode::F8, VK_F8); - append(Keyboard::Scancode::F9, VK_F9); - append(Keyboard::Scancode::F10, VK_F10); - append(Keyboard::Scancode::F11, VK_F11); - append(Keyboard::Scancode::F12, VK_F12); - - append(Keyboard::Scancode::PrintScreen, VK_SNAPSHOT); - append(Keyboard::Scancode::ScrollLock, VK_SCROLL); - append(Keyboard::Scancode::Pause, VK_PAUSE); - - append(Keyboard::Scancode::Insert, VK_INSERT); - append(Keyboard::Scancode::Delete, VK_DELETE); - append(Keyboard::Scancode::Home, VK_HOME); - append(Keyboard::Scancode::End, VK_END); - append(Keyboard::Scancode::PageUp, VK_PRIOR); - append(Keyboard::Scancode::PageDown, VK_NEXT); - - append(Keyboard::Scancode::Up, VK_UP); - append(Keyboard::Scancode::Down, VK_DOWN); - append(Keyboard::Scancode::Left, VK_LEFT); - append(Keyboard::Scancode::Right, VK_RIGHT); - - append(Keyboard::Scancode::Grave, VK_OEM_3); - append(Keyboard::Scancode::Number1, '1'); - append(Keyboard::Scancode::Number2, '2'); - append(Keyboard::Scancode::Number3, '3'); - append(Keyboard::Scancode::Number4, '4'); - append(Keyboard::Scancode::Number5, '5'); - append(Keyboard::Scancode::Number6, '6'); - append(Keyboard::Scancode::Number7, '7'); - append(Keyboard::Scancode::Number8, '8'); - append(Keyboard::Scancode::Number9, '9'); - append(Keyboard::Scancode::Number0, '0'); - append(Keyboard::Scancode::Minus, VK_OEM_MINUS); - append(Keyboard::Scancode::Equal, VK_OEM_PLUS); - append(Keyboard::Scancode::Backspace, VK_BACK); - - append(Keyboard::Scancode::BracketLeft, VK_OEM_4); - append(Keyboard::Scancode::BracketRight, VK_OEM_6); - append(Keyboard::Scancode::Backslash, VK_OEM_5); - append(Keyboard::Scancode::Semicolon, VK_OEM_1); - append(Keyboard::Scancode::Apostrophe, VK_OEM_7); - append(Keyboard::Scancode::Comma, VK_OEM_COMMA); - append(Keyboard::Scancode::Period, VK_OEM_PERIOD); - append(Keyboard::Scancode::Slash, VK_OEM_2); - - append(Keyboard::Scancode::Tab, VK_TAB); - append(Keyboard::Scancode::CapsLock, VK_CAPITAL); - append(Keyboard::Scancode::Return, VK_RETURN); - append(Keyboard::Scancode::ShiftLeft, VK_LSHIFT); - append(Keyboard::Scancode::ShiftRight, VK_RSHIFT); - append(Keyboard::Scancode::ControlLeft, VK_LCONTROL); - append(Keyboard::Scancode::ControlRight, VK_RCONTROL); - append(Keyboard::Scancode::SuperLeft, VK_LWIN); - append(Keyboard::Scancode::SuperRight, VK_RWIN); - append(Keyboard::Scancode::AltLeft, VK_LMENU); - append(Keyboard::Scancode::AltRight, VK_RMENU); - append(Keyboard::Scancode::Space, VK_SPACE); - append(Keyboard::Scancode::Menu, VK_APPS); - - append(Keyboard::Scancode::A, 'A'); - append(Keyboard::Scancode::B, 'B'); - append(Keyboard::Scancode::C, 'C'); - append(Keyboard::Scancode::D, 'D'); - append(Keyboard::Scancode::E, 'E'); - append(Keyboard::Scancode::F, 'F'); - append(Keyboard::Scancode::G, 'G'); - append(Keyboard::Scancode::H, 'H'); - append(Keyboard::Scancode::I, 'I'); - append(Keyboard::Scancode::J, 'J'); - append(Keyboard::Scancode::K, 'K'); - append(Keyboard::Scancode::L, 'L'); - append(Keyboard::Scancode::M, 'M'); - append(Keyboard::Scancode::N, 'N'); - append(Keyboard::Scancode::O, 'O'); - append(Keyboard::Scancode::P, 'P'); - append(Keyboard::Scancode::Q, 'Q'); - append(Keyboard::Scancode::R, 'R'); - append(Keyboard::Scancode::S, 'S'); - append(Keyboard::Scancode::T, 'T'); - append(Keyboard::Scancode::U, 'U'); - append(Keyboard::Scancode::V, 'V'); - append(Keyboard::Scancode::W, 'W'); - append(Keyboard::Scancode::X, 'X'); - append(Keyboard::Scancode::Y, 'Y'); - append(Keyboard::Scancode::Z, 'Z'); - - append(Keyboard::Scancode::NumLock, VK_NUMLOCK); - append(Keyboard::Scancode::Divide, VK_DIVIDE); - append(Keyboard::Scancode::Multiply, VK_MULTIPLY); - append(Keyboard::Scancode::Subtract, VK_SUBTRACT); - append(Keyboard::Scancode::Add, VK_ADD); -//append(Keyboard::Scancode::Enter, ...); - append(Keyboard::Scancode::Point, VK_DECIMAL); - - append(Keyboard::Scancode::Keypad1, VK_NUMPAD1); - append(Keyboard::Scancode::Keypad2, VK_NUMPAD2); - append(Keyboard::Scancode::Keypad3, VK_NUMPAD3); - append(Keyboard::Scancode::Keypad4, VK_NUMPAD4); - append(Keyboard::Scancode::Keypad5, VK_NUMPAD5); - append(Keyboard::Scancode::Keypad6, VK_NUMPAD6); - append(Keyboard::Scancode::Keypad7, VK_NUMPAD7); - append(Keyboard::Scancode::Keypad8, VK_NUMPAD8); - append(Keyboard::Scancode::Keypad9, VK_NUMPAD9); - append(Keyboard::Scancode::Keypad0, VK_NUMPAD0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return GetAsyncKeyState(settings->keymap.lhs[scancode]) & 0x8000; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - for(auto &n : settings->keymap.rhs) { - if(GetAsyncKeyState(n.name) & 0x8000) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/kaijuu/phoenix/windows/message-window.cpp b/kaijuu/phoenix/windows/message-window.cpp deleted file mode 100644 index fca126f4..00000000 --- a/kaijuu/phoenix/windows/message-window.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, UINT response) { - if(response == IDOK) return MessageWindow::Response::Ok; - if(response == IDCANCEL) return MessageWindow::Response::Cancel; - if(response == IDYES) return MessageWindow::Response::Yes; - if(response == IDNO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONINFORMATION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONQUESTION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONWARNING; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONERROR; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} diff --git a/kaijuu/phoenix/windows/mouse.cpp b/kaijuu/phoenix/windows/mouse.cpp deleted file mode 100644 index e5004645..00000000 --- a/kaijuu/phoenix/windows/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - POINT point = { 0 }; - GetCursorPos(&point); - return { point.x, point.y }; -} - -bool pMouse::pressed(Mouse::Button button) { - switch(button) { - case Mouse::Button::Left: return GetAsyncKeyState(VK_LBUTTON) & 0x8000; - case Mouse::Button::Middle: return GetAsyncKeyState(VK_MBUTTON) & 0x8000; - case Mouse::Button::Right: return GetAsyncKeyState(VK_RBUTTON) & 0x8000; - } - return false; -} \ No newline at end of file diff --git a/kaijuu/phoenix/windows/object.cpp b/kaijuu/phoenix/windows/object.cpp deleted file mode 100644 index 78811d79..00000000 --- a/kaijuu/phoenix/windows/object.cpp +++ /dev/null @@ -1,13 +0,0 @@ -vector pObject::objects; - -pObject::pObject(Object &object) : object(object) { - static unsigned uniqueId = 100; - objects.append(this); - id = uniqueId++; - locked = false; -} - -pObject* pObject::find(unsigned id) { - for(auto &item : objects) if(item->id == id) return item; - return 0; -} diff --git a/kaijuu/phoenix/windows/phoenix.Manifest b/kaijuu/phoenix/windows/phoenix.Manifest deleted file mode 100644 index 45fbb4cd..00000000 --- a/kaijuu/phoenix/windows/phoenix.Manifest +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - true - - - diff --git a/kaijuu/phoenix/windows/phoenix.rc b/kaijuu/phoenix/windows/phoenix.rc deleted file mode 100644 index 89fb8dc2..00000000 --- a/kaijuu/phoenix/windows/phoenix.rc +++ /dev/null @@ -1 +0,0 @@ -1 24 "phoenix.Manifest" diff --git a/kaijuu/phoenix/windows/platform.cpp b/kaijuu/phoenix/windows/platform.cpp deleted file mode 100644 index 1214f2c2..00000000 --- a/kaijuu/phoenix/windows/platform.cpp +++ /dev/null @@ -1,479 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "object.cpp" -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -static bool OS_keyboardProc(HWND, UINT, WPARAM, LPARAM); -static void OS_processDialogMessage(MSG&); -static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM); - -void pOS::main() { - MSG msg; - while(GetMessage(&msg, 0, 0, 0)) { - OS_processDialogMessage(msg); - } -} - -bool pOS::pendingEvents() { - MSG msg; - return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); -} - -void pOS::processEvents() { - while(pendingEvents()) { - MSG msg; - if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { - OS_processDialogMessage(msg); - } - } -} - -void OS_processDialogMessage(MSG &msg) { - if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP - || msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) { - if(OS_keyboardProc(msg.hwnd, msg.message, msg.wParam, msg.lParam)) { - DispatchMessage(&msg); - return; - } - } - - if(!IsDialogMessage(GetForegroundWindow(), &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -void pOS::quit() { - osQuit = true; - PostQuitMessage(0); -} - -void pOS::initialize() { - CoInitialize(0); - InitCommonControls(); - - WNDCLASS wc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(2)); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = OS_windowProc; - wc.lpszClassName = L"phoenix_window"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Canvas_windowProc; - wc.lpszClassName = L"phoenix_canvas"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Label_windowProc; - wc.lpszClassName = L"phoenix_label"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Viewport_windowProc; - wc.lpszClassName = L"phoenix_viewport"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - settings = new Settings; - pKeyboard::initialize(); -} - -static bool OS_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - if(msg != WM_KEYDOWN && msg != WM_SYSKEYDOWN && msg != WM_KEYUP && msg != WM_SYSKEYUP) return false; - - GUITHREADINFO info; - memset(&info, 0, sizeof(GUITHREADINFO)); - info.cbSize = sizeof(GUITHREADINFO); - GetGUIThreadInfo(GetCurrentThreadId(), &info); - Object *object = (Object*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA); - if(object == nullptr) return false; - - if(dynamic_cast(object)) { - Window &window = (Window&)*object; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) return false; - Keyboard::Keycode keysym = Keysym(wparam, lparam); - if(keysym != Keyboard::Keycode::None) { - if((msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) && window.onKeyPress) window.onKeyPress(keysym); - if((msg == WM_KEYUP || msg == WM_SYSKEYUP) && window.onKeyRelease) window.onKeyRelease(keysym); - } - return false; - } - - if(msg == WM_KEYDOWN) { - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - if(wparam == VK_RETURN) { - if(listView.onActivate) listView.onActivate(); - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(wparam == VK_RETURN) { - if(lineEdit.onActivate) lineEdit.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(wparam == 'A' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+A = select all text - //note: this is not a standard accelerator on Windows - Edit_SetSel(textEdit.p.hwnd, 0, ~0); - return true; - } else if(wparam == 'V' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+V = paste text - //note: this formats Unix (LF) and OS9 (CR) line-endings to Windows (CR+LF) line-endings - //this is necessary as the EDIT control only supports Windows line-endings - OpenClipboard(hwnd); - HANDLE handle = GetClipboardData(CF_UNICODETEXT); - if(handle) { - wchar_t *text = (wchar_t*)GlobalLock(handle); - if(text) { - string data = (const char*)utf8_t(text); - data.replace("\r\n", "\n"); - data.replace("\r", "\n"); - data.replace("\n", "\r\n"); - GlobalUnlock(handle); - utf16_t output(data); - HGLOBAL resource = GlobalAlloc(GMEM_MOVEABLE, (wcslen(output) + 1) * sizeof(wchar_t)); - if(resource) { - wchar_t *write = (wchar_t*)GlobalLock(resource); - if(write) { - wcscpy(write, output); - GlobalUnlock(write); - if(SetClipboardData(CF_UNICODETEXT, resource) == FALSE) { - GlobalFree(resource); - } - } - } - } - } - CloseClipboard(); - return false; - } - } - } - - return false; -} - -static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!object || !dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Window &window = (Window&)*object; - - bool process = true; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) process = false; - if(osQuit) process = false; - - if(process) switch(msg) { - case WM_CLOSE: { - window.state.ignore = false; - if(window.onClose) window.onClose(); - if(window.state.ignore == false) { - window.setVisible(false); - window.setModal(false); - } - return TRUE; - } - - case WM_MOVE: { - if(window.p.locked) break; - - Geometry geometry = window.geometry(); - window.state.geometry.x = geometry.x; - window.state.geometry.y = geometry.y; - - if(window.onMove) window.onMove(); - break; - } - - case WM_SIZE: { - if(window.p.locked) break; - SetWindowPos(window.p.hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - - Geometry geometry = window.geometry(); - window.state.geometry.width = geometry.width; - window.state.geometry.height = geometry.height; - - for(auto &layout : window.state.layout) { - Geometry geom = window.geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - - if(window.onSize) window.onSize(); - break; - } - - case WM_GETMINMAXINFO: { - MINMAXINFO *mmi = (MINMAXINFO*)lparam; - //mmi->ptMinTrackSize.x = 256 + window.p.frameMargin().width; - //mmi->ptMinTrackSize.y = 256 + window.p.frameMargin().height; - //return TRUE; - break; - } - - case WM_ERASEBKGND: { - if(window.p.brush == 0) break; - RECT rc; - GetClientRect(window.p.hwnd, &rc); - PAINTSTRUCT ps; - BeginPaint(window.p.hwnd, &ps); - FillRect(ps.hdc, &rc, window.p.brush); - EndPaint(window.p.hwnd, &ps); - return TRUE; - } - - case WM_CTLCOLORBTN: - case WM_CTLCOLORSTATIC: { - Object *object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - if(object && window.p.brush) { - HDC hdc = (HDC)wparam; - SetBkColor((HDC)wparam, window.p.brushColor); - return (INT_PTR)window.p.brush; - } - break; - } - - case WM_COMMAND: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) { - pObject *object = (pObject*)pObject::find(id); - if(!object) break; - if(dynamic_cast(object)) { - Item &item = ((pItem*)object)->item; - if(item.onActivate) item.onActivate(); - } else if(dynamic_cast(object)) { - CheckItem &checkItem = ((pCheckItem*)object)->checkItem; - checkItem.setChecked(!checkItem.state.checked); - if(checkItem.onToggle) checkItem.onToggle(); - } else if(dynamic_cast(object)) { - RadioItem &radioItem = ((pRadioItem*)object)->radioItem; - if(radioItem.state.checked == false) { - radioItem.setChecked(); - if(radioItem.onActivate) radioItem.onActivate(); - } - } - } else { - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(!object) break; - if(dynamic_cast(object)) { - Button &button = (Button&)*object; - if(button.onActivate) button.onActivate(); - } else if(dynamic_cast(object)) { - CheckBox &checkBox = (CheckBox&)*object; - checkBox.setChecked(!checkBox.state.checked); - if(checkBox.onToggle) checkBox.onToggle(); - } else if(dynamic_cast(object)) { - ComboBox &comboBox = (ComboBox&)*object; - if(HIWORD(wparam) == CBN_SELCHANGE) { - if(comboBox.state.selection != comboBox.selection()) { - comboBox.state.selection = comboBox.selection(); - if(comboBox.onChange) comboBox.onChange(); - } - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(lineEdit.p.locked == false && lineEdit.onChange) lineEdit.onChange(); - } - } else if(dynamic_cast(object)) { - RadioBox &radioBox = (RadioBox&)*object; - if(radioBox.state.checked == false) { - radioBox.setChecked(); - if(radioBox.onActivate) radioBox.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(textEdit.p.locked == false && textEdit.onChange) textEdit.onChange(); - } - } - } - break; - } - - case WM_NOTIFY: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(object == 0) break; - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - LPNMHDR nmhdr = (LPNMHDR)lparam; - LPNMLISTVIEW nmlistview = (LPNMLISTVIEW)lparam; - - if(nmhdr->code == LVN_ITEMCHANGED && (nmlistview->uChanged & LVIF_STATE)) { - unsigned imagemask = ((nmlistview->uNewState & LVIS_STATEIMAGEMASK) >> 12) - 1; - if(imagemask == 0 || imagemask == 1) { - if(listView.p.locked == false && listView.onToggle) listView.onToggle(nmlistview->iItem); - } else if((nmlistview->uOldState & LVIS_FOCUSED) && !(nmlistview->uNewState & LVIS_FOCUSED)) { - listView.p.lostFocus = true; - } else if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) { - listView.p.lostFocus = false; - listView.state.selected = true; - listView.state.selection = listView.selection(); - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } else if(listView.p.lostFocus == false && listView.selected() == false) { - listView.p.lostFocus = false; - listView.state.selected = false; - listView.state.selection = 0; - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } - } else if(nmhdr->code == LVN_ITEMACTIVATE) { - if(listView.onActivate) listView.onActivate(); - } else if(nmhdr->code == NM_CUSTOMDRAW) { - LPNMLVCUSTOMDRAW lvcd = (LPNMLVCUSTOMDRAW)nmhdr; - switch(lvcd->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - return CDRF_NOTIFYITEMDRAW; - case CDDS_ITEMPREPAINT: - if(listView.state.headerText.size() >= 2) { - //draw alternating row colors of there are two or more columns - if(lvcd->nmcd.dwItemSpec % 2) lvcd->clrTextBk = GetSysColor(COLOR_WINDOW) ^ 0x070707; - } - return CDRF_DODEFAULT; - default: - return CDRF_DODEFAULT; - } - } - } - break; - } - - case WM_HSCROLL: - case WM_VSCROLL: { - Object *object = 0; - if(lparam) { - object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - } else { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - } - if(object == 0) break; - - if(dynamic_cast(object) - || dynamic_cast(object)) { - SCROLLINFO info; - memset(&info, 0, sizeof(SCROLLINFO)); - info.cbSize = sizeof(SCROLLINFO); - info.fMask = SIF_ALL; - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - switch(LOWORD(wparam)) { - case SB_LEFT: info.nPos = info.nMin; break; - case SB_RIGHT: info.nPos = info.nMax; break; - case SB_LINELEFT: info.nPos--; break; - case SB_LINERIGHT: info.nPos++; break; - case SB_PAGELEFT: info.nPos -= info.nMax >> 3; break; - case SB_PAGERIGHT: info.nPos += info.nMax >> 3; break; - case SB_THUMBTRACK: info.nPos = info.nTrackPos; break; - } - - info.fMask = SIF_POS; - SetScrollInfo((HWND)lparam, SB_CTL, &info, TRUE); - - //Windows may clamp position to scrollbar range - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - if(dynamic_cast(object)) { - HorizontalScrollBar &horizontalScrollBar = (HorizontalScrollBar&)*object; - if(horizontalScrollBar.state.position != info.nPos) { - horizontalScrollBar.state.position = info.nPos; - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); - } - } else { - VerticalScrollBar &verticalScrollBar = (VerticalScrollBar&)*object; - if(verticalScrollBar.state.position != info.nPos) { - verticalScrollBar.state.position = info.nPos; - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); - } - } - - return TRUE; - } - - if(dynamic_cast(object)) { - HorizontalSlider &horizontalSlider = (HorizontalSlider&)*object; - if(horizontalSlider.state.position != horizontalSlider.position()) { - horizontalSlider.state.position = horizontalSlider.position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); - } - } else if(dynamic_cast(object)) { - VerticalSlider &verticalSlider = (VerticalSlider&)*object; - if(verticalSlider.state.position != verticalSlider.position()) { - verticalSlider.state.position = verticalSlider.position(); - if(verticalSlider.onChange) verticalSlider.onChange(); - } - } - - break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/kaijuu/phoenix/windows/platform.hpp b/kaijuu/phoenix/windows/platform.hpp deleted file mode 100644 index 96811796..00000000 --- a/kaijuu/phoenix/windows/platform.hpp +++ /dev/null @@ -1,481 +0,0 @@ -struct Settings { - bidirectional_map keymap; -}; - -struct pFont; -struct pObject; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -static bool osQuit = false; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static HFONT create(const string &description); - static void free(HFONT hfont); - static Geometry geometry(HFONT hfont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - static vector objects; - - Object &object; - uintptr_t id; - bool locked; - - pObject(Object &object); - static pObject* find(unsigned id); - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - UINT_PTR htimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - static vector modal; - static void updateModality(); - - Window &window; - HWND hwnd; - HMENU hmenu; - HWND hstatus; - HFONT hstatusfont; - HBRUSH brush; - COLORREF brushColor; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateMenu(); -}; - -struct pAction : public pObject { - Action &action; - Menu *parentMenu; - Window *parentWindow; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - HMENU hmenu; - HBITMAP hbitmap; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); - void update(Window &parentWindow, Menu *parentMenu = 0); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - HBITMAP hbitmap; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - Window *parentWindow; - HWND hwnd; - HFONT hfont; - - bool enabled(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) { parentWindow = &Window::none(); } - void constructor(); - void destructor(); - virtual void orphan(); - void setDefaultFont(); - void synchronize(); -}; - -struct pButton : public pWidget { - Button &button; - HBITMAP hbitmap; - HIMAGELIST himagelist; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button), hbitmap(0), himagelist(0) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - uint32_t *data; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - void paint(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - LRESULT CALLBACK (*windowProc)(HWND, UINT, LPARAM, WPARAM); - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - bool keyPress(unsigned key); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - HIMAGELIST imageList; - bool lostFocus; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView), imageList(nullptr) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); - void setImageList(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/kaijuu/phoenix/windows/settings.cpp b/kaijuu/phoenix/windows/settings.cpp deleted file mode 100644 index 343fc9fb..00000000 --- a/kaijuu/phoenix/windows/settings.cpp +++ /dev/null @@ -1 +0,0 @@ -static Settings *settings = nullptr; \ No newline at end of file diff --git a/kaijuu/phoenix/windows/timer.cpp b/kaijuu/phoenix/windows/timer.cpp deleted file mode 100644 index 99fb5c00..00000000 --- a/kaijuu/phoenix/windows/timer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static vector timers; - -static void CALLBACK Timer_timeoutProc(HWND hwnd, UINT msg, UINT_PTR timerID, DWORD time) { - for(auto &timer : timers) { - if(timer->htimer == timerID) { - if(timer->timer.onTimeout) timer->timer.onTimeout(); - return; - } - } -} - -void pTimer::setEnabled(bool enabled) { - if(htimer) { - KillTimer(NULL, htimer); - htimer = 0; - } - - if(enabled == true) { - htimer = SetTimer(NULL, 0U, timer.state.milliseconds, Timer_timeoutProc); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - //destroy and recreate timer if interval changed - setEnabled(timer.state.enabled); -} - -void pTimer::constructor() { - timers.append(this); - htimer = 0; -} diff --git a/kaijuu/phoenix/windows/utility.cpp b/kaijuu/phoenix/windows/utility.cpp deleted file mode 100644 index c247d5cc..00000000 --- a/kaijuu/phoenix/windows/utility.cpp +++ /dev/null @@ -1,150 +0,0 @@ -static const unsigned Windows2000 = 0x0500; -static const unsigned WindowsXP = 0x0501; -static const unsigned WindowsVista = 0x0600; -static const unsigned Windows7 = 0x0601; - -static unsigned OsVersion() { - OSVERSIONINFO versionInfo = { 0 }; - versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&versionInfo); - return (versionInfo.dwMajorVersion << 8) + (versionInfo.dwMajorVersion << 0); -} - -static HBITMAP CreateBitmap(const image &image) { - HDC hdc = GetDC(0); - BITMAPINFO bitmapInfo; - memset(&bitmapInfo, 0, sizeof(BITMAPINFO)); - bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bitmapInfo.bmiHeader.biWidth = image.width; - bitmapInfo.bmiHeader.biHeight = -image.height; //bitmaps are stored upside down unless we negate height - bitmapInfo.bmiHeader.biPlanes = 1; - bitmapInfo.bmiHeader.biBitCount = 32; - bitmapInfo.bmiHeader.biCompression = BI_RGB; - bitmapInfo.bmiHeader.biSizeImage = image.width * image.height * 4; - void *bits = nullptr; - HBITMAP hbitmap = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0); - if(bits) memcpy(bits, image.data, image.width * image.height * 4); - ReleaseDC(0, hdc); - return hbitmap; -} - -static Keyboard::Keycode Keysym(unsigned keysym, unsigned keyflags) { - #define pressed(keysym) (GetAsyncKeyState(keysym) & 0x8000) - #define enabled(keysym) (GetKeyState(keysym)) - #define shifted() (pressed(VK_LSHIFT) || pressed(VK_RSHIFT)) - #define extended() (keyflags & (1 << 24)) - - switch(keysym) { - case VK_ESCAPE: return Keyboard::Keycode::Escape; - case VK_F1: return Keyboard::Keycode::F1; - case VK_F2: return Keyboard::Keycode::F2; - case VK_F3: return Keyboard::Keycode::F3; - case VK_F4: return Keyboard::Keycode::F4; - case VK_F5: return Keyboard::Keycode::F5; - case VK_F6: return Keyboard::Keycode::F6; - case VK_F7: return Keyboard::Keycode::F7; - case VK_F8: return Keyboard::Keycode::F8; - case VK_F9: return Keyboard::Keycode::F9; - //Keyboard::Keycode::F10 (should be captured under VK_MENU from WM_SYSKEY(UP,DOWN); but this is not working...) - case VK_F11: return Keyboard::Keycode::F11; - case VK_F12: return Keyboard::Keycode::F12; - - //Keyboard::Keycode::PrintScreen - //Keyboard::Keycode::SysRq - case VK_SCROLL: return Keyboard::Keycode::ScrollLock; - case VK_PAUSE: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case VK_INSERT: return extended() ? Keyboard::Keycode::Insert : Keyboard::Keycode::KeypadInsert; - case VK_DELETE: return extended() ? Keyboard::Keycode::Delete : Keyboard::Keycode::KeypadDelete; - case VK_HOME: return extended() ? Keyboard::Keycode::Home : Keyboard::Keycode::KeypadHome; - case VK_END: return extended() ? Keyboard::Keycode::End : Keyboard::Keycode::KeypadEnd; - case VK_PRIOR: return extended() ? Keyboard::Keycode::PageUp : Keyboard::Keycode::KeypadPageUp; - case VK_NEXT: return extended() ? Keyboard::Keycode::PageDown : Keyboard::Keycode::KeypadPageDown; - - case VK_UP: return extended() ? Keyboard::Keycode::Up : Keyboard::Keycode::KeypadUp; - case VK_DOWN: return extended() ? Keyboard::Keycode::Down : Keyboard::Keycode::KeypadDown; - case VK_LEFT: return extended() ? Keyboard::Keycode::Left : Keyboard::Keycode::KeypadLeft; - case VK_RIGHT: return extended() ? Keyboard::Keycode::Right : Keyboard::Keycode::KeypadRight; - - case VK_OEM_3: return !shifted() ? Keyboard::Keycode::Grave : Keyboard::Keycode::Tilde; - case '1': return !shifted() ? Keyboard::Keycode::Number1 : Keyboard::Keycode::Exclamation; - case '2': return !shifted() ? Keyboard::Keycode::Number2 : Keyboard::Keycode::At; - case '3': return !shifted() ? Keyboard::Keycode::Number3 : Keyboard::Keycode::Pound; - case '4': return !shifted() ? Keyboard::Keycode::Number4 : Keyboard::Keycode::Dollar; - case '5': return !shifted() ? Keyboard::Keycode::Number5 : Keyboard::Keycode::Percent; - case '6': return !shifted() ? Keyboard::Keycode::Number6 : Keyboard::Keycode::Power; - case '7': return !shifted() ? Keyboard::Keycode::Number7 : Keyboard::Keycode::Ampersand; - case '8': return !shifted() ? Keyboard::Keycode::Number8 : Keyboard::Keycode::Asterisk; - case '9': return !shifted() ? Keyboard::Keycode::Number9 : Keyboard::Keycode::ParenthesisLeft; - case '0': return !shifted() ? Keyboard::Keycode::Number0 : Keyboard::Keycode::ParenthesisRight; - case VK_OEM_MINUS: return !shifted() ? Keyboard::Keycode::Minus : Keyboard::Keycode::Underscore; - case VK_OEM_PLUS: return !shifted() ? Keyboard::Keycode::Equal : Keyboard::Keycode::Plus; - case VK_BACK: return Keyboard::Keycode::Backspace; - - case VK_OEM_4: return !shifted() ? Keyboard::Keycode::BracketLeft : Keyboard::Keycode::BraceLeft; - case VK_OEM_6: return !shifted() ? Keyboard::Keycode::BracketRight : Keyboard::Keycode::BraceRight; - case VK_OEM_5: return !shifted() ? Keyboard::Keycode::Backslash : Keyboard::Keycode::Pipe; - case VK_OEM_1: return !shifted() ? Keyboard::Keycode::Semicolon : Keyboard::Keycode::Colon; - case VK_OEM_7: return !shifted() ? Keyboard::Keycode::Apostrophe : Keyboard::Keycode::Quote; - case VK_OEM_COMMA: return !shifted() ? Keyboard::Keycode::Comma : Keyboard::Keycode::CaretLeft; - case VK_OEM_PERIOD: return !shifted() ? Keyboard::Keycode::Period : Keyboard::Keycode::CaretRight; - case VK_OEM_2: return !shifted() ? Keyboard::Keycode::Slash : Keyboard::Keycode::Question; - - case VK_TAB: return Keyboard::Keycode::Tab; - case VK_CAPITAL: return Keyboard::Keycode::CapsLock; - case VK_RETURN: return !extended() ? Keyboard::Keycode::Return : Keyboard::Keycode::Enter; - case VK_SHIFT: return !pressed(VK_RSHIFT) ? Keyboard::Keycode::ShiftLeft : Keyboard::Keycode::ShiftRight; - case VK_CONTROL: return !pressed(VK_RCONTROL) ? Keyboard::Keycode::ControlLeft : Keyboard::Keycode::ControlRight; - case VK_LWIN: return Keyboard::Keycode::SuperLeft; - case VK_RWIN: return Keyboard::Keycode::SuperRight; - case VK_MENU: - if(keyflags & (1 << 24)) return Keyboard::Keycode::AltRight; - return Keyboard::Keycode::AltLeft; - case VK_SPACE: return Keyboard::Keycode::Space; - case VK_APPS: return Keyboard::Keycode::Menu; - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': - case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': - if(enabled(VK_CAPITAL)) { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } - } else { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } - } - break; - - case VK_NUMLOCK: return Keyboard::Keycode::NumLock; - case VK_DIVIDE: return Keyboard::Keycode::Divide; - case VK_MULTIPLY: return Keyboard::Keycode::Multiply; - case VK_SUBTRACT: return Keyboard::Keycode::Subtract; - case VK_ADD: return Keyboard::Keycode::Add; - case VK_DECIMAL: return Keyboard::Keycode::Point; - case VK_NUMPAD1: return Keyboard::Keycode::Keypad1; - case VK_NUMPAD2: return Keyboard::Keycode::Keypad2; - case VK_NUMPAD3: return Keyboard::Keycode::Keypad3; - case VK_NUMPAD4: return Keyboard::Keycode::Keypad4; - case VK_NUMPAD5: return Keyboard::Keycode::Keypad5; - case VK_NUMPAD6: return Keyboard::Keycode::Keypad6; - case VK_NUMPAD7: return Keyboard::Keycode::Keypad7; - case VK_NUMPAD8: return Keyboard::Keycode::Keypad8; - case VK_NUMPAD9: return Keyboard::Keycode::Keypad9; - case VK_NUMPAD0: return Keyboard::Keycode::Keypad0; - - case VK_CLEAR: return Keyboard::Keycode::KeypadCenter; - } - - return Keyboard::Keycode::None; - - #undef pressed - #undef enabled - #undef shifted - #undef extended -} diff --git a/kaijuu/phoenix/windows/widget/button.cpp b/kaijuu/phoenix/windows/widget/button.cpp deleted file mode 100644 index 41e7e283..00000000 --- a/kaijuu/phoenix/windows/widget/button.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef Button_SetImageList - //MinGW/32-bit has painfully outdated platform headers ... - typedef struct { - HIMAGELIST himl; - RECT margin; - UINT uAlign; - } BUTTON_IMAGELIST, *PBUTTON_IMAGELIST; - - #define BUTTON_IMAGELIST_ALIGN_LEFT 0 - #define BUTTON_IMAGELIST_ALIGN_RIGHT 1 - #define BUTTON_IMAGELIST_ALIGN_TOP 2 - #define BUTTON_IMAGELIST_ALIGN_BOTTOM 3 - #define BUTTON_IMAGELIST_ALIGN_CENTER 4 - - #define BCM_FIRST 0x1600 - #define BCM_SETIMAGELIST (BCM_FIRST+2) - #define Button_SetImageList(hwnd, pbuttonImagelist) (WINBOOL)SNDMSG((hwnd),BCM_SETIMAGELIST,0,(LPARAM)(pbuttonImagelist)) -#endif - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 10 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - nall::image nallImage = image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - - if(OsVersion() >= WindowsVista) { - hbitmap = CreateBitmap(nallImage); - SendMessage(hwnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmap); - switch(orientation) { - case Orientation::Horizontal: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_TOP); break; - case Orientation::Vertical: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_TOP); break; - } - } else { - //Windows XP and earlier cannot display bitmaps and text at the same time with BM_SETIMAGE - //Use BCM_SETIMAGELIST instead. It does not support alpha blending, so blend with button color - //The XP theme and above use a gradient fade background, so it won't be a perfect match there - nallImage.alphaBlend(GetSysColor(COLOR_BTNFACE)); - hbitmap = CreateBitmap(nallImage); - himagelist = ImageList_Create(nallImage.width, nallImage.height, ILC_COLOR32, 1, 0); - ImageList_Add(himagelist, hbitmap, NULL); - BUTTON_IMAGELIST list; - list.himl = himagelist; - switch(orientation) { - case Orientation::Horizontal: SetRect(&list.margin, 5, 0, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; break; - case Orientation::Vertical: SetRect(&list.margin, 0, 5, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_TOP; break; - } - Button_SetImageList(hwnd, &list); - } -} - -void pButton::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pButton::constructor() { - hwnd = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&button); - setDefaultFont(); - setImage(button.state.image, button.state.orientation); - setText(button.state.text); - synchronize(); -} - -void pButton::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - DestroyWindow(hwnd); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/canvas.cpp b/kaijuu/phoenix/windows/widget/canvas.cpp deleted file mode 100644 index f2be9e38..00000000 --- a/kaijuu/phoenix/windows/widget/canvas.cpp +++ /dev/null @@ -1,92 +0,0 @@ -static LRESULT CALLBACK Canvas_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Canvas &canvas = (Canvas&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_PAINT) { - canvas.p.paint(); - return TRUE; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(canvas.onMouseMove) canvas.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(canvas.onMouseLeave) canvas.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(canvas.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: canvas.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: canvas.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: canvas.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(canvas.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: canvas.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: canvas.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: canvas.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -void pCanvas::setSize(const Size &size) { - delete[] data; - data = new uint32_t[size.width * size.height]; -} - -void pCanvas::update() { - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - InvalidateRect(hwnd, 0, false); -} - -void pCanvas::constructor() { - data = new uint32_t[canvas.state.width * canvas.state.height]; - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas); - synchronize(); -} - -void pCanvas::destructor() { - DestroyWindow(hwnd); - delete[] data; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::paint() { - RECT rc; - GetClientRect(hwnd, &rc); - unsigned width = canvas.state.width, height = canvas.state.height; - - BITMAPINFO bmi; - memset(&bmi, 0, sizeof(BITMAPINFO)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = 32; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biWidth = width; - bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap - bmi.bmiHeader.biSizeImage = sizeof(uint32_t) * width * height; - - PAINTSTRUCT ps; - BeginPaint(hwnd, &ps); - SetDIBitsToDevice(ps.hdc, 0, 0, width, height, 0, 0, 0, height, (void*)data, &bmi, DIB_RGB_COLORS); - EndPaint(hwnd, &ps); -} diff --git a/kaijuu/phoenix/windows/widget/check-box.cpp b/kaijuu/phoenix/windows/widget/check-box.cpp deleted file mode 100644 index 8f0d2eb8..00000000 --- a/kaijuu/phoenix/windows/widget/check-box.cpp +++ /dev/null @@ -1,39 +0,0 @@ -bool pCheckBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, checkBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - SendMessage(hwnd, BM_SETCHECK, (WPARAM)checked, 0); -} - -void pCheckBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pCheckBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_CHECKBOX, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&checkBox); - setDefaultFont(); - if(checkBox.state.checked) setChecked(true); - setText(checkBox.state.text); - synchronize(); - -} - -void pCheckBox::destructor() { - DestroyWindow(hwnd); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/combo-box.cpp b/kaijuu/phoenix/windows/widget/combo-box.cpp deleted file mode 100644 index bff1170d..00000000 --- a/kaijuu/phoenix/windows/widget/combo-box.cpp +++ /dev/null @@ -1,70 +0,0 @@ -void pComboBox::append(const string &text) { - SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(text)); - if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) == 1) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(hfont, text).width); - return { 0, 0, maximumWidth + 24, pFont::geometry(hfont, " ").height + 10 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - SendMessage(hwnd, CB_INSERTSTRING, row, (LPARAM)(wchar_t*)utf16_t(text)); - setSelection(position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - if(position == row) setSelection(0); - locked = false; -} - -void pComboBox::reset() { - SendMessage(hwnd, CB_RESETCONTENT, 0, 0); -} - -unsigned pComboBox::selection() { - return SendMessage(hwnd, CB_GETCURSEL, 0, 0); -} - -void pComboBox::setSelection(unsigned row) { - SendMessage(hwnd, CB_SETCURSEL, row, 0); -} - -void pComboBox::constructor() { - hwnd = CreateWindow( - L"COMBOBOX", L"", - WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, - 0, 0, 0, 0, - parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&comboBox); - setDefaultFont(); - for(auto &text : comboBox.state.text) append(text); - setSelection(comboBox.state.selection); - synchronize(); -} - -void pComboBox::destructor() { - DestroyWindow(hwnd); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER); - RECT rc; - GetWindowRect(hwnd, &rc); - unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); - SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); -} diff --git a/kaijuu/phoenix/windows/widget/hex-edit.cpp b/kaijuu/phoenix/windows/widget/hex-edit.cpp deleted file mode 100644 index 789f4faf..00000000 --- a/kaijuu/phoenix/windows/widget/hex-edit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -static LRESULT CALLBACK HexEdit_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - HexEdit &hexEdit = *(HexEdit*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(msg == WM_CHAR) { - if(hexEdit.p.keyPress(wparam)) return 0; - } - return hexEdit.p.windowProc(hwnd, msg, wparam, lparam); -} - -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - update(); -} - -void pHexEdit::setRows(unsigned rows) { - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - SetWindowText(hwnd, L""); - return; - } - - unsigned cursorPosition = Edit_GetSel(hwnd); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\r\n"); - } - - SetWindowText(hwnd, utf16_t(output)); - Edit_SetSel(hwnd, LOWORD(cursorPosition), HIWORD(cursorPosition)); -} - -void pHexEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_READONLY | ES_MULTILINE | ES_WANTRETURN, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&hexEdit); - setDefaultFont(); - update(); - - windowProc = (LRESULT CALLBACK (*)(HWND, UINT, LPARAM, WPARAM))GetWindowLongPtr(hwnd, GWLP_WNDPROC); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)HexEdit_windowProc); - synchronize(); -} - -void pHexEdit::destructor() { - DestroyWindow(hwnd); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = LOWORD(Edit_GetSel(hwnd)); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 2; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble or byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - Edit_SetSel(hwnd, position, position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} diff --git a/kaijuu/phoenix/windows/widget/horizontal-scroll-bar.cpp b/kaijuu/phoenix/windows/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 250ac247..00000000 --- a/kaijuu/phoenix/windows/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 18 }; -} - -unsigned pHorizontalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - horizontalScrollBar.setPosition(0); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pHorizontalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | WS_TABSTOP | SBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalScrollBar); - unsigned position = horizontalScrollBar.state.position; - setLength(horizontalScrollBar.state.length); - horizontalScrollBar.setPosition(position); - synchronize(); -} - -void pHorizontalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/horizontal-slider.cpp b/kaijuu/phoenix/windows/widget/horizontal-slider.cpp deleted file mode 100644 index 807086ae..00000000 --- a/kaijuu/phoenix/windows/widget/horizontal-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pHorizontalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - horizontalSlider.setPosition(0); -} - -void pHorizontalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pHorizontalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalSlider); - unsigned position = horizontalSlider.state.position; - setLength(horizontalSlider.state.length); - horizontalSlider.setPosition(position); - synchronize(); -} - -void pHorizontalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/label.cpp b/kaijuu/phoenix/windows/widget/label.cpp deleted file mode 100644 index 56f0d433..00000000 --- a/kaijuu/phoenix/windows/widget/label.cpp +++ /dev/null @@ -1,64 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); - InvalidateRect(hwnd, 0, false); -} - -void pLabel::constructor() { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label); - setDefaultFont(); - setText(label.state.text); - synchronize(); -} - -void pLabel::destructor() { - DestroyWindow(hwnd); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} - -static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Window *window = (Window*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam); - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_ERASEBKGND) { - //background is erased during WM_PAINT to prevent flickering - return TRUE; - } - - if(msg == WM_PAINT) { - PAINTSTRUCT ps; - RECT rc; - BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - FillRect(ps.hdc, &rc, window->p.brush ? window->p.brush : GetSysColorBrush(COLOR_3DFACE)); - SetBkColor(ps.hdc, window->p.brush ? window->p.brushColor : GetSysColor(COLOR_3DFACE)); - SelectObject(ps.hdc, ((Widget*)label)->p.hfont); - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); - unsigned height = rc.bottom; - GetClientRect(hwnd, &rc); - rc.top = (rc.bottom - height) / 2; - rc.bottom = rc.top + height; - DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); - EndPaint(hwnd, &ps); - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/kaijuu/phoenix/windows/widget/line-edit.cpp b/kaijuu/phoenix/windows/widget/line-edit.cpp deleted file mode 100644 index eb6a8fb7..00000000 --- a/kaijuu/phoenix/windows/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, 0); -} - -void pLineEdit::setText(const string &text) { - locked = true; - SetWindowText(hwnd, utf16_t(text)); - locked = false; -} - -string pLineEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - return (const char*)utf8_t(text); -} - -void pLineEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&lineEdit); - setDefaultFont(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); - synchronize(); -} - -void pLineEdit::destructor() { - lineEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/list-view.cpp b/kaijuu/phoenix/windows/widget/list-view.cpp deleted file mode 100644 index 11ae023f..00000000 --- a/kaijuu/phoenix/windows/widget/list-view.cpp +++ /dev/null @@ -1,210 +0,0 @@ -unsigned ListView_GetColumnCount(HWND hwnd) { - unsigned count = 0; - LVCOLUMN column; - column.mask = LVCF_WIDTH; - while(ListView_GetColumn(hwnd, count++, &column)); - return --count; -} - -void pListView::append(const lstring &list) { - wchar_t empty[] = L""; - unsigned row = ListView_GetItemCount(hwnd); - LVITEM item; - item.mask = LVIF_TEXT; - item.iItem = row; - item.iSubItem = 0; - item.pszText = empty; - locked = true; - ListView_InsertItem(hwnd, &item); - locked = false; - for(unsigned column = 0; column < list.size(); column++) { - utf16_t wtext(list(column, "")); - ListView_SetItemText(hwnd, row, column, wtext); - } -} - -void pListView::autoSizeColumns() { - unsigned columns = ListView_GetColumnCount(hwnd); - for(unsigned n = 0; n < columns; n++) { - ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER); - } -} - -bool pListView::checked(unsigned row) { - return ListView_GetCheckState(hwnd, row); -} - -void pListView::modify(unsigned row, const lstring &list) { - for(unsigned n = 0; n < list.size(); n++) { - utf16_t wtext(list(n, "")); - ListView_SetItemText(hwnd, row, n, wtext); - } -} - -void pListView::remove(unsigned row) { - ListView_DeleteItem(hwnd, row); - setImageList(); -} - -void pListView::reset() { - ListView_DeleteAllItems(hwnd); -} - -bool pListView::selected() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return true; - } - return false; -} - -unsigned pListView::selection() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return n; - } - return listView.state.selection; -} - -void pListView::setCheckable(bool checkable) { - ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES | (checkable ? LVS_EX_CHECKBOXES : 0)); -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - ListView_SetCheckState(hwnd, row, checked); - locked = false; -} - -void pListView::setHeaderText(const lstring &list) { - while(ListView_DeleteColumn(hwnd, 0)); - - lstring headers = list; - if(headers.size() == 0) headers.append(""); //must have at least one column - - for(unsigned n = 0; n < headers.size(); n++) { - LVCOLUMN column; - column.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM; - column.fmt = LVCFMT_LEFT; - column.iSubItem = n; - utf16_t headerText(headers[n]); - column.pszText = headerText; - ListView_InsertColumn(hwnd, n, &column); - } - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - SetWindowLong( - hwnd, GWL_STYLE, - (GetWindowLong(hwnd, GWL_STYLE) & ~LVS_NOCOLUMNHEADER) | - (visible ? 0 : LVS_NOCOLUMNHEADER) - ); -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { - setImageList(); -} - -void pListView::setSelected(bool selected) { - locked = true; - lostFocus = false; - if(selected == false) { - ListView_SetItemState(hwnd, -1, 0, LVIS_FOCUSED | LVIS_SELECTED); - } else { - setSelection(listView.state.selection); - } - locked = false; -} - -void pListView::setSelection(unsigned row) { - locked = true; - lostFocus = false; - ListView_SetItemState(hwnd, row, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); - locked = false; -} - -void pListView::constructor() { - lostFocus = false; - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", - WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&listView); - setDefaultFont(); - setHeaderText(listView.state.headerText); - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - setImageList(); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); - synchronize(); -} - -void pListView::destructor() { - DestroyWindow(hwnd); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setGeometry(const Geometry &geometry) { - pWidget::setGeometry(geometry); - autoSizeColumns(); -} - -void pListView::setImageList() { - auto &list = listView.state.image; - - if(imageList) { - ImageList_Destroy(imageList); - imageList = nullptr; - } - - bool found = false; - for(auto &row : listView.state.image) { - for(auto &column : row) { - if(column.empty() == false) { - found = true; - break; - } - } - } - if(found == false) return; - - imageList = ImageList_Create(15, 15, ILC_COLOR32, 1, 0); - nall::image image; - image.allocate(15, 15); - image.clear(GetSysColor(COLOR_WINDOW)); - ImageList_Add(imageList, CreateBitmap(image), NULL); - - for(unsigned row = 0; row < list.size(); row++) { - for(unsigned column = 0; column < list(row).size(); column++) { - nall::image image = list(row)(column); - if(image.empty()) continue; - image.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - image.scale(15, 15, Interpolation::Linear); - ImageList_Add(imageList, CreateBitmap(image), NULL); - } - } - - ListView_SetImageList(hwnd, imageList, LVSIL_SMALL); - - unsigned ID = 1; - for(unsigned row = 0; row < list.size(); row++) { - for(unsigned column = 0; column < list(row).size(); column++) { - if(list(row)(column).empty()) continue; //I_IMAGENONE does not work properly - LVITEM item; - item.mask = LVIF_IMAGE; - item.iItem = row; - item.iSubItem = column; - item.iImage = ID++; - ListView_SetItem(hwnd, &item); - } - } -} diff --git a/kaijuu/phoenix/windows/widget/progress-bar.cpp b/kaijuu/phoenix/windows/widget/progress-bar.cpp deleted file mode 100644 index f4703f1e..00000000 --- a/kaijuu/phoenix/windows/widget/progress-bar.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 23 }; -} - -void pProgressBar::setPosition(unsigned position) { - SendMessage(hwnd, PBM_SETPOS, (WPARAM)position, 0); -} - -void pProgressBar::constructor() { - hwnd = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | PBS_SMOOTH, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&progressBar); - SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); - SendMessage(hwnd, PBM_SETSTEP, MAKEWPARAM(1, 0), 0); - setPosition(progressBar.state.position); - synchronize(); -} - -void pProgressBar::destructor() { - DestroyWindow(hwnd); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/radio-box.cpp b/kaijuu/phoenix/windows/widget/radio-box.cpp deleted file mode 100644 index ebcb1edc..00000000 --- a/kaijuu/phoenix/windows/widget/radio-box.cpp +++ /dev/null @@ -1,43 +0,0 @@ -bool pRadioBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, radioBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - for(auto &item : radioBox.state.group) { - SendMessage(item.p.hwnd, BM_SETCHECK, (WPARAM)(&item == &radioBox), 0); - } -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pRadioBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_RADIOBUTTON, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&radioBox); - setDefaultFont(); - if(radioBox.state.checked) setChecked(); - setText(radioBox.state.text); - synchronize(); -} - -void pRadioBox::destructor() { - DestroyWindow(hwnd); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/text-edit.cpp b/kaijuu/phoenix/windows/widget/text-edit.cpp deleted file mode 100644 index 8e1df517..00000000 --- a/kaijuu/phoenix/windows/widget/text-edit.cpp +++ /dev/null @@ -1,58 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - if(position == ~0) position >>= 1; //Edit_SetSel takes signed type - Edit_SetSel(hwnd, position, position); - Edit_ScrollCaret(hwnd); -} - -void pTextEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, (LPARAM)0); -} - -void pTextEdit::setText(const string &text) { - locked = true; - string output = text; - output.replace("\r", ""); - output.replace("\n", "\r\n"); - SetWindowText(hwnd, utf16_t(output)); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - //ES_AUTOHSCROLL cannot be changed after widget creation. - //As a result, we must destroy and re-create widget to change this setting. - orphan(); -} - -string pTextEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t buffer[length + 1]; - GetWindowText(hwnd, buffer, length + 1); - buffer[length] = 0; - string text = (const char*)utf8_t(buffer); - text.replace("\r", ""); - return text; -} - -void pTextEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | (textEdit.state.wordWrap == false ? WS_HSCROLL | ES_AUTOHSCROLL : 0), - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&textEdit); - setDefaultFont(); - setCursorPosition(textEdit.state.cursorPosition); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - synchronize(); -} - -void pTextEdit::destructor() { - textEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/vertical-scroll-bar.cpp b/kaijuu/phoenix/windows/widget/vertical-scroll-bar.cpp deleted file mode 100644 index dcc281f2..00000000 --- a/kaijuu/phoenix/windows/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 18, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - verticalScrollBar.setPosition(0); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pVerticalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | SBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalScrollBar); - unsigned position = verticalScrollBar.state.position; - setLength(verticalScrollBar.state.length); - verticalScrollBar.setPosition(position); - synchronize(); -} - -void pVerticalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/vertical-slider.cpp b/kaijuu/phoenix/windows/widget/vertical-slider.cpp deleted file mode 100644 index ac5cb1ce..00000000 --- a/kaijuu/phoenix/windows/widget/vertical-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pVerticalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pVerticalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - verticalSlider.setPosition(0); -} - -void pVerticalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pVerticalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalSlider); - unsigned position = verticalSlider.state.position; - setLength(verticalSlider.state.length); - verticalSlider.setPosition(position); - synchronize(); -} - -void pVerticalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/kaijuu/phoenix/windows/widget/viewport.cpp b/kaijuu/phoenix/windows/widget/viewport.cpp deleted file mode 100644 index c0b13b69..00000000 --- a/kaijuu/phoenix/windows/widget/viewport.cpp +++ /dev/null @@ -1,57 +0,0 @@ -static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Viewport &viewport = (Viewport&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(viewport.onMouseMove) viewport.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(viewport.onMouseLeave) viewport.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(viewport.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: viewport.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: viewport.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: viewport.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(viewport.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: viewport.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: viewport.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: viewport.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -uintptr_t pViewport::handle() { - return (uintptr_t)hwnd; -} - -void pViewport::constructor() { - hwnd = CreateWindow(L"phoenix_viewport", L"", WS_CHILD | WS_DISABLED, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&viewport); - synchronize(); -} - -void pViewport::destructor() { - DestroyWindow(hwnd); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} \ No newline at end of file diff --git a/kaijuu/phoenix/windows/widget/widget.cpp b/kaijuu/phoenix/windows/widget/widget.cpp deleted file mode 100644 index b0e60c7d..00000000 --- a/kaijuu/phoenix/windows/widget/widget.cpp +++ /dev/null @@ -1,66 +0,0 @@ -bool pWidget::enabled() { - return IsWindowEnabled(hwnd); -} - -Geometry pWidget::minimumGeometry() { - return { 0, 0, 0, 0 }; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - EnableWindow(hwnd, enabled); -} - -void pWidget::setFocused() { - SetFocus(hwnd); -} - -void pWidget::setFont(const string &font) { - if(hfont) DeleteObject(hfont); - hfont = pFont::create(font); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -void pWidget::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, geometry.height, SWP_NOZORDER); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); -} - -void pWidget::constructor() { - hfont = pFont::create("Tahoma, 8"); - if(widget.state.abstract) { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&widget); - } -} - -void pWidget::destructor() { - if(widget.state.abstract) { - DestroyWindow(hwnd); - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} - -void pWidget::setDefaultFont() { - string description = widget.state.font; - if(description == "") description = "Tahoma, 8"; - hfont = pFont::create(description); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -//calling Widget::setParent destroys widget and re-creates it: -//need to re-apply visiblity and enabled status; called by each subclassed setParent() function -void pWidget::synchronize() { - widget.setEnabled(widget.enabled()); - widget.setVisible(widget.visible()); -} diff --git a/kaijuu/phoenix/windows/window.cpp b/kaijuu/phoenix/windows/window.cpp deleted file mode 100644 index dc8aea28..00000000 --- a/kaijuu/phoenix/windows/window.cpp +++ /dev/null @@ -1,229 +0,0 @@ -vector pWindow::modal; - -void pWindow::updateModality() { - for(auto &object : pObject::objects) { - if(dynamic_cast(object) == nullptr) continue; - pWindow *p = (pWindow*)object; - if(modal.size() == 0) EnableWindow(p->hwnd, true); - else EnableWindow(p->hwnd, modal.find(p)); - } -} - -static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; -static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geom = window.state.geometry; - geom.x = geom.y = 0; - layout.setGeometry(geom); -} - -void pWindow::append(Menu &menu) { - menu.p.parentWindow = &window; - updateMenu(); -} - -void pWindow::append(Widget &widget) { - widget.p.parentWindow = &window; - widget.p.orphan(); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Tahoma, 8"); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - DWORD color = GetSysColor(COLOR_3DFACE); - return { (uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color >> 0), 255 }; -} - -bool pWindow::focused() { - return (GetForegroundWindow() == hwnd); -} - -Geometry pWindow::frameMargin() { - unsigned style = window.state.resizable ? ResizableStyle : FixedStyle; - if(window.state.fullScreen) style = 0; - RECT rc = { 0, 0, 640, 480 }; - AdjustWindowRect(&rc, style, window.state.menuVisible); - unsigned statusHeight = 0; - if(window.state.statusVisible) { - RECT src; - GetClientRect(hstatus, &src); - statusHeight = src.bottom - src.top; - } - return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 }; -} - -Geometry pWindow::geometry() { - Geometry margin = frameMargin(); - - RECT rc; - if(IsIconic(hwnd)) { - //GetWindowRect returns -32000(x),-32000(y) when window is minimized - WINDOWPLACEMENT wp; - GetWindowPlacement(hwnd, &wp); - rc = wp.rcNormalPosition; - } else { - GetWindowRect(hwnd, &rc); - } - - signed x = rc.left + margin.x; - signed y = rc.top + margin.y; - unsigned width = (rc.right - rc.left) - margin.width; - unsigned height = (rc.bottom - rc.top) - margin.height; - - return { x, y, width, height }; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - updateMenu(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - if(brush) DeleteObject(brush); - brushColor = RGB(color.red, color.green, color.blue); - brush = CreateSolidBrush(brushColor); -} - -void pWindow::setFocused() { - if(window.state.visible == false) setVisible(true); - SetFocus(hwnd); -} - -void pWindow::setFullScreen(bool fullScreen) { - locked = true; - if(fullScreen == false) { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | (window.state.resizable ? ResizableStyle : FixedStyle)); - setGeometry(window.state.geometry); - } else { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); - Geometry margin = frameMargin(); - setGeometry({ margin.x, margin.y, GetSystemMetrics(SM_CXSCREEN) - margin.width, GetSystemMetrics(SM_CYSCREEN) - margin.height }); - } - locked = false; -} - -void pWindow::setGeometry(const Geometry &geometry) { - locked = true; - Geometry margin = frameMargin(); - SetWindowPos( - hwnd, NULL, - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height, - SWP_NOZORDER | SWP_FRAMECHANGED - ); - SetWindowPos(hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - for(auto &layout : window.state.layout) { - Geometry geom = this->geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { - locked = true; - SetMenu(hwnd, visible ? hmenu : 0); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setModal(bool modality) { - if(modality == false) { - if(auto position = modal.find(this)) modal.remove(position()); - } else { - modal.appendonce(this); - } - updateModality(); -} - -void pWindow::setResizable(bool resizable) { - SetWindowLongPtr(hwnd, GWL_STYLE, window.state.resizable ? ResizableStyle : FixedStyle); - setGeometry(window.state.geometry); -} - -void pWindow::setStatusFont(const string &font) { - if(hstatusfont) DeleteObject(hstatusfont); - hstatusfont = pFont::create(font); - SendMessage(hstatus, WM_SETFONT, (WPARAM)hstatusfont, 0); -} - -void pWindow::setStatusText(const string &text) { - SendMessage(hstatus, SB_SETTEXT, 0, (LPARAM)(wchar_t*)utf16_t(text)); -} - -void pWindow::setStatusVisible(bool visible) { - locked = true; - ShowWindow(hstatus, visible ? SW_SHOWNORMAL : SW_HIDE); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setTitle(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pWindow::setVisible(bool visible) { - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); - if(visible == false) setModal(false); -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &widget : window.state.widget) { - if(widget.state.font == "") widget.setFont(font); - } -} - -void pWindow::constructor() { - brush = 0; - - hwnd = CreateWindow(L"phoenix_window", L"", ResizableStyle, 128, 128, 256, 256, 0, 0, GetModuleHandle(0), 0); - hmenu = CreateMenu(); - hstatus = CreateWindow(STATUSCLASSNAME, L"", WS_CHILD, 0, 0, 0, 0, hwnd, 0, GetModuleHandle(0), 0); - hstatusfont = 0; - setStatusFont("Tahoma, 8"); - - //status bar will be capable of receiving tab focus if it is not disabled - SetWindowLongPtr(hstatus, GWL_STYLE, GetWindowLong(hstatus, GWL_STYLE) | WS_DISABLED); - - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&window); - setGeometry({ 128, 128, 256, 256 }); -} - -void pWindow::destructor() { - DeleteObject(hstatusfont); - DestroyWindow(hstatus); - DestroyMenu(hmenu); - DestroyWindow(hwnd); -} - -void pWindow::updateMenu() { - if(hmenu) DestroyMenu(hmenu); - hmenu = CreateMenu(); - - for(auto &menu : window.state.menu) { - menu.p.update(window); - if(menu.visible()) { - AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR)menu.p.hmenu, utf16_t(menu.state.text)); - } - } - - SetMenu(hwnd, window.state.menuVisible ? hmenu : 0); -} diff --git a/kaijuu/resource/kaijuu.png b/kaijuu/resource/kaijuu.png deleted file mode 100644 index 8155bd9a..00000000 Binary files a/kaijuu/resource/kaijuu.png and /dev/null differ diff --git a/kaijuu/resource/resource.cpp b/kaijuu/resource/resource.cpp deleted file mode 100644 index 05af6315..00000000 --- a/kaijuu/resource/resource.cpp +++ /dev/null @@ -1,413 +0,0 @@ -namespace resource { - -const uint8_t icon[13013] = { - 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,80,0,0,0,88,8,6,0,0,0,98,66,112, - 192,0,0,0,4,103,65,77,65,0,0,177,142,124,251,81,147,0,0,0,32,99,72,82,77,0,0,135,15,0,0,140, - 15,0,0,253,82,0,0,129,64,0,0,125,121,0,0,233,139,0,0,60,229,0,0,25,204,115,60,133,119,0,0,10, - 47,105,67,67,80,73,67,67,32,80,114,111,102,105,108,101,0,0,72,199,157,150,119,84,84,215,22,135,207,189,119,122, - 161,205,48,2,82,134,222,187,192,0,210,123,147,94,69,97,152,25,96,40,3,14,51,52,177,33,162,2,17,69,68,154, - 34,72,80,196,128,209,80,36,86,68,177,16,20,84,176,7,36,8,40,49,24,69,84,44,111,70,214,139,174,172,188,247, - 242,242,251,227,172,111,237,179,247,185,251,236,189,207,90,23,0,146,167,47,151,151,6,75,1,144,202,19,240,131,60,156, - 233,17,145,81,116,236,0,128,1,30,96,128,41,0,76,86,70,186,95,176,123,8,16,201,203,205,133,158,33,114,2,95, - 4,1,240,122,88,188,2,112,211,208,51,128,78,7,255,159,164,89,233,124,129,232,152,0,17,155,179,57,25,44,17,23, - 136,56,37,75,144,46,182,207,138,152,26,151,44,102,24,37,102,190,40,65,17,203,137,57,97,145,13,62,251,44,178,163, - 152,217,169,60,182,136,197,57,167,179,83,217,98,238,21,241,182,76,33,71,196,136,175,136,11,51,185,156,44,17,223,18, - 177,70,138,48,149,43,226,55,226,216,84,14,51,3,0,20,73,108,23,112,88,137,34,54,17,49,137,31,18,228,34,226, - 229,0,224,72,9,95,113,220,87,44,224,100,11,196,151,114,73,75,207,225,115,19,18,5,116,29,150,46,221,212,218,154, - 65,247,228,100,165,112,4,2,195,0,38,43,153,201,103,211,93,210,82,211,153,188,28,0,22,239,252,89,50,226,218,210, - 69,69,182,52,181,182,180,52,52,51,50,253,170,80,255,117,243,111,74,220,219,69,122,25,248,185,103,16,173,255,139,237, - 175,252,210,26,0,96,204,137,106,179,243,139,45,174,10,128,206,45,0,200,221,251,98,211,56,0,128,164,168,111,29,215, - 191,186,15,77,60,47,137,2,65,186,141,177,113,86,86,150,17,151,195,50,18,23,244,15,253,79,135,191,161,175,190,103, - 36,62,238,143,242,208,93,57,241,76,97,138,128,46,174,27,43,45,37,77,200,167,103,164,51,89,28,186,225,159,135,248, - 31,7,254,117,30,6,65,156,120,14,159,195,19,69,132,137,166,140,203,75,16,181,155,199,230,10,184,105,60,58,151,247, - 159,154,248,15,195,254,164,197,185,22,137,210,248,17,80,99,140,128,212,117,42,64,126,237,7,40,10,17,32,209,251,197, - 93,255,163,111,190,248,48,32,126,121,225,42,147,139,115,255,239,55,253,103,193,165,226,37,131,155,240,57,206,37,40,132, - 206,18,242,51,23,247,196,207,18,160,1,1,72,2,42,144,7,202,64,29,232,0,67,96,6,172,128,45,112,4,110,192, - 27,248,131,16,16,9,86,3,22,72,4,169,128,15,178,64,30,216,4,10,65,49,216,9,246,128,106,80,7,26,65,51, - 104,5,199,65,39,56,5,206,131,75,224,26,184,1,110,131,251,96,20,76,128,103,96,22,188,6,11,16,4,97,33,50, - 68,129,228,33,21,72,19,210,135,204,32,6,100,15,185,65,190,80,16,20,9,197,66,9,16,15,18,66,121,208,102,168, - 24,42,131,170,161,122,168,25,250,30,58,9,157,135,174,64,131,208,93,104,12,154,134,126,135,222,193,8,76,130,169,176, - 18,172,5,27,195,12,216,9,246,129,67,224,85,112,2,188,6,206,133,11,224,29,112,37,220,0,31,133,59,224,243,240, - 53,248,54,60,10,63,131,231,16,128,16,17,26,162,138,24,34,12,196,5,241,71,162,144,120,132,143,172,71,138,144,10, - 164,1,105,69,186,145,62,228,38,50,138,204,32,111,81,24,20,5,69,71,25,162,108,81,158,168,80,20,11,181,6,181, - 30,85,130,170,70,29,70,117,160,122,81,55,81,99,168,89,212,71,52,25,173,136,214,71,219,160,189,208,17,232,4,116, - 22,186,16,93,129,110,66,183,163,47,162,111,163,39,208,175,49,24,12,13,163,141,177,194,120,98,34,49,73,152,181,152, - 18,204,62,76,27,230,28,102,16,51,142,153,195,98,177,242,88,125,172,29,214,31,203,196,10,176,133,216,42,236,81,236, - 89,236,16,118,2,251,6,71,196,169,224,204,112,238,184,40,28,15,151,143,171,192,29,193,157,193,13,225,38,113,11,120, - 41,188,38,222,6,239,143,103,227,115,240,165,248,70,124,55,254,58,126,2,191,64,144,38,104,19,236,8,33,132,36,194, - 38,66,37,161,149,112,145,240,128,240,146,72,36,170,17,173,137,129,68,46,113,35,177,146,120,140,120,153,56,70,124,75, - 146,33,233,145,92,72,209,36,33,105,7,233,16,233,28,233,46,233,37,153,76,214,34,59,146,163,200,2,242,14,114,51, - 249,2,249,17,249,141,4,69,194,72,194,75,130,45,177,65,162,70,162,67,98,72,226,185,36,94,82,83,210,73,114,181, - 100,174,100,133,228,9,201,235,146,51,82,120,41,45,41,23,41,166,212,122,169,26,169,147,82,35,82,115,210,20,105,83, - 105,127,233,84,233,18,233,35,210,87,164,167,100,176,50,90,50,110,50,108,153,2,153,131,50,23,100,198,41,8,69,157, - 226,66,97,81,54,83,26,41,23,41,19,84,12,85,155,234,69,77,162,22,83,191,163,14,80,103,101,101,100,151,201,134, - 201,102,203,214,200,158,150,29,165,33,52,45,154,23,45,133,86,74,59,78,27,166,189,91,162,180,196,105,9,103,201,246, - 37,173,75,134,150,204,203,45,149,115,148,227,200,21,201,181,201,221,150,123,39,79,151,119,147,79,150,223,37,223,41,255, - 80,1,165,160,167,16,168,144,165,176,95,225,162,194,204,82,234,82,219,165,172,165,69,75,143,47,189,167,8,43,234,41, - 6,41,174,85,60,168,216,175,56,167,164,172,228,161,148,174,84,165,116,65,105,70,153,166,236,168,156,164,92,174,124,70, - 121,90,133,162,98,175,194,85,41,87,57,171,242,148,46,75,119,162,167,208,43,233,189,244,89,85,69,85,79,85,161,106, - 189,234,128,234,130,154,182,90,168,90,190,90,155,218,67,117,130,58,67,61,94,189,92,189,71,125,86,67,69,195,79,35, - 79,163,69,227,158,38,94,147,161,153,168,185,87,179,79,115,94,75,91,43,92,107,171,86,167,214,148,182,156,182,151,118, - 174,118,139,246,3,29,178,142,131,206,26,157,6,157,91,186,24,93,134,110,178,238,62,221,27,122,176,158,133,94,162,94, - 141,222,117,125,88,223,82,159,171,191,79,127,208,0,109,96,109,192,51,104,48,24,49,36,25,58,25,102,26,182,24,142, - 25,209,140,124,141,242,141,58,141,158,27,107,24,71,25,239,50,238,51,254,104,98,97,146,98,210,104,114,223,84,198,212, - 219,52,223,180,219,244,119,51,61,51,150,89,141,217,45,115,178,185,187,249,6,243,46,243,23,203,244,151,113,150,237,95, - 118,199,130,98,225,103,177,213,162,199,226,131,165,149,37,223,178,213,114,218,74,195,42,214,170,214,106,132,65,101,4,48, - 74,24,151,173,209,214,206,214,27,172,79,89,191,181,177,180,17,216,28,183,249,205,214,208,54,217,246,136,237,212,114,237, - 229,156,229,141,203,199,237,212,236,152,118,245,118,163,246,116,251,88,251,3,246,163,14,170,14,76,135,6,135,199,142,234, - 142,108,199,38,199,73,39,93,167,36,167,163,78,207,157,77,156,249,206,237,206,243,46,54,46,235,92,206,185,34,174,30, - 174,69,174,3,110,50,110,161,110,213,110,143,220,213,220,19,220,91,220,103,61,44,60,214,122,156,243,68,123,250,120,238, - 242,28,241,82,242,98,121,53,123,205,122,91,121,175,243,238,245,33,249,4,251,84,251,60,246,213,243,229,251,118,251,193, - 126,222,126,187,253,30,172,208,92,193,91,209,233,15,252,189,252,119,251,63,12,208,14,88,19,240,99,32,38,48,32,176, - 38,240,73,144,105,80,94,80,95,48,37,56,38,248,72,240,235,16,231,144,210,144,251,161,58,161,194,208,158,48,201,176, - 232,176,230,176,249,112,215,240,178,240,209,8,227,136,117,17,215,34,21,34,185,145,93,81,216,168,176,168,166,168,185,149, - 110,43,247,172,156,136,182,136,46,140,30,94,165,189,42,123,213,149,213,10,171,83,86,159,142,145,140,97,198,156,136,69, - 199,134,199,30,137,125,207,244,103,54,48,231,226,188,226,106,227,102,89,46,172,189,172,103,108,71,118,57,123,154,99,199, - 41,227,76,198,219,197,151,197,79,37,216,37,236,78,152,78,116,72,172,72,156,225,186,112,171,185,47,146,60,147,234,146, - 230,147,253,147,15,37,127,74,9,79,105,75,197,165,198,166,158,228,201,240,146,121,189,105,202,105,217,105,131,233,250,233, - 133,233,163,107,108,214,236,89,51,203,247,225,55,101,64,25,171,50,186,4,84,209,207,84,191,80,71,184,69,56,150,105, - 159,89,147,249,38,43,44,235,68,182,116,54,47,187,63,71,47,103,123,206,100,174,123,238,183,107,81,107,89,107,123,242, - 84,243,54,229,141,173,115,90,87,191,30,90,31,183,190,103,131,250,134,130,13,19,27,61,54,30,222,68,216,148,188,233, - 167,124,147,252,178,252,87,155,195,55,119,23,40,21,108,44,24,223,226,177,165,165,80,162,144,95,56,178,213,118,107,221, - 54,212,54,238,182,129,237,230,219,171,182,127,44,98,23,93,45,54,41,174,40,126,95,194,42,185,250,141,233,55,149,223, - 124,218,17,191,99,160,212,178,116,255,78,204,78,222,206,225,93,14,187,14,151,73,151,229,150,141,239,246,219,221,81,78, - 47,47,42,127,181,39,102,207,149,138,101,21,117,123,9,123,133,123,71,43,125,43,187,170,52,170,118,86,189,175,78,172, - 190,93,227,92,211,86,171,88,187,189,118,126,31,123,223,208,126,199,253,173,117,74,117,197,117,239,14,112,15,220,169,247, - 168,239,104,208,106,168,56,136,57,152,121,240,73,99,88,99,223,183,140,111,155,155,20,154,138,155,62,28,226,29,26,61, - 28,116,184,183,217,170,185,249,136,226,145,210,22,184,69,216,50,125,52,250,232,141,239,92,191,235,106,53,108,173,111,163, - 181,21,31,3,199,132,199,158,126,31,251,253,240,113,159,227,61,39,24,39,90,127,208,252,161,182,157,210,94,212,1,117, - 228,116,204,118,38,118,142,118,69,118,13,158,244,62,217,211,109,219,221,254,163,209,143,135,78,169,158,170,57,45,123,186, - 244,12,225,76,193,153,79,103,115,207,206,157,75,63,55,115,62,225,252,120,79,76,207,253,11,17,23,110,245,6,246,14, - 92,244,185,120,249,146,251,165,11,125,78,125,103,47,219,93,62,117,197,230,202,201,171,140,171,157,215,44,175,117,244,91, - 244,183,255,100,241,83,251,128,229,64,199,117,171,235,93,55,172,111,116,15,46,31,60,51,228,48,116,254,166,235,205,75, - 183,188,110,93,187,189,226,246,224,112,232,240,157,145,232,145,209,59,236,59,83,119,83,238,190,184,151,121,111,225,254,198, - 7,232,7,69,15,165,30,86,60,82,124,212,240,179,238,207,109,163,150,163,167,199,92,199,250,31,7,63,190,63,206,26, - 127,246,75,198,47,239,39,10,158,144,159,84,76,170,76,54,79,153,77,157,154,118,159,190,241,116,229,211,137,103,233,207, - 22,102,10,127,149,254,181,246,185,206,243,31,126,115,252,173,127,54,98,118,226,5,255,197,167,223,75,94,202,191,60,244, - 106,217,171,158,185,128,185,71,175,83,95,47,204,23,189,145,127,115,248,45,227,109,223,187,240,119,147,11,89,239,177,239, - 43,63,232,126,232,254,232,243,241,193,167,212,79,159,254,5,3,152,243,252,111,38,220,15,0,0,0,9,112,72,89,115, - 0,0,14,196,0,0,14,196,1,149,43,14,27,0,0,40,16,73,68,65,84,120,94,237,157,119,84,149,251,185,231,207, - 189,201,157,53,201,189,51,107,101,77,114,255,201,154,201,90,201,36,39,201,220,220,115,78,78,63,246,134,8,210,68,122, - 7,27,138,40,205,126,236,5,4,123,199,222,177,96,197,46,130,5,17,164,247,38,8,74,151,42,160,34,240,157,239,243, - 219,123,211,81,80,79,110,146,149,247,228,183,246,118,243,214,207,251,244,231,247,190,249,8,255,88,222,139,192,71,239,181, - 245,63,54,198,63,0,190,167,16,252,93,3,172,172,120,133,204,204,120,100,101,93,226,56,131,140,140,196,247,196,213,115, - 243,191,59,128,21,149,175,144,156,114,1,41,201,243,81,89,54,9,104,155,13,180,122,115,248,112,76,199,205,107,43,63, - 40,196,191,27,128,217,217,143,144,152,184,14,21,101,174,4,68,96,109,243,128,215,243,209,214,188,0,120,53,95,51,94, - 47,64,219,75,15,68,134,31,248,96,16,255,230,1,166,101,164,33,33,110,62,90,94,78,39,52,63,5,9,58,104,237, - 240,180,191,53,19,34,22,33,63,201,6,133,69,165,31,4,226,223,20,192,182,182,182,246,139,206,203,45,64,124,220,2, - 180,54,11,184,185,90,104,58,80,125,125,18,96,203,34,84,60,153,129,187,215,169,210,31,96,249,155,2,40,215,91,86, - 214,128,184,135,254,120,209,48,133,255,162,154,182,46,36,20,221,32,184,22,237,208,73,98,103,105,20,9,108,91,132,228, - 132,201,200,122,96,137,172,204,148,247,70,248,55,3,176,181,21,136,141,61,137,170,170,201,188,104,170,236,235,121,104,124, - 62,7,117,213,190,168,121,230,131,170,10,111,212,84,250,162,142,163,161,202,23,77,53,115,208,220,72,192,148,56,224,123, - 13,88,129,74,21,46,121,236,137,139,33,102,184,123,211,75,1,108,227,127,239,186,252,85,3,212,169,108,81,105,41,50, - 11,228,98,189,145,145,59,13,81,23,29,113,127,191,29,98,182,216,225,254,90,43,68,249,91,227,225,122,91,68,239,176, - 65,116,136,29,238,221,112,68,70,214,84,148,151,122,33,35,115,26,238,92,114,64,45,1,55,214,248,17,174,31,202,114, - 60,241,224,150,19,98,110,152,32,191,32,255,93,217,169,237,122,0,236,108,103,222,107,207,31,104,227,203,49,199,17,125, - 194,24,89,43,108,145,110,108,134,70,19,123,192,210,25,176,113,1,108,181,195,78,62,181,191,89,243,187,149,11,82,245, - 38,32,116,130,62,42,204,109,1,35,23,220,57,107,143,178,18,79,20,103,123,162,52,215,19,81,215,29,145,114,207,1, - 49,247,214,189,215,153,246,42,129,89,41,201,120,224,53,27,15,23,47,70,70,122,58,18,18,18,222,235,32,239,178,113, - 210,131,7,72,242,243,67,141,161,9,96,77,56,246,28,206,28,46,50,156,248,157,67,62,59,15,249,205,213,25,249,86, - 86,120,102,79,208,147,38,163,120,226,68,212,219,218,226,174,158,17,146,190,183,197,131,123,46,40,47,155,141,103,133,179, - 17,121,217,30,201,81,86,120,245,250,93,206,80,179,77,15,128,209,103,206,32,247,139,47,240,100,216,240,46,123,141,143, - 125,136,146,226,226,119,63,82,63,183,76,186,115,7,73,214,214,192,132,9,132,102,167,1,38,96,20,48,29,64,45,204, - 206,16,219,191,243,111,147,92,209,234,236,130,116,35,35,196,143,51,68,234,248,241,168,176,179,67,147,141,35,90,76,29, - 17,235,49,17,241,49,110,40,204,159,129,180,104,91,36,39,222,234,231,217,245,92,173,11,192,178,134,122,36,127,249,21, - 158,24,25,162,98,214,172,30,107,23,102,102,226,49,37,242,125,150,190,76,68,97,89,57,226,93,169,126,102,166,128,147, - 99,39,96,221,165,77,11,145,146,6,87,6,205,178,141,12,55,126,119,115,67,139,147,19,30,155,155,35,110,220,56,36, - 27,26,34,121,188,64,52,64,51,247,249,136,146,169,182,113,112,65,147,145,29,238,172,178,68,81,233,116,196,221,247,127, - 231,75,234,2,240,65,80,32,74,244,245,81,106,102,134,221,127,252,99,175,59,77,240,245,65,125,235,187,123,45,217,105, - 234,145,35,200,157,62,29,121,222,94,200,91,190,28,247,252,215,160,96,172,30,47,204,17,109,58,137,211,169,170,75,103, - 64,174,4,225,132,122,59,91,84,217,88,161,212,210,10,197,22,150,106,228,154,77,64,10,37,77,192,37,25,16,156,161, - 145,26,169,4,152,165,103,136,92,83,222,152,73,76,237,58,75,179,173,43,210,236,205,113,46,140,102,226,29,151,46,0, - 239,240,4,74,121,160,187,163,71,99,235,111,126,141,220,176,139,61,118,219,252,48,22,55,228,36,212,242,110,32,99,71, - 12,71,49,213,171,216,196,4,213,19,204,209,34,42,43,23,167,147,168,78,208,94,82,245,42,205,44,80,168,111,132,220, - 17,250,200,29,58,22,143,134,140,69,238,224,49,200,29,36,223,245,145,63,204,0,143,70,26,32,119,148,1,178,9,43, - 211,192,8,105,4,39,159,169,223,141,134,255,44,99,164,12,25,131,23,14,14,26,105,213,218,80,117,179,156,92,241,120, - 220,88,100,23,60,126,39,132,237,0,107,24,229,39,127,253,53,202,105,116,67,191,251,14,251,62,255,28,187,62,254,184, - 199,78,95,151,148,34,247,15,191,103,117,35,243,157,14,40,27,69,81,138,146,244,198,34,209,96,60,18,40,45,162,98, - 73,134,6,40,160,221,171,181,177,193,107,27,123,84,26,152,33,251,155,49,56,55,108,24,182,77,50,192,178,37,22,240, - 216,110,11,199,99,78,48,15,115,131,217,173,169,48,13,159,138,137,55,166,192,250,180,51,166,236,177,199,194,181,214,216, - 232,101,138,16,163,49,72,255,122,36,174,82,16,76,162,166,195,186,122,49,22,250,153,32,111,140,33,225,185,41,71,211, - 238,136,148,68,186,160,196,96,28,242,203,202,6,124,77,237,0,243,10,11,81,48,100,8,42,38,90,224,224,87,95,97, - 255,151,95,98,223,39,159,226,40,47,160,243,82,123,240,32,29,204,48,68,76,145,76,224,221,150,228,83,39,145,50,98, - 36,82,168,98,41,148,20,25,25,132,153,63,114,28,226,190,24,142,109,78,227,224,190,205,6,70,209,238,176,44,154,15, - 187,71,115,97,159,227,7,167,172,57,112,206,240,131,107,186,31,92,210,124,225,154,230,163,62,93,248,155,83,166,31,28, - 185,142,125,238,92,216,149,45,196,208,179,14,152,152,50,27,174,220,198,236,188,11,190,9,177,65,6,165,49,197,192,0, - 207,172,109,148,189,84,18,79,105,108,19,239,78,27,153,71,173,120,54,64,173,106,7,152,150,156,140,39,35,70,40,9, - 220,255,213,151,56,64,128,135,248,185,239,211,207,176,235,55,255,23,97,78,14,56,97,108,132,200,161,67,81,54,201,13, - 25,159,125,134,146,166,198,1,19,124,41,18,200,16,35,122,204,24,26,248,241,200,28,55,30,69,67,199,225,132,193,40, - 204,220,98,11,163,44,111,216,22,204,39,44,130,74,37,164,100,66,74,242,214,124,38,107,62,93,229,223,106,240,187,252, - 166,253,187,124,78,202,156,11,211,19,142,112,73,229,250,4,109,114,194,1,198,33,246,48,188,232,2,31,215,81,200,255, - 102,52,50,245,12,104,31,13,80,99,43,32,5,162,179,198,246,242,188,30,78,145,76,167,255,75,59,192,244,212,52,60, - 25,62,28,101,244,96,71,191,249,70,73,224,33,74,162,64,60,200,239,251,63,253,20,219,126,249,75,188,108,214,4,77, - 197,60,129,164,19,33,253,63,146,118,205,123,243,152,248,59,216,35,207,216,20,133,67,245,169,110,163,96,125,202,25,150, - 79,23,192,81,160,165,104,1,9,168,78,240,218,191,19,154,139,130,217,125,16,94,198,28,152,158,114,132,83,34,191,139, - 228,133,58,41,128,242,155,140,17,135,172,96,30,63,27,27,38,211,169,124,59,26,105,99,199,33,141,82,215,196,243,209, - 129,132,249,4,196,159,63,215,239,235,106,7,248,184,188,28,143,6,15,66,217,132,137,56,63,120,8,246,51,22,212,0, - 236,24,193,191,251,29,30,71,104,98,166,18,198,104,15,231,50,215,28,192,146,28,117,15,48,53,97,96,236,136,219,223, - 13,135,235,30,91,88,16,156,168,160,146,172,206,67,73,23,7,129,186,81,18,221,168,170,147,40,81,110,28,147,148,250, - 114,168,223,249,27,191,79,206,156,3,171,240,105,176,187,231,1,203,107,147,49,145,118,82,36,79,7,207,244,148,3,12, - 246,90,195,54,122,38,108,159,44,132,249,205,169,56,110,60,26,133,195,245,145,64,27,156,71,231,41,82,248,140,65,119, - 44,237,115,115,63,175,171,29,96,3,55,136,255,246,91,148,211,43,222,29,61,10,123,122,1,40,146,184,249,183,191,165, - 215,50,164,209,53,196,77,211,209,40,168,44,234,215,161,90,184,86,54,195,14,24,91,97,131,245,40,24,101,120,195,41, - 103,142,70,5,117,224,116,208,4,140,216,57,194,179,143,246,132,181,56,11,113,28,161,206,148,40,123,24,29,183,235,50, - 140,153,255,154,156,116,128,57,109,221,248,195,54,48,59,45,146,215,25,158,35,255,46,195,1,38,148,68,181,239,116,95, - 76,124,50,15,158,254,19,233,172,40,141,226,208,120,93,233,38,198,136,102,18,113,255,208,161,126,93,87,151,48,38,198, - 116,2,238,27,234,33,111,188,49,130,255,252,231,30,18,120,128,210,184,147,222,57,135,1,106,177,169,25,34,245,244,120, - 167,102,178,74,114,77,29,236,77,121,116,86,108,44,48,72,31,238,139,141,97,89,76,169,163,141,106,183,97,90,128,34, - 73,46,41,190,176,139,152,142,9,103,157,97,116,212,14,198,132,101,18,194,11,151,65,40,10,66,95,67,212,85,251,183, - 14,201,211,168,175,12,19,145,194,125,86,74,189,117,199,118,200,159,71,105,156,130,123,67,70,35,155,161,146,132,63,23, - 233,76,15,140,28,57,112,128,151,151,172,198,131,100,23,84,142,49,83,240,52,142,164,67,133,197,59,239,18,128,198,198, - 40,33,192,8,189,145,120,241,146,133,201,150,105,136,143,191,242,198,3,230,47,91,15,183,32,19,216,21,206,235,226,20, - 196,150,137,26,138,163,176,184,60,137,208,108,9,141,160,148,237,210,72,140,92,184,6,64,7,140,190,0,105,214,239,99, - 189,211,142,208,219,54,1,142,177,179,53,82,168,164,223,27,206,84,127,227,212,89,184,160,55,10,143,8,49,158,33,205, - 213,63,253,39,138,202,223,30,214,116,145,192,140,71,33,120,90,225,142,220,97,134,136,29,59,22,193,132,37,78,164,29, - 34,129,238,162,100,62,101,166,82,98,100,140,8,103,119,68,199,44,65,67,197,44,20,22,216,19,102,223,12,157,79,121, - 194,46,143,118,75,167,166,226,57,197,190,81,234,44,175,78,134,209,17,91,141,148,81,130,4,92,79,64,218,223,9,193, - 148,195,68,28,68,168,124,106,254,221,5,176,86,85,123,223,135,147,58,214,196,75,110,42,28,106,55,31,60,15,163,92, - 95,156,209,31,141,71,140,12,194,191,249,22,241,39,79,190,85,10,219,1,214,213,1,165,37,83,81,88,60,3,217,131, - 13,81,201,112,230,112,123,56,163,145,66,145,200,99,95,127,131,50,11,11,20,143,213,71,234,254,195,200,126,148,128,151, - 53,238,200,76,103,209,178,143,101,245,165,117,176,78,247,232,18,110,184,80,234,28,99,103,181,135,25,157,37,77,167,110, - 2,102,60,1,141,61,237,128,209,252,28,206,207,193,135,173,48,100,247,68,12,219,110,138,145,219,205,49,132,159,131,246, - 91,98,232,9,59,140,10,117,128,30,135,161,128,237,4,181,171,68,106,110,142,56,24,51,218,69,177,179,202,243,83,18, - 229,156,140,51,189,113,131,234,155,61,106,52,162,87,175,233,63,192,228,228,243,92,217,15,15,19,167,32,251,171,145,120, - 58,193,12,143,153,216,239,254,243,231,216,251,249,23,56,64,167,178,243,63,62,69,38,83,166,50,61,83,36,125,62,20, - 100,142,168,27,82,229,245,65,106,234,25,117,176,103,207,42,113,60,62,20,161,9,23,144,150,157,134,200,7,183,97,146, - 52,169,253,78,171,152,142,6,220,238,246,12,165,174,58,195,46,106,170,83,85,129,54,230,140,19,6,29,178,132,213,70, - 115,248,175,179,198,233,64,71,196,5,49,99,216,236,142,198,221,179,240,114,175,23,94,237,243,194,139,61,94,168,217,225, - 129,236,245,147,113,221,223,9,59,215,217,97,234,134,137,10,242,40,6,211,227,21,72,141,41,232,44,145,234,184,98,83, - 105,46,196,238,106,194,36,14,70,4,166,247,103,32,245,207,67,16,237,235,219,127,128,169,41,108,5,178,84,158,16,55, - 155,213,222,147,40,26,52,8,37,84,213,167,98,235,190,28,134,3,127,248,2,215,167,25,33,125,159,35,210,46,186,34, - 147,235,37,38,45,69,106,130,51,226,19,28,240,228,73,189,58,152,233,46,123,232,95,178,134,201,45,23,198,92,83,96, - 124,219,21,86,215,167,40,155,35,119,89,62,173,111,78,211,168,108,39,227,46,23,103,32,208,66,152,174,173,159,128,99, - 107,237,80,190,101,58,154,15,122,163,126,191,23,170,14,204,66,197,254,89,40,221,231,137,146,189,51,81,188,167,99,200, - 191,203,247,205,194,51,174,83,123,128,80,101,155,157,158,56,23,224,0,215,245,230,24,116,194,86,35,149,234,120,29,230, - 65,73,61,109,173,9,165,81,7,81,76,140,99,222,92,76,217,56,17,137,246,111,207,182,148,10,23,21,85,161,169,65, - 34,240,69,40,125,58,21,165,207,129,132,11,87,145,242,237,112,196,143,210,71,82,40,171,32,210,87,192,82,142,197,106, - 61,128,141,28,2,215,124,206,163,19,97,128,204,197,126,207,100,24,158,176,209,56,130,99,246,48,216,111,133,209,155,204, - 224,248,112,150,242,126,54,17,238,10,158,82,83,173,173,26,47,224,142,89,195,59,112,34,50,131,38,227,21,1,212,16, - 132,192,122,186,123,38,158,236,158,129,178,3,44,130,134,248,161,238,204,124,60,63,191,16,141,23,23,161,49,108,33,26, - 46,44,66,253,217,249,168,57,57,23,21,135,189,21,216,167,187,61,80,186,215,19,213,220,230,245,65,31,164,5,185,97, - 106,16,213,253,36,61,186,216,206,46,54,86,50,21,241,222,142,154,216,82,27,17,88,229,123,99,71,128,92,219,155,23, - 5,176,170,186,9,15,35,232,89,51,39,225,101,173,47,106,159,77,65,86,254,121,132,199,134,225,37,213,83,211,148,225, - 206,164,3,38,223,91,23,177,97,61,31,173,210,172,102,151,11,109,2,119,54,30,231,222,192,230,171,123,160,23,98,209, - 30,54,152,50,38,51,62,230,128,113,187,44,53,78,130,96,219,195,10,2,28,125,214,17,22,235,204,144,177,97,18,193, - 249,40,41,19,104,79,41,85,181,167,230,226,229,213,37,192,157,213,96,205,11,184,43,131,118,233,78,183,33,191,201,144, - 117,238,173,65,243,205,101,168,63,51,15,197,251,52,48,43,246,207,70,203,33,31,220,89,235,132,81,219,39,192,128,33, - 82,119,7,35,82,104,202,56,83,130,117,177,139,182,177,30,48,190,204,124,185,63,0,53,16,95,177,63,16,204,70,139, - 37,202,178,92,81,95,54,67,211,168,86,128,22,162,229,213,2,60,175,246,67,204,109,23,68,156,180,197,237,67,214,184, - 119,216,22,225,71,173,240,56,219,131,123,240,193,163,71,23,240,56,191,24,131,14,26,118,216,28,173,87,53,161,3,144, - 24,77,238,180,46,212,248,142,234,186,105,149,5,90,15,120,163,146,23,249,36,120,6,42,142,120,107,160,69,5,104,97, - 17,222,237,126,142,200,213,104,147,117,5,184,0,229,62,94,112,95,229,135,188,240,52,216,3,213,7,189,208,184,115,38, - 220,252,77,49,250,28,29,201,73,221,205,212,134,75,226,88,206,17,98,246,28,88,92,154,4,227,72,39,156,10,215,216, - 246,190,150,30,37,125,233,15,36,196,93,67,92,164,3,138,179,60,80,87,230,139,202,18,111,92,161,81,14,155,51,14, - 137,139,205,144,190,122,34,210,86,153,171,145,185,218,2,103,253,244,81,152,99,139,226,146,103,234,56,38,82,20,56,69, - 21,238,28,191,105,193,41,213,165,97,255,150,222,244,166,191,3,94,80,50,158,238,241,224,69,82,221,110,44,231,69,139, - 116,105,129,17,72,191,224,201,122,189,13,5,115,21,192,138,243,139,203,75,148,68,150,238,157,133,54,74,250,162,21,19, - 48,130,78,70,19,54,233,28,140,166,240,48,225,140,11,61,178,15,70,108,52,130,249,78,214,16,185,244,213,250,236,1, - 80,71,58,234,154,41,202,242,60,81,144,53,3,167,125,198,34,115,205,68,100,4,90,34,113,205,4,100,173,179,68,106, - 128,5,82,214,90,32,149,35,238,251,177,184,21,209,145,250,68,198,223,198,168,227,19,84,250,212,195,104,243,100,191,61, - 108,205,118,164,11,158,83,34,68,93,27,195,104,2,116,224,250,11,77,43,149,109,145,4,36,144,110,47,211,192,238,109, - 123,249,237,174,152,129,53,180,163,190,74,173,5,226,188,149,19,40,137,221,109,162,198,54,75,222,60,106,131,41,190,218, - 49,6,85,90,193,232,77,10,251,4,120,251,154,23,106,159,78,199,169,64,99,220,244,27,135,116,194,203,93,111,9,127, - 87,61,156,242,102,242,189,193,18,41,132,40,0,147,150,233,227,82,88,71,38,82,93,82,133,207,215,143,100,78,218,53, - 43,144,19,27,28,106,135,51,171,236,241,92,156,196,193,217,84,57,1,208,79,73,235,85,149,87,226,241,5,182,5,194, - 47,160,249,58,109,114,95,234,174,3,27,229,143,231,23,22,18,226,12,180,236,99,233,44,200,12,227,207,118,133,40,154, - 51,254,128,53,244,182,78,192,160,109,227,112,38,170,103,101,94,7,179,79,128,117,117,175,17,21,62,19,161,155,135,32, - 116,198,40,100,4,89,34,51,144,49,217,84,99,108,154,109,133,227,179,244,240,104,163,37,210,8,48,97,133,33,182,172, - 208,120,97,89,98,82,99,49,238,10,243,216,99,118,93,243,80,26,111,95,74,112,51,109,94,197,81,58,39,145,186,254, - 218,183,222,214,19,40,119,150,34,246,234,17,117,220,132,51,129,252,247,138,222,165,176,243,246,116,54,77,87,150,160,100, - 207,12,134,74,238,24,188,215,74,217,101,99,222,240,113,98,122,24,242,72,140,170,191,99,34,6,111,50,192,154,11,125, - 247,142,251,4,168,131,145,93,80,136,96,187,255,196,195,149,102,8,155,55,14,187,124,109,176,215,207,18,91,188,44,177, - 119,250,24,60,222,100,141,184,229,198,240,182,234,72,190,35,210,239,194,252,1,141,176,120,54,173,26,155,156,114,194,208, - 96,115,212,109,247,192,179,99,157,225,137,4,114,206,222,187,130,140,13,128,147,217,48,117,186,169,9,247,185,47,170,178, - 168,245,27,246,167,212,254,222,106,52,209,46,214,209,38,110,13,176,196,176,11,12,222,153,217,44,216,233,136,145,251,44, - 97,118,198,25,99,152,55,143,220,105,138,153,199,230,244,223,137,244,182,102,72,128,23,174,251,142,192,17,175,241,8,246, - 179,194,110,95,11,236,33,196,29,132,185,109,42,251,15,107,76,177,210,97,24,30,23,106,74,91,183,51,163,96,196,169, - 19,18,11,106,12,180,3,198,48,92,9,94,99,141,231,135,24,176,119,150,60,218,175,236,83,139,240,226,58,189,253,187, - 64,140,11,194,36,163,47,97,201,62,202,96,102,73,184,247,102,120,29,199,16,136,107,208,112,126,1,158,110,114,199,180, - 32,11,194,167,231,127,16,136,2,198,155,131,143,219,42,128,163,182,155,96,202,209,89,239,7,80,26,72,167,221,62,195, - 134,105,134,216,59,71,11,144,16,119,19,226,222,57,54,240,119,25,141,109,30,70,184,113,246,152,58,80,108,74,44,198, - 71,116,0,20,175,251,221,110,11,212,80,93,212,221,239,4,234,213,181,121,40,172,108,68,194,141,195,252,157,94,88,108, - 226,64,64,62,88,139,3,139,109,240,209,63,253,11,62,250,232,199,72,57,194,57,52,18,2,245,103,31,114,46,177,129, - 184,189,137,241,94,108,80,199,54,247,131,96,19,104,10,147,115,46,24,186,105,60,166,28,122,79,128,2,101,219,228,145, - 88,100,63,18,251,231,90,183,75,224,30,63,129,104,161,129,234,61,1,187,150,107,14,84,81,88,142,49,87,45,219,43, - 194,6,180,41,62,114,135,207,49,16,167,234,180,95,28,3,226,162,227,12,149,88,197,41,41,175,68,91,56,255,222,159, - 11,239,102,207,74,46,44,192,71,255,252,19,252,248,39,255,19,161,171,217,148,167,20,189,117,63,2,143,160,227,14,120, - 106,2,240,206,251,164,109,13,10,176,194,88,106,205,240,109,70,88,24,202,27,219,199,242,86,27,168,219,238,92,200,33, - 120,27,125,134,253,243,108,168,190,26,21,110,31,74,165,45,176,194,97,68,251,97,70,31,50,135,177,182,42,60,230,140, - 3,142,173,225,36,159,238,39,202,96,183,246,242,2,24,77,180,67,232,165,27,200,58,194,224,189,251,58,125,57,15,221, - 239,2,34,99,11,126,241,239,255,142,31,253,247,255,129,61,243,44,41,77,107,219,129,180,169,16,71,55,186,222,188,146, - 243,243,81,193,148,176,75,20,32,17,193,205,229,56,22,96,7,189,51,236,163,236,53,69,240,205,253,239,15,80,246,224, - 52,236,247,216,234,105,74,137,19,120,221,32,242,223,219,220,245,144,150,150,170,14,246,253,165,85,24,23,98,173,156,200, - 16,38,243,57,219,220,123,170,150,156,236,195,32,170,222,63,113,124,132,235,27,153,188,71,119,92,124,187,84,8,36,221, - 208,101,25,157,193,114,31,129,158,70,74,133,15,126,207,78,91,140,236,99,149,50,23,109,151,86,163,245,58,51,148,107, - 226,241,53,230,65,133,78,180,127,113,44,62,40,123,220,57,118,164,86,180,92,94,140,48,222,112,41,143,13,63,110,134, - 132,228,190,39,87,245,91,2,5,202,230,101,190,88,100,195,134,211,92,170,172,146,192,206,16,45,176,147,23,17,118,108, - 143,2,152,144,158,136,33,135,141,84,177,243,219,61,230,104,13,101,217,75,210,171,110,170,130,244,205,248,249,47,126,161, - 164,39,120,1,123,38,180,73,93,214,97,220,166,126,75,96,40,17,191,22,229,55,150,160,240,226,92,180,197,240,119,21, - 63,106,109,102,210,6,252,230,87,191,68,25,11,12,34,197,45,55,86,163,229,212,90,180,92,240,71,235,233,0,180,222, - 165,167,215,129,34,188,196,195,179,21,196,30,170,206,115,124,201,98,197,149,53,246,170,28,246,221,134,177,125,74,159,252, - 97,64,0,243,242,30,97,202,136,143,9,206,74,171,190,93,1,138,29,220,190,112,106,251,1,141,183,90,195,232,180,61, - 190,219,106,6,92,99,124,166,212,169,147,26,201,5,241,194,199,13,249,4,31,253,203,191,34,96,150,137,146,72,117,161, - 209,116,4,201,235,144,72,27,21,198,144,105,51,59,104,55,141,205,17,107,98,133,84,115,123,156,27,103,140,198,187,221, - 130,112,238,75,224,181,221,94,161,0,42,104,114,76,25,157,164,236,101,248,10,228,156,100,173,175,251,13,149,115,99,193, - 226,249,201,57,184,232,79,175,126,154,137,195,217,55,207,31,28,16,64,33,51,219,106,12,2,38,233,99,159,206,27,139, - 36,250,90,34,216,139,14,133,23,186,196,114,112,59,192,140,204,12,124,189,79,31,131,118,154,211,174,200,197,116,203,56, - 228,162,232,253,118,204,179,160,250,253,55,4,206,38,104,145,54,122,214,219,254,174,216,248,229,183,8,97,251,115,215,224, - 225,40,116,157,132,92,23,87,100,115,54,65,186,163,35,178,108,156,16,207,122,33,238,107,165,72,87,72,16,181,85,55, - 73,62,187,130,83,55,79,84,247,32,85,87,102,100,245,150,246,241,6,212,50,197,60,30,104,143,63,6,143,70,99,21, - 107,123,111,88,6,12,240,242,153,16,120,25,253,25,7,232,76,118,121,90,96,157,155,41,252,89,104,221,31,96,141,208, - 96,59,28,9,52,193,149,203,23,218,15,185,242,68,0,254,180,207,80,213,239,84,25,74,123,210,114,113,173,58,9,98, - 44,247,209,71,255,140,115,129,156,248,35,54,48,46,16,135,172,13,17,58,98,52,182,15,25,138,6,78,180,124,62,119, - 14,234,231,116,140,34,215,169,136,15,152,166,145,212,118,135,162,43,66,104,37,189,59,32,222,192,134,235,203,240,232,52, - 3,99,201,141,123,3,200,117,170,89,75,12,8,52,195,146,183,72,223,128,85,88,71,197,105,200,199,88,230,160,143,155, - 231,93,209,208,36,205,117,70,255,44,172,54,55,177,252,5,73,233,60,89,96,213,196,132,178,152,7,79,193,173,67,116, - 16,188,251,2,174,141,39,217,66,227,222,66,219,212,22,193,139,229,197,180,74,173,79,73,147,84,79,2,16,187,109,26, - 142,124,61,20,119,41,109,77,115,231,162,150,211,234,106,125,88,171,148,193,82,123,131,151,31,210,54,176,140,38,146,212, - 223,216,145,246,244,254,122,198,124,188,73,221,227,81,117,19,120,94,175,174,45,69,205,94,15,204,158,111,244,70,201,211, - 253,113,192,18,40,27,110,15,90,136,218,114,15,60,175,241,193,233,29,150,216,48,219,24,43,156,198,35,192,197,24,203, - 29,198,99,251,18,125,100,164,46,233,114,2,199,131,9,154,89,130,146,188,35,129,52,238,244,118,87,9,78,103,23,187, - 171,119,82,16,150,126,253,5,170,8,172,142,192,4,154,110,212,240,183,134,89,190,72,223,69,71,32,78,230,77,177,163, - 202,151,121,227,120,156,82,22,105,211,143,136,243,232,99,27,222,200,58,86,183,43,118,77,66,74,12,211,194,126,44,239, - 4,48,57,218,1,119,46,218,98,185,157,1,109,159,37,118,251,48,35,209,198,133,98,27,87,59,12,199,227,39,57,93, - 14,95,248,164,4,77,151,152,3,43,67,173,43,65,105,237,84,23,0,90,245,163,20,70,236,152,130,103,238,94,61,0, - 10,200,202,233,94,200,63,71,105,23,85,124,19,64,74,253,43,170,109,25,213,50,42,192,73,5,217,202,54,246,182,13, - 215,173,60,234,141,156,32,107,84,214,191,232,7,190,1,122,97,221,30,147,239,89,98,142,195,55,116,38,134,216,39,33, - 141,4,210,116,36,123,180,233,221,206,25,6,72,140,127,216,227,4,30,134,210,195,222,145,116,237,109,229,43,237,5,38, - 4,226,238,92,55,52,121,207,105,87,93,81,225,122,2,140,159,204,9,153,15,197,254,245,132,161,212,83,192,210,203,86, - 159,154,195,74,55,11,182,251,61,145,192,18,86,223,21,32,185,169,107,88,161,153,142,187,107,185,239,126,46,3,146,64, - 221,212,141,170,234,106,236,223,177,8,62,38,236,21,119,207,76,8,81,226,193,115,7,183,245,56,133,170,134,215,40,56, - 206,212,41,74,3,176,87,59,212,77,26,95,61,88,133,152,105,147,9,209,79,169,112,13,109,97,227,44,182,95,55,18, - 134,178,127,157,111,134,54,172,161,138,54,72,205,143,182,76,154,76,165,236,179,228,109,157,134,98,166,124,202,145,245,118, - 3,105,66,26,47,127,143,178,93,83,145,116,110,119,63,241,189,163,4,234,246,238,60,236,99,108,153,105,166,205,76,58, - 82,187,221,62,19,176,209,151,57,105,47,75,46,99,201,130,157,156,139,39,25,128,54,14,235,19,164,182,146,92,127,119, - 25,238,77,119,195,243,153,180,125,30,126,136,244,164,183,230,227,94,29,57,181,38,60,145,253,73,177,180,132,234,42,109, - 130,18,105,129,170,54,168,39,42,143,49,238,123,147,189,148,106,245,113,95,20,111,117,70,122,70,250,95,6,224,174,160, - 101,88,100,61,152,82,216,185,192,160,1,185,218,97,8,154,251,152,66,157,147,155,139,132,53,86,120,121,129,142,69,171, - 106,93,250,32,186,254,134,78,82,84,202,23,128,12,86,144,83,216,84,87,240,218,59,113,98,227,232,57,217,214,148,42, - 179,72,156,64,19,169,147,33,223,165,89,213,42,222,254,77,53,66,30,163,132,219,223,95,43,143,203,246,127,25,144,10, - 119,223,109,41,43,40,110,67,127,195,180,78,50,19,25,154,204,68,42,52,59,166,179,1,21,23,211,203,153,104,168,86, - 212,55,33,34,200,3,101,219,157,81,207,184,76,32,104,58,105,34,77,58,71,163,109,48,169,150,37,1,72,250,166,205, - 115,155,174,44,86,208,4,144,244,56,138,233,97,59,131,83,0,181,125,229,186,115,218,52,178,175,126,11,111,98,253,217, - 5,202,251,198,93,59,213,127,122,92,243,189,0,202,145,230,187,77,192,26,87,61,102,38,2,78,151,31,211,14,50,45, - 11,221,187,241,173,39,19,23,121,21,15,86,219,162,98,135,27,103,23,80,213,232,5,171,9,70,26,232,245,188,112,25, - 117,236,241,202,111,149,108,3,40,137,18,96,108,70,233,160,149,208,65,148,114,102,130,78,234,212,119,174,39,210,168,90, - 7,18,108,171,166,82,95,217,199,106,21,226,196,175,177,65,227,91,207,184,235,10,239,13,48,226,230,21,120,25,126,194, - 50,151,181,54,63,182,98,217,223,18,187,124,38,98,163,143,166,37,216,219,210,233,209,95,245,231,216,168,187,56,179,216, - 1,153,155,39,227,25,91,156,114,65,237,211,55,228,187,72,24,109,153,146,50,5,75,62,59,84,181,51,60,1,90,188, - 199,83,245,131,165,180,149,119,202,15,89,39,253,112,127,55,83,191,238,118,144,80,235,66,37,246,155,140,216,203,39,6, - 136,239,3,72,160,28,209,101,228,127,168,50,151,244,73,54,187,143,195,73,95,35,156,244,49,196,60,179,207,209,40,83, - 83,251,88,234,57,143,54,41,246,54,210,47,111,69,225,105,102,49,41,235,113,125,173,51,195,68,71,20,82,194,52,80, - 180,208,180,54,173,179,109,107,135,214,233,111,2,88,164,179,82,250,46,84,119,201,123,115,78,112,223,15,2,144,195,153, - 14,15,246,209,30,234,242,100,122,228,215,44,44,72,232,114,39,136,153,210,59,44,239,45,129,114,204,253,155,215,96,38, - 67,154,155,11,249,168,2,219,157,89,172,62,203,200,94,165,143,196,7,119,123,156,86,106,90,10,82,194,54,163,48,132, - 161,72,36,231,218,176,122,34,94,57,141,23,93,75,213,45,163,180,41,233,162,164,149,104,225,148,243,179,98,63,85,114, - 239,116,14,119,84,106,63,43,8,68,126,47,99,109,79,36,84,230,209,200,124,25,81,219,130,211,115,209,192,105,30,169, - 162,198,12,121,210,143,177,31,195,188,59,138,30,26,209,44,115,69,172,100,179,157,83,63,56,135,38,124,145,9,74,159, - 85,15,24,225,7,1,40,7,246,27,245,43,228,176,111,44,125,98,105,184,203,72,91,53,30,247,143,111,82,39,37,115, - 251,19,162,174,16,18,165,33,156,70,93,160,49,189,210,133,48,45,148,138,180,227,188,64,230,169,42,134,147,9,66,156, - 73,80,177,135,176,118,185,33,53,200,22,81,27,103,34,106,255,106,220,59,182,25,119,142,110,69,212,177,77,184,179,119, - 57,238,174,155,142,100,62,51,92,39,55,68,250,42,226,132,168,170,73,135,165,63,194,152,144,153,136,202,115,35,120,76, - 58,164,87,183,150,35,155,37,171,70,214,253,36,200,22,41,175,218,239,129,251,123,249,247,1,46,31,4,160,28,243,192, - 92,91,68,46,208,103,3,94,211,108,79,13,224,244,143,128,9,184,177,202,25,57,89,25,200,58,198,139,185,77,105,235, - 173,38,200,180,45,129,82,36,69,4,77,203,81,188,239,82,164,239,156,132,123,33,219,112,37,34,26,137,79,26,144,253, - 172,13,153,124,23,76,86,217,75,53,114,202,95,161,176,174,13,85,52,19,149,236,171,164,164,167,34,249,250,126,20,157, - 156,133,134,107,11,81,202,142,155,198,179,251,227,53,203,244,47,232,185,91,111,177,172,70,233,76,20,251,72,181,174,9, - 157,171,129,200,155,149,185,214,18,21,117,77,3,66,248,193,0,62,188,119,11,167,38,127,137,140,117,44,120,174,157,168, - 32,74,211,61,114,225,56,228,108,114,234,40,59,117,43,159,203,197,213,157,158,135,100,1,40,94,146,61,226,210,208,89, - 136,141,56,131,106,138,173,152,208,87,28,13,175,218,80,219,244,90,141,186,166,22,245,239,151,252,227,11,174,211,244,186, - 141,3,120,201,8,73,214,173,226,247,203,4,143,40,141,196,149,209,41,73,44,168,166,202,241,179,138,65,117,11,143,147, - 67,41,20,211,241,58,124,57,189,60,95,31,112,196,3,169,209,87,255,107,0,202,81,183,218,127,137,216,229,38,72,235, - 36,133,233,156,243,23,177,140,125,10,93,55,174,125,230,148,191,154,133,85,78,251,115,159,51,75,85,90,198,140,35,238, - 248,34,20,85,53,170,231,52,4,138,128,106,100,68,222,251,104,69,67,183,191,41,176,220,54,43,234,44,143,185,92,133, - 69,101,180,151,207,118,79,66,85,176,27,237,231,52,53,65,179,146,80,83,143,211,54,74,25,77,21,56,36,214,92,169, - 28,218,64,150,15,38,129,114,208,203,251,215,227,210,236,161,156,6,162,145,66,101,7,249,121,107,137,185,154,29,37,118, - 168,249,198,82,21,180,138,7,21,59,87,70,103,17,191,157,133,81,230,188,81,199,86,64,158,87,121,193,23,76,8,24, - 13,156,214,78,240,228,187,110,244,14,85,0,138,20,166,133,109,64,203,181,239,81,73,27,26,185,217,27,55,239,39,225, - 122,108,6,110,132,236,65,209,102,71,229,56,98,215,185,160,77,23,214,168,178,215,74,100,30,239,152,162,210,31,144,31, - 20,96,69,93,35,118,219,252,1,201,1,230,237,206,36,131,18,120,121,222,120,101,164,75,152,168,151,202,108,83,218,27, - 241,170,226,57,101,94,96,206,209,217,200,60,197,128,153,42,72,237,68,227,27,165,238,77,18,73,232,90,9,204,60,179, - 28,13,39,188,17,205,25,175,233,85,64,30,95,151,242,168,180,30,5,181,188,209,151,175,50,3,114,66,5,111,94,186, - 52,226,117,205,37,222,224,167,39,103,171,115,232,239,242,65,1,202,65,15,46,226,4,204,249,99,53,206,68,28,9,63, - 239,44,208,195,221,115,71,144,120,116,13,98,54,123,50,130,112,192,195,213,214,92,199,22,113,43,45,241,244,52,39,137, - 63,46,86,54,236,125,224,233,212,92,220,64,206,153,133,168,166,202,94,187,114,29,121,229,47,144,243,180,22,217,28,57, - 79,106,145,207,217,241,17,219,23,161,138,33,76,18,179,149,246,2,43,1,214,158,231,100,207,1,56,146,15,14,48,158, - 113,223,201,201,95,112,14,161,21,114,56,143,48,59,104,34,114,86,234,33,43,67,211,47,214,45,162,102,50,210,115,242, - 56,7,123,133,10,115,222,108,239,222,44,121,157,109,164,148,66,147,105,231,178,3,173,145,80,84,143,220,226,58,5,80, - 65,124,82,67,105,108,196,141,187,15,149,77,140,221,202,0,186,83,118,210,112,217,15,197,229,253,143,7,63,56,64,1, - 180,205,233,43,132,207,31,135,45,238,6,88,61,101,60,150,59,141,198,249,67,157,235,131,157,94,225,148,124,23,233,113, - 183,148,225,255,80,0,101,95,34,89,177,65,236,228,145,69,206,211,154,118,128,237,32,249,123,252,90,71,196,240,209,9, - 85,160,208,206,217,169,15,243,65,121,141,88,226,254,45,63,8,192,203,7,183,96,230,120,62,91,50,223,78,205,155,217, - 227,59,17,91,231,247,94,229,77,139,10,67,81,73,57,94,136,237,235,211,219,246,95,250,116,78,36,113,199,44,196,236, - 240,67,238,179,214,30,240,68,141,115,159,181,32,154,65,121,60,31,133,104,188,196,248,84,197,158,44,42,132,122,162,94, - 108,73,63,151,31,4,96,35,227,50,167,193,191,110,159,132,180,87,230,205,216,13,233,245,148,194,175,95,197,115,6,116, - 141,140,91,62,36,192,184,61,11,16,179,115,110,239,0,169,202,185,12,200,35,79,238,65,238,102,23,85,173,86,19,219, - 37,192,222,218,49,49,160,63,12,127,16,128,114,96,127,223,169,88,229,60,154,101,46,169,210,200,188,25,125,164,165,246, - 124,217,215,237,219,183,81,223,244,234,131,1,148,155,32,49,100,20,211,189,152,77,30,200,165,7,206,161,221,211,169,174, - 238,51,175,252,37,110,135,157,66,254,22,87,100,17,154,196,134,37,193,211,112,127,167,60,121,213,255,229,7,3,152,146, - 148,136,25,122,127,108,159,205,181,99,166,17,174,157,234,249,12,110,25,95,244,80,81,93,175,130,230,15,33,129,178,143, - 38,198,145,55,195,206,35,145,249,177,198,6,106,28,72,231,145,75,207,28,25,118,22,57,27,29,81,32,121,55,243,225, - 138,221,236,135,92,57,222,127,122,92,243,7,3,40,103,225,110,252,29,54,78,55,106,159,63,184,115,41,67,134,94,150, - 216,196,52,48,124,99,224,220,57,104,238,191,221,211,129,151,237,37,181,43,171,125,133,123,169,69,200,92,62,22,49,121, - 85,93,188,112,187,4,86,80,2,47,156,64,156,191,13,131,106,198,164,140,75,139,54,219,33,239,113,225,95,15,192,115, - 33,135,49,207,156,111,0,209,118,238,86,58,143,234,245,228,238,68,199,169,186,161,2,241,142,65,116,195,43,13,124,145, - 228,76,62,186,246,168,134,181,212,117,174,8,191,193,56,176,172,169,167,4,86,52,227,222,241,237,136,89,109,131,114,206, - 133,169,96,160,127,87,102,58,12,112,249,65,37,80,206,197,105,232,111,17,236,195,89,172,44,247,111,154,204,87,4,20, - 61,233,113,138,249,156,200,158,94,84,141,151,84,61,129,240,46,225,140,0,228,255,80,88,241,156,0,171,85,240,28,126, - 49,20,15,130,23,34,191,186,77,5,208,29,177,32,131,105,102,36,49,219,253,88,144,177,71,5,31,183,40,223,233,134, - 180,4,62,85,63,192,229,7,7,184,101,197,60,172,112,28,161,26,240,59,102,26,34,242,138,60,86,219,117,201,127,148, - 141,51,103,67,81,240,236,165,170,176,52,169,60,184,191,234,172,89,79,182,43,171,105,66,102,97,181,22,86,13,178,171, - 90,113,109,129,9,30,230,148,32,183,164,190,29,98,94,201,115,68,103,149,33,150,79,43,229,239,156,129,106,150,182,174, - 48,95,175,108,228,29,24,224,242,131,3,124,82,82,194,57,133,191,83,173,207,93,156,190,22,178,181,163,104,89,86,221, - 128,216,208,181,104,189,198,232,63,212,139,246,170,14,217,197,53,120,78,81,122,169,117,42,34,89,2,179,235,208,21,25, - 58,224,21,87,53,32,93,193,211,121,92,102,28,124,236,244,97,102,33,78,44,112,64,1,159,198,125,84,246,156,163,1, - 69,236,28,157,219,180,136,246,207,14,53,44,186,198,5,186,226,249,205,37,40,56,229,139,124,78,65,25,200,242,131,3, - 148,147,153,235,98,138,245,83,13,148,26,175,157,49,81,157,95,76,248,57,148,51,104,85,15,198,168,121,123,203,25,122, - 44,71,14,189,102,70,97,21,138,89,210,18,123,38,1,182,212,251,58,123,104,145,80,85,255,227,223,164,62,152,75,232, - 25,180,123,157,213,84,167,174,143,152,182,37,231,22,99,251,250,181,56,127,243,62,46,223,73,196,174,85,243,89,37,178, - 69,29,235,130,177,65,174,40,149,169,119,42,144,94,129,154,243,94,234,193,157,58,201,51,251,177,252,69,0,222,139,12, - 135,143,241,103,56,200,204,100,153,195,24,164,156,151,105,188,124,62,174,219,204,81,68,45,197,133,157,171,65,65,100,206, - 90,75,144,207,240,152,54,173,130,211,248,107,26,95,227,57,235,92,117,116,179,213,13,205,40,225,35,186,57,37,4,199, - 117,36,191,237,13,158,14,162,168,111,1,95,208,93,80,213,76,19,194,71,120,15,76,86,143,211,222,92,98,141,154,43, - 242,156,94,183,118,39,171,225,69,39,102,35,249,218,62,100,229,100,191,241,101,80,127,17,128,114,35,39,27,124,141,229, - 206,122,120,198,249,39,186,185,49,61,38,56,178,232,218,112,212,3,151,183,46,70,90,69,139,74,250,5,78,86,81,141, - 178,109,25,218,33,78,66,126,83,224,122,137,241,122,4,205,90,251,151,207,244,237,120,208,2,196,241,129,159,4,122,232, - 74,122,223,166,48,166,113,189,205,221,150,194,111,228,50,180,222,152,135,172,163,94,72,187,178,29,105,15,174,242,165,107, - 25,180,181,13,208,89,203,191,0,64,77,94,121,104,215,122,52,223,146,156,243,13,243,249,100,126,10,213,170,106,223,52, - 214,241,166,32,252,65,138,242,150,185,229,141,200,125,202,138,74,39,79,218,1,73,11,81,254,198,33,146,43,127,203,35, - 180,188,210,58,20,148,63,71,4,247,147,87,82,167,226,193,180,178,87,184,195,38,84,221,1,119,205,235,3,88,155,84, - 211,74,250,124,196,86,55,21,143,205,170,136,37,192,173,69,104,186,56,11,231,57,53,69,76,201,15,10,80,55,155,43, - 241,225,61,180,92,151,121,48,111,121,184,144,0,53,221,56,102,5,236,145,20,111,117,64,196,182,5,184,126,51,18,41, - 101,175,241,184,166,141,32,158,83,117,9,131,128,242,233,16,196,81,8,44,249,183,124,127,196,145,91,92,139,112,169,64, - 71,197,225,218,157,135,218,106,140,86,205,185,94,6,165,251,50,77,69,217,86,134,48,60,142,244,146,95,93,151,103,149, - 181,51,24,116,48,213,4,117,205,4,77,53,179,129,21,235,215,87,253,232,248,214,41,27,44,203,15,10,80,14,240,164, - 184,28,149,103,180,119,89,57,11,206,162,239,54,71,69,117,226,216,145,147,198,142,154,129,160,230,181,104,154,234,117,135, - 102,162,229,152,7,10,215,91,33,116,221,60,36,164,229,240,117,4,79,145,150,91,136,43,145,49,72,200,126,194,167,67, - 243,148,148,133,71,39,225,70,84,130,26,121,37,148,66,86,160,5,170,146,86,157,244,170,79,74,38,37,59,252,94,28, - 110,175,157,204,194,43,29,201,110,119,148,49,30,148,41,37,77,124,78,68,38,101,54,223,88,198,217,254,203,241,250,18, - 223,201,112,108,26,30,30,93,172,108,98,231,229,7,7,152,124,78,251,8,42,155,55,210,251,141,98,87,76,217,64,29, - 68,185,187,52,226,53,156,8,41,93,51,105,50,213,178,17,254,146,179,8,192,6,121,12,39,158,123,24,126,205,23,92, - 186,33,112,195,38,44,95,182,20,11,230,207,199,92,78,56,159,54,117,10,70,143,214,67,224,150,93,40,98,12,41,243, - 90,42,89,142,126,90,67,251,41,146,170,3,215,155,234,243,55,177,177,185,4,121,245,70,36,34,183,206,69,1,223,69, - 93,197,166,125,13,27,78,13,52,37,205,39,124,145,179,101,50,82,206,5,163,232,73,113,175,62,249,157,1,62,127,254, - 28,213,156,104,217,219,168,169,169,105,127,143,86,193,37,218,60,78,217,200,225,252,148,76,62,45,46,143,48,104,122,181, - 28,236,196,181,114,86,86,61,231,229,189,8,97,139,145,13,245,58,194,59,225,107,6,171,193,127,84,51,247,229,9,166, - 254,142,255,253,127,126,133,201,238,179,112,236,204,37,198,123,245,168,167,249,173,102,105,166,130,80,75,235,91,81,82,251, - 154,112,57,216,47,149,207,98,130,46,171,111,1,29,180,122,7,78,62,159,104,184,127,227,18,246,206,54,199,76,253,79, - 241,167,143,127,131,121,75,215,224,212,185,139,200,204,202,26,56,192,251,247,239,227,147,79,62,193,79,127,250,211,126,95, - 68,111,23,235,199,103,232,138,66,105,3,117,47,146,160,106,188,160,170,228,239,112,199,213,239,173,16,196,138,181,197,160, - 63,224,127,253,219,79,222,235,56,189,29,251,227,63,252,63,140,55,53,135,187,167,55,22,46,93,141,192,77,187,176,110, - 203,110,142,96,44,93,179,30,179,253,22,192,210,214,9,159,127,241,53,126,250,175,255,246,214,227,255,236,103,63,131,151, - 23,27,81,218,229,173,18,152,157,157,141,176,176,48,108,223,190,29,139,22,45,194,180,105,211,224,200,71,15,140,248,226, - 194,113,124,99,174,62,223,250,219,125,24,243,229,100,191,255,253,239,223,122,50,253,149,172,191,182,245,228,186,251,13,176, - 31,193,248,27,87,73,76,76,68,112,112,48,102,206,156,9,61,190,46,239,215,191,254,53,126,244,163,31,255,213,195,253, - 249,207,127,142,47,248,186,43,27,190,20,119,197,138,21,184,120,241,34,255,143,16,88,157,237,182,188,85,2,223,23,224, - 219,182,111,110,110,70,49,223,144,158,150,150,134,168,168,40,92,186,116,9,33,33,33,216,187,119,47,54,111,222,12,127, - 127,127,44,230,43,233,253,248,180,146,168,142,135,135,7,166,78,157,202,247,199,186,194,137,111,3,118,224,171,141,237,249, - 238,83,249,20,205,112,230,11,101,39,241,149,202,238,238,238,152,197,151,137,251,248,240,237,28,243,230,97,57,223,87,189, - 110,221,58,236,220,185,19,135,15,31,70,104,104,40,194,195,195,249,64,80,60,114,57,229,184,182,150,222,228,29,150,255, - 15,187,196,238,208,143,8,92,235,0,0,0,0,73,69,78,68,174,66,96,130, -}; - -}; diff --git a/kaijuu/resource/resource.hpp b/kaijuu/resource/resource.hpp deleted file mode 100644 index bc301d6c..00000000 --- a/kaijuu/resource/resource.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace resource { - extern const uint8_t icon[13013]; -}; diff --git a/kaijuu/resource/resource.xml b/kaijuu/resource/resource.xml deleted file mode 100644 index f18f1b5d..00000000 --- a/kaijuu/resource/resource.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/kaijuu/settings.hpp b/kaijuu/settings.hpp deleted file mode 100644 index 4f3387ed..00000000 --- a/kaijuu/settings.hpp +++ /dev/null @@ -1,45 +0,0 @@ -struct Settings { - struct Rule { - string name; - string pattern; - bool defaultAction; - bool matchFiles; - bool matchFolders; - string command; - bool multiSelection; - }; - vector rules; - - void load() { - rules.reset(); - lstring ruleIDs = registry::contents("HKCU/Software/Kaijuu/"); - for(auto &ruleID : ruleIDs) { - string path = {"HKCU/Software/Kaijuu/", ruleID, "/"}; - rules.append({ - registry::read({path, "Name"}), - registry::read({path, "Pattern"}), - registry::read({path, "Default"}) == "true", - registry::read({path, "Files"}) == "true", - registry::read({path, "Folders"}) == "true", - registry::read({path, "Command"}), - }); - } - for(auto &rule : rules) { - rule.multiSelection = rule.command.position("{paths}") || rule.command.position("{files}"); - } - } - - void save() { - registry::remove("HKCU/Software/Kaijuu/"); - for(unsigned id = 0; id < rules.size(); id++) { - auto &rule = rules(id); - string path = {"HKCU/Software/Kaijuu/", id, "/"}; - registry::write({path, "Name"}, rule.name); - registry::write({path, "Pattern"}, rule.pattern); - registry::write({path, "Default"}, rule.defaultAction); - registry::write({path, "Files"}, rule.matchFiles); - registry::write({path, "Folders"}, rule.matchFolders); - registry::write({path, "Command"}, rule.command); - } - } -} settings; diff --git a/kaijuu/sync.sh b/kaijuu/sync.sh deleted file mode 100644 index 9185adcd..00000000 --- a/kaijuu/sync.sh +++ /dev/null @@ -1,7 +0,0 @@ -if [ -d ./nall ]; then rm -r ./nall; fi -if [ -d ./phoenix ]; then rm -r ./phoenix; fi -cp -r ../nall ./nall -cp -r ../phoenix ./phoenix -rm -r nall/test -rm -r phoenix/nall -rm -r phoenix/test diff --git a/higan/libco/amd64.c b/libco/amd64.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/amd64.c rename to libco/amd64.c diff --git a/higan/libco/fiber.c b/libco/fiber.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/fiber.c rename to libco/fiber.c diff --git a/higan/libco/libco.c b/libco/libco.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/libco.c rename to libco/libco.c diff --git a/higan/libco/libco.h b/libco/libco.h old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/libco.h rename to libco/libco.h diff --git a/higan/libco/ppc.c b/libco/ppc.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/ppc.c rename to libco/ppc.c diff --git a/higan/libco/sjlj.c b/libco/sjlj.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/sjlj.c rename to libco/sjlj.c diff --git a/higan/libco/ucontext.c b/libco/ucontext.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/ucontext.c rename to libco/ucontext.c diff --git a/higan/libco/x86.c b/libco/x86.c old mode 100755 new mode 100644 similarity index 100% rename from higan/libco/x86.c rename to libco/x86.c diff --git a/higan/nall/Makefile b/nall/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/Makefile rename to nall/Makefile diff --git a/higan/nall/algorithm.hpp b/nall/algorithm.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/algorithm.hpp rename to nall/algorithm.hpp diff --git a/higan/nall/any.hpp b/nall/any.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/any.hpp rename to nall/any.hpp diff --git a/higan/nall/atoi.hpp b/nall/atoi.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/atoi.hpp rename to nall/atoi.hpp diff --git a/nall/base64.hpp b/nall/base64.hpp new file mode 100644 index 00000000..7d9fb116 --- /dev/null +++ b/nall/base64.hpp @@ -0,0 +1,137 @@ +#ifndef NALL_BASE64_HPP +#define NALL_BASE64_HPP + +#include +#include +#include + +namespace nall { + +struct Base64 { + enum class Format : unsigned { MIME, URI }; + + inline static string encode(const uint8_t* data, unsigned size, Format format = Format::MIME); + inline static string encode(const vector& buffer, Format format = Format::MIME); + inline static string encode(const string& text, Format format = Format::MIME); + + inline static vector decode(const string& text); + +private: + inline static void table(char* data, Format format); + inline static uint8_t value(char data); +}; + +string Base64::encode(const uint8_t* data, unsigned size, Format format) { + vector result; + + char lookup[65]; + table(lookup, format); + + unsigned overflow = (3 - (size % 3)) % 3; //bytes to round to nearest multiple of 3 + uint8_t buffer; + + for(unsigned i = 0; i < size; i++) { + switch(i % 3) { + case 0: + buffer = data[i] >> 2; + result.append(lookup[buffer]); + buffer = (data[i] & 3) << 4; + result.append(lookup[buffer]); + break; + + case 1: + buffer |= data[i] >> 4; + result.last() = lookup[buffer]; + buffer = (data[i] & 15) << 2; + result.append(lookup[buffer]); + break; + + case 2: + buffer |= data[i] >> 6; + result.last() = lookup[buffer]; + buffer = (data[i] & 63); + result.append(lookup[buffer]); + break; + } + } + + if(lookup[64]) { + if(overflow >= 1) result.append(lookup[64]); + if(overflow >= 2) result.append(lookup[64]); + } + + return result; +} + +string Base64::encode(const vector& buffer, Format format) { + return encode(buffer.data(), buffer.size(), format); +} + +string Base64::encode(const string& text, Format format) { + return encode((const uint8_t*)text.data(), text.size(), format); +} + +vector Base64::decode(const string& text) { + vector result; + + uint8_t buffer, output; + for(unsigned i = 0; i < text.size(); i++) { + uint8_t buffer = value(text[i]); + if(buffer == 0) break; + + switch(i & 3) { + case 0: + output = buffer << 2; + break; + + case 1: + result.append(output | buffer >> 4); + output = (buffer & 15) << 4; + break; + + case 2: + result.append(output | buffer >> 2); + output = (buffer & 3) << 6; + break; + + case 3: + result.append(output | buffer); + break; + } + } + + return result; +} + +void Base64::table(char* data, Format format) { + for(unsigned n = 0; n < 26; n++) data[ 0 + n] = 'A' + n; + for(unsigned n = 0; n < 26; n++) data[26 + n] = 'a' + n; + for(unsigned n = 0; n < 10; n++) data[52 + n] = '0' + n; + + switch(format) { + case Format::MIME: + data[62] = '+'; + data[63] = '/'; + data[64] = '='; + break; + + case Format::URI: + data[62] = '-'; + data[63] = '_'; + data[64] = 0; + break; + } +} + +uint8_t Base64::value(char n) { + if(n >= 'A' && n <= 'Z') return n - 'A' + 0; + if(n >= 'a' && n <= 'z') return n - 'a' + 26; + if(n >= '0' && n <= '9') return n - '0' + 52; + if(n == '+' || n == '-') return 62; + if(n == '/' || n == '_') return 63; + return 0; +} + +} + +#endif diff --git a/higan/nall/beat/archive.hpp b/nall/beat/archive.hpp similarity index 100% rename from higan/nall/beat/archive.hpp rename to nall/beat/archive.hpp diff --git a/higan/nall/beat/base.hpp b/nall/beat/base.hpp similarity index 100% rename from higan/nall/beat/base.hpp rename to nall/beat/base.hpp diff --git a/higan/nall/beat/delta.hpp b/nall/beat/delta.hpp similarity index 100% rename from higan/nall/beat/delta.hpp rename to nall/beat/delta.hpp diff --git a/higan/nall/beat/linear.hpp b/nall/beat/linear.hpp similarity index 100% rename from higan/nall/beat/linear.hpp rename to nall/beat/linear.hpp diff --git a/higan/nall/beat/metadata.hpp b/nall/beat/metadata.hpp similarity index 100% rename from higan/nall/beat/metadata.hpp rename to nall/beat/metadata.hpp diff --git a/higan/nall/beat/multi.hpp b/nall/beat/multi.hpp similarity index 100% rename from higan/nall/beat/multi.hpp rename to nall/beat/multi.hpp diff --git a/higan/nall/beat/patch.hpp b/nall/beat/patch.hpp similarity index 100% rename from higan/nall/beat/patch.hpp rename to nall/beat/patch.hpp diff --git a/higan/nall/bit.hpp b/nall/bit.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/bit.hpp rename to nall/bit.hpp diff --git a/higan/nall/bmp.hpp b/nall/bmp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/bmp.hpp rename to nall/bmp.hpp diff --git a/higan/nall/compositor.hpp b/nall/compositor.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/compositor.hpp rename to nall/compositor.hpp diff --git a/higan/nall/config.hpp b/nall/config.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/config.hpp rename to nall/config.hpp diff --git a/higan/nall/crc16.hpp b/nall/crc16.hpp similarity index 100% rename from higan/nall/crc16.hpp rename to nall/crc16.hpp diff --git a/higan/nall/crc32.hpp b/nall/crc32.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/crc32.hpp rename to nall/crc32.hpp diff --git a/higan/nall/directory.hpp b/nall/directory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/directory.hpp rename to nall/directory.hpp diff --git a/higan/nall/dl.hpp b/nall/dl.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dl.hpp rename to nall/dl.hpp diff --git a/ananke/nall/dsp.hpp b/nall/dsp.hpp similarity index 100% rename from ananke/nall/dsp.hpp rename to nall/dsp.hpp diff --git a/higan/nall/dsp/buffer.hpp b/nall/dsp/buffer.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/buffer.hpp rename to nall/dsp/buffer.hpp diff --git a/higan/nall/dsp/core.hpp b/nall/dsp/core.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/core.hpp rename to nall/dsp/core.hpp diff --git a/higan/nall/dsp/resample/average.hpp b/nall/dsp/resample/average.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/average.hpp rename to nall/dsp/resample/average.hpp diff --git a/higan/nall/dsp/resample/cosine.hpp b/nall/dsp/resample/cosine.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/cosine.hpp rename to nall/dsp/resample/cosine.hpp diff --git a/higan/nall/dsp/resample/cubic.hpp b/nall/dsp/resample/cubic.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/cubic.hpp rename to nall/dsp/resample/cubic.hpp diff --git a/higan/nall/dsp/resample/hermite.hpp b/nall/dsp/resample/hermite.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/hermite.hpp rename to nall/dsp/resample/hermite.hpp diff --git a/higan/nall/dsp/resample/lib/sinc.hpp b/nall/dsp/resample/lib/sinc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/lib/sinc.hpp rename to nall/dsp/resample/lib/sinc.hpp diff --git a/higan/nall/dsp/resample/linear.hpp b/nall/dsp/resample/linear.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/linear.hpp rename to nall/dsp/resample/linear.hpp diff --git a/higan/nall/dsp/resample/nearest.hpp b/nall/dsp/resample/nearest.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/nearest.hpp rename to nall/dsp/resample/nearest.hpp diff --git a/higan/nall/dsp/resample/sinc.hpp b/nall/dsp/resample/sinc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/dsp/resample/sinc.hpp rename to nall/dsp/resample/sinc.hpp diff --git a/ananke/nall/dsp/settings.hpp b/nall/dsp/settings.hpp similarity index 100% rename from ananke/nall/dsp/settings.hpp rename to nall/dsp/settings.hpp diff --git a/higan/nall/emulation/super-famicom-usart.hpp b/nall/emulation/super-famicom-usart.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/emulation/super-famicom-usart.hpp rename to nall/emulation/super-famicom-usart.hpp diff --git a/ananke/nall/endian.hpp b/nall/endian.hpp similarity index 100% rename from ananke/nall/endian.hpp rename to nall/endian.hpp diff --git a/higan/nall/file.hpp b/nall/file.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/file.hpp rename to nall/file.hpp diff --git a/higan/nall/filemap.hpp b/nall/filemap.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/filemap.hpp rename to nall/filemap.hpp diff --git a/higan/nall/function.hpp b/nall/function.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/function.hpp rename to nall/function.hpp diff --git a/higan/nall/group.hpp b/nall/group.hpp similarity index 100% rename from higan/nall/group.hpp rename to nall/group.hpp diff --git a/higan/nall/gzip.hpp b/nall/gzip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/gzip.hpp rename to nall/gzip.hpp diff --git a/higan/nall/hashset.hpp b/nall/hashset.hpp similarity index 100% rename from higan/nall/hashset.hpp rename to nall/hashset.hpp diff --git a/higan/nall/http.hpp b/nall/http.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/http.hpp rename to nall/http.hpp diff --git a/higan/nall/image.hpp b/nall/image.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/image.hpp rename to nall/image.hpp diff --git a/higan/nall/inflate.hpp b/nall/inflate.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/inflate.hpp rename to nall/inflate.hpp diff --git a/higan/nall/input.hpp b/nall/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/input.hpp rename to nall/input.hpp diff --git a/ananke/nall/interpolation.hpp b/nall/interpolation.hpp similarity index 100% rename from ananke/nall/interpolation.hpp rename to nall/interpolation.hpp diff --git a/higan/nall/intrinsics.hpp b/nall/intrinsics.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/intrinsics.hpp rename to nall/intrinsics.hpp diff --git a/higan/nall/invoke.hpp b/nall/invoke.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/invoke.hpp rename to nall/invoke.hpp diff --git a/higan/nall/ips.hpp b/nall/ips.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/ips.hpp rename to nall/ips.hpp diff --git a/higan/nall/map.hpp b/nall/map.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/map.hpp rename to nall/map.hpp diff --git a/higan/nall/matrix.hpp b/nall/matrix.hpp similarity index 100% rename from higan/nall/matrix.hpp rename to nall/matrix.hpp diff --git a/ananke/nall/mosaic.hpp b/nall/mosaic.hpp similarity index 100% rename from ananke/nall/mosaic.hpp rename to nall/mosaic.hpp diff --git a/higan/nall/mosaic/bitstream.hpp b/nall/mosaic/bitstream.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/mosaic/bitstream.hpp rename to nall/mosaic/bitstream.hpp diff --git a/higan/nall/mosaic/context.hpp b/nall/mosaic/context.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/mosaic/context.hpp rename to nall/mosaic/context.hpp diff --git a/higan/nall/mosaic/parser.hpp b/nall/mosaic/parser.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/mosaic/parser.hpp rename to nall/mosaic/parser.hpp diff --git a/higan/nall/nall.hpp b/nall/nall.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/nall.hpp rename to nall/nall.hpp diff --git a/nall/odbc.hpp b/nall/odbc.hpp new file mode 100644 index 00000000..64504726 --- /dev/null +++ b/nall/odbc.hpp @@ -0,0 +1,153 @@ +#ifndef NALL_ODBC_HPP +#define NALL_ODBC_HPP + +//minimal wrapper for core ODBC v3 API +//requires Windows or unixODBC + +#include +#include + +#include +#include +#include + +namespace nall { + +struct ODBC { + inline ODBC(); + inline ODBC(const string& database, const string& username, const string& password); + inline ~ODBC(); + + inline bool connected(); + inline bool connect(const string& hostname, const string& username, const string& password); + inline void disconnect(); + template inline bool execute(Args&&... args); + inline void release(); + inline unsigned rows(); + inline optional read(); + +private: + char* buffer = nullptr; + SQLHANDLE sqlEnvironment = nullptr; + SQLHANDLE sqlConnection = nullptr; + SQLHANDLE sqlStatement = nullptr; +}; + +ODBC::ODBC() { + auto result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlEnvironment); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return; + + SQLSetEnvAttr(sqlEnvironment, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); + buffer = new char[65536](); +} + +ODBC::ODBC(const string& database, const string& username, const string& password) : ODBC() { + connect(database, username, password); +} + +ODBC::~ODBC() { + if(sqlEnvironment) { + disconnect(); + SQLFreeHandle(SQL_HANDLE_ENV, sqlEnvironment); + sqlEnvironment = nullptr; + + delete[] buffer; + buffer = nullptr; + } +} + +bool ODBC::connected() { + return sqlConnection; +} + +bool ODBC::connect(const string& hostname, const string& username, const string& password) { + if(!sqlEnvironment) return false; + disconnect(); + + auto result = SQLAllocHandle(SQL_HANDLE_DBC, sqlEnvironment, &sqlConnection); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return false; + + SQLSetConnectAttr(sqlConnection, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0); + result = SQLConnectA(sqlConnection, + (SQLCHAR*)(const char*)hostname, SQL_NTS, + (SQLCHAR*)(const char*)username, SQL_NTS, + (SQLCHAR*)(const char*)password, SQL_NTS + ); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) { + disconnect(); + return false; + } + + return true; +} + +void ODBC::disconnect() { + if(sqlConnection) { + release(); + SQLDisconnect(sqlConnection); + SQLFreeHandle(SQL_HANDLE_DBC, sqlConnection); + sqlConnection = nullptr; + } +} + +template +bool ODBC::execute(Args&&... args) { + string statement({args...}); + + if(!sqlConnection) return false; + release(); + + auto result = SQLAllocHandle(SQL_HANDLE_STMT, sqlConnection, &sqlStatement); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return false; + + result = SQLExecDirectA(sqlStatement, (SQLCHAR*)(const char*)statement, SQL_NTS); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) { + release(); + return false; + } + + return true; +} + +void ODBC::release() { + if(sqlStatement) { + SQLFreeHandle(SQL_HANDLE_STMT, sqlStatement); + sqlStatement = nullptr; + } +} + +//valid after update, insert or delete +unsigned ODBC::rows() { + if(!sqlStatement) return 0; + + SQLLEN sqlRows = 0; + auto result = SQLRowCount(sqlStatement, &sqlRows); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return 0; + + return sqlRows; +} + +//valid after select +optional ODBC::read() { + if(!sqlStatement) return false; + + auto result = SQLFetch(sqlStatement); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return false; + + SQLSMALLINT sqlColumns = 0; + result = SQLNumResultCols(sqlStatement, &sqlColumns); + if(result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) return false; + + lstring data; + for(unsigned column = 0; column < sqlColumns; column++) { + SQLLEN length = 0; + SQLGetData(sqlStatement, 1 + column, SQL_C_CHAR, buffer, 65535, &length); + data.append(buffer); + } + + return {true, data}; +} + +} + +#endif diff --git a/higan/nall/platform.hpp b/nall/platform.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/platform.hpp rename to nall/platform.hpp diff --git a/higan/nall/png.hpp b/nall/png.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/png.hpp rename to nall/png.hpp diff --git a/higan/nall/priority-queue.hpp b/nall/priority-queue.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/priority-queue.hpp rename to nall/priority-queue.hpp diff --git a/higan/nall/property.hpp b/nall/property.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/property.hpp rename to nall/property.hpp diff --git a/higan/nall/public-cast.hpp b/nall/public-cast.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/public-cast.hpp rename to nall/public-cast.hpp diff --git a/higan/nall/random.hpp b/nall/random.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/random.hpp rename to nall/random.hpp diff --git a/higan/nall/serial.hpp b/nall/serial.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/serial.hpp rename to nall/serial.hpp diff --git a/higan/nall/serializer.hpp b/nall/serializer.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/serializer.hpp rename to nall/serializer.hpp diff --git a/higan/nall/set.hpp b/nall/set.hpp similarity index 100% rename from higan/nall/set.hpp rename to nall/set.hpp diff --git a/higan/nall/sha256.hpp b/nall/sha256.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/sha256.hpp rename to nall/sha256.hpp diff --git a/nall/smtp.hpp b/nall/smtp.hpp new file mode 100644 index 00000000..ce1a02ad --- /dev/null +++ b/nall/smtp.hpp @@ -0,0 +1,318 @@ +#ifndef NALL_SMTP_HPP +#define NALL_SMTP_HPP + +#include +#include +#include + +#if !defined(_WIN32) + #include + #include + #include + #include +#else + #include + #include + #include +#endif + +namespace nall { + +struct SMTP { + enum class Format : unsigned { Plain, HTML }; + + inline void server(string server, uint16_t port = 25); + inline void from(string mail, string name = ""); + inline void to(string mail, string name = ""); + inline void cc(string mail, string name = ""); + inline void bcc(string mail, string name = ""); + inline void attachment(const uint8_t* data, unsigned size, string name); + inline bool attachment(string filename, string name = ""); + inline void subject(string subject); + inline void body(string body, Format format = Format::Plain); + + inline bool send(); + inline string message(); + inline string response(); + + #ifdef _WIN32 + inline int close(int); + inline SMTP(); + #endif + +private: + struct Information { + string server; + uint16_t port; + struct Contact { + string mail; + string name; + }; + Contact from; + vector to; + vector cc; + vector bcc; + struct Attachment { + vector buffer; + string name; + }; + string subject; + string body; + Format format = Format::Plain; + vector attachments; + + string message; + string response; + } info; + + inline bool send(int sock, const string& text); + inline string recv(int sock); + inline string boundary(); + inline string filename(const string& filename); + inline string contact(const Information::Contact& contact); + inline string contacts(const vector& contacts); + inline string split(const string& text); +}; + +void SMTP::server(string server, uint16_t port) { + info.server = server; + info.port = port; +} + +void SMTP::from(string mail, string name) { + info.from = {mail, name}; +} + +void SMTP::to(string mail, string name) { + info.to.append({mail, name}); +} + +void SMTP::cc(string mail, string name) { + info.cc.append({mail, name}); +} + +void SMTP::bcc(string mail, string name) { + info.bcc.append({mail, name}); +} + +void SMTP::attachment(const uint8_t* data, unsigned size, string name) { + vector buffer; + buffer.resize(size); + memcpy(buffer.data(), data, size); + info.attachments.append({std::move(buffer), name}); +} + +bool SMTP::attachment(string filename, string name) { + if(!file::exists(filename)) return false; + if(name == "") name = notdir(filename); + auto buffer = file::read(filename); + info.attachments.append({std::move(buffer), name}); + return true; +} + +void SMTP::subject(string subject) { + info.subject = subject; +} + +void SMTP::body(string body, Format format) { + info.body = body; + info.format = format; +} + +bool SMTP::send() { + info.message.append("From: =?UTF-8?B?", Base64::encode(contact(info.from)), "?=\r\n"); + info.message.append("To: =?UTF-8?B?", Base64::encode(contacts(info.to)), "?=\r\n"); + info.message.append("Cc: =?UTF-8?B?", Base64::encode(contacts(info.cc)), "?=\r\n"); + info.message.append("Subject: =?UTF-8?B?", Base64::encode(info.subject), "?=\r\n"); + + string uniqueID = boundary(); + + info.message.append("MIME-Version: 1.0\r\n"); + info.message.append("Content-Type: multipart/mixed; boundary=", uniqueID, "\r\n"); + info.message.append("\r\n"); + + string format = (info.format == Format::Plain ? "text/plain" : "text/html"); + + info.message.append("--", uniqueID, "\r\n"); + info.message.append("Content-Type: ", format, "; charset=UTF-8\r\n"); + info.message.append("Content-Transfer-Encoding: base64\r\n"); + info.message.append("\r\n"); + info.message.append(split(Base64::encode(info.body)), "\r\n"); + info.message.append("\r\n"); + + for(auto& attachment : info.attachments) { + info.message.append("--", uniqueID, "\r\n"); + info.message.append("Content-Type: application/octet-stream\r\n"); + info.message.append("Content-Transfer-Encoding: base64\r\n"); + info.message.append("Content-Disposition: attachment; size=", attachment.buffer.size(), "; filename*=UTF-8''", filename(attachment.name), "\r\n"); + info.message.append("\r\n"); + info.message.append(split(Base64::encode(attachment.buffer)), "\r\n"); + info.message.append("\r\n"); + } + + info.message.append("--", uniqueID, "--\r\n"); + + addrinfo hints; + memset(&hints, 0, sizeof(addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + + addrinfo* serverinfo; + int status = getaddrinfo(info.server, string(info.port), &hints, &serverinfo); + if(status != 0) return false; + + int sock = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); + if(sock == -1) return false; + + int result = connect(sock, serverinfo->ai_addr, serverinfo->ai_addrlen); + if(result == -1) return false; + + string response; + info.response.append(response = recv(sock)); + if(!response.beginswith("220 ")) { close(sock); return false; } + + send(sock, {"HELO ", info.server, "\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + + send(sock, {"MAIL FROM: <", info.from.mail, ">\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + + for(auto& contact : info.to) { + send(sock, {"RCPT TO: <", contact.mail, ">\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + } + + for(auto& contact : info.cc) { + send(sock, {"RCPT TO: <", contact.mail, ">\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + } + + for(auto& contact : info.bcc) { + send(sock, {"RCPT TO: <", contact.mail, ">\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + } + + send(sock, {"DATA\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("354 ")) { close(sock); return false; } + + send(sock, {info.message, "\r\n", ".\r\n"}); + info.response.append(response = recv(sock)); + if(!response.beginswith("250 ")) { close(sock); return false; } + + send(sock, {"QUIT\r\n"}); + info.response.append(response = recv(sock)); +//if(!response.beginswith("221 ")) { close(sock); return false; } + + close(sock); + return true; +} + +string SMTP::message() { + return info.message; +} + +string SMTP::response() { + return info.response; +} + +bool SMTP::send(int sock, const string& text) { + const char* data = text.data(); + unsigned size = text.size(); + while(size) { + int length = ::send(sock, (const char*)data, size, 0); + if(length == -1) return false; + data += length; + size -= length; + } + return true; +} + +string SMTP::recv(int sock) { + vector buffer; + while(true) { + char c; + if(::recv(sock, &c, sizeof(char), 0) < 1) break; + buffer.append(c); + if(c == '\n') break; + } + buffer.append(0); + return buffer; +} + +string SMTP::boundary() { + random_lfsr random; + random.seed(time(0)); + string boundary; + for(unsigned n = 0; n < 16; n++) boundary.append(hex<2>(random())); + return boundary; +} + +string SMTP::filename(const string& filename) { + string result; + for(auto& n : filename) { + if(n <= 32 || n >= 127) result.append("%", hex<2>(n)); + else result.append(n); + } + return result; +} + +string SMTP::contact(const Information::Contact& contact) { + if(!contact.name) return contact.mail; + return {"\"", contact.name, "\" <", contact.mail, ">"}; +} + +string SMTP::contacts(const vector& contacts) { + string result; + for(auto& contact : contacts) { + result.append(this->contact(contact), "; "); + } + result.rtrim<1>("; "); + return result; +} + +string SMTP::split(const string& text) { + string result; + + unsigned offset = 0; + while(offset < text.size()) { + unsigned length = min(76, text.size() - offset); + if(length < 76) { + result.append(text.slice(offset)); + } else { + result.append(text.slice(offset, 76), "\r\n"); + } + offset += length; + } + + return result; +} + +#ifdef _WIN32 +int SMTP::close(int sock) { + return closesocket(sock); +} + +SMTP::SMTP() { + int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) { + WSADATA wsaData; + if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + WSACleanup(); + return; + } + } else { + close(sock); + } +} +#endif + +} + +#endif diff --git a/higan/nall/sort.hpp b/nall/sort.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/sort.hpp rename to nall/sort.hpp diff --git a/higan/nall/stdint.hpp b/nall/stdint.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stdint.hpp rename to nall/stdint.hpp diff --git a/ananke/nall/stream.hpp b/nall/stream.hpp similarity index 100% rename from ananke/nall/stream.hpp rename to nall/stream.hpp diff --git a/higan/nall/stream/auto.hpp b/nall/stream/auto.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/auto.hpp rename to nall/stream/auto.hpp diff --git a/higan/nall/stream/file.hpp b/nall/stream/file.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/file.hpp rename to nall/stream/file.hpp diff --git a/higan/nall/stream/gzip.hpp b/nall/stream/gzip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/gzip.hpp rename to nall/stream/gzip.hpp diff --git a/higan/nall/stream/http.hpp b/nall/stream/http.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/http.hpp rename to nall/stream/http.hpp diff --git a/higan/nall/stream/memory.hpp b/nall/stream/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/memory.hpp rename to nall/stream/memory.hpp diff --git a/higan/nall/stream/mmap.hpp b/nall/stream/mmap.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/mmap.hpp rename to nall/stream/mmap.hpp diff --git a/higan/nall/stream/stream.hpp b/nall/stream/stream.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/stream.hpp rename to nall/stream/stream.hpp diff --git a/higan/nall/stream/vector.hpp b/nall/stream/vector.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/vector.hpp rename to nall/stream/vector.hpp diff --git a/higan/nall/stream/zip.hpp b/nall/stream/zip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/stream/zip.hpp rename to nall/stream/zip.hpp diff --git a/higan/nall/string.hpp b/nall/string.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string.hpp rename to nall/string.hpp diff --git a/higan/nall/string/allocator/copy-on-write.hpp b/nall/string/allocator/copy-on-write.hpp similarity index 100% rename from higan/nall/string/allocator/copy-on-write.hpp rename to nall/string/allocator/copy-on-write.hpp diff --git a/higan/nall/string/allocator/small-string-optimization.hpp b/nall/string/allocator/small-string-optimization.hpp similarity index 100% rename from higan/nall/string/allocator/small-string-optimization.hpp rename to nall/string/allocator/small-string-optimization.hpp diff --git a/higan/nall/string/allocator/vector.hpp b/nall/string/allocator/vector.hpp similarity index 100% rename from higan/nall/string/allocator/vector.hpp rename to nall/string/allocator/vector.hpp diff --git a/higan/nall/string/base.hpp b/nall/string/base.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/base.hpp rename to nall/string/base.hpp diff --git a/higan/nall/string/cast.hpp b/nall/string/cast.hpp old mode 100755 new mode 100644 similarity index 98% rename from higan/nall/string/cast.hpp rename to nall/string/cast.hpp index 48405970..ef79a47d --- a/higan/nall/string/cast.hpp +++ b/nall/string/cast.hpp @@ -15,9 +15,9 @@ template<> struct stringify { }; template<> struct stringify { - char data[256]; + char data[2]; operator const char*() const { return data; } - stringify(char value) { integer(data, value); } + stringify(char value) { data[0] = value, data[1] = 0; } }; // signed integers diff --git a/higan/nall/string/char.hpp b/nall/string/char.hpp similarity index 100% rename from higan/nall/string/char.hpp rename to nall/string/char.hpp diff --git a/higan/nall/string/char/base.hpp b/nall/string/char/base.hpp similarity index 100% rename from higan/nall/string/char/base.hpp rename to nall/string/char/base.hpp diff --git a/higan/nall/string/char/compare.hpp b/nall/string/char/compare.hpp similarity index 100% rename from higan/nall/string/char/compare.hpp rename to nall/string/char/compare.hpp diff --git a/higan/nall/string/char/convert.hpp b/nall/string/char/convert.hpp similarity index 100% rename from higan/nall/string/char/convert.hpp rename to nall/string/char/convert.hpp diff --git a/higan/nall/string/char/match.hpp b/nall/string/char/match.hpp similarity index 100% rename from higan/nall/string/char/match.hpp rename to nall/string/char/match.hpp diff --git a/higan/nall/string/char/strm.hpp b/nall/string/char/strm.hpp similarity index 100% rename from higan/nall/string/char/strm.hpp rename to nall/string/char/strm.hpp diff --git a/higan/nall/string/char/strpos.hpp b/nall/string/char/strpos.hpp similarity index 100% rename from higan/nall/string/char/strpos.hpp rename to nall/string/char/strpos.hpp diff --git a/higan/nall/string/char/trim.hpp b/nall/string/char/trim.hpp similarity index 100% rename from higan/nall/string/char/trim.hpp rename to nall/string/char/trim.hpp diff --git a/higan/nall/string/char/utf8.hpp b/nall/string/char/utf8.hpp similarity index 100% rename from higan/nall/string/char/utf8.hpp rename to nall/string/char/utf8.hpp diff --git a/higan/nall/string/char/utility.hpp b/nall/string/char/utility.hpp similarity index 100% rename from higan/nall/string/char/utility.hpp rename to nall/string/char/utility.hpp diff --git a/higan/nall/string/core.hpp b/nall/string/core.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/core.hpp rename to nall/string/core.hpp diff --git a/higan/nall/string/datetime.hpp b/nall/string/datetime.hpp similarity index 100% rename from higan/nall/string/datetime.hpp rename to nall/string/datetime.hpp diff --git a/higan/nall/string/eval/evaluator.hpp b/nall/string/eval/evaluator.hpp similarity index 100% rename from higan/nall/string/eval/evaluator.hpp rename to nall/string/eval/evaluator.hpp diff --git a/higan/nall/string/eval/literal.hpp b/nall/string/eval/literal.hpp similarity index 100% rename from higan/nall/string/eval/literal.hpp rename to nall/string/eval/literal.hpp diff --git a/higan/nall/string/eval/node.hpp b/nall/string/eval/node.hpp similarity index 100% rename from higan/nall/string/eval/node.hpp rename to nall/string/eval/node.hpp diff --git a/higan/nall/string/eval/parser.hpp b/nall/string/eval/parser.hpp similarity index 100% rename from higan/nall/string/eval/parser.hpp rename to nall/string/eval/parser.hpp diff --git a/higan/nall/string/file.hpp b/nall/string/file.hpp similarity index 100% rename from higan/nall/string/file.hpp rename to nall/string/file.hpp diff --git a/higan/nall/string/filename.hpp b/nall/string/filename.hpp old mode 100755 new mode 100644 similarity index 94% rename from higan/nall/string/filename.hpp rename to nall/string/filename.hpp index a176e441..1d54bec1 --- a/higan/nall/string/filename.hpp +++ b/nall/string/filename.hpp @@ -8,7 +8,7 @@ namespace nall { string dir(string name) { for(signed i = name.length(); i >= 0; i--) { if(name[i] == '/' || name[i] == '\\') { - name[i + 1] = 0; + name.resize(i + 1); break; } if(i == 0) name = "./"; @@ -41,7 +41,7 @@ string parentdir(string name) { } } if(last + 1 == length) last = prev; //if name ends in slash; use previous slash - if(paths > 1) name[last + 1] = 0; + if(paths > 1) name.resize(last + 1); return name; } @@ -50,7 +50,7 @@ string basename(string name) { for(signed i = name.length(); i >= 0; i--) { if(name[i] == '/' || name[i] == '\\') break; //file has no extension if(name[i] == '.') { - name[i] = 0; + name.resize(i); break; } } diff --git a/higan/nall/string/format.hpp b/nall/string/format.hpp similarity index 100% rename from higan/nall/string/format.hpp rename to nall/string/format.hpp diff --git a/higan/nall/string/list.hpp b/nall/string/list.hpp similarity index 100% rename from higan/nall/string/list.hpp rename to nall/string/list.hpp diff --git a/higan/nall/string/markup/bml.hpp b/nall/string/markup/bml.hpp similarity index 100% rename from higan/nall/string/markup/bml.hpp rename to nall/string/markup/bml.hpp diff --git a/higan/nall/string/markup/document.hpp b/nall/string/markup/document.hpp similarity index 100% rename from higan/nall/string/markup/document.hpp rename to nall/string/markup/document.hpp diff --git a/higan/nall/string/markup/node.hpp b/nall/string/markup/node.hpp similarity index 100% rename from higan/nall/string/markup/node.hpp rename to nall/string/markup/node.hpp diff --git a/higan/nall/string/markup/xml.hpp b/nall/string/markup/xml.hpp similarity index 100% rename from higan/nall/string/markup/xml.hpp rename to nall/string/markup/xml.hpp diff --git a/higan/nall/string/platform.hpp b/nall/string/platform.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/platform.hpp rename to nall/string/platform.hpp diff --git a/higan/nall/string/ref.hpp b/nall/string/ref.hpp similarity index 100% rename from higan/nall/string/ref.hpp rename to nall/string/ref.hpp diff --git a/higan/nall/string/replace.hpp b/nall/string/replace.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/replace.hpp rename to nall/string/replace.hpp diff --git a/higan/nall/string/split.hpp b/nall/string/split.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/split.hpp rename to nall/string/split.hpp diff --git a/higan/nall/string/utility.hpp b/nall/string/utility.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/utility.hpp rename to nall/string/utility.hpp diff --git a/higan/nall/string/variadic.hpp b/nall/string/variadic.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/variadic.hpp rename to nall/string/variadic.hpp diff --git a/higan/nall/string/wrapper.hpp b/nall/string/wrapper.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/string/wrapper.hpp rename to nall/string/wrapper.hpp diff --git a/higan/nall/thread.hpp b/nall/thread.hpp similarity index 100% rename from higan/nall/thread.hpp rename to nall/thread.hpp diff --git a/ananke/nall/traits.hpp b/nall/traits.hpp similarity index 100% rename from ananke/nall/traits.hpp rename to nall/traits.hpp diff --git a/higan/nall/udl.hpp b/nall/udl.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/udl.hpp rename to nall/udl.hpp diff --git a/higan/nall/unzip.hpp b/nall/unzip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/unzip.hpp rename to nall/unzip.hpp diff --git a/higan/nall/ups.hpp b/nall/ups.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/ups.hpp rename to nall/ups.hpp diff --git a/higan/nall/utility.hpp b/nall/utility.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/utility.hpp rename to nall/utility.hpp diff --git a/higan/nall/varint.hpp b/nall/varint.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/varint.hpp rename to nall/varint.hpp diff --git a/higan/nall/vector.hpp b/nall/vector.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/vector.hpp rename to nall/vector.hpp diff --git a/higan/nall/windows/detour.hpp b/nall/windows/detour.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/windows/detour.hpp rename to nall/windows/detour.hpp diff --git a/higan/nall/windows/guid.hpp b/nall/windows/guid.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/windows/guid.hpp rename to nall/windows/guid.hpp diff --git a/higan/nall/windows/launcher.hpp b/nall/windows/launcher.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/windows/launcher.hpp rename to nall/windows/launcher.hpp diff --git a/higan/nall/windows/registry.hpp b/nall/windows/registry.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/windows/registry.hpp rename to nall/windows/registry.hpp diff --git a/higan/nall/windows/utf8.hpp b/nall/windows/utf8.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/windows/utf8.hpp rename to nall/windows/utf8.hpp diff --git a/higan/nall/xorg/guard.hpp b/nall/xorg/guard.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/xorg/guard.hpp rename to nall/xorg/guard.hpp diff --git a/ananke/nall/xorg/xorg.hpp b/nall/xorg/xorg.hpp similarity index 100% rename from ananke/nall/xorg/xorg.hpp rename to nall/xorg/xorg.hpp diff --git a/higan/nall/zip.hpp b/nall/zip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/nall/zip.hpp rename to nall/zip.hpp diff --git a/higan/obj/.gitignore b/obj/.gitignore similarity index 100% rename from higan/obj/.gitignore rename to obj/.gitignore diff --git a/higan/out/.gitignore b/out/.gitignore similarity index 100% rename from higan/out/.gitignore rename to out/.gitignore diff --git a/higan/phoenix/Makefile b/phoenix/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/Makefile rename to phoenix/Makefile diff --git a/higan/phoenix/cocoa/action/action.cpp b/phoenix/cocoa/action/action.cpp similarity index 100% rename from higan/phoenix/cocoa/action/action.cpp rename to phoenix/cocoa/action/action.cpp diff --git a/higan/phoenix/cocoa/action/action.hpp b/phoenix/cocoa/action/action.hpp similarity index 100% rename from higan/phoenix/cocoa/action/action.hpp rename to phoenix/cocoa/action/action.hpp diff --git a/higan/phoenix/cocoa/action/check-item.cpp b/phoenix/cocoa/action/check-item.cpp similarity index 100% rename from higan/phoenix/cocoa/action/check-item.cpp rename to phoenix/cocoa/action/check-item.cpp diff --git a/higan/phoenix/cocoa/action/check-item.hpp b/phoenix/cocoa/action/check-item.hpp similarity index 100% rename from higan/phoenix/cocoa/action/check-item.hpp rename to phoenix/cocoa/action/check-item.hpp diff --git a/higan/phoenix/cocoa/action/item.cpp b/phoenix/cocoa/action/item.cpp similarity index 100% rename from higan/phoenix/cocoa/action/item.cpp rename to phoenix/cocoa/action/item.cpp diff --git a/higan/phoenix/cocoa/action/item.hpp b/phoenix/cocoa/action/item.hpp similarity index 100% rename from higan/phoenix/cocoa/action/item.hpp rename to phoenix/cocoa/action/item.hpp diff --git a/higan/phoenix/cocoa/action/menu.cpp b/phoenix/cocoa/action/menu.cpp similarity index 100% rename from higan/phoenix/cocoa/action/menu.cpp rename to phoenix/cocoa/action/menu.cpp diff --git a/higan/phoenix/cocoa/action/menu.hpp b/phoenix/cocoa/action/menu.hpp similarity index 100% rename from higan/phoenix/cocoa/action/menu.hpp rename to phoenix/cocoa/action/menu.hpp diff --git a/higan/phoenix/cocoa/action/radio-item.cpp b/phoenix/cocoa/action/radio-item.cpp similarity index 100% rename from higan/phoenix/cocoa/action/radio-item.cpp rename to phoenix/cocoa/action/radio-item.cpp diff --git a/higan/phoenix/cocoa/action/radio-item.hpp b/phoenix/cocoa/action/radio-item.hpp similarity index 100% rename from higan/phoenix/cocoa/action/radio-item.hpp rename to phoenix/cocoa/action/radio-item.hpp diff --git a/higan/phoenix/cocoa/action/separator.cpp b/phoenix/cocoa/action/separator.cpp similarity index 100% rename from higan/phoenix/cocoa/action/separator.cpp rename to phoenix/cocoa/action/separator.cpp diff --git a/higan/phoenix/cocoa/action/separator.hpp b/phoenix/cocoa/action/separator.hpp similarity index 100% rename from higan/phoenix/cocoa/action/separator.hpp rename to phoenix/cocoa/action/separator.hpp diff --git a/higan/phoenix/cocoa/application.cpp b/phoenix/cocoa/application.cpp similarity index 100% rename from higan/phoenix/cocoa/application.cpp rename to phoenix/cocoa/application.cpp diff --git a/higan/phoenix/cocoa/application.hpp b/phoenix/cocoa/application.hpp similarity index 100% rename from higan/phoenix/cocoa/application.hpp rename to phoenix/cocoa/application.hpp diff --git a/higan/phoenix/cocoa/browser-window.cpp b/phoenix/cocoa/browser-window.cpp similarity index 100% rename from higan/phoenix/cocoa/browser-window.cpp rename to phoenix/cocoa/browser-window.cpp diff --git a/higan/phoenix/cocoa/browser-window.hpp b/phoenix/cocoa/browser-window.hpp similarity index 100% rename from higan/phoenix/cocoa/browser-window.hpp rename to phoenix/cocoa/browser-window.hpp diff --git a/higan/phoenix/cocoa/desktop.cpp b/phoenix/cocoa/desktop.cpp similarity index 100% rename from higan/phoenix/cocoa/desktop.cpp rename to phoenix/cocoa/desktop.cpp diff --git a/higan/phoenix/cocoa/desktop.hpp b/phoenix/cocoa/desktop.hpp similarity index 100% rename from higan/phoenix/cocoa/desktop.hpp rename to phoenix/cocoa/desktop.hpp diff --git a/higan/phoenix/cocoa/font.cpp b/phoenix/cocoa/font.cpp similarity index 100% rename from higan/phoenix/cocoa/font.cpp rename to phoenix/cocoa/font.cpp diff --git a/higan/phoenix/cocoa/font.hpp b/phoenix/cocoa/font.hpp similarity index 100% rename from higan/phoenix/cocoa/font.hpp rename to phoenix/cocoa/font.hpp diff --git a/higan/phoenix/cocoa/header.hpp b/phoenix/cocoa/header.hpp similarity index 100% rename from higan/phoenix/cocoa/header.hpp rename to phoenix/cocoa/header.hpp diff --git a/higan/phoenix/cocoa/keyboard.cpp b/phoenix/cocoa/keyboard.cpp similarity index 100% rename from higan/phoenix/cocoa/keyboard.cpp rename to phoenix/cocoa/keyboard.cpp diff --git a/higan/phoenix/cocoa/keyboard.hpp b/phoenix/cocoa/keyboard.hpp similarity index 100% rename from higan/phoenix/cocoa/keyboard.hpp rename to phoenix/cocoa/keyboard.hpp diff --git a/higan/phoenix/cocoa/message-window.cpp b/phoenix/cocoa/message-window.cpp similarity index 100% rename from higan/phoenix/cocoa/message-window.cpp rename to phoenix/cocoa/message-window.cpp diff --git a/higan/phoenix/cocoa/message-window.hpp b/phoenix/cocoa/message-window.hpp similarity index 100% rename from higan/phoenix/cocoa/message-window.hpp rename to phoenix/cocoa/message-window.hpp diff --git a/higan/phoenix/cocoa/mouse.cpp b/phoenix/cocoa/mouse.cpp similarity index 100% rename from higan/phoenix/cocoa/mouse.cpp rename to phoenix/cocoa/mouse.cpp diff --git a/higan/phoenix/cocoa/mouse.hpp b/phoenix/cocoa/mouse.hpp similarity index 100% rename from higan/phoenix/cocoa/mouse.hpp rename to phoenix/cocoa/mouse.hpp diff --git a/higan/phoenix/cocoa/object.cpp b/phoenix/cocoa/object.cpp similarity index 100% rename from higan/phoenix/cocoa/object.cpp rename to phoenix/cocoa/object.cpp diff --git a/higan/phoenix/cocoa/object.hpp b/phoenix/cocoa/object.hpp similarity index 100% rename from higan/phoenix/cocoa/object.hpp rename to phoenix/cocoa/object.hpp diff --git a/higan/phoenix/cocoa/platform.cpp b/phoenix/cocoa/platform.cpp similarity index 100% rename from higan/phoenix/cocoa/platform.cpp rename to phoenix/cocoa/platform.cpp diff --git a/higan/phoenix/cocoa/platform.hpp b/phoenix/cocoa/platform.hpp similarity index 100% rename from higan/phoenix/cocoa/platform.hpp rename to phoenix/cocoa/platform.hpp diff --git a/higan/phoenix/cocoa/timer.cpp b/phoenix/cocoa/timer.cpp similarity index 100% rename from higan/phoenix/cocoa/timer.cpp rename to phoenix/cocoa/timer.cpp diff --git a/higan/phoenix/cocoa/timer.hpp b/phoenix/cocoa/timer.hpp similarity index 100% rename from higan/phoenix/cocoa/timer.hpp rename to phoenix/cocoa/timer.hpp diff --git a/higan/phoenix/cocoa/utility.cpp b/phoenix/cocoa/utility.cpp similarity index 100% rename from higan/phoenix/cocoa/utility.cpp rename to phoenix/cocoa/utility.cpp diff --git a/higan/phoenix/cocoa/widget/button.cpp b/phoenix/cocoa/widget/button.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/button.cpp rename to phoenix/cocoa/widget/button.cpp diff --git a/higan/phoenix/cocoa/widget/button.hpp b/phoenix/cocoa/widget/button.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/button.hpp rename to phoenix/cocoa/widget/button.hpp diff --git a/higan/phoenix/cocoa/widget/canvas.cpp b/phoenix/cocoa/widget/canvas.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/canvas.cpp rename to phoenix/cocoa/widget/canvas.cpp diff --git a/higan/phoenix/cocoa/widget/canvas.hpp b/phoenix/cocoa/widget/canvas.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/canvas.hpp rename to phoenix/cocoa/widget/canvas.hpp diff --git a/higan/phoenix/cocoa/widget/check-button.cpp b/phoenix/cocoa/widget/check-button.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/check-button.cpp rename to phoenix/cocoa/widget/check-button.cpp diff --git a/higan/phoenix/cocoa/widget/check-button.hpp b/phoenix/cocoa/widget/check-button.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/check-button.hpp rename to phoenix/cocoa/widget/check-button.hpp diff --git a/higan/phoenix/cocoa/widget/combo-button.cpp b/phoenix/cocoa/widget/combo-button.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/combo-button.cpp rename to phoenix/cocoa/widget/combo-button.cpp diff --git a/higan/phoenix/cocoa/widget/combo-button.hpp b/phoenix/cocoa/widget/combo-button.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/combo-button.hpp rename to phoenix/cocoa/widget/combo-button.hpp diff --git a/higan/phoenix/cocoa/widget/hex-edit.cpp b/phoenix/cocoa/widget/hex-edit.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/hex-edit.cpp rename to phoenix/cocoa/widget/hex-edit.cpp diff --git a/higan/phoenix/cocoa/widget/hex-edit.hpp b/phoenix/cocoa/widget/hex-edit.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/hex-edit.hpp rename to phoenix/cocoa/widget/hex-edit.hpp diff --git a/higan/phoenix/cocoa/widget/horizontal-scroller.cpp b/phoenix/cocoa/widget/horizontal-scroller.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/horizontal-scroller.cpp rename to phoenix/cocoa/widget/horizontal-scroller.cpp diff --git a/higan/phoenix/cocoa/widget/horizontal-scroller.hpp b/phoenix/cocoa/widget/horizontal-scroller.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/horizontal-scroller.hpp rename to phoenix/cocoa/widget/horizontal-scroller.hpp diff --git a/higan/phoenix/cocoa/widget/horizontal-slider.cpp b/phoenix/cocoa/widget/horizontal-slider.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/horizontal-slider.cpp rename to phoenix/cocoa/widget/horizontal-slider.cpp diff --git a/higan/phoenix/cocoa/widget/horizontal-slider.hpp b/phoenix/cocoa/widget/horizontal-slider.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/horizontal-slider.hpp rename to phoenix/cocoa/widget/horizontal-slider.hpp diff --git a/higan/phoenix/cocoa/widget/label.cpp b/phoenix/cocoa/widget/label.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/label.cpp rename to phoenix/cocoa/widget/label.cpp diff --git a/higan/phoenix/cocoa/widget/label.hpp b/phoenix/cocoa/widget/label.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/label.hpp rename to phoenix/cocoa/widget/label.hpp diff --git a/higan/phoenix/cocoa/widget/layout.hpp b/phoenix/cocoa/widget/layout.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/layout.hpp rename to phoenix/cocoa/widget/layout.hpp diff --git a/higan/phoenix/cocoa/widget/line-edit.cpp b/phoenix/cocoa/widget/line-edit.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/line-edit.cpp rename to phoenix/cocoa/widget/line-edit.cpp diff --git a/higan/phoenix/cocoa/widget/line-edit.hpp b/phoenix/cocoa/widget/line-edit.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/line-edit.hpp rename to phoenix/cocoa/widget/line-edit.hpp diff --git a/higan/phoenix/cocoa/widget/list-view.cpp b/phoenix/cocoa/widget/list-view.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/list-view.cpp rename to phoenix/cocoa/widget/list-view.cpp diff --git a/higan/phoenix/cocoa/widget/list-view.hpp b/phoenix/cocoa/widget/list-view.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/list-view.hpp rename to phoenix/cocoa/widget/list-view.hpp diff --git a/higan/phoenix/cocoa/widget/progress-bar.cpp b/phoenix/cocoa/widget/progress-bar.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/progress-bar.cpp rename to phoenix/cocoa/widget/progress-bar.cpp diff --git a/higan/phoenix/cocoa/widget/progress-bar.hpp b/phoenix/cocoa/widget/progress-bar.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/progress-bar.hpp rename to phoenix/cocoa/widget/progress-bar.hpp diff --git a/higan/phoenix/cocoa/widget/radio-button.cpp b/phoenix/cocoa/widget/radio-button.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/radio-button.cpp rename to phoenix/cocoa/widget/radio-button.cpp diff --git a/higan/phoenix/cocoa/widget/radio-button.hpp b/phoenix/cocoa/widget/radio-button.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/radio-button.hpp rename to phoenix/cocoa/widget/radio-button.hpp diff --git a/higan/phoenix/cocoa/widget/sizable.hpp b/phoenix/cocoa/widget/sizable.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/sizable.hpp rename to phoenix/cocoa/widget/sizable.hpp diff --git a/higan/phoenix/cocoa/widget/text-edit.cpp b/phoenix/cocoa/widget/text-edit.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/text-edit.cpp rename to phoenix/cocoa/widget/text-edit.cpp diff --git a/higan/phoenix/cocoa/widget/text-edit.hpp b/phoenix/cocoa/widget/text-edit.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/text-edit.hpp rename to phoenix/cocoa/widget/text-edit.hpp diff --git a/higan/phoenix/cocoa/widget/vertical-scroller.cpp b/phoenix/cocoa/widget/vertical-scroller.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/vertical-scroller.cpp rename to phoenix/cocoa/widget/vertical-scroller.cpp diff --git a/higan/phoenix/cocoa/widget/vertical-scroller.hpp b/phoenix/cocoa/widget/vertical-scroller.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/vertical-scroller.hpp rename to phoenix/cocoa/widget/vertical-scroller.hpp diff --git a/higan/phoenix/cocoa/widget/vertical-slider.cpp b/phoenix/cocoa/widget/vertical-slider.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/vertical-slider.cpp rename to phoenix/cocoa/widget/vertical-slider.cpp diff --git a/higan/phoenix/cocoa/widget/vertical-slider.hpp b/phoenix/cocoa/widget/vertical-slider.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/vertical-slider.hpp rename to phoenix/cocoa/widget/vertical-slider.hpp diff --git a/higan/phoenix/cocoa/widget/viewport.cpp b/phoenix/cocoa/widget/viewport.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/viewport.cpp rename to phoenix/cocoa/widget/viewport.cpp diff --git a/higan/phoenix/cocoa/widget/viewport.hpp b/phoenix/cocoa/widget/viewport.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/viewport.hpp rename to phoenix/cocoa/widget/viewport.hpp diff --git a/higan/phoenix/cocoa/widget/widget.cpp b/phoenix/cocoa/widget/widget.cpp similarity index 100% rename from higan/phoenix/cocoa/widget/widget.cpp rename to phoenix/cocoa/widget/widget.cpp diff --git a/higan/phoenix/cocoa/widget/widget.hpp b/phoenix/cocoa/widget/widget.hpp similarity index 100% rename from higan/phoenix/cocoa/widget/widget.hpp rename to phoenix/cocoa/widget/widget.hpp diff --git a/higan/phoenix/cocoa/window.cpp b/phoenix/cocoa/window.cpp similarity index 100% rename from higan/phoenix/cocoa/window.cpp rename to phoenix/cocoa/window.cpp diff --git a/higan/phoenix/cocoa/window.hpp b/phoenix/cocoa/window.hpp similarity index 100% rename from higan/phoenix/cocoa/window.hpp rename to phoenix/cocoa/window.hpp diff --git a/higan/phoenix/core/core.cpp b/phoenix/core/core.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/core.cpp rename to phoenix/core/core.cpp diff --git a/higan/phoenix/core/core.hpp b/phoenix/core/core.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/core.hpp rename to phoenix/core/core.hpp diff --git a/ananke/phoenix/core/keyboard.hpp b/phoenix/core/keyboard.hpp similarity index 100% rename from ananke/phoenix/core/keyboard.hpp rename to phoenix/core/keyboard.hpp diff --git a/higan/phoenix/core/layout/fixed-layout.cpp b/phoenix/core/layout/fixed-layout.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/fixed-layout.cpp rename to phoenix/core/layout/fixed-layout.cpp diff --git a/higan/phoenix/core/layout/fixed-layout.hpp b/phoenix/core/layout/fixed-layout.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/fixed-layout.hpp rename to phoenix/core/layout/fixed-layout.hpp diff --git a/higan/phoenix/core/layout/horizontal-layout.cpp b/phoenix/core/layout/horizontal-layout.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/horizontal-layout.cpp rename to phoenix/core/layout/horizontal-layout.cpp diff --git a/higan/phoenix/core/layout/horizontal-layout.hpp b/phoenix/core/layout/horizontal-layout.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/horizontal-layout.hpp rename to phoenix/core/layout/horizontal-layout.hpp diff --git a/higan/phoenix/core/layout/vertical-layout.cpp b/phoenix/core/layout/vertical-layout.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/vertical-layout.cpp rename to phoenix/core/layout/vertical-layout.cpp diff --git a/higan/phoenix/core/layout/vertical-layout.hpp b/phoenix/core/layout/vertical-layout.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/layout/vertical-layout.hpp rename to phoenix/core/layout/vertical-layout.hpp diff --git a/higan/phoenix/core/state.hpp b/phoenix/core/state.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/core/state.hpp rename to phoenix/core/state.hpp diff --git a/higan/phoenix/gtk/action/action.cpp b/phoenix/gtk/action/action.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/action.cpp rename to phoenix/gtk/action/action.cpp diff --git a/higan/phoenix/gtk/action/check-item.cpp b/phoenix/gtk/action/check-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/check-item.cpp rename to phoenix/gtk/action/check-item.cpp diff --git a/higan/phoenix/gtk/action/item.cpp b/phoenix/gtk/action/item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/item.cpp rename to phoenix/gtk/action/item.cpp diff --git a/higan/phoenix/gtk/action/menu.cpp b/phoenix/gtk/action/menu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/menu.cpp rename to phoenix/gtk/action/menu.cpp diff --git a/higan/phoenix/gtk/action/radio-item.cpp b/phoenix/gtk/action/radio-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/radio-item.cpp rename to phoenix/gtk/action/radio-item.cpp diff --git a/higan/phoenix/gtk/action/separator.cpp b/phoenix/gtk/action/separator.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/action/separator.cpp rename to phoenix/gtk/action/separator.cpp diff --git a/higan/phoenix/gtk/application.cpp b/phoenix/gtk/application.cpp similarity index 100% rename from higan/phoenix/gtk/application.cpp rename to phoenix/gtk/application.cpp diff --git a/higan/phoenix/gtk/browser-window.cpp b/phoenix/gtk/browser-window.cpp similarity index 100% rename from higan/phoenix/gtk/browser-window.cpp rename to phoenix/gtk/browser-window.cpp diff --git a/higan/phoenix/gtk/desktop.cpp b/phoenix/gtk/desktop.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/desktop.cpp rename to phoenix/gtk/desktop.cpp diff --git a/higan/phoenix/gtk/font.cpp b/phoenix/gtk/font.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/font.cpp rename to phoenix/gtk/font.cpp diff --git a/higan/phoenix/gtk/header.hpp b/phoenix/gtk/header.hpp similarity index 100% rename from higan/phoenix/gtk/header.hpp rename to phoenix/gtk/header.hpp diff --git a/higan/phoenix/gtk/keyboard.cpp b/phoenix/gtk/keyboard.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/keyboard.cpp rename to phoenix/gtk/keyboard.cpp diff --git a/higan/phoenix/gtk/message-window.cpp b/phoenix/gtk/message-window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/message-window.cpp rename to phoenix/gtk/message-window.cpp diff --git a/higan/phoenix/gtk/mouse.cpp b/phoenix/gtk/mouse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/mouse.cpp rename to phoenix/gtk/mouse.cpp diff --git a/higan/phoenix/gtk/platform.cpp b/phoenix/gtk/platform.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/platform.cpp rename to phoenix/gtk/platform.cpp diff --git a/higan/phoenix/gtk/platform.hpp b/phoenix/gtk/platform.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/platform.hpp rename to phoenix/gtk/platform.hpp diff --git a/higan/phoenix/gtk/settings.cpp b/phoenix/gtk/settings.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/settings.cpp rename to phoenix/gtk/settings.cpp diff --git a/higan/phoenix/gtk/timer.cpp b/phoenix/gtk/timer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/timer.cpp rename to phoenix/gtk/timer.cpp diff --git a/higan/phoenix/gtk/utility.cpp b/phoenix/gtk/utility.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/utility.cpp rename to phoenix/gtk/utility.cpp diff --git a/higan/phoenix/gtk/widget/button.cpp b/phoenix/gtk/widget/button.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/button.cpp rename to phoenix/gtk/widget/button.cpp diff --git a/higan/phoenix/gtk/widget/canvas.cpp b/phoenix/gtk/widget/canvas.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/canvas.cpp rename to phoenix/gtk/widget/canvas.cpp diff --git a/higan/phoenix/gtk/widget/check-button.cpp b/phoenix/gtk/widget/check-button.cpp similarity index 100% rename from higan/phoenix/gtk/widget/check-button.cpp rename to phoenix/gtk/widget/check-button.cpp diff --git a/higan/phoenix/gtk/widget/combo-button.cpp b/phoenix/gtk/widget/combo-button.cpp similarity index 100% rename from higan/phoenix/gtk/widget/combo-button.cpp rename to phoenix/gtk/widget/combo-button.cpp diff --git a/higan/phoenix/gtk/widget/hex-edit.cpp b/phoenix/gtk/widget/hex-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/hex-edit.cpp rename to phoenix/gtk/widget/hex-edit.cpp diff --git a/higan/phoenix/gtk/widget/horizontal-scroller.cpp b/phoenix/gtk/widget/horizontal-scroller.cpp similarity index 100% rename from higan/phoenix/gtk/widget/horizontal-scroller.cpp rename to phoenix/gtk/widget/horizontal-scroller.cpp diff --git a/higan/phoenix/gtk/widget/horizontal-slider.cpp b/phoenix/gtk/widget/horizontal-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/horizontal-slider.cpp rename to phoenix/gtk/widget/horizontal-slider.cpp diff --git a/higan/phoenix/gtk/widget/label.cpp b/phoenix/gtk/widget/label.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/label.cpp rename to phoenix/gtk/widget/label.cpp diff --git a/higan/phoenix/gtk/widget/line-edit.cpp b/phoenix/gtk/widget/line-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/line-edit.cpp rename to phoenix/gtk/widget/line-edit.cpp diff --git a/higan/phoenix/gtk/widget/list-view.cpp b/phoenix/gtk/widget/list-view.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/list-view.cpp rename to phoenix/gtk/widget/list-view.cpp diff --git a/higan/phoenix/gtk/widget/progress-bar.cpp b/phoenix/gtk/widget/progress-bar.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/progress-bar.cpp rename to phoenix/gtk/widget/progress-bar.cpp diff --git a/higan/phoenix/gtk/widget/radio-button.cpp b/phoenix/gtk/widget/radio-button.cpp similarity index 100% rename from higan/phoenix/gtk/widget/radio-button.cpp rename to phoenix/gtk/widget/radio-button.cpp diff --git a/higan/phoenix/gtk/widget/text-edit.cpp b/phoenix/gtk/widget/text-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/text-edit.cpp rename to phoenix/gtk/widget/text-edit.cpp diff --git a/higan/phoenix/gtk/widget/vertical-scroller.cpp b/phoenix/gtk/widget/vertical-scroller.cpp similarity index 100% rename from higan/phoenix/gtk/widget/vertical-scroller.cpp rename to phoenix/gtk/widget/vertical-scroller.cpp diff --git a/higan/phoenix/gtk/widget/vertical-slider.cpp b/phoenix/gtk/widget/vertical-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/vertical-slider.cpp rename to phoenix/gtk/widget/vertical-slider.cpp diff --git a/higan/phoenix/gtk/widget/viewport.cpp b/phoenix/gtk/widget/viewport.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/viewport.cpp rename to phoenix/gtk/widget/viewport.cpp diff --git a/higan/phoenix/gtk/widget/widget.cpp b/phoenix/gtk/widget/widget.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/widget/widget.cpp rename to phoenix/gtk/widget/widget.cpp diff --git a/higan/phoenix/gtk/window.cpp b/phoenix/gtk/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/gtk/window.cpp rename to phoenix/gtk/window.cpp diff --git a/higan/phoenix/phoenix.cpp b/phoenix/phoenix.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/phoenix.cpp rename to phoenix/phoenix.cpp diff --git a/higan/phoenix/phoenix.hpp b/phoenix/phoenix.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/phoenix.hpp rename to phoenix/phoenix.hpp diff --git a/higan/phoenix/qt/action/action.cpp b/phoenix/qt/action/action.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/action.cpp rename to phoenix/qt/action/action.cpp diff --git a/higan/phoenix/qt/action/check-item.cpp b/phoenix/qt/action/check-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/check-item.cpp rename to phoenix/qt/action/check-item.cpp diff --git a/higan/phoenix/qt/action/item.cpp b/phoenix/qt/action/item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/item.cpp rename to phoenix/qt/action/item.cpp diff --git a/higan/phoenix/qt/action/menu.cpp b/phoenix/qt/action/menu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/menu.cpp rename to phoenix/qt/action/menu.cpp diff --git a/higan/phoenix/qt/action/radio-item.cpp b/phoenix/qt/action/radio-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/radio-item.cpp rename to phoenix/qt/action/radio-item.cpp diff --git a/higan/phoenix/qt/action/separator.cpp b/phoenix/qt/action/separator.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/action/separator.cpp rename to phoenix/qt/action/separator.cpp diff --git a/higan/phoenix/qt/application.cpp b/phoenix/qt/application.cpp similarity index 100% rename from higan/phoenix/qt/application.cpp rename to phoenix/qt/application.cpp diff --git a/higan/phoenix/qt/browser-window.cpp b/phoenix/qt/browser-window.cpp similarity index 100% rename from higan/phoenix/qt/browser-window.cpp rename to phoenix/qt/browser-window.cpp diff --git a/higan/phoenix/qt/desktop.cpp b/phoenix/qt/desktop.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/desktop.cpp rename to phoenix/qt/desktop.cpp diff --git a/higan/phoenix/qt/font.cpp b/phoenix/qt/font.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/font.cpp rename to phoenix/qt/font.cpp diff --git a/higan/phoenix/qt/header.hpp b/phoenix/qt/header.hpp similarity index 100% rename from higan/phoenix/qt/header.hpp rename to phoenix/qt/header.hpp diff --git a/higan/phoenix/qt/keyboard.cpp b/phoenix/qt/keyboard.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/keyboard.cpp rename to phoenix/qt/keyboard.cpp diff --git a/higan/phoenix/qt/message-window.cpp b/phoenix/qt/message-window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/message-window.cpp rename to phoenix/qt/message-window.cpp diff --git a/higan/phoenix/qt/mouse.cpp b/phoenix/qt/mouse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/mouse.cpp rename to phoenix/qt/mouse.cpp diff --git a/higan/phoenix/qt/platform.cpp b/phoenix/qt/platform.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/platform.cpp rename to phoenix/qt/platform.cpp diff --git a/higan/phoenix/qt/platform.moc b/phoenix/qt/platform.moc old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/platform.moc rename to phoenix/qt/platform.moc diff --git a/higan/phoenix/qt/platform.moc.hpp b/phoenix/qt/platform.moc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/platform.moc.hpp rename to phoenix/qt/platform.moc.hpp diff --git a/higan/phoenix/qt/settings.cpp b/phoenix/qt/settings.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/settings.cpp rename to phoenix/qt/settings.cpp diff --git a/higan/phoenix/qt/timer.cpp b/phoenix/qt/timer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/timer.cpp rename to phoenix/qt/timer.cpp diff --git a/higan/phoenix/qt/utility.cpp b/phoenix/qt/utility.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/utility.cpp rename to phoenix/qt/utility.cpp diff --git a/higan/phoenix/qt/widget/button.cpp b/phoenix/qt/widget/button.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/button.cpp rename to phoenix/qt/widget/button.cpp diff --git a/higan/phoenix/qt/widget/canvas.cpp b/phoenix/qt/widget/canvas.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/canvas.cpp rename to phoenix/qt/widget/canvas.cpp diff --git a/higan/phoenix/qt/widget/check-button.cpp b/phoenix/qt/widget/check-button.cpp similarity index 100% rename from higan/phoenix/qt/widget/check-button.cpp rename to phoenix/qt/widget/check-button.cpp diff --git a/higan/phoenix/qt/widget/combo-button.cpp b/phoenix/qt/widget/combo-button.cpp similarity index 100% rename from higan/phoenix/qt/widget/combo-button.cpp rename to phoenix/qt/widget/combo-button.cpp diff --git a/higan/phoenix/qt/widget/hex-edit.cpp b/phoenix/qt/widget/hex-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/hex-edit.cpp rename to phoenix/qt/widget/hex-edit.cpp diff --git a/higan/phoenix/qt/widget/horizontal-scroller.cpp b/phoenix/qt/widget/horizontal-scroller.cpp similarity index 100% rename from higan/phoenix/qt/widget/horizontal-scroller.cpp rename to phoenix/qt/widget/horizontal-scroller.cpp diff --git a/higan/phoenix/qt/widget/horizontal-slider.cpp b/phoenix/qt/widget/horizontal-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/horizontal-slider.cpp rename to phoenix/qt/widget/horizontal-slider.cpp diff --git a/higan/phoenix/qt/widget/label.cpp b/phoenix/qt/widget/label.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/label.cpp rename to phoenix/qt/widget/label.cpp diff --git a/higan/phoenix/qt/widget/line-edit.cpp b/phoenix/qt/widget/line-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/line-edit.cpp rename to phoenix/qt/widget/line-edit.cpp diff --git a/higan/phoenix/qt/widget/list-view.cpp b/phoenix/qt/widget/list-view.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/list-view.cpp rename to phoenix/qt/widget/list-view.cpp diff --git a/higan/phoenix/qt/widget/progress-bar.cpp b/phoenix/qt/widget/progress-bar.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/progress-bar.cpp rename to phoenix/qt/widget/progress-bar.cpp diff --git a/higan/phoenix/qt/widget/radio-button.cpp b/phoenix/qt/widget/radio-button.cpp similarity index 100% rename from higan/phoenix/qt/widget/radio-button.cpp rename to phoenix/qt/widget/radio-button.cpp diff --git a/higan/phoenix/qt/widget/text-edit.cpp b/phoenix/qt/widget/text-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/text-edit.cpp rename to phoenix/qt/widget/text-edit.cpp diff --git a/higan/phoenix/qt/widget/vertical-scroller.cpp b/phoenix/qt/widget/vertical-scroller.cpp similarity index 100% rename from higan/phoenix/qt/widget/vertical-scroller.cpp rename to phoenix/qt/widget/vertical-scroller.cpp diff --git a/higan/phoenix/qt/widget/vertical-slider.cpp b/phoenix/qt/widget/vertical-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/vertical-slider.cpp rename to phoenix/qt/widget/vertical-slider.cpp diff --git a/higan/phoenix/qt/widget/viewport.cpp b/phoenix/qt/widget/viewport.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/viewport.cpp rename to phoenix/qt/widget/viewport.cpp diff --git a/higan/phoenix/qt/widget/widget.cpp b/phoenix/qt/widget/widget.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/widget/widget.cpp rename to phoenix/qt/widget/widget.cpp diff --git a/higan/phoenix/qt/window.cpp b/phoenix/qt/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/qt/window.cpp rename to phoenix/qt/window.cpp diff --git a/higan/phoenix/reference/action/action.cpp b/phoenix/reference/action/action.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/action.cpp rename to phoenix/reference/action/action.cpp diff --git a/higan/phoenix/reference/action/action.hpp b/phoenix/reference/action/action.hpp similarity index 100% rename from higan/phoenix/reference/action/action.hpp rename to phoenix/reference/action/action.hpp diff --git a/higan/phoenix/reference/action/check-item.cpp b/phoenix/reference/action/check-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/check-item.cpp rename to phoenix/reference/action/check-item.cpp diff --git a/higan/phoenix/reference/action/check-item.hpp b/phoenix/reference/action/check-item.hpp similarity index 100% rename from higan/phoenix/reference/action/check-item.hpp rename to phoenix/reference/action/check-item.hpp diff --git a/higan/phoenix/reference/action/item.cpp b/phoenix/reference/action/item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/item.cpp rename to phoenix/reference/action/item.cpp diff --git a/higan/phoenix/reference/action/item.hpp b/phoenix/reference/action/item.hpp similarity index 100% rename from higan/phoenix/reference/action/item.hpp rename to phoenix/reference/action/item.hpp diff --git a/higan/phoenix/reference/action/menu.cpp b/phoenix/reference/action/menu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/menu.cpp rename to phoenix/reference/action/menu.cpp diff --git a/higan/phoenix/reference/action/menu.hpp b/phoenix/reference/action/menu.hpp similarity index 100% rename from higan/phoenix/reference/action/menu.hpp rename to phoenix/reference/action/menu.hpp diff --git a/higan/phoenix/reference/action/radio-item.cpp b/phoenix/reference/action/radio-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/radio-item.cpp rename to phoenix/reference/action/radio-item.cpp diff --git a/higan/phoenix/reference/action/radio-item.hpp b/phoenix/reference/action/radio-item.hpp similarity index 100% rename from higan/phoenix/reference/action/radio-item.hpp rename to phoenix/reference/action/radio-item.hpp diff --git a/higan/phoenix/reference/action/separator.cpp b/phoenix/reference/action/separator.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/action/separator.cpp rename to phoenix/reference/action/separator.cpp diff --git a/higan/phoenix/reference/action/separator.hpp b/phoenix/reference/action/separator.hpp similarity index 100% rename from higan/phoenix/reference/action/separator.hpp rename to phoenix/reference/action/separator.hpp diff --git a/higan/phoenix/reference/application.cpp b/phoenix/reference/application.cpp similarity index 100% rename from higan/phoenix/reference/application.cpp rename to phoenix/reference/application.cpp diff --git a/higan/phoenix/reference/application.hpp b/phoenix/reference/application.hpp similarity index 100% rename from higan/phoenix/reference/application.hpp rename to phoenix/reference/application.hpp diff --git a/higan/phoenix/reference/browser-window.cpp b/phoenix/reference/browser-window.cpp similarity index 100% rename from higan/phoenix/reference/browser-window.cpp rename to phoenix/reference/browser-window.cpp diff --git a/higan/phoenix/reference/browser-window.hpp b/phoenix/reference/browser-window.hpp similarity index 100% rename from higan/phoenix/reference/browser-window.hpp rename to phoenix/reference/browser-window.hpp diff --git a/higan/phoenix/reference/desktop.cpp b/phoenix/reference/desktop.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/desktop.cpp rename to phoenix/reference/desktop.cpp diff --git a/higan/phoenix/reference/desktop.hpp b/phoenix/reference/desktop.hpp similarity index 100% rename from higan/phoenix/reference/desktop.hpp rename to phoenix/reference/desktop.hpp diff --git a/higan/phoenix/reference/font.cpp b/phoenix/reference/font.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/font.cpp rename to phoenix/reference/font.cpp diff --git a/higan/phoenix/reference/font.hpp b/phoenix/reference/font.hpp similarity index 100% rename from higan/phoenix/reference/font.hpp rename to phoenix/reference/font.hpp diff --git a/higan/phoenix/reference/header.hpp b/phoenix/reference/header.hpp similarity index 100% rename from higan/phoenix/reference/header.hpp rename to phoenix/reference/header.hpp diff --git a/higan/phoenix/reference/keyboard.cpp b/phoenix/reference/keyboard.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/keyboard.cpp rename to phoenix/reference/keyboard.cpp diff --git a/higan/phoenix/reference/keyboard.hpp b/phoenix/reference/keyboard.hpp similarity index 100% rename from higan/phoenix/reference/keyboard.hpp rename to phoenix/reference/keyboard.hpp diff --git a/higan/phoenix/reference/message-window.cpp b/phoenix/reference/message-window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/message-window.cpp rename to phoenix/reference/message-window.cpp diff --git a/higan/phoenix/reference/message-window.hpp b/phoenix/reference/message-window.hpp similarity index 100% rename from higan/phoenix/reference/message-window.hpp rename to phoenix/reference/message-window.hpp diff --git a/higan/phoenix/reference/mouse.cpp b/phoenix/reference/mouse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/mouse.cpp rename to phoenix/reference/mouse.cpp diff --git a/higan/phoenix/reference/mouse.hpp b/phoenix/reference/mouse.hpp similarity index 100% rename from higan/phoenix/reference/mouse.hpp rename to phoenix/reference/mouse.hpp diff --git a/higan/phoenix/reference/object.cpp b/phoenix/reference/object.cpp similarity index 100% rename from higan/phoenix/reference/object.cpp rename to phoenix/reference/object.cpp diff --git a/higan/phoenix/reference/object.hpp b/phoenix/reference/object.hpp similarity index 100% rename from higan/phoenix/reference/object.hpp rename to phoenix/reference/object.hpp diff --git a/higan/phoenix/reference/platform.cpp b/phoenix/reference/platform.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/platform.cpp rename to phoenix/reference/platform.cpp diff --git a/higan/phoenix/reference/platform.hpp b/phoenix/reference/platform.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/platform.hpp rename to phoenix/reference/platform.hpp diff --git a/higan/phoenix/reference/timer.cpp b/phoenix/reference/timer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/timer.cpp rename to phoenix/reference/timer.cpp diff --git a/higan/phoenix/reference/timer.hpp b/phoenix/reference/timer.hpp similarity index 100% rename from higan/phoenix/reference/timer.hpp rename to phoenix/reference/timer.hpp diff --git a/higan/phoenix/reference/widget/button.cpp b/phoenix/reference/widget/button.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/button.cpp rename to phoenix/reference/widget/button.cpp diff --git a/higan/phoenix/reference/widget/button.hpp b/phoenix/reference/widget/button.hpp similarity index 100% rename from higan/phoenix/reference/widget/button.hpp rename to phoenix/reference/widget/button.hpp diff --git a/higan/phoenix/reference/widget/canvas.cpp b/phoenix/reference/widget/canvas.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/canvas.cpp rename to phoenix/reference/widget/canvas.cpp diff --git a/higan/phoenix/reference/widget/canvas.hpp b/phoenix/reference/widget/canvas.hpp similarity index 100% rename from higan/phoenix/reference/widget/canvas.hpp rename to phoenix/reference/widget/canvas.hpp diff --git a/higan/phoenix/reference/widget/check-button.cpp b/phoenix/reference/widget/check-button.cpp similarity index 100% rename from higan/phoenix/reference/widget/check-button.cpp rename to phoenix/reference/widget/check-button.cpp diff --git a/higan/phoenix/reference/widget/check-button.hpp b/phoenix/reference/widget/check-button.hpp similarity index 100% rename from higan/phoenix/reference/widget/check-button.hpp rename to phoenix/reference/widget/check-button.hpp diff --git a/higan/phoenix/reference/widget/combo-button.cpp b/phoenix/reference/widget/combo-button.cpp similarity index 100% rename from higan/phoenix/reference/widget/combo-button.cpp rename to phoenix/reference/widget/combo-button.cpp diff --git a/higan/phoenix/reference/widget/combo-button.hpp b/phoenix/reference/widget/combo-button.hpp similarity index 100% rename from higan/phoenix/reference/widget/combo-button.hpp rename to phoenix/reference/widget/combo-button.hpp diff --git a/higan/phoenix/reference/widget/hex-edit.cpp b/phoenix/reference/widget/hex-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/hex-edit.cpp rename to phoenix/reference/widget/hex-edit.cpp diff --git a/higan/phoenix/reference/widget/hex-edit.hpp b/phoenix/reference/widget/hex-edit.hpp similarity index 100% rename from higan/phoenix/reference/widget/hex-edit.hpp rename to phoenix/reference/widget/hex-edit.hpp diff --git a/higan/phoenix/reference/widget/horizontal-scroller.cpp b/phoenix/reference/widget/horizontal-scroller.cpp similarity index 100% rename from higan/phoenix/reference/widget/horizontal-scroller.cpp rename to phoenix/reference/widget/horizontal-scroller.cpp diff --git a/higan/phoenix/reference/widget/horizontal-scroller.hpp b/phoenix/reference/widget/horizontal-scroller.hpp similarity index 100% rename from higan/phoenix/reference/widget/horizontal-scroller.hpp rename to phoenix/reference/widget/horizontal-scroller.hpp diff --git a/higan/phoenix/reference/widget/horizontal-slider.cpp b/phoenix/reference/widget/horizontal-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/horizontal-slider.cpp rename to phoenix/reference/widget/horizontal-slider.cpp diff --git a/higan/phoenix/reference/widget/horizontal-slider.hpp b/phoenix/reference/widget/horizontal-slider.hpp similarity index 100% rename from higan/phoenix/reference/widget/horizontal-slider.hpp rename to phoenix/reference/widget/horizontal-slider.hpp diff --git a/higan/phoenix/reference/widget/label.cpp b/phoenix/reference/widget/label.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/label.cpp rename to phoenix/reference/widget/label.cpp diff --git a/higan/phoenix/reference/widget/label.hpp b/phoenix/reference/widget/label.hpp similarity index 100% rename from higan/phoenix/reference/widget/label.hpp rename to phoenix/reference/widget/label.hpp diff --git a/higan/phoenix/reference/widget/layout.hpp b/phoenix/reference/widget/layout.hpp similarity index 100% rename from higan/phoenix/reference/widget/layout.hpp rename to phoenix/reference/widget/layout.hpp diff --git a/higan/phoenix/reference/widget/line-edit.cpp b/phoenix/reference/widget/line-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/line-edit.cpp rename to phoenix/reference/widget/line-edit.cpp diff --git a/higan/phoenix/reference/widget/line-edit.hpp b/phoenix/reference/widget/line-edit.hpp similarity index 100% rename from higan/phoenix/reference/widget/line-edit.hpp rename to phoenix/reference/widget/line-edit.hpp diff --git a/higan/phoenix/reference/widget/list-view.cpp b/phoenix/reference/widget/list-view.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/list-view.cpp rename to phoenix/reference/widget/list-view.cpp diff --git a/higan/phoenix/reference/widget/list-view.hpp b/phoenix/reference/widget/list-view.hpp similarity index 100% rename from higan/phoenix/reference/widget/list-view.hpp rename to phoenix/reference/widget/list-view.hpp diff --git a/higan/phoenix/reference/widget/progress-bar.cpp b/phoenix/reference/widget/progress-bar.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/progress-bar.cpp rename to phoenix/reference/widget/progress-bar.cpp diff --git a/higan/phoenix/reference/widget/progress-bar.hpp b/phoenix/reference/widget/progress-bar.hpp similarity index 100% rename from higan/phoenix/reference/widget/progress-bar.hpp rename to phoenix/reference/widget/progress-bar.hpp diff --git a/higan/phoenix/reference/widget/radio-button.cpp b/phoenix/reference/widget/radio-button.cpp similarity index 100% rename from higan/phoenix/reference/widget/radio-button.cpp rename to phoenix/reference/widget/radio-button.cpp diff --git a/higan/phoenix/reference/widget/radio-button.hpp b/phoenix/reference/widget/radio-button.hpp similarity index 100% rename from higan/phoenix/reference/widget/radio-button.hpp rename to phoenix/reference/widget/radio-button.hpp diff --git a/higan/phoenix/reference/widget/sizable.hpp b/phoenix/reference/widget/sizable.hpp similarity index 100% rename from higan/phoenix/reference/widget/sizable.hpp rename to phoenix/reference/widget/sizable.hpp diff --git a/higan/phoenix/reference/widget/text-edit.cpp b/phoenix/reference/widget/text-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/text-edit.cpp rename to phoenix/reference/widget/text-edit.cpp diff --git a/higan/phoenix/reference/widget/text-edit.hpp b/phoenix/reference/widget/text-edit.hpp similarity index 100% rename from higan/phoenix/reference/widget/text-edit.hpp rename to phoenix/reference/widget/text-edit.hpp diff --git a/higan/phoenix/reference/widget/vertical-scroller.cpp b/phoenix/reference/widget/vertical-scroller.cpp similarity index 100% rename from higan/phoenix/reference/widget/vertical-scroller.cpp rename to phoenix/reference/widget/vertical-scroller.cpp diff --git a/higan/phoenix/reference/widget/vertical-scroller.hpp b/phoenix/reference/widget/vertical-scroller.hpp similarity index 100% rename from higan/phoenix/reference/widget/vertical-scroller.hpp rename to phoenix/reference/widget/vertical-scroller.hpp diff --git a/higan/phoenix/reference/widget/vertical-slider.cpp b/phoenix/reference/widget/vertical-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/vertical-slider.cpp rename to phoenix/reference/widget/vertical-slider.cpp diff --git a/higan/phoenix/reference/widget/vertical-slider.hpp b/phoenix/reference/widget/vertical-slider.hpp similarity index 100% rename from higan/phoenix/reference/widget/vertical-slider.hpp rename to phoenix/reference/widget/vertical-slider.hpp diff --git a/higan/phoenix/reference/widget/viewport.cpp b/phoenix/reference/widget/viewport.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/viewport.cpp rename to phoenix/reference/widget/viewport.cpp diff --git a/higan/phoenix/reference/widget/viewport.hpp b/phoenix/reference/widget/viewport.hpp similarity index 100% rename from higan/phoenix/reference/widget/viewport.hpp rename to phoenix/reference/widget/viewport.hpp diff --git a/higan/phoenix/reference/widget/widget.cpp b/phoenix/reference/widget/widget.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/widget/widget.cpp rename to phoenix/reference/widget/widget.cpp diff --git a/higan/phoenix/reference/widget/widget.hpp b/phoenix/reference/widget/widget.hpp similarity index 100% rename from higan/phoenix/reference/widget/widget.hpp rename to phoenix/reference/widget/widget.hpp diff --git a/higan/phoenix/reference/window.cpp b/phoenix/reference/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/reference/window.cpp rename to phoenix/reference/window.cpp diff --git a/higan/phoenix/reference/window.hpp b/phoenix/reference/window.hpp similarity index 100% rename from higan/phoenix/reference/window.hpp rename to phoenix/reference/window.hpp diff --git a/higan/phoenix/windows/action/action.cpp b/phoenix/windows/action/action.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/action.cpp rename to phoenix/windows/action/action.cpp diff --git a/higan/phoenix/windows/action/check-item.cpp b/phoenix/windows/action/check-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/check-item.cpp rename to phoenix/windows/action/check-item.cpp diff --git a/higan/phoenix/windows/action/item.cpp b/phoenix/windows/action/item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/item.cpp rename to phoenix/windows/action/item.cpp diff --git a/higan/phoenix/windows/action/menu.cpp b/phoenix/windows/action/menu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/menu.cpp rename to phoenix/windows/action/menu.cpp diff --git a/higan/phoenix/windows/action/radio-item.cpp b/phoenix/windows/action/radio-item.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/radio-item.cpp rename to phoenix/windows/action/radio-item.cpp diff --git a/higan/phoenix/windows/action/separator.cpp b/phoenix/windows/action/separator.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/action/separator.cpp rename to phoenix/windows/action/separator.cpp diff --git a/higan/phoenix/windows/application.cpp b/phoenix/windows/application.cpp similarity index 100% rename from higan/phoenix/windows/application.cpp rename to phoenix/windows/application.cpp diff --git a/higan/phoenix/windows/browser-window.cpp b/phoenix/windows/browser-window.cpp similarity index 100% rename from higan/phoenix/windows/browser-window.cpp rename to phoenix/windows/browser-window.cpp diff --git a/higan/phoenix/windows/desktop.cpp b/phoenix/windows/desktop.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/desktop.cpp rename to phoenix/windows/desktop.cpp diff --git a/higan/phoenix/windows/font.cpp b/phoenix/windows/font.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/font.cpp rename to phoenix/windows/font.cpp diff --git a/higan/phoenix/windows/header.hpp b/phoenix/windows/header.hpp similarity index 100% rename from higan/phoenix/windows/header.hpp rename to phoenix/windows/header.hpp diff --git a/higan/phoenix/windows/keyboard.cpp b/phoenix/windows/keyboard.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/keyboard.cpp rename to phoenix/windows/keyboard.cpp diff --git a/higan/phoenix/windows/message-window.cpp b/phoenix/windows/message-window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/message-window.cpp rename to phoenix/windows/message-window.cpp diff --git a/higan/phoenix/windows/mouse.cpp b/phoenix/windows/mouse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/mouse.cpp rename to phoenix/windows/mouse.cpp diff --git a/higan/phoenix/windows/object.cpp b/phoenix/windows/object.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/object.cpp rename to phoenix/windows/object.cpp diff --git a/ananke/phoenix/windows/phoenix.Manifest b/phoenix/windows/phoenix.Manifest similarity index 100% rename from ananke/phoenix/windows/phoenix.Manifest rename to phoenix/windows/phoenix.Manifest diff --git a/ananke/phoenix/windows/phoenix.rc b/phoenix/windows/phoenix.rc similarity index 100% rename from ananke/phoenix/windows/phoenix.rc rename to phoenix/windows/phoenix.rc diff --git a/higan/phoenix/windows/platform.cpp b/phoenix/windows/platform.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/platform.cpp rename to phoenix/windows/platform.cpp diff --git a/higan/phoenix/windows/platform.hpp b/phoenix/windows/platform.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/platform.hpp rename to phoenix/windows/platform.hpp diff --git a/higan/phoenix/windows/settings.cpp b/phoenix/windows/settings.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/settings.cpp rename to phoenix/windows/settings.cpp diff --git a/higan/phoenix/windows/timer.cpp b/phoenix/windows/timer.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/timer.cpp rename to phoenix/windows/timer.cpp diff --git a/higan/phoenix/windows/utility.cpp b/phoenix/windows/utility.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/utility.cpp rename to phoenix/windows/utility.cpp diff --git a/higan/phoenix/windows/widget/button.cpp b/phoenix/windows/widget/button.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/button.cpp rename to phoenix/windows/widget/button.cpp diff --git a/higan/phoenix/windows/widget/canvas.cpp b/phoenix/windows/widget/canvas.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/canvas.cpp rename to phoenix/windows/widget/canvas.cpp diff --git a/higan/phoenix/windows/widget/check-button.cpp b/phoenix/windows/widget/check-button.cpp similarity index 100% rename from higan/phoenix/windows/widget/check-button.cpp rename to phoenix/windows/widget/check-button.cpp diff --git a/higan/phoenix/windows/widget/combo-button.cpp b/phoenix/windows/widget/combo-button.cpp similarity index 100% rename from higan/phoenix/windows/widget/combo-button.cpp rename to phoenix/windows/widget/combo-button.cpp diff --git a/higan/phoenix/windows/widget/hex-edit.cpp b/phoenix/windows/widget/hex-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/hex-edit.cpp rename to phoenix/windows/widget/hex-edit.cpp diff --git a/higan/phoenix/windows/widget/horizontal-scroller.cpp b/phoenix/windows/widget/horizontal-scroller.cpp similarity index 100% rename from higan/phoenix/windows/widget/horizontal-scroller.cpp rename to phoenix/windows/widget/horizontal-scroller.cpp diff --git a/higan/phoenix/windows/widget/horizontal-slider.cpp b/phoenix/windows/widget/horizontal-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/horizontal-slider.cpp rename to phoenix/windows/widget/horizontal-slider.cpp diff --git a/higan/phoenix/windows/widget/label.cpp b/phoenix/windows/widget/label.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/label.cpp rename to phoenix/windows/widget/label.cpp diff --git a/higan/phoenix/windows/widget/line-edit.cpp b/phoenix/windows/widget/line-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/line-edit.cpp rename to phoenix/windows/widget/line-edit.cpp diff --git a/higan/phoenix/windows/widget/list-view.cpp b/phoenix/windows/widget/list-view.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/list-view.cpp rename to phoenix/windows/widget/list-view.cpp diff --git a/higan/phoenix/windows/widget/progress-bar.cpp b/phoenix/windows/widget/progress-bar.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/progress-bar.cpp rename to phoenix/windows/widget/progress-bar.cpp diff --git a/higan/phoenix/windows/widget/radio-button.cpp b/phoenix/windows/widget/radio-button.cpp similarity index 100% rename from higan/phoenix/windows/widget/radio-button.cpp rename to phoenix/windows/widget/radio-button.cpp diff --git a/higan/phoenix/windows/widget/text-edit.cpp b/phoenix/windows/widget/text-edit.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/text-edit.cpp rename to phoenix/windows/widget/text-edit.cpp diff --git a/higan/phoenix/windows/widget/vertical-scroller.cpp b/phoenix/windows/widget/vertical-scroller.cpp similarity index 100% rename from higan/phoenix/windows/widget/vertical-scroller.cpp rename to phoenix/windows/widget/vertical-scroller.cpp diff --git a/higan/phoenix/windows/widget/vertical-slider.cpp b/phoenix/windows/widget/vertical-slider.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/vertical-slider.cpp rename to phoenix/windows/widget/vertical-slider.cpp diff --git a/higan/phoenix/windows/widget/viewport.cpp b/phoenix/windows/widget/viewport.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/viewport.cpp rename to phoenix/windows/widget/viewport.cpp diff --git a/higan/phoenix/windows/widget/widget.cpp b/phoenix/windows/widget/widget.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/widget/widget.cpp rename to phoenix/windows/widget/widget.cpp diff --git a/higan/phoenix/windows/window.cpp b/phoenix/windows/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/phoenix/windows/window.cpp rename to phoenix/windows/window.cpp diff --git a/higan/processor/Makefile b/processor/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/Makefile rename to processor/Makefile diff --git a/higan/processor/arm/algorithms.cpp b/processor/arm/algorithms.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/algorithms.cpp rename to processor/arm/algorithms.cpp diff --git a/higan/processor/arm/arm.cpp b/processor/arm/arm.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/arm.cpp rename to processor/arm/arm.cpp diff --git a/higan/processor/arm/arm.hpp b/processor/arm/arm.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/arm.hpp rename to processor/arm/arm.hpp diff --git a/higan/processor/arm/disassembler.cpp b/processor/arm/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/disassembler.cpp rename to processor/arm/disassembler.cpp diff --git a/higan/processor/arm/disassembler.hpp b/processor/arm/disassembler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/disassembler.hpp rename to processor/arm/disassembler.hpp diff --git a/higan/processor/arm/instructions-arm.cpp b/processor/arm/instructions-arm.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/instructions-arm.cpp rename to processor/arm/instructions-arm.cpp diff --git a/higan/processor/arm/instructions-arm.hpp b/processor/arm/instructions-arm.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/instructions-arm.hpp rename to processor/arm/instructions-arm.hpp diff --git a/higan/processor/arm/instructions-thumb.cpp b/processor/arm/instructions-thumb.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/instructions-thumb.cpp rename to processor/arm/instructions-thumb.cpp diff --git a/higan/processor/arm/instructions-thumb.hpp b/processor/arm/instructions-thumb.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/instructions-thumb.hpp rename to processor/arm/instructions-thumb.hpp diff --git a/higan/processor/arm/registers.cpp b/processor/arm/registers.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/registers.cpp rename to processor/arm/registers.cpp diff --git a/higan/processor/arm/registers.hpp b/processor/arm/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/registers.hpp rename to processor/arm/registers.hpp diff --git a/higan/processor/arm/serialization.cpp b/processor/arm/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/arm/serialization.cpp rename to processor/arm/serialization.cpp diff --git a/higan/processor/gsu/gsu.cpp b/processor/gsu/gsu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/gsu.cpp rename to processor/gsu/gsu.cpp diff --git a/higan/processor/gsu/gsu.hpp b/processor/gsu/gsu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/gsu.hpp rename to processor/gsu/gsu.hpp diff --git a/higan/processor/gsu/instructions.cpp b/processor/gsu/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/instructions.cpp rename to processor/gsu/instructions.cpp diff --git a/higan/processor/gsu/registers.hpp b/processor/gsu/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/registers.hpp rename to processor/gsu/registers.hpp diff --git a/higan/processor/gsu/serialization.cpp b/processor/gsu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/serialization.cpp rename to processor/gsu/serialization.cpp diff --git a/higan/processor/gsu/table.cpp b/processor/gsu/table.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/gsu/table.cpp rename to processor/gsu/table.cpp diff --git a/higan/processor/hg51b/hg51b.cpp b/processor/hg51b/hg51b.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/hg51b.cpp rename to processor/hg51b/hg51b.cpp diff --git a/higan/processor/hg51b/hg51b.hpp b/processor/hg51b/hg51b.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/hg51b.hpp rename to processor/hg51b/hg51b.hpp diff --git a/higan/processor/hg51b/instructions.cpp b/processor/hg51b/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/instructions.cpp rename to processor/hg51b/instructions.cpp diff --git a/higan/processor/hg51b/registers.cpp b/processor/hg51b/registers.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/registers.cpp rename to processor/hg51b/registers.cpp diff --git a/higan/processor/hg51b/registers.hpp b/processor/hg51b/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/registers.hpp rename to processor/hg51b/registers.hpp diff --git a/higan/processor/hg51b/serialization.cpp b/processor/hg51b/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/hg51b/serialization.cpp rename to processor/hg51b/serialization.cpp diff --git a/higan/processor/lr35902/disassembler.cpp b/processor/lr35902/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/disassembler.cpp rename to processor/lr35902/disassembler.cpp diff --git a/higan/processor/lr35902/instructions.cpp b/processor/lr35902/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/instructions.cpp rename to processor/lr35902/instructions.cpp diff --git a/higan/processor/lr35902/lr35902.cpp b/processor/lr35902/lr35902.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/lr35902.cpp rename to processor/lr35902/lr35902.cpp diff --git a/higan/processor/lr35902/lr35902.hpp b/processor/lr35902/lr35902.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/lr35902.hpp rename to processor/lr35902/lr35902.hpp diff --git a/higan/processor/lr35902/registers.hpp b/processor/lr35902/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/registers.hpp rename to processor/lr35902/registers.hpp diff --git a/higan/processor/lr35902/serialization.cpp b/processor/lr35902/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/lr35902/serialization.cpp rename to processor/lr35902/serialization.cpp diff --git a/higan/processor/processor.hpp b/processor/processor.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/processor.hpp rename to processor/processor.hpp diff --git a/higan/processor/r6502/disassembler.cpp b/processor/r6502/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/disassembler.cpp rename to processor/r6502/disassembler.cpp diff --git a/higan/processor/r6502/instructions.cpp b/processor/r6502/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/instructions.cpp rename to processor/r6502/instructions.cpp diff --git a/higan/processor/r6502/memory.cpp b/processor/r6502/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/memory.cpp rename to processor/r6502/memory.cpp diff --git a/higan/processor/r6502/r6502.cpp b/processor/r6502/r6502.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/r6502.cpp rename to processor/r6502/r6502.cpp diff --git a/higan/processor/r6502/r6502.hpp b/processor/r6502/r6502.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/r6502.hpp rename to processor/r6502/r6502.hpp diff --git a/higan/processor/r6502/registers.hpp b/processor/r6502/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/registers.hpp rename to processor/r6502/registers.hpp diff --git a/higan/processor/r6502/serialization.cpp b/processor/r6502/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r6502/serialization.cpp rename to processor/r6502/serialization.cpp diff --git a/higan/processor/r65816/algorithms.cpp b/processor/r65816/algorithms.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/algorithms.cpp rename to processor/r65816/algorithms.cpp diff --git a/higan/processor/r65816/disassembler.cpp b/processor/r65816/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/disassembler.cpp rename to processor/r65816/disassembler.cpp diff --git a/higan/processor/r65816/disassembler.hpp b/processor/r65816/disassembler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/disassembler.hpp rename to processor/r65816/disassembler.hpp diff --git a/higan/processor/r65816/memory.hpp b/processor/r65816/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/memory.hpp rename to processor/r65816/memory.hpp diff --git a/higan/processor/r65816/opcode_misc.cpp b/processor/r65816/opcode_misc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/opcode_misc.cpp rename to processor/r65816/opcode_misc.cpp diff --git a/higan/processor/r65816/opcode_pc.cpp b/processor/r65816/opcode_pc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/opcode_pc.cpp rename to processor/r65816/opcode_pc.cpp diff --git a/higan/processor/r65816/opcode_read.cpp b/processor/r65816/opcode_read.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/opcode_read.cpp rename to processor/r65816/opcode_read.cpp diff --git a/higan/processor/r65816/opcode_rmw.cpp b/processor/r65816/opcode_rmw.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/opcode_rmw.cpp rename to processor/r65816/opcode_rmw.cpp diff --git a/higan/processor/r65816/opcode_write.cpp b/processor/r65816/opcode_write.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/opcode_write.cpp rename to processor/r65816/opcode_write.cpp diff --git a/higan/processor/r65816/r65816.cpp b/processor/r65816/r65816.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/r65816.cpp rename to processor/r65816/r65816.cpp diff --git a/higan/processor/r65816/r65816.hpp b/processor/r65816/r65816.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/r65816.hpp rename to processor/r65816/r65816.hpp diff --git a/higan/processor/r65816/registers.hpp b/processor/r65816/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/registers.hpp rename to processor/r65816/registers.hpp diff --git a/higan/processor/r65816/serialization.cpp b/processor/r65816/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/serialization.cpp rename to processor/r65816/serialization.cpp diff --git a/higan/processor/r65816/table.cpp b/processor/r65816/table.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/r65816/table.cpp rename to processor/r65816/table.cpp diff --git a/higan/processor/spc700/algorithms.cpp b/processor/spc700/algorithms.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/algorithms.cpp rename to processor/spc700/algorithms.cpp diff --git a/higan/processor/spc700/disassembler.cpp b/processor/spc700/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/disassembler.cpp rename to processor/spc700/disassembler.cpp diff --git a/higan/processor/spc700/instructions.cpp b/processor/spc700/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/instructions.cpp rename to processor/spc700/instructions.cpp diff --git a/higan/processor/spc700/memory.hpp b/processor/spc700/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/memory.hpp rename to processor/spc700/memory.hpp diff --git a/higan/processor/spc700/registers.hpp b/processor/spc700/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/registers.hpp rename to processor/spc700/registers.hpp diff --git a/higan/processor/spc700/serialization.cpp b/processor/spc700/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/serialization.cpp rename to processor/spc700/serialization.cpp diff --git a/higan/processor/spc700/spc700.cpp b/processor/spc700/spc700.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/spc700.cpp rename to processor/spc700/spc700.cpp diff --git a/higan/processor/spc700/spc700.hpp b/processor/spc700/spc700.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/spc700/spc700.hpp rename to processor/spc700/spc700.hpp diff --git a/higan/processor/upd96050/disassembler.cpp b/processor/upd96050/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/disassembler.cpp rename to processor/upd96050/disassembler.cpp diff --git a/higan/processor/upd96050/instructions.cpp b/processor/upd96050/instructions.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/instructions.cpp rename to processor/upd96050/instructions.cpp diff --git a/higan/processor/upd96050/memory.cpp b/processor/upd96050/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/memory.cpp rename to processor/upd96050/memory.cpp diff --git a/higan/processor/upd96050/registers.hpp b/processor/upd96050/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/registers.hpp rename to processor/upd96050/registers.hpp diff --git a/higan/processor/upd96050/serialization.cpp b/processor/upd96050/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/serialization.cpp rename to processor/upd96050/serialization.cpp diff --git a/higan/processor/upd96050/upd96050.cpp b/processor/upd96050/upd96050.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/upd96050.cpp rename to processor/upd96050/upd96050.cpp diff --git a/higan/processor/upd96050/upd96050.hpp b/processor/upd96050/upd96050.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/processor/upd96050/upd96050.hpp rename to processor/upd96050/upd96050.hpp diff --git a/higan/profile/Famicom.sys/manifest.bml b/profile/Famicom.sys/manifest.bml similarity index 100% rename from higan/profile/Famicom.sys/manifest.bml rename to profile/Famicom.sys/manifest.bml diff --git a/higan/profile/Game Boy Advance.sys/manifest.bml b/profile/Game Boy Advance.sys/manifest.bml similarity index 100% rename from higan/profile/Game Boy Advance.sys/manifest.bml rename to profile/Game Boy Advance.sys/manifest.bml diff --git a/higan/profile/Game Boy Color.sys/boot.rom b/profile/Game Boy Color.sys/boot.rom old mode 100755 new mode 100644 similarity index 100% rename from higan/profile/Game Boy Color.sys/boot.rom rename to profile/Game Boy Color.sys/boot.rom diff --git a/higan/profile/Game Boy Color.sys/manifest.bml b/profile/Game Boy Color.sys/manifest.bml similarity index 100% rename from higan/profile/Game Boy Color.sys/manifest.bml rename to profile/Game Boy Color.sys/manifest.bml diff --git a/higan/profile/Game Boy.sys/boot.rom b/profile/Game Boy.sys/boot.rom old mode 100755 new mode 100644 similarity index 100% rename from higan/profile/Game Boy.sys/boot.rom rename to profile/Game Boy.sys/boot.rom diff --git a/higan/profile/Game Boy.sys/manifest.bml b/profile/Game Boy.sys/manifest.bml similarity index 100% rename from higan/profile/Game Boy.sys/manifest.bml rename to profile/Game Boy.sys/manifest.bml diff --git a/higan/profile/Super Famicom.sys/ipl.rom b/profile/Super Famicom.sys/ipl.rom similarity index 100% rename from higan/profile/Super Famicom.sys/ipl.rom rename to profile/Super Famicom.sys/ipl.rom diff --git a/higan/profile/Super Famicom.sys/manifest.bml b/profile/Super Famicom.sys/manifest.bml similarity index 100% rename from higan/profile/Super Famicom.sys/manifest.bml rename to profile/Super Famicom.sys/manifest.bml diff --git a/purify/Makefile b/purify/Makefile deleted file mode 100644 index 53ba038f..00000000 --- a/purify/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -include nall/Makefile -include phoenix/Makefile - -path := /usr/local/bin -flags := -I. -O3 -fomit-frame-pointer -link := -s -objects := obj/phoenix.o obj/purify.o - -ifeq ($(platform),x) - link += -Wl,-export-dynamic -else ifeq ($(platform),win) - link += -mwindows -endif - -all: build; - -obj/phoenix.o: phoenix/phoenix.cpp - $(cpp) $(flags) -o obj/phoenix.o -c phoenix/phoenix.cpp $(phoenixflags) - -obj/purify.o: purify.cpp - $(cpp) $(flags) -o obj/purify.o -c purify.cpp - -build: $(objects) -ifeq ($(platform),x) - $(cpp) -pthread $(link) -o purify $(objects) $(phoenixlink) -else ifeq ($(platform),win) - windres phoenix/windows/phoenix.rc obj/phoenix-resource.o - $(cpp) -shared -o phoenix.dll obj/phoenix.o $(phoenixlink) - $(cpp) -o purify obj/purify.o obj/phoenix-resource.o $(link) -L. -lphoenix -endif - -resource: force - sourcery resource/resource.bml resource/resource.cpp resource/resource.hpp - -clean: - -@$(call delete,obj/*.o) - -install: uninstall -ifeq ($(platform),x) - sudo cp ./purify $(path)/purify -endif - -uninstall: -ifeq ($(platform),x) - if [ -f $(path)/purify ]; then sudo rm $(path)/purify; fi -endif - -sync: -ifeq ($(shell id -un),byuu) - if [ -d ./nall ]; then rm -r ./nall; fi - if [ -d ./phoenix ]; then rm -r ./phoenix; fi - cp -r ../nall ./nall - cp -r ../phoenix ./phoenix - rm -r nall/test - rm -r phoenix/nall - rm -r phoenix/test -endif - -force: diff --git a/purify/nall/Makefile b/purify/nall/Makefile deleted file mode 100644 index f422f49d..00000000 --- a/purify/nall/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# Makefile -# author: byuu -# license: public domain - -[A-Z] = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -[a-z] = a b c d e f g h i j k l m n o p q r s t u v w x y z -[0-9] = 0 1 2 3 4 5 6 7 8 9 -[markup] = ` ~ ! @ \# $$ % ^ & * ( ) - _ = + [ { ] } \ | ; : ' " , < . > / ? -[all] = $([A-Z]) $([a-z]) $([0-9]) $([markup]) -[space] := -[space] += - -##### -# platform detection -##### - -ifeq ($(platform),) - uname := $(shell uname -a) - ifeq ($(uname),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Windows,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring CYGWIN,$(uname)),) - platform := win - delete = del $(subst /,\,$1) - else ifneq ($(findstring Darwin,$(uname)),) - platform := osx - delete = rm -f $1 - else - platform := x - delete = rm -f $1 - endif -endif - -ifeq ($(compiler),) - ifeq ($(platform),win) - compiler := g++ - else ifeq ($(platform),osx) - compiler := g++-mp-4.7 - else - compiler := g++-4.7 - endif -endif - -c := $(compiler) -x c -std=gnu99 -cpp := $(compiler) -std=gnu++11 - -ifeq ($(arch),x86) - c := $(c) -m32 - cpp := $(cpp) -m32 -endif - -ifeq ($(prefix),) - prefix := /usr/local -endif - -##### -# function rwildcard(directory, pattern) -##### -rwildcard = \ - $(strip \ - $(filter $(if $2,$2,%), \ - $(foreach f, \ - $(wildcard $1*), \ - $(eval t = $(call rwildcard,$f/)) \ - $(if $t,$t,$f) \ - ) \ - ) \ - ) - -##### -# function strtr(source, from, to) -##### -strtr = \ - $(eval __temp := $1) \ - $(strip \ - $(foreach c, \ - $(join $(addsuffix :,$2),$3), \ - $(eval __temp := \ - $(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) - -##### -# function strupper(source) -##### -strupper = $(call strtr,$1,$([a-z]),$([A-Z])) - -##### -# function strlower(source) -##### -strlower = $(call strtr,$1,$([A-Z]),$([a-z])) - -##### -# function strlen(source) -##### -strlen = \ - $(eval __temp := $(subst $([space]),_,$1)) \ - $(words \ - $(strip \ - $(foreach c, \ - $([all]), \ - $(eval __temp := \ - $(subst $c,$c ,$(__temp)) \ - ) \ - ) \ - $(__temp) \ - ) \ - ) - -##### -# function streq(source) -##### -streq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),,1) - -##### -# function strne(source) -##### -strne = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),1,) diff --git a/purify/nall/algorithm.hpp b/purify/nall/algorithm.hpp deleted file mode 100644 index 037f0bb7..00000000 --- a/purify/nall/algorithm.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NALL_ALGORITHM_HPP -#define NALL_ALGORITHM_HPP - -#undef min -#undef max - -namespace nall { - template T min(const T &t, const U &u) { - return t < u ? t : u; - } - - template T max(const T &t, const U &u) { - return t > u ? t : u; - } -} - -#endif diff --git a/purify/nall/any.hpp b/purify/nall/any.hpp deleted file mode 100644 index 7661a2a4..00000000 --- a/purify/nall/any.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef NALL_ANY_HPP -#define NALL_ANY_HPP - -#include -#include - -namespace nall { - struct any { - bool empty() const { return container; } - const std::type_info& type() const { return container ? container->type() : typeid(void); } - - template any& operator=(const T& value_) { - typedef typename type_if< - std::is_array::value, - typename std::remove_extent::type>::type*, - T - >::type auto_t; - - if(type() == typeid(auto_t)) { - static_cast*>(container)->value = (auto_t)value_; - } else { - if(container) delete container; - container = new holder((auto_t)value_); - } - - return *this; - } - - any() : container(nullptr) {} - ~any() { if(container) delete container; } - template any(const T& value_) : container(nullptr) { operator=(value_); } - - private: - struct placeholder { - virtual const std::type_info& type() const = 0; - } *container; - - template struct holder : placeholder { - T value; - const std::type_info& type() const { return typeid(T); } - holder(const T& value_) : value(value_) {} - }; - - template friend T any_cast(any&); - template friend T any_cast(const any&); - template friend T* any_cast(any*); - template friend const T* any_cast(const any*); - }; - - template T any_cast(any &value) { - typedef typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T any_cast(const any &value) { - typedef const typename std::remove_reference::type nonref; - if(value.type() != typeid(nonref)) throw; - return static_cast*>(value.container)->value; - } - - template T* any_cast(any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } - - template const T* any_cast(const any *value) { - if(!value || value->type() != typeid(T)) return nullptr; - return &static_cast*>(value->container)->value; - } -} - -#endif diff --git a/purify/nall/atoi.hpp b/purify/nall/atoi.hpp deleted file mode 100644 index 26756c79..00000000 --- a/purify/nall/atoi.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_ATOI_HPP -#define NALL_ATOI_HPP - -#include - -namespace nall { - -//note: this header is intended to form the base for user-defined literals; -//once they are supported by GCC. eg: -//unsigned operator "" b(const char *s) { return binary(s); } -//-> signed data = 1001b; -//(0b1001 is nicer, but is not part of the C++ standard) - -constexpr inline uintmax_t binary_(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? binary_(s + 1, (sum << 1) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t octal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '7' ? octal_(s + 1, (sum << 3) | *s - '0') : - sum - ); -} - -constexpr inline uintmax_t decimal_(const char *s, uintmax_t sum = 0) { - return ( - *s >= '0' && *s <= '9' ? decimal_(s + 1, (sum * 10) + *s - '0') : - sum - ); -} - -constexpr inline uintmax_t hex_(const char *s, uintmax_t sum = 0) { - return ( - *s >= 'A' && *s <= 'F' ? hex_(s + 1, (sum << 4) | *s - 'A' + 10) : - *s >= 'a' && *s <= 'f' ? hex_(s + 1, (sum << 4) | *s - 'a' + 10) : - *s >= '0' && *s <= '9' ? hex_(s + 1, (sum << 4) | *s - '0') : - sum - ); -} - -// - -constexpr inline uintmax_t binary(const char *s) { - return ( - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '%' ? binary_(s + 1) : - binary_(s) - ); -} - -constexpr inline uintmax_t octal(const char *s) { - return ( - octal_(s) - ); -} - -constexpr inline intmax_t integer(const char *s) { - return ( - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -constexpr inline uintmax_t decimal(const char *s) { - return ( - decimal_(s) - ); -} - -constexpr inline uintmax_t hex(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '$' ? hex_(s + 1) : - hex_(s) - ); -} - -constexpr inline intmax_t numeral(const char *s) { - return ( - *s == '0' && *(s + 1) == 'X' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'x' ? hex_(s + 2) : - *s == '0' && *(s + 1) == 'B' ? binary_(s + 2) : - *s == '0' && *(s + 1) == 'b' ? binary_(s + 2) : - *s == '0' ? octal_(s + 1) : - *s == '+' ? +decimal_(s + 1) : - *s == '-' ? -decimal_(s + 1) : - decimal_(s) - ); -} - -inline double fp(const char *s) { - return atof(s); -} - -} - -#endif diff --git a/purify/nall/base64.hpp b/purify/nall/base64.hpp deleted file mode 100644 index daf3fa60..00000000 --- a/purify/nall/base64.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef NALL_BASE64_HPP -#define NALL_BASE64_HPP - -#include -#include - -namespace nall { - struct base64 { - static bool encode(char *&output, const uint8_t* input, unsigned inlength) { - output = new char[inlength * 8 / 6 + 8](); - - unsigned i = 0, o = 0; - while(i < inlength) { - switch(i % 3) { - - case 0: { - output[o++] = enc(input[i] >> 2); - output[o] = enc((input[i] & 3) << 4); - break; - } - - case 1: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 4)); - output[o] = enc((input[i] & 15) << 2); - break; - } - - case 2: { - uint8_t prev = dec(output[o]); - output[o++] = enc(prev + (input[i] >> 6)); - output[o++] = enc(input[i] & 63); - break; - } - - } - - i++; - } - - return true; - } - - static string encode(const string &data) { - char *buffer = nullptr; - encode(buffer, (const uint8_t*)(const char*)data, data.length()); - string result = buffer; - delete[] buffer; - return result; - } - - static bool decode(uint8_t *&output, unsigned &outlength, const char *input) { - unsigned inlength = strlen(input), infix = 0; - output = new uint8_t[inlength + 1](); - - unsigned i = 0, o = 0; - while(i < inlength) { - uint8_t x = dec(input[i]); - - switch(i++ & 3) { - - case 0: { - output[o] = x << 2; - break; - } - - case 1: { - output[o++] |= x >> 4; - output[o] = (x & 15) << 4; - break; - } - - case 2: { - output[o++] |= x >> 2; - output[o] = (x & 3) << 6; - break; - } - - case 3: { - output[o++] |= x; - break; - } - - } - } - - outlength = o; - return true; - } - - static string decode(const string &data) { - uint8_t *buffer = nullptr; - unsigned size = 0; - decode(buffer, size, (const char*)data); - string result = (const char*)buffer; - delete[] buffer; - return result; - } - - private: - static char enc(uint8_t n) { - //base64 for URL encodings (URL = -_, MIME = +/) - static char lookup_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - return lookup_table[n & 63]; - } - - static uint8_t dec(char n) { - if(n >= 'A' && n <= 'Z') return n - 'A'; - if(n >= 'a' && n <= 'z') return n - 'a' + 26; - if(n >= '0' && n <= '9') return n - '0' + 52; - if(n == '-') return 62; - if(n == '_') return 63; - return 0; - } - }; -} - -#endif diff --git a/purify/nall/beat/archive.hpp b/purify/nall/beat/archive.hpp deleted file mode 100644 index ef7294cf..00000000 --- a/purify/nall/beat/archive.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef NALL_BEAT_ARCHIVE_HPP -#define NALL_BEAT_ARCHIVE_HPP - -#include - -namespace nall { - -struct beatArchive : beatBase { - bool create(const string &beatname, string pathname, const string &metadata = "") { - if(fp.open(beatname, file::mode::write) == false) return false; - if(pathname.endswith("/") == false) pathname.append("/"); - - checksum = ~0; - writeString("BPA1"); - writeNumber(metadata.length()); - writeString(metadata); - - lstring list; - ls(list, pathname, pathname); - for(auto &name : list) { - if(name.endswith("/")) { - name.rtrim<1>("/"); - writeNumber(0 | ((name.length() - 1) << 1)); - writeString(name); - } else { - file stream; - if(stream.open({pathname, name}, file::mode::read) == false) return false; - writeNumber(1 | ((name.length() - 1) << 1)); - writeString(name); - unsigned size = stream.size(); - writeNumber(size); - uint32_t checksum = ~0; - while(size--) { - uint8_t data = stream.read(); - write(data); - checksum = crc32_adjust(checksum, data); - } - writeChecksum(~checksum); - } - } - - writeChecksum(~checksum); - fp.close(); - return true; - } - - bool unpack(const string &beatname, string pathname) { - if(fp.open(beatname, file::mode::read) == false) return false; - if(pathname.endswith("/") == false) pathname.append("/"); - - checksum = ~0; - if(readString(4) != "BPA1") return false; - unsigned length = readNumber(); - while(length--) read(); - - directory::create(pathname); - while(fp.offset() < fp.size() - 4) { - unsigned data = readNumber(); - string name = readString((data >> 1) + 1); - if(name.position("\\") || name.position("../")) return false; //block path exploits - - if((data & 1) == 0) { - directory::create({pathname, name}); - } else { - file stream; - if(stream.open({pathname, name}, file::mode::write) == false) return false; - unsigned size = readNumber(); - uint32_t checksum = ~0; - while(size--) { - uint8_t data = read(); - stream.write(data); - checksum = crc32_adjust(checksum, data); - } - if(readChecksum(~checksum) == false) return false; - } - } - - return readChecksum(~checksum); - } -}; - -} - -#endif diff --git a/purify/nall/beat/base.hpp b/purify/nall/beat/base.hpp deleted file mode 100644 index 8e0001be..00000000 --- a/purify/nall/beat/base.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef NALL_BEAT_BASE_HPP -#define NALL_BEAT_BASE_HPP - -namespace nall { - -struct beatBase { -protected: - file fp; - uint32_t checksum; - - void ls(lstring &list, const string &path, const string &basepath) { - lstring paths = directory::folders(path); - for(auto &pathname : paths) { - list.append(string{path, pathname}.ltrim<1>(basepath)); - ls(list, {path, pathname}, basepath); - } - - lstring files = directory::files(path); - for(auto &filename : files) { - list.append(string{path, filename}.ltrim<1>(basepath)); - } - } - - void write(uint8_t data) { - fp.write(data); - checksum = crc32_adjust(checksum, data); - } - - void writeNumber(uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) return write(0x80 | x); - write(x); - data--; - } - } - - void writeString(const string &text) { - unsigned length = text.length(); - for(unsigned n = 0; n < length; n++) write(text[n]); - } - - void writeChecksum(uint32_t checksum) { - write(checksum >> 0); - write(checksum >> 8); - write(checksum >> 16); - write(checksum >> 24); - } - - uint8_t read() { - uint8_t data = fp.read(); - checksum = crc32_adjust(checksum, data); - return data; - } - - uint64_t readNumber() { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - } - - string readString(unsigned length) { - string text; - text.reserve(length + 1); - for(unsigned n = 0; n < length; n++) { - text[n] = fp.read(); - checksum = crc32_adjust(checksum, text[n]); - } - text[length] = 0; - return text; - } - - bool readChecksum(uint32_t source) { - uint32_t checksum = 0; - checksum |= read() << 0; - checksum |= read() << 8; - checksum |= read() << 16; - checksum |= read() << 24; - return checksum == source; - } -}; - -} - -#endif diff --git a/purify/nall/beat/delta.hpp b/purify/nall/beat/delta.hpp deleted file mode 100644 index ce120537..00000000 --- a/purify/nall/beat/delta.hpp +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef NALL_BEAT_DELTA_HPP -#define NALL_BEAT_DELTA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsdelta { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpsdelta::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpsdelta::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpsdelta::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpsdelta::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpsdelta::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t sourceChecksum = ~0, modifyChecksum = ~0; - unsigned sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - Node *sourceTree[65536], *targetTree[65536]; - for(unsigned n = 0; n < 65536; n++) sourceTree[n] = 0, targetTree[n] = 0; - - //source tree creation - for(unsigned offset = 0; offset < sourceSize; offset++) { - uint16_t symbol = sourceData[offset + 0]; - sourceChecksum = crc32_adjust(sourceChecksum, symbol); - if(offset < sourceSize - 1) symbol |= sourceData[offset + 1] << 8; - Node *node = new Node; - node->offset = offset; - node->next = sourceTree[symbol]; - sourceTree[symbol] = node; - } - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - while(outputOffset < targetSize) { - unsigned maxLength = 0, maxOffset = 0, mode = TargetRead; - - uint16_t symbol = targetData[outputOffset + 0]; - if(outputOffset < targetSize - 1) symbol |= targetData[outputOffset + 1] << 8; - - { //source read - unsigned length = 0, offset = outputOffset; - while(offset < sourceSize && offset < targetSize && sourceData[offset] == targetData[offset]) { - length++; - offset++; - } - if(length > maxLength) maxLength = length, mode = SourceRead; - } - - { //source copy - Node *node = sourceTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(x < sourceSize && y < targetSize && sourceData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = SourceCopy; - node = node->next; - } - } - - { //target copy - Node *node = targetTree[symbol]; - while(node) { - unsigned length = 0, x = node->offset, y = outputOffset; - while(y < targetSize && targetData[x++] == targetData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset, mode = TargetCopy; - node = node->next; - } - - //target tree append - node = new Node; - node->offset = outputOffset; - node->next = targetTree[symbol]; - targetTree[symbol] = node; - } - - { //target read - if(maxLength < 4) { - maxLength = min((unsigned)Granularity, targetSize - outputOffset); - mode = TargetRead; - } - } - - if(mode != TargetRead) targetReadFlush(); - - switch(mode) { - case SourceRead: - encode(SourceRead | ((maxLength - 1) << 2)); - break; - case TargetRead: - //delay write to group sequential TargetRead commands into one - targetReadLength += maxLength; - break; - case SourceCopy: - case TargetCopy: - encode(mode | ((maxLength - 1) << 2)); - signed relativeOffset; - if(mode == SourceCopy) { - relativeOffset = maxOffset - sourceRelativeOffset; - sourceRelativeOffset = maxOffset + maxLength; - } else { - relativeOffset = maxOffset - targetRelativeOffset; - targetRelativeOffset = maxOffset + maxLength; - } - encode((relativeOffset < 0) | (abs(relativeOffset) << 1)); - break; - } - - outputOffset += maxLength; - } - - targetReadFlush(); - - sourceChecksum = ~sourceChecksum; - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/purify/nall/beat/linear.hpp b/purify/nall/beat/linear.hpp deleted file mode 100644 index 078aae34..00000000 --- a/purify/nall/beat/linear.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_BEAT_LINEAR_HPP -#define NALL_BEAT_LINEAR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpslinear { - inline void source(const uint8_t *data, unsigned size); - inline void target(const uint8_t *data, unsigned size); - - inline bool source(const string &filename); - inline bool target(const string &filename); - inline bool create(const string &filename, const string &metadata = ""); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - enum : unsigned { Granularity = 1 }; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - const uint8_t *targetData; - unsigned targetSize; -}; - -void bpslinear::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpslinear::target(const uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpslinear::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpslinear::target(const string &filename) { - if(targetFile.open(filename, filemap::mode::read) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -bool bpslinear::create(const string &filename, const string &metadata) { - file modifyFile; - if(modifyFile.open(filename, file::mode::write) == false) return false; - - uint32_t modifyChecksum = ~0; - unsigned targetRelativeOffset = 0, outputOffset = 0; - - auto write = [&](uint8_t data) { - modifyFile.write(data); - modifyChecksum = crc32_adjust(modifyChecksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - unsigned targetReadLength = 0; - - auto targetReadFlush = [&]() { - if(targetReadLength) { - encode(TargetRead | ((targetReadLength - 1) << 2)); - unsigned offset = outputOffset - targetReadLength; - while(targetReadLength) write(targetData[offset++]), targetReadLength--; - } - }; - - write('B'); - write('P'); - write('S'); - write('1'); - - encode(sourceSize); - encode(targetSize); - - unsigned markupSize = metadata.length(); - encode(markupSize); - for(unsigned n = 0; n < markupSize; n++) write(metadata[n]); - - while(outputOffset < targetSize) { - unsigned sourceLength = 0; - for(unsigned n = 0; outputOffset + n < min(sourceSize, targetSize); n++) { - if(sourceData[outputOffset + n] != targetData[outputOffset + n]) break; - sourceLength++; - } - - unsigned rleLength = 0; - for(unsigned n = 1; outputOffset + n < targetSize; n++) { - if(targetData[outputOffset] != targetData[outputOffset + n]) break; - rleLength++; - } - - if(rleLength >= 4) { - //write byte to repeat - targetReadLength++; - outputOffset++; - targetReadFlush(); - - //copy starting from repetition byte - encode(TargetCopy | ((rleLength - 1) << 2)); - unsigned relativeOffset = (outputOffset - 1) - targetRelativeOffset; - encode(relativeOffset << 1); - outputOffset += rleLength; - targetRelativeOffset = outputOffset - 1; - } else if(sourceLength >= 4) { - targetReadFlush(); - encode(SourceRead | ((sourceLength - 1) << 2)); - outputOffset += sourceLength; - } else { - targetReadLength += Granularity; - outputOffset += Granularity; - } - } - - targetReadFlush(); - - uint32_t sourceChecksum = crc32_calculate(sourceData, sourceSize); - for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n); - uint32_t targetChecksum = crc32_calculate(targetData, targetSize); - for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n); - uint32_t outputChecksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - modifyFile.close(); - return true; -} - -} - -#endif diff --git a/purify/nall/beat/metadata.hpp b/purify/nall/beat/metadata.hpp deleted file mode 100644 index 58e6ab0a..00000000 --- a/purify/nall/beat/metadata.hpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef NALL_BEAT_METADATA_HPP -#define NALL_BEAT_METADATA_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpsmetadata { - inline bool load(const string &filename); - inline bool save(const string &filename, const string &metadata); - inline string metadata() const; - -protected: - file sourceFile; - string metadataString; -}; - -bool bpsmetadata::load(const string &filename) { - if(sourceFile.open(filename, file::mode::read) == false) return false; - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - if(read() != 'B') return false; - if(read() != 'P') return false; - if(read() != 'S') return false; - if(read() != '1') return false; - decode(); - decode(); - unsigned metadataSize = decode(); - char data[metadataSize + 1]; - for(unsigned n = 0; n < metadataSize; n++) data[n] = read(); - data[metadataSize] = 0; - metadataString = (const char*)data; - - return true; -} - -bool bpsmetadata::save(const string &filename, const string &metadata) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - if(sourceFile.open() == false) return false; - sourceFile.seek(0); - - auto read = [&]() -> uint8_t { - return sourceFile.read(); - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - uint32_t checksum = ~0; - - auto write = [&](uint8_t data) { - targetFile.write(data); - checksum = crc32_adjust(checksum, data); - }; - - auto encode = [&](uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - }; - - for(unsigned n = 0; n < 4; n++) write(read()); - encode(decode()); - encode(decode()); - unsigned sourceLength = decode(); - unsigned targetLength = metadata.length(); - encode(targetLength); - sourceFile.seek(sourceLength, file::index::relative); - for(unsigned n = 0; n < targetLength; n++) write(metadata[n]); - unsigned length = sourceFile.size() - sourceFile.offset() - 4; - for(unsigned n = 0; n < length; n++) write(read()); - uint32_t outputChecksum = ~checksum; - for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n); - - targetFile.close(); - return true; -} - -string bpsmetadata::metadata() const { - return metadataString; -} - -} - -#endif diff --git a/purify/nall/beat/multi.hpp b/purify/nall/beat/multi.hpp deleted file mode 100644 index cddf5d6b..00000000 --- a/purify/nall/beat/multi.hpp +++ /dev/null @@ -1,242 +0,0 @@ -#ifndef NALL_BEAT_MULTI_HPP -#define NALL_BEAT_MULTI_HPP - -#include -#include -#include - -namespace nall { - -struct bpsmulti { - enum : unsigned { - CreatePath = 0, - CreateFile = 1, - ModifyFile = 2, - MirrorFile = 3, - }; - - enum : unsigned { - OriginSource = 0, - OriginTarget = 1, - }; - - bool create(const string &patchName, const string &sourcePath, const string &targetPath, bool delta = false, const string &metadata = "") { - if(fp.open()) fp.close(); - fp.open(patchName, file::mode::write); - checksum = ~0; - - writeString("BPM1"); //signature - writeNumber(metadata.length()); - writeString(metadata); - - lstring sourceList, targetList; - ls(sourceList, sourcePath, sourcePath); - ls(targetList, targetPath, targetPath); - - for(auto &targetName : targetList) { - if(targetName.endswith("/")) { - targetName.rtrim<1>("/"); - writeNumber(CreatePath | ((targetName.length() - 1) << 2)); - writeString(targetName); - } else if(auto position = sourceList.find(targetName)) { //if sourceName == targetName - file sp, dp; - sp.open({sourcePath, targetName}, file::mode::read); - dp.open({targetPath, targetName}, file::mode::read); - - bool identical = sp.size() == dp.size(); - uint32_t cksum = ~0; - - for(unsigned n = 0; n < sp.size(); n++) { - uint8_t byte = sp.read(); - if(identical && byte != dp.read()) identical = false; - cksum = crc32_adjust(cksum, byte); - } - - if(identical) { - writeNumber(MirrorFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - writeNumber(OriginSource); - writeChecksum(~cksum); - } else { - writeNumber(ModifyFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - writeNumber(OriginSource); - - if(delta == false) { - bpslinear patch; - patch.source({sourcePath, targetName}); - patch.target({targetPath, targetName}); - patch.create({temppath(), "temp.bps"}); - } else { - bpsdelta patch; - patch.source({sourcePath, targetName}); - patch.target({targetPath, targetName}); - patch.create({temppath(), "temp.bps"}); - } - - auto buffer = file::read({temppath(), "temp.bps"}); - writeNumber(buffer.size()); - for(auto &byte : buffer) write(byte); - } - } else { - writeNumber(CreateFile | ((targetName.length() - 1) << 2)); - writeString(targetName); - auto buffer = file::read({targetPath, targetName}); - writeNumber(buffer.size()); - for(auto &byte : buffer) write(byte); - writeChecksum(crc32_calculate(buffer.data(), buffer.size())); - } - } - - //checksum - writeChecksum(~checksum); - fp.close(); - return true; - } - - bool apply(const string &patchName, const string &sourcePath, const string &targetPath) { - directory::remove(targetPath); //start with a clean directory - directory::create(targetPath); - - if(fp.open()) fp.close(); - fp.open(patchName, file::mode::read); - checksum = ~0; - - if(readString(4) != "BPM1") return false; - auto metadataLength = readNumber(); - while(metadataLength--) read(); - - while(fp.offset() < fp.size() - 4) { - auto encoding = readNumber(); - unsigned action = encoding & 3; - unsigned targetLength = (encoding >> 2) + 1; - string targetName = readString(targetLength); - - if(action == CreatePath) { - directory::create({targetPath, targetName, "/"}); - } else if(action == CreateFile) { - file fp; - fp.open({targetPath, targetName}, file::mode::write); - auto fileSize = readNumber(); - while(fileSize--) fp.write(read()); - uint32_t cksum = readChecksum(); - } else if(action == ModifyFile) { - auto encoding = readNumber(); - string originPath = encoding & 1 ? targetPath : sourcePath; - string sourceName = (encoding >> 1) == 0 ? targetName : readString(encoding >> 1); - auto patchSize = readNumber(); - vector buffer; - buffer.resize(patchSize); - for(unsigned n = 0; n < patchSize; n++) buffer[n] = read(); - bpspatch patch; - patch.modify(buffer.data(), buffer.size()); - patch.source({originPath, sourceName}); - patch.target({targetPath, targetName}); - if(patch.apply() != bpspatch::result::success) return false; - } else if(action == MirrorFile) { - auto encoding = readNumber(); - string originPath = encoding & 1 ? targetPath : sourcePath; - string sourceName = (encoding >> 1) == 0 ? targetName : readString(encoding >> 1); - file::copy({originPath, sourceName}, {targetPath, targetName}); - uint32_t cksum = readChecksum(); - } - } - - uint32_t cksum = ~checksum; - if(read() != (uint8_t)(cksum >> 0)) return false; - if(read() != (uint8_t)(cksum >> 8)) return false; - if(read() != (uint8_t)(cksum >> 16)) return false; - if(read() != (uint8_t)(cksum >> 24)) return false; - - fp.close(); - return true; - } - -protected: - file fp; - uint32_t checksum; - - //create() functions - void ls(lstring &list, const string &path, const string &basepath) { - lstring paths = directory::folders(path); - for(auto &pathname : paths) { - list.append(string{path, pathname}.ltrim<1>(basepath)); - ls(list, {path, pathname}, basepath); - } - - lstring files = directory::files(path); - for(auto &filename : files) { - list.append(string{path, filename}.ltrim<1>(basepath)); - } - } - - void write(uint8_t data) { - fp.write(data); - checksum = crc32_adjust(checksum, data); - } - - void writeNumber(uint64_t data) { - while(true) { - uint64_t x = data & 0x7f; - data >>= 7; - if(data == 0) { - write(0x80 | x); - break; - } - write(x); - data--; - } - } - - void writeString(const string &text) { - unsigned length = text.length(); - for(unsigned n = 0; n < length; n++) write(text[n]); - } - - void writeChecksum(uint32_t cksum) { - write(cksum >> 0); - write(cksum >> 8); - write(cksum >> 16); - write(cksum >> 24); - } - - //apply() functions - uint8_t read() { - uint8_t data = fp.read(); - checksum = crc32_adjust(checksum, data); - return data; - } - - uint64_t readNumber() { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - } - - string readString(unsigned length) { - string text; - text.reserve(length + 1); - for(unsigned n = 0; n < length; n++) text[n] = read(); - text[length] = 0; - return text; - } - - uint32_t readChecksum() { - uint32_t checksum = 0; - checksum |= read() << 0; - checksum |= read() << 8; - checksum |= read() << 16; - checksum |= read() << 24; - return checksum; - } -}; - -} - -#endif diff --git a/purify/nall/beat/patch.hpp b/purify/nall/beat/patch.hpp deleted file mode 100644 index 8c6de75b..00000000 --- a/purify/nall/beat/patch.hpp +++ /dev/null @@ -1,219 +0,0 @@ -#ifndef NALL_BEAT_PATCH_HPP -#define NALL_BEAT_PATCH_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -struct bpspatch { - inline bool modify(const uint8_t *data, unsigned size); - inline void source(const uint8_t *data, unsigned size); - inline void target(uint8_t *data, unsigned size); - - inline bool modify(const string &filename); - inline bool source(const string &filename); - inline bool target(const string &filename); - - inline string metadata() const; - inline unsigned size() const; - - enum result : unsigned { - unknown, - success, - patch_too_small, - patch_invalid_header, - source_too_small, - target_too_small, - source_checksum_invalid, - target_checksum_invalid, - patch_checksum_invalid, - }; - - inline result apply(); - -protected: - enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy }; - - filemap modifyFile; - const uint8_t *modifyData; - unsigned modifySize; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - - filemap targetFile; - uint8_t *targetData; - unsigned targetSize; - - unsigned modifySourceSize; - unsigned modifyTargetSize; - unsigned modifyMarkupSize; - string metadataString; -}; - -bool bpspatch::modify(const uint8_t *data, unsigned size) { - if(size < 19) return false; - modifyData = data; - modifySize = size; - - unsigned offset = 4; - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = modifyData[offset++]; - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - - char buffer[modifyMarkupSize + 1]; - for(unsigned n = 0; n < modifyMarkupSize; n++) buffer[n] = modifyData[offset++]; - buffer[modifyMarkupSize] = 0; - metadataString = (const char*)buffer; - - return true; -} - -void bpspatch::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -void bpspatch::target(uint8_t *data, unsigned size) { - targetData = data; - targetSize = size; -} - -bool bpspatch::modify(const string &filename) { - if(modifyFile.open(filename, filemap::mode::read) == false) return false; - return modify(modifyFile.data(), modifyFile.size()); -} - -bool bpspatch::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - source(sourceFile.data(), sourceFile.size()); - return true; -} - -bool bpspatch::target(const string &filename) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(modifyTargetSize); - fp.close(); - - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - target(targetFile.data(), targetFile.size()); - return true; -} - -string bpspatch::metadata() const { - return metadataString; -} - -unsigned bpspatch::size() const { - return modifyTargetSize; -} - -bpspatch::result bpspatch::apply() { - if(modifySize < 19) return result::patch_too_small; - - uint32_t modifyChecksum = ~0, targetChecksum = ~0; - unsigned modifyOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0, outputOffset = 0; - - auto read = [&]() -> uint8_t { - uint8_t data = modifyData[modifyOffset++]; - modifyChecksum = crc32_adjust(modifyChecksum, data); - return data; - }; - - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; - while(true) { - uint8_t x = read(); - data += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - data += shift; - } - return data; - }; - - auto write = [&](uint8_t data) { - targetData[outputOffset++] = data; - targetChecksum = crc32_adjust(targetChecksum, data); - }; - - if(read() != 'B') return result::patch_invalid_header; - if(read() != 'P') return result::patch_invalid_header; - if(read() != 'S') return result::patch_invalid_header; - if(read() != '1') return result::patch_invalid_header; - - modifySourceSize = decode(); - modifyTargetSize = decode(); - modifyMarkupSize = decode(); - for(unsigned n = 0; n < modifyMarkupSize; n++) read(); - - if(modifySourceSize > sourceSize) return result::source_too_small; - if(modifyTargetSize > targetSize) return result::target_too_small; - - while(modifyOffset < modifySize - 12) { - unsigned length = decode(); - unsigned mode = length & 3; - length = (length >> 2) + 1; - - switch(mode) { - case SourceRead: - while(length--) write(sourceData[outputOffset]); - break; - case TargetRead: - while(length--) write(read()); - break; - case SourceCopy: - case TargetCopy: - signed offset = decode(); - bool negative = offset & 1; - offset >>= 1; - if(negative) offset = -offset; - - if(mode == SourceCopy) { - sourceRelativeOffset += offset; - while(length--) write(sourceData[sourceRelativeOffset++]); - } else { - targetRelativeOffset += offset; - while(length--) write(targetData[targetRelativeOffset++]); - } - break; - } - } - - uint32_t modifySourceChecksum = 0, modifyTargetChecksum = 0, modifyModifyChecksum = 0; - for(unsigned n = 0; n < 32; n += 8) modifySourceChecksum |= read() << n; - for(unsigned n = 0; n < 32; n += 8) modifyTargetChecksum |= read() << n; - uint32_t checksum = ~modifyChecksum; - for(unsigned n = 0; n < 32; n += 8) modifyModifyChecksum |= read() << n; - - uint32_t sourceChecksum = crc32_calculate(sourceData, modifySourceSize); - targetChecksum = ~targetChecksum; - - if(sourceChecksum != modifySourceChecksum) return result::source_checksum_invalid; - if(targetChecksum != modifyTargetChecksum) return result::target_checksum_invalid; - if(checksum != modifyModifyChecksum) return result::patch_checksum_invalid; - - return result::success; -} - -} - -#endif diff --git a/purify/nall/bit.hpp b/purify/nall/bit.hpp deleted file mode 100644 index 63403eb0..00000000 --- a/purify/nall/bit.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef NALL_BIT_HPP -#define NALL_BIT_HPP - -#include - -namespace nall { - template - inline uintmax_t uclamp(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), y = b * 2 - 1 }; - return y + ((x - y) & -(x < y)); //min(x, y); - } - - template - inline uintmax_t uclip(const uintmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return (x & m); - } - - template - inline intmax_t sclamp(const intmax_t x) { - enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 }; - return (x > m) ? m : (x < -b) ? -b : x; - } - - template - inline intmax_t sclip(const intmax_t x) { - enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; - return ((x & m) ^ b) - b; - } - - namespace bit { - constexpr inline uintmax_t mask(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) : - *s == ' ' || *s == '_' ? mask(s + 1, sum) : - *s ? mask(s + 1, sum << 1) : - sum - ); - } - - constexpr inline uintmax_t test(const char *s, uintmax_t sum = 0) { - return ( - *s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) : - *s == ' ' || *s == '_' ? test(s + 1, sum) : - *s ? test(s + 1, sum << 1) : - sum - ); - } - - //lowest(0b1110) == 0b0010 - constexpr inline uintmax_t lowest(const uintmax_t x) { - return x & -x; - } - - //clear_lowest(0b1110) == 0b1100 - constexpr inline uintmax_t clear_lowest(const uintmax_t x) { - return x & (x - 1); - } - - //set_lowest(0b0101) == 0b0111 - constexpr inline uintmax_t set_lowest(const uintmax_t x) { - return x | (x + 1); - } - - //count number of bits set in a byte - inline unsigned count(uintmax_t x) { - unsigned count = 0; - do count += x & 1; while(x >>= 1); - return count; - } - - //round up to next highest single bit: - //round(15) == 16, round(16) == 16, round(17) == 32 - inline uintmax_t round(uintmax_t x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } - } -} - -#endif diff --git a/purify/nall/bmp.hpp b/purify/nall/bmp.hpp deleted file mode 100644 index 33cdf4dc..00000000 --- a/purify/nall/bmp.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef NALL_BMP_HPP -#define NALL_BMP_HPP - -#include - -//BMP reader / writer -//author: byuu -//note: only 24-bit RGB and 32-bit ARGB uncompressed images supported - -namespace nall { - -struct bmp { - inline static bool read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height); - inline static bool write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha = false); -}; - -bool bmp::read(const string &filename, uint32_t *&data, unsigned &width, unsigned &height) { - file fp; - if(fp.open(filename, file::mode::read) == false) return false; - if(fp.size() < 0x36) return false; - - if(fp.readm(2) != 0x424d) return false; - fp.seek(0x000a); - unsigned offset = fp.readl(4); - unsigned dibsize = fp.readl(4); - if(dibsize != 40) return false; - signed headerWidth = fp.readl(4); - if(headerWidth < 0) return false; - signed headerHeight = fp.readl(4); - fp.readl(2); - unsigned bitsPerPixel = fp.readl(2); - if(bitsPerPixel != 24 && bitsPerPixel != 32) return false; - unsigned compression = fp.readl(4); - if(compression != 0) return false; - fp.seek(offset); - - bool noFlip = headerHeight < 0; - width = headerWidth, height = abs(headerHeight); - data = new uint32_t[width * height]; - - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - for(unsigned y = 0; y < height; y++) { - uint32_t *p = noFlip ? data + y * width : data + (height - 1 - y) * width; - for(unsigned x = 0; x < width; x++, p++) { - *p = fp.readl(bytesPerPixel); - if(bytesPerPixel == 3) *p |= 255 << 24; - } - if(paddingLength) fp.readl(paddingLength); - } - - fp.close(); - return true; -} - -bool bmp::write(const string &filename, const uint32_t *data, unsigned width, unsigned height, unsigned pitch, bool alpha) { - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - - unsigned bitsPerPixel = alpha ? 32 : 24; - unsigned bytesPerPixel = bitsPerPixel / 8; - unsigned alignedWidth = width * bytesPerPixel; - unsigned paddingLength = 0; - unsigned imageSize = alignedWidth * height; - unsigned fileSize = 0x36 + imageSize; - while(alignedWidth % 4) alignedWidth++, paddingLength++; - - fp.writem(0x424d, 2); //signature - fp.writel(fileSize, 4); //file size - fp.writel(0, 2); //reserved - fp.writel(0, 2); //reserved - fp.writel(0x36, 4); //offset - - fp.writel(40, 4); //DIB size - fp.writel(width, 4); //width - fp.writel(-height, 4); //height - fp.writel(1, 2); //color planes - fp.writel(bitsPerPixel, 2); //bits per pixel - fp.writel(0, 4); //compression method (BI_RGB) - fp.writel(imageSize, 4); //image data size - fp.writel(3780, 4); //horizontal resolution - fp.writel(3780, 4); //vertical resolution - fp.writel(0, 4); //palette size - fp.writel(0, 4); //important color count - - for(unsigned y = 0; y < height; y++) { - const uint32_t *p = (const uint32_t*)((const uint8_t*)data + y * pitch); - for(unsigned x = 0; x < width; x++) fp.writel(*p++, bytesPerPixel); - if(paddingLength) fp.writel(0, paddingLength); - } - - fp.close(); - return true; -} - -} - -#endif diff --git a/purify/nall/compositor.hpp b/purify/nall/compositor.hpp deleted file mode 100644 index 6b9245f6..00000000 --- a/purify/nall/compositor.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef NALL_COMPOSITOR_HPP -#define NALL_COMPOSITOR_HPP - -#include - -namespace nall { - -struct compositor { - inline static bool enabled(); - inline static bool enable(bool status); - - #if defined(PLATFORM_X) - enum class Compositor : unsigned { Unknown, Metacity, Xfwm4 }; - inline static Compositor detect(); - - inline static bool enabled_metacity(); - inline static bool enable_metacity(bool status); - - inline static bool enabled_xfwm4(); - inline static bool enable_xfwm4(bool status); - #endif -}; - -#if defined(PLATFORM_X) - -//Metacity - -bool compositor::enabled_metacity() { - FILE *fp = popen("gconftool-2 --get /apps/metacity/general/compositing_manager", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_metacity(bool status) { - FILE *fp; - if(status) { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager true", "r"); - } else { - fp = popen("gconftool-2 --set --type bool /apps/metacity/general/compositing_manager false", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//Xfwm4 - -bool compositor::enabled_xfwm4() { - FILE *fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing'", "r"); - if(fp == 0) return false; - - char buffer[512]; - if(fgets(buffer, sizeof buffer, fp) == 0) return false; - - if(!memcmp(buffer, "true", 4)) return true; - return false; -} - -bool compositor::enable_xfwm4(bool status) { - FILE *fp; - if(status) { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'true'", "r"); - } else { - fp = popen("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'false'", "r"); - } - if(fp == 0) return false; - pclose(fp); - return true; -} - -//General - -compositor::Compositor compositor::detect() { - Compositor result = Compositor::Unknown; - - FILE *fp; - char buffer[512]; - - fp = popen("pidof metacity", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Metacity; - pclose(fp); - - fp = popen("pidof xfwm4", "r"); - if(fp && fgets(buffer, sizeof buffer, fp)) result = Compositor::Xfwm4; - pclose(fp); - - return result; -} - -bool compositor::enabled() { - switch(detect()) { - case Compositor::Metacity: return enabled_metacity(); - case Compositor::Xfwm4: return enabled_xfwm4(); - default: return false; - } -} - -bool compositor::enable(bool status) { - switch(detect()) { - case Compositor::Metacity: return enable_metacity(status); - case Compositor::Xfwm4: return enable_xfwm4(status); - default: return false; - } -} - -#elif defined(PLATFORM_WINDOWS) - -bool compositor::enabled() { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmIsCompositionEnabled = (HRESULT (WINAPI*)(BOOL*))GetProcAddress(module, "DwmIsCompositionEnabled"); - if(pDwmIsCompositionEnabled == 0) return false; - - BOOL result; - if(pDwmIsCompositionEnabled(&result) != S_OK) return false; - return result; -} - -bool compositor::enable(bool status) { - HMODULE module = GetModuleHandleW(L"dwmapi"); - if(module == 0) module = LoadLibraryW(L"dwmapi"); - if(module == 0) return false; - - auto pDwmEnableComposition = (HRESULT (WINAPI*)(UINT))GetProcAddress(module, "DwmEnableComposition"); - if(pDwmEnableComposition == 0) return false; - - if(pDwmEnableComposition(status) != S_OK) return false; - return true; -} - -#else - -bool compositor::enabled() { - return false; -} - -bool compositor::enable(bool) { - return false; -} - -#endif - -} - -#endif diff --git a/purify/nall/config.hpp b/purify/nall/config.hpp deleted file mode 100644 index 94be7dc1..00000000 --- a/purify/nall/config.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_CONFIG_HPP -#define NALL_CONFIG_HPP - -#include -#include -#include - -namespace nall { - namespace configuration_traits { - template struct is_boolean { enum { value = false }; }; - template<> struct is_boolean { enum { value = true }; }; - - template struct is_signed { enum { value = false }; }; - template<> struct is_signed { enum { value = true }; }; - - template struct is_unsigned { enum { value = false }; }; - template<> struct is_unsigned { enum { value = true }; }; - - template struct is_double { enum { value = false }; }; - template<> struct is_double { enum { value = true }; }; - - template struct is_string { enum { value = false }; }; - template<> struct is_string { enum { value = true }; }; - } - - class configuration { - public: - enum type_t { boolean_t, signed_t, unsigned_t, double_t, string_t, unknown_t }; - struct item_t { - uintptr_t data; - string name; - string desc; - type_t type; - - inline string get() const { - switch(type) { - case boolean_t: return { *(bool*)data }; - case signed_t: return { *(signed*)data }; - case unsigned_t: return { *(unsigned*)data }; - case double_t: return { *(double*)data }; - case string_t: return { "\"", *(string*)data, "\"" }; - } - return "???"; - } - - inline void set(string s) { - switch(type) { - case boolean_t: *(bool*)data = (s == "true"); break; - case signed_t: *(signed*)data = integer(s); break; - case unsigned_t: *(unsigned*)data = decimal(s); break; - case double_t: *(double*)data = fp(s); break; - case string_t: s.trim("\""); *(string*)data = s; break; - } - } - }; - vector list; - - template - inline void append(T &data, const char *name, const char *desc = "") { - item_t item = { (uintptr_t)&data, name, desc }; - if(configuration_traits::is_boolean::value) item.type = boolean_t; - else if(configuration_traits::is_signed::value) item.type = signed_t; - else if(configuration_traits::is_unsigned::value) item.type = unsigned_t; - else if(configuration_traits::is_double::value) item.type = double_t; - else if(configuration_traits::is_string::value) item.type = string_t; - else item.type = unknown_t; - list.append(item); - } - - //deprecated - template - inline void attach(T &data, const char *name, const char *desc = "") { - append(data, name, desc); - } - - inline virtual bool load(const string &filename) { - string data; - if(data.readfile(filename) == true) { - data.replace("\r", ""); - lstring line; - line.split("\n", data); - - for(unsigned i = 0; i < line.size(); i++) { - if(auto position = qstrpos(line[i], "#")) line[i][position()] = 0; - if(!qstrpos(line[i], " = ")) continue; - - lstring part; - part.qsplit(" = ", line[i]); - part[0].trim(); - part[1].trim(); - - for(unsigned n = 0; n < list.size(); n++) { - if(part[0] == list[n].name) { - list[n].set(part[1]); - break; - } - } - } - - return true; - } else { - return false; - } - } - - inline virtual bool save(const string &filename) const { - file fp; - if(fp.open(filename, file::mode::write)) { - for(unsigned i = 0; i < list.size(); i++) { - string output; - output.append(list[i].name, " = ", list[i].get()); - if(list[i].desc != "") output.append(" # ", list[i].desc); - output.append("\r\n"); - fp.print(output); - } - - fp.close(); - return true; - } else { - return false; - } - } - }; -} - -#endif diff --git a/purify/nall/crc16.hpp b/purify/nall/crc16.hpp deleted file mode 100644 index cd6e72fd..00000000 --- a/purify/nall/crc16.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NALL_CRC16_HPP -#define NALL_CRC16_HPP - -#include - -namespace nall { - inline uint16_t crc16_adjust(uint16_t crc16, uint8_t data) { - for(unsigned n = 0; n < 8; n++) { - if((crc16 & 1) ^ (data & 1)) crc16 = (crc16 >> 1) ^ 0x8408; - else crc16 >>= 1; - data >>= 1; - } - return crc16; - } - - inline uint16_t crc16_calculate(const uint8_t *data, unsigned length) { - uint16_t crc16 = ~0; - for(unsigned n = 0; n < length; n++) { - crc16 = crc16_adjust(crc16, data[n]); - } - return ~crc16; - } -} - -#endif diff --git a/purify/nall/crc32.hpp b/purify/nall/crc32.hpp deleted file mode 100644 index ad36fbf6..00000000 --- a/purify/nall/crc32.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef NALL_CRC32_HPP -#define NALL_CRC32_HPP - -#include - -namespace nall { - const uint32_t crc32_table[256] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; - - inline uint32_t crc32_adjust(uint32_t crc32, uint8_t input) { - return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff]; - } - - inline uint32_t crc32_calculate(const uint8_t *data, unsigned length) { - uint32_t crc32 = ~0; - for(unsigned i = 0; i < length; i++) { - crc32 = crc32_adjust(crc32, data[i]); - } - return ~crc32; - } -} - -#endif diff --git a/purify/nall/directory.hpp b/purify/nall/directory.hpp deleted file mode 100644 index 5617ee4e..00000000 --- a/purify/nall/directory.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#ifndef NALL_DIRECTORY_HPP -#define NALL_DIRECTORY_HPP - -#include -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include -#else - #include - #include - #include -#endif - -namespace nall { - -struct directory { - static bool create(const string &pathname, unsigned permissions = 0755); //recursive - static bool remove(const string &pathname); //recursive - static bool exists(const string &pathname); - - static lstring folders(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname, pattern); - folders.sort(); - return folders; - } - - static lstring files(const string &pathname, const string &pattern = "*") { - lstring files = directory::ufiles(pathname, pattern); - files.sort(); - return files; - } - - static lstring contents(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files - lstring files = directory::ufiles(pathname, pattern); - folders.sort(); - files.sort(); - for(auto &file : files) folders.append(file); - return folders; - } - - static lstring ifolders(const string &pathname, const string &pattern = "*") { - lstring folders = ufolders(pathname, pattern); - folders.isort(); - return folders; - } - - static lstring ifiles(const string &pathname, const string &pattern = "*") { - lstring files = ufiles(pathname, pattern); - files.isort(); - return files; - } - - static lstring icontents(const string &pathname, const string &pattern = "*") { - lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files - lstring files = directory::ufiles(pathname, pattern); - folders.isort(); - files.isort(); - for(auto &file : files) folders.append(file); - return folders; - } - -private: - //internal functions; these return unsorted lists - static lstring ufolders(const string &pathname, const string &pattern = "*"); - static lstring ufiles(const string &pathname, const string &pattern = "*"); -}; - -#if defined(PLATFORM_WINDOWS) - inline bool directory::create(const string &pathname, unsigned permissions) { - string path; - lstring list = string{pathname}.transform("\\", "/").rtrim<1>("/").split("/"); - bool result = true; - for(auto &part : list) { - path.append(part, "/"); - result &= (_wmkdir(utf16_t(path)) == 0); - } - return result; - } - - inline bool directory::remove(const string &pathname) { - lstring list = directory::contents(pathname); - for(auto &name : list) { - if(name.endswith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); - } - return _wrmdir(utf16_t(pathname)) == 0; - } - - inline bool directory::exists(const string &pathname) { - string name = pathname; - name.trim<1>("\""); - DWORD result = GetFileAttributes(utf16_t(name)); - if(result == INVALID_FILE_ATTRIBUTES) return false; - return (result & FILE_ATTRIBUTE_DIRECTORY); - } - - inline lstring directory::ufolders(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - while(FindNextFile(handle, &data) != false) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - } - FindClose(handle); - } - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::ufiles(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - while(FindNextFile(handle, &data) != false) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = (const char*)utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - FindClose(handle); - } - return list; - } -#else - inline bool directory::create(const string &pathname, unsigned permissions) { - string path; - lstring list = string{pathname}.rtrim<1>("/").split("/"); - bool result = true; - for(auto &part : list) { - path.append(part, "/"); - result &= (mkdir(path, permissions) == 0); - } - return result; - } - - inline bool directory::remove(const string &pathname) { - lstring list = directory::contents(pathname); - for(auto &name : list) { - if(name.endswith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); - } - return rmdir(pathname) == 0; - } - - inline bool directory::exists(const string &pathname) { - DIR *dp = opendir(pathname); - if(!dp) return false; - closedir(dp); - return true; - } - - inline lstring directory::ufolders(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if(ep->d_type & DT_DIR) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - for(auto &name : list) name.append("/"); //must append after sorting - return list; - } - - inline lstring directory::ufiles(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if((ep->d_type & DT_DIR) == 0) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - return list; - } -#endif - -} - -#endif diff --git a/purify/nall/dl.hpp b/purify/nall/dl.hpp deleted file mode 100644 index 3bd7d4d2..00000000 --- a/purify/nall/dl.hpp +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NALL_DL_HPP -#define NALL_DL_HPP - -//dynamic linking support - -#include -#include -#include -#include - -#if defined(PLATFORM_X) || defined(PLATFORM_OSX) - #include -#elif defined(PLATFORM_WINDOWS) - #include - #include -#endif - -namespace nall { - struct library { - bool opened() const { return handle; } - bool open(const char*, const char* = ""); - bool open_absolute(const char*); - void* sym(const char*); - void close(); - - library() : handle(0) {} - ~library() { close(); } - - library& operator=(const library&) = delete; - library(const library&) = delete; - - private: - uintptr_t handle; - }; - - #if defined(PLATFORM_X) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".so"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_OSX) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".dylib"), RTLD_LAZY); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)dlopen(name, RTLD_LAZY); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return dlsym((void*)handle, name); - } - - inline void library::close() { - if(!handle) return; - dlclose((void*)handle); - handle = 0; - } - #elif defined(PLATFORM_WINDOWS) - inline bool library::open(const char *name, const char *path) { - if(handle) close(); - string filepath(path, *path && !strend(path, "/") && !strend(path, "\\") ? "\\" : "", name, ".dll"); - handle = (uintptr_t)LoadLibraryW(utf16_t(filepath)); - return handle; - } - - inline bool library::open_absolute(const char *name) { - if(handle) close(); - handle = (uintptr_t)LoadLibraryW(utf16_t(name)); - return handle; - } - - inline void* library::sym(const char *name) { - if(!handle) return 0; - return (void*)GetProcAddress((HMODULE)handle, name); - } - - inline void library::close() { - if(!handle) return; - FreeLibrary((HMODULE)handle); - handle = 0; - } - #else - inline bool library::open(const char*, const char*) { return false; } - inline void* library::sym(const char*) { return 0; } - inline void library::close() {} - #endif -}; - -#endif diff --git a/purify/nall/dsp.hpp b/purify/nall/dsp.hpp deleted file mode 100644 index a2400ec7..00000000 --- a/purify/nall/dsp.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef NALL_DSP_HPP -#define NALL_DSP_HPP - -#include -#ifdef __SSE__ - #include -#endif - -#define NALL_DSP_INTERNAL_HPP -#include -#undef NALL_DSP_INTERNAL_HPP - -#endif diff --git a/purify/nall/dsp/buffer.hpp b/purify/nall/dsp/buffer.hpp deleted file mode 100644 index 4386d0e9..00000000 --- a/purify/nall/dsp/buffer.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct Buffer { - double **sample; - uint16_t rdoffset; - uint16_t wroffset; - unsigned channels; - - void setChannels(unsigned channels) { - for(unsigned c = 0; c < this->channels; c++) { - if(sample[c]) delete[] sample[c]; - } - if(sample) delete[] sample; - - this->channels = channels; - if(channels == 0) return; - - sample = new double*[channels]; - for(unsigned c = 0; c < channels; c++) { - sample[c] = new double[65536](); - } - } - - inline double& read(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(rdoffset + offset)]; - } - - inline double& write(unsigned channel, signed offset = 0) { - return sample[channel][(uint16_t)(wroffset + offset)]; - } - - inline void clear() { - for(unsigned c = 0; c < channels; c++) { - for(unsigned n = 0; n < 65536; n++) { - sample[c][n] = 0; - } - } - rdoffset = 0; - wroffset = 0; - } - - Buffer() { - channels = 0; - } - - ~Buffer() { - setChannels(0); - } -}; - -#endif diff --git a/purify/nall/dsp/core.hpp b/purify/nall/dsp/core.hpp deleted file mode 100644 index a5b967b1..00000000 --- a/purify/nall/dsp/core.hpp +++ /dev/null @@ -1,167 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include -#include - -namespace nall { - -//precision: can be float, double or long double -#define real float - -struct DSP; - -struct Resampler { - DSP &dsp; - real frequency; - - virtual void setFrequency() = 0; - virtual void clear() = 0; - virtual void sample() = 0; - Resampler(DSP &dsp) : dsp(dsp) {} -}; - -struct DSP { - enum class ResampleEngine : unsigned { - Nearest, - Linear, - Cosine, - Cubic, - Hermite, - Average, - Sinc, - }; - - inline void setChannels(unsigned channels); - inline void setPrecision(unsigned precision); - inline void setFrequency(real frequency); //inputFrequency - inline void setVolume(real volume); - inline void setBalance(real balance); - - inline void setResampler(ResampleEngine resamplingEngine); - inline void setResamplerFrequency(real frequency); //outputFrequency - - inline void sample(signed channel[]); - inline bool pending(); - inline void read(signed channel[]); - - inline void clear(); - inline DSP(); - inline ~DSP(); - -protected: - friend class ResampleNearest; - friend class ResampleLinear; - friend class ResampleCosine; - friend class ResampleCubic; - friend class ResampleAverage; - friend class ResampleHermite; - friend class ResampleSinc; - - struct Settings { - unsigned channels; - unsigned precision; - real frequency; - real volume; - real balance; - - //internal - real intensity; - real intensityInverse; - } settings; - - Resampler *resampler; - inline void write(real channel[]); - - #include "buffer.hpp" - Buffer buffer; - Buffer output; - - inline void adjustVolume(); - inline void adjustBalance(); - inline signed clamp(const unsigned bits, const signed x); -}; - -#include "resample/nearest.hpp" -#include "resample/linear.hpp" -#include "resample/cosine.hpp" -#include "resample/cubic.hpp" -#include "resample/hermite.hpp" -#include "resample/average.hpp" -#include "resample/sinc.hpp" -#include "settings.hpp" - -void DSP::sample(signed channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - buffer.write(c) = (real)channel[c] * settings.intensityInverse; - } - buffer.wroffset++; - resampler->sample(); -} - -bool DSP::pending() { - return output.rdoffset != output.wroffset; -} - -void DSP::read(signed channel[]) { - adjustVolume(); - adjustBalance(); - - for(unsigned c = 0; c < settings.channels; c++) { - channel[c] = clamp(settings.precision, output.read(c) * settings.intensity); - } - output.rdoffset++; -} - -void DSP::write(real channel[]) { - for(unsigned c = 0; c < settings.channels; c++) { - output.write(c) = channel[c]; - } - output.wroffset++; -} - -void DSP::adjustVolume() { - for(unsigned c = 0; c < settings.channels; c++) { - output.read(c) *= settings.volume; - } -} - -void DSP::adjustBalance() { - if(settings.channels != 2) return; //TODO: support > 2 channels - if(settings.balance < 0.0) output.read(1) *= 1.0 + settings.balance; - if(settings.balance > 0.0) output.read(0) *= 1.0 - settings.balance; -} - -signed DSP::clamp(const unsigned bits, const signed x) { - const signed b = 1U << (bits - 1); - const signed m = (1U << (bits - 1)) - 1; - return (x > m) ? m : (x < -b) ? -b : x; -} - -void DSP::clear() { - buffer.clear(); - output.clear(); - resampler->clear(); -} - -DSP::DSP() { - setResampler(ResampleEngine::Hermite); - setResamplerFrequency(44100.0); - - setChannels(2); - setPrecision(16); - setFrequency(44100.0); - setVolume(1.0); - setBalance(0.0); - - clear(); -} - -DSP::~DSP() { - if(resampler) delete resampler; -} - -#undef real - -} - -#endif diff --git a/purify/nall/dsp/resample/average.hpp b/purify/nall/dsp/resample/average.hpp deleted file mode 100644 index 867b13bf..00000000 --- a/purify/nall/dsp/resample/average.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleAverage : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline void sampleLinear(); - ResampleAverage(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleAverage::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleAverage::clear() { - fraction = 0.0; -} - -void ResampleAverage::sample() { - //can only average if input frequency >= output frequency - if(step < 1.0) return sampleLinear(); - - fraction += 1.0; - - real scalar = 1.0; - if(fraction > step) scalar = 1.0 - (fraction - step); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) += dsp.buffer.read(c) * scalar; - } - - if(fraction >= step) { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) /= step; - } - dsp.output.wroffset++; - - fraction -= step; - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = dsp.buffer.read(c) * fraction; - } - } - - dsp.buffer.rdoffset++; -} - -void ResampleAverage::sampleLinear() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/cosine.hpp b/purify/nall/dsp/resample/cosine.hpp deleted file mode 100644 index 3363d5f6..00000000 --- a/purify/nall/dsp/resample/cosine.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCosine : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCosine(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCosine::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCosine::clear() { - fraction = 0.0; -} - -void ResampleCosine::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/cubic.hpp b/purify/nall/dsp/resample/cubic.hpp deleted file mode 100644 index bc4cc955..00000000 --- a/purify/nall/dsp/resample/cubic.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleCubic : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleCubic(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleCubic::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleCubic::clear() { - fraction = 0.0; -} - -void ResampleCubic::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - real mu = fraction; - - real A = d - c - a + b; - real B = a - b - A; - real C = c - a; - real D = b; - - channel[n] = A * (mu * 3) + B * (mu * 2) + C * mu + D; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/hermite.hpp b/purify/nall/dsp/resample/hermite.hpp deleted file mode 100644 index 0cc9ba0e..00000000 --- a/purify/nall/dsp/resample/hermite.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleHermite : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleHermite(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleHermite::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleHermite::clear() { - fraction = 0.0; -} - -void ResampleHermite::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -3); - real b = dsp.buffer.read(n, -2); - real c = dsp.buffer.read(n, -1); - real d = dsp.buffer.read(n, -0); - - const real tension = 0.0; //-1 = low, 0 = normal, +1 = high - const real bias = 0.0; //-1 = left, 0 = even, +1 = right - - real mu1, mu2, mu3, m0, m1, a0, a1, a2, a3; - - mu1 = fraction; - mu2 = mu1 * mu1; - mu3 = mu2 * mu1; - - m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - a0 = +2 * mu3 - 3 * mu2 + 1; - a1 = mu3 - 2 * mu2 + mu1; - a2 = mu3 - mu2; - a3 = -2 * mu3 + 3 * mu2; - - channel[n] = (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c); - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/lib/sinc.hpp b/purify/nall/dsp/resample/lib/sinc.hpp deleted file mode 100644 index 3e953679..00000000 --- a/purify/nall/dsp/resample/lib/sinc.hpp +++ /dev/null @@ -1,600 +0,0 @@ -// If these types are changed to anything other than "float", you should comment out the SSE detection directives below -// so that the SSE code is not used. - -typedef float resample_coeff_t; // note: sizeof(resample_coeff_t) must be == to a power of 2, and not larger than 16 -typedef float resample_samp_t; - - -// ...but don't comment this single RESAMPLE_SSEREGPARM define out when disabling SSE. -#define RESAMPLE_SSEREGPARM - -#if defined(__SSE__) - #define SINCRESAMPLE_USE_SSE 1 - #ifndef __x86_64__ - #undef RESAMPLE_SSEREGPARM - #define RESAMPLE_SSEREGPARM __attribute__((sseregparm)) - #endif -#else - // TODO: altivec here -#endif - -namespace ResampleUtility -{ - inline void kaiser_window(double* io, int count, double beta); - inline void gen_sinc(double* out, int size, double cutoff, double kaiser); - inline void gen_sinc_os(double* out, int size, double cutoff, double kaiser); - inline void normalize(double* io, int size, double gain = 1.0); - - inline void* make_aligned(void* ptr, unsigned boundary); // boundary must be a power of 2 -} - -class SincResampleHR -{ - private: - - inline void Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count); - - unsigned ratio; - unsigned num_convolutions; - - resample_coeff_t *coeffs; - std::vector coeffs_mem; - - // second half of ringbuffer should be copy of first half. - resample_samp_t *rb; - std::vector rb_mem; - - signed rb_readpos; - signed rb_writepos; - signed rb_in; - signed rb_eff_size; - - friend class SincResample; -}; - -class SincResample -{ - public: - - enum - { - QUALITY_LOW = 0, - QUALITY_MEDIUM = 2, - QUALITY_HIGH = 4 - }; - - inline SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality = QUALITY_HIGH); - - inline void write(resample_samp_t sample) RESAMPLE_SSEREGPARM; - inline resample_samp_t read(void) RESAMPLE_SSEREGPARM; - inline bool output_avail(void); - - private: - - inline void Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min); - - inline resample_samp_t mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) RESAMPLE_SSEREGPARM; - - unsigned num_convolutions; - unsigned num_phases; - - unsigned step_int; - double step_fract; - - double input_pos_fract; - - - std::vector coeffs; // Pointers into coeff_mem. - std::vector coeff_mem; - - - std::vector rb; // second half should be copy of first half. - signed rb_readpos; - signed rb_writepos; - signed rb_in; - - bool hr_used; - SincResampleHR hr; -}; - - -// -// Code: -// -//#include "resample.hpp" - -#if 0 -namespace bit -{ - inline unsigned round(unsigned x) { - if((x & (x - 1)) == 0) return x; - while(x & (x - 1)) x &= x - 1; - return x << 1; - } -} -#endif - -void SincResampleHR::Init(unsigned ratio_arg, double desired_bandwidth, double beta, double d) -{ - const unsigned align_boundary = 16; - std::vector coeffs_tmp; - double cutoff; // 1.0 = f/2 - - ratio = ratio_arg; - - //num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) + 1) &~ 1; // round up to be even - num_convolutions = ((unsigned)ceil(d / ((1.0 - desired_bandwidth) / ratio)) | 1); - - cutoff = (1.0 / ratio) - (d / num_convolutions); - -//printf("%d %d %.20f\n", ratio, num_convolutions, cutoff); - assert(num_convolutions > ratio); - - - // Generate windowed sinc of POWER - coeffs_tmp.resize(num_convolutions); - //ResampleUtility::gen_sinc(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::gen_sinc_os(&coeffs_tmp[0], num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeffs_tmp[0], num_convolutions); - - // Copy from coeffs_tmp to coeffs~ - // We multiply many coefficients at a time in the mac loop, so make sure the last few that don't really - // exist are allocated, zero'd mem. - - coeffs_mem.resize(((num_convolutions + 7) &~ 7) * sizeof(resample_coeff_t) + (align_boundary - 1)); - coeffs = (resample_coeff_t *)ResampleUtility::make_aligned(&coeffs_mem[0], align_boundary); - - - for(unsigned i = 0; i < num_convolutions; i++) - coeffs[i] = coeffs_tmp[i]; - - rb_eff_size = nall::bit::round(num_convolutions * 2) >> 1; - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; - - rb_mem.resize(rb_eff_size * 2 * sizeof(resample_samp_t) + (align_boundary - 1)); - rb = (resample_samp_t *)ResampleUtility::make_aligned(&rb_mem[0], align_boundary); -} - - -inline bool SincResampleHR::output_avail(void) -{ - return(rb_in >= (signed)num_convolutions); -} - -inline void SincResampleHR::write(resample_samp_t sample) -{ - assert(!output_avail()); - - rb[rb_writepos] = sample; - rb[rb_writepos + rb_eff_size] = sample; - rb_writepos = (rb_writepos + 1) & (rb_eff_size - 1); - rb_in++; -} - -resample_samp_t SincResampleHR::mac(const resample_samp_t *wave, const resample_coeff_t *coeff, unsigned count) -{ -#if SINCRESAMPLE_USE_SSE - __m128 accum_veca[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - resample_samp_t accum; - - for(unsigned c = 0; c < count; c += 8) - { - for(unsigned i = 0; i < 2; i++) - { - __m128 co[2]; - __m128 w[2]; - - co[i] = _mm_load_ps(&coeff[c + i * 4]); - w[i] = _mm_load_ps(&wave[c + i * 4]); - - w[i] = _mm_mul_ps(w[i], co[i]); - - accum_veca[i] = _mm_add_ps(w[i], accum_veca[i]); - } - } - - __m128 accum_vec = _mm_add_ps(accum_veca[0], accum_veca[1]); //_mm_add_ps(_mm_add_ps(accum_veca[0], accum_veca[1]), _mm_add_ps(accum_veca[2], accum_veca[3])); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); - - return accum; -#else - resample_samp_t accum[4] = { 0, 0, 0, 0 }; - - for(unsigned c = 0; c < count; c+= 4) - { - accum[0] += wave[c + 0] * coeff[c + 0]; - accum[1] += wave[c + 1] * coeff[c + 1]; - accum[2] += wave[c + 2] * coeff[c + 2]; - accum[3] += wave[c + 3] * coeff[c + 3]; - } - - return (accum[0] + accum[1]) + (accum[2] + accum[3]); // don't mess with parentheses(assuming compiler doesn't already, which it may... - -#endif -} - - -resample_samp_t SincResampleHR::read(void) -{ - assert(output_avail()); - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[0], num_convolutions); - - rb_readpos = (rb_readpos + ratio) & (rb_eff_size - 1); - rb_in -= ratio; - - return ret; -} - - -SincResample::SincResample(double input_rate, double output_rate, double desired_bandwidth, unsigned quality) -{ - const struct - { - double beta; - double d; - unsigned pn_nume; - unsigned phases_min; - } qtab[5] = - { - { 5.658, 3.62, 4096, 4 }, - { 6.764, 4.32, 8192, 4 }, - { 7.865, 5.0, 16384, 8 }, - { 8.960, 5.7, 32768, 16 }, - { 10.056, 6.4, 65536, 32 } - }; - - // Sanity checks - assert(ceil(input_rate) > 0); - assert(ceil(output_rate) > 0); - assert(ceil(input_rate / output_rate) <= 1024); - assert(ceil(output_rate / input_rate) <= 1024); - - // The simplistic number-of-phases calculation code doesn't work well enough for when desired_bandwidth is close to 1.0 and when - // upsampling. - assert(desired_bandwidth >= 0.25 && desired_bandwidth < 0.96); - assert(quality >= 0 && quality <= 4); - - hr_used = false; - -#if 1 - // Round down to the nearest multiple of 4(so wave buffer remains aligned) - // It also adjusts the effective intermediate sampling rate up slightly, so that the upper frequencies below f/2 - // aren't overly attenuated so much. In the future, we might want to do an FFT or something to choose the intermediate rate more accurately - // to virtually eliminate over-attenuation. - unsigned ioratio_rd = (unsigned)floor(input_rate / (output_rate * (1.0 + (1.0 - desired_bandwidth) / 2) )) & ~3; - - if(ioratio_rd >= 8) - { - hr.Init(ioratio_rd, desired_bandwidth, qtab[quality].beta, qtab[quality].d); //10.056, 6.4); - hr_used = true; - - input_rate /= ioratio_rd; - } -#endif - - Init(input_rate, output_rate, desired_bandwidth, qtab[quality].beta, qtab[quality].d, qtab[quality].pn_nume, qtab[quality].phases_min); -} - -void SincResample::Init(double input_rate, double output_rate, double desired_bandwidth, double beta, double d, unsigned pn_nume, unsigned phases_min) -{ - const unsigned max_mult_atatime = 8; // multiply "granularity". must be power of 2. - const unsigned max_mult_minus1 = (max_mult_atatime - 1); - const unsigned conv_alignment_bytes = 16; // must be power of 2 - const double input_to_output_ratio = input_rate / output_rate; - const double output_to_input_ratio = output_rate / input_rate; - double cutoff; // 1.0 = input_rate / 2 - std::vector coeff_init_buffer; - - // Round up num_convolutions to be even. - if(output_rate > input_rate) - num_convolutions = ((unsigned)ceil(d / (1.0 - desired_bandwidth)) + 1) & ~1; - else - num_convolutions = ((unsigned)ceil(d / (output_to_input_ratio * (1.0 - desired_bandwidth))) + 1) & ~1; - - if(output_rate > input_rate) // Upsampling - cutoff = desired_bandwidth; - else // Downsampling - cutoff = output_to_input_ratio * desired_bandwidth; - - // Round up to be even. - num_phases = (std::max(pn_nume / num_convolutions, phases_min) + 1) &~1; - - // Adjust cutoff to account for the multiple phases. - cutoff = cutoff / num_phases; - - assert((num_convolutions & 1) == 0); - assert((num_phases & 1) == 0); - -// fprintf(stderr, "num_convolutions=%u, num_phases=%u, total expected coeff byte size=%lu\n", num_convolutions, num_phases, -// (long)((num_phases + 2) * ((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * sizeof(float) + conv_alignment_bytes)); - - coeff_init_buffer.resize(num_phases * num_convolutions); - - coeffs.resize(num_phases + 1 + 1); - - coeff_mem.resize((num_phases + 1 + 1) * ((num_convolutions + max_mult_minus1) &~ max_mult_minus1) * sizeof(resample_coeff_t) + conv_alignment_bytes); - - // Assign aligned pointers into coeff_mem - { - resample_coeff_t *base_ptr = (resample_coeff_t *)ResampleUtility::make_aligned(&coeff_mem[0], conv_alignment_bytes); - - for(unsigned phase = 0; phase < (num_phases + 1 + 1); phase++) - { - coeffs[phase] = base_ptr + (((num_convolutions + max_mult_minus1) & ~max_mult_minus1) * phase); - } - } - - ResampleUtility::gen_sinc(&coeff_init_buffer[0], num_phases * num_convolutions, cutoff, beta); - ResampleUtility::normalize(&coeff_init_buffer[0], num_phases * num_convolutions, num_phases); - - // Reorder coefficients to allow for more efficient convolution. - for(int phase = -1; phase < ((int)num_phases + 1); phase++) - { - for(int conv = 0; conv < (int)num_convolutions; conv++) - { - double coeff; - - if(phase == -1 && conv == 0) - coeff = 0; - else if(phase == (int)num_phases && conv == ((int)num_convolutions - 1)) - coeff = 0; - else - coeff = coeff_init_buffer[conv * num_phases + phase]; - - coeffs[phase + 1][conv] = coeff; - } - } - - // Free a bit of mem - coeff_init_buffer.resize(0); - - step_int = floor(input_to_output_ratio); - step_fract = input_to_output_ratio - step_int; - - input_pos_fract = 0; - - // Do NOT use rb.size() later in the code, since it'll include the padding. - // We should only need one "max_mult_minus1" here, not two, since it won't matter if it over-reads(due to doing "max_mult_atatime" multiplications at a time - // rather than just 1, in which case this over-read wouldn't happen), from the first half into the duplicated half, - // since those corresponding coefficients will be zero anyway; this is just to handle the case of reading off the end of the duplicated half to - // prevent illegal memory accesses. - rb.resize(num_convolutions * 2 + max_mult_minus1); - - rb_readpos = 0; - rb_writepos = 0; - rb_in = 0; -} - -resample_samp_t SincResample::mac(const resample_samp_t *wave, const resample_coeff_t *coeffs_a, const resample_coeff_t *coeffs_b, const double ffract, unsigned count) -{ - resample_samp_t accum = 0; -#if SINCRESAMPLE_USE_SSE - __m128 accum_vec_a[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - __m128 accum_vec_b[2] = { _mm_set1_ps(0), _mm_set1_ps(0) }; - - for(unsigned c = 0; c < count; c += 8) //8) //4) - { - __m128 coeff_a[2]; - __m128 coeff_b[2]; - __m128 w[2]; - __m128 result_a[2], result_b[2]; - - for(unsigned i = 0; i < 2; i++) - { - coeff_a[i] = _mm_load_ps(&coeffs_a[c + (i * 4)]); - coeff_b[i] = _mm_load_ps(&coeffs_b[c + (i * 4)]); - w[i] = _mm_loadu_ps(&wave[c + (i * 4)]); - - result_a[i] = _mm_mul_ps(coeff_a[i], w[i]); - result_b[i] = _mm_mul_ps(coeff_b[i], w[i]); - - accum_vec_a[i] = _mm_add_ps(result_a[i], accum_vec_a[i]); - accum_vec_b[i] = _mm_add_ps(result_b[i], accum_vec_b[i]); - } - } - - __m128 accum_vec, av_a, av_b; - __m128 mult_a_vec = _mm_set1_ps(1.0 - ffract); - __m128 mult_b_vec = _mm_set1_ps(ffract); - - av_a = _mm_mul_ps(mult_a_vec, /*accum_vec_a[0]);*/ _mm_add_ps(accum_vec_a[0], accum_vec_a[1])); - av_b = _mm_mul_ps(mult_b_vec, /*accum_vec_b[0]);*/ _mm_add_ps(accum_vec_b[0], accum_vec_b[1])); - - accum_vec = _mm_add_ps(av_a, av_b); - - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (3 << 0) | (2 << 2) | (1 << 4) | (0 << 6))); - accum_vec = _mm_add_ps(accum_vec, _mm_shuffle_ps(accum_vec, accum_vec, (1 << 0) | (0 << 2) | (1 << 4) | (0 << 6))); - - _mm_store_ss(&accum, accum_vec); -#else - resample_coeff_t mult_a = 1.0 - ffract; - resample_coeff_t mult_b = ffract; - - for(unsigned c = 0; c < count; c += 4) - { - accum += wave[c + 0] * (coeffs_a[c + 0] * mult_a + coeffs_b[c + 0] * mult_b); - accum += wave[c + 1] * (coeffs_a[c + 1] * mult_a + coeffs_b[c + 1] * mult_b); - accum += wave[c + 2] * (coeffs_a[c + 2] * mult_a + coeffs_b[c + 2] * mult_b); - accum += wave[c + 3] * (coeffs_a[c + 3] * mult_a + coeffs_b[c + 3] * mult_b); - } -#endif - - return accum; -} - -inline bool SincResample::output_avail(void) -{ - return(rb_in >= (int)num_convolutions); -} - -resample_samp_t SincResample::read(void) -{ - assert(output_avail()); - double phase = input_pos_fract * num_phases - 0.5; - signed phase_int = (signed)floor(phase); - double phase_fract = phase - phase_int; - unsigned phase_a = num_phases - 1 - phase_int; - unsigned phase_b = phase_a - 1; - resample_samp_t ret; - - ret = mac(&rb[rb_readpos], &coeffs[phase_a + 1][0], &coeffs[phase_b + 1][0], phase_fract, num_convolutions); - - unsigned int_increment = step_int; - - input_pos_fract += step_fract; - int_increment += floor(input_pos_fract); - input_pos_fract -= floor(input_pos_fract); - - rb_readpos = (rb_readpos + int_increment) % num_convolutions; - rb_in -= int_increment; - - return ret; -} - -inline void SincResample::write(resample_samp_t sample) -{ - assert(!output_avail()); - - if(hr_used) - { - hr.write(sample); - - if(hr.output_avail()) - { - sample = hr.read(); - } - else - { - return; - } - } - - rb[rb_writepos + 0 * num_convolutions] = sample; - rb[rb_writepos + 1 * num_convolutions] = sample; - rb_writepos = (rb_writepos + 1) % num_convolutions; - rb_in++; -} - -void ResampleUtility::kaiser_window( double* io, int count, double beta) -{ - int const accuracy = 24; //16; //12; - - double* end = io + count; - - double beta2 = beta * beta * (double) -0.25; - double to_fract = beta2 / ((double) count * count); - double i = 0; - double rescale = 0; // Doesn't need an initializer, to shut up gcc - - for ( ; io < end; ++io, i += 1 ) - { - double x = i * i * to_fract - beta2; - double u = x; - double k = x + 1; - - double n = 2; - do - { - u *= x / (n * n); - n += 1; - k += u; - } - while ( k <= u * (1 << accuracy) ); - - if ( !i ) - rescale = 1 / k; // otherwise values get large - - *io *= k * rescale; - } -} - -void ResampleUtility::gen_sinc(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 0 ); // size must be even - - int const half_size = size / 2; - double* const mid = &out [half_size]; - - // Generate right half of sinc - for ( int i = 0; i < half_size; i++ ) - { - double angle = (i * 2 + 1) * (M_PI / 2); - mid [i] = sin( angle * cutoff ) / angle; - } - - kaiser_window( mid, half_size, kaiser ); - - // Mirror for left half - for ( int i = 0; i < half_size; i++ ) - out [i] = mid [half_size - 1 - i]; -} - -void ResampleUtility::gen_sinc_os(double* out, int size, double cutoff, double kaiser) -{ - assert( size % 2 == 1); // size must be odd - - for(int i = 0; i < size; i++) - { - if(i == (size / 2)) - out[i] = 2 * M_PI * (cutoff / 2); //0.078478; //1.0; //sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - else - out[i] = sin(2 * M_PI * (cutoff / 2) * (i - size / 2)) / (i - (size / 2)); - -// out[i] *= 0.3635819 - 0.4891775 * cos(2 * M_PI * i / (size - 1)) + 0.1365995 * cos(4 * M_PI * i / (size - 1)) - 0.0106411 * cos(6 * M_PI * i / (size - 1)); -//0.42 - 0.5 * cos(2 * M_PI * i / (size - 1)) + 0.08 * cos(4 * M_PI * i / (size - 1)); - -// printf("%d %f\n", i, out[i]); - } - - kaiser_window(&out[size / 2], size / 2 + 1, kaiser); - - // Mirror for left half - for ( int i = 0; i < size / 2; i++ ) - out [i] = out [size - 1 - i]; - -} - -void ResampleUtility::normalize(double* io, int size, double gain) -{ - double sum = 0; - for ( int i = 0; i < size; i++ ) - sum += io [i]; - - double scale = gain / sum; - for ( int i = 0; i < size; i++ ) - io [i] *= scale; -} - -void* ResampleUtility::make_aligned(void* ptr, unsigned boundary) -{ - unsigned char* null_ptr = (unsigned char *)NULL; - unsigned char* uc_ptr = (unsigned char *)ptr; - - uc_ptr += (boundary - ((uc_ptr - null_ptr) & (boundary - 1))) & (boundary - 1); - - //while((uc_ptr - null_ptr) & (boundary - 1)) - // uc_ptr++; - - //printf("%16llx %16llx\n", (unsigned long long)ptr, (unsigned long long)uc_ptr); - - assert((uc_ptr - (unsigned char *)ptr) < boundary && (uc_ptr >= (unsigned char *)ptr)); - - return uc_ptr; -} diff --git a/purify/nall/dsp/resample/linear.hpp b/purify/nall/dsp/resample/linear.hpp deleted file mode 100644 index 3c2dc9e6..00000000 --- a/purify/nall/dsp/resample/linear.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleLinear : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleLinear(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleLinear::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleLinear::clear() { - fraction = 0.0; -} - -void ResampleLinear::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = a * (1.0 - mu) + b * mu; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/nearest.hpp b/purify/nall/dsp/resample/nearest.hpp deleted file mode 100644 index 14b401eb..00000000 --- a/purify/nall/dsp/resample/nearest.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -struct ResampleNearest : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - ResampleNearest(DSP &dsp) : Resampler(dsp) {} - - real fraction; - real step; -}; - -void ResampleNearest::setFrequency() { - fraction = 0.0; - step = dsp.settings.frequency / frequency; -} - -void ResampleNearest::clear() { - fraction = 0.0; -} - -void ResampleNearest::sample() { - while(fraction <= 1.0) { - real channel[dsp.settings.channels]; - - for(unsigned n = 0; n < dsp.settings.channels; n++) { - real a = dsp.buffer.read(n, -1); - real b = dsp.buffer.read(n, -0); - - real mu = fraction; - - channel[n] = mu < 0.5 ? a : b; - } - - dsp.write(channel); - fraction += step; - } - - dsp.buffer.rdoffset++; - fraction -= 1.0; -} - -#endif diff --git a/purify/nall/dsp/resample/sinc.hpp b/purify/nall/dsp/resample/sinc.hpp deleted file mode 100644 index a77a1eeb..00000000 --- a/purify/nall/dsp/resample/sinc.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -#include "lib/sinc.hpp" - -struct ResampleSinc : Resampler { - inline void setFrequency(); - inline void clear(); - inline void sample(); - inline ResampleSinc(DSP &dsp); - -private: - inline void remakeSinc(); - SincResample *sinc_resampler[8]; -}; - -void ResampleSinc::setFrequency() { - remakeSinc(); -} - -void ResampleSinc::clear() { - remakeSinc(); -} - -void ResampleSinc::sample() { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - sinc_resampler[c]->write(dsp.buffer.read(c)); - } - - if(sinc_resampler[0]->output_avail()) { - do { - for(unsigned c = 0; c < dsp.settings.channels; c++) { - dsp.output.write(c) = sinc_resampler[c]->read(); - } - dsp.output.wroffset++; - } while(sinc_resampler[0]->output_avail()); - } - - dsp.buffer.rdoffset++; -} - -ResampleSinc::ResampleSinc(DSP &dsp) : Resampler(dsp) { - for(unsigned n = 0; n < 8; n++) sinc_resampler[n] = 0; -} - -void ResampleSinc::remakeSinc() { - assert(dsp.settings.channels < 8); - - for(unsigned c = 0; c < dsp.settings.channels; c++) { - if(sinc_resampler[c]) delete sinc_resampler[c]; - sinc_resampler[c] = new SincResample(dsp.settings.frequency, frequency, 0.85, SincResample::QUALITY_HIGH); - } -} - -#endif diff --git a/purify/nall/dsp/settings.hpp b/purify/nall/dsp/settings.hpp deleted file mode 100644 index 3a8f24c6..00000000 --- a/purify/nall/dsp/settings.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef NALL_DSP_INTERNAL_HPP - -void DSP::setChannels(unsigned channels) { - assert(channels > 0); - buffer.setChannels(channels); - output.setChannels(channels); - settings.channels = channels; -} - -void DSP::setPrecision(unsigned precision) { - settings.precision = precision; - settings.intensity = 1 << (settings.precision - 1); - settings.intensityInverse = 1.0 / settings.intensity; -} - -void DSP::setFrequency(real frequency) { - settings.frequency = frequency; - resampler->setFrequency(); -} - -void DSP::setVolume(real volume) { - settings.volume = volume; -} - -void DSP::setBalance(real balance) { - settings.balance = balance; -} - -void DSP::setResampler(ResampleEngine engine) { - if(resampler) delete resampler; - - switch(engine) { - case ResampleEngine::Nearest: resampler = new ResampleNearest(*this); return; - case ResampleEngine::Linear: resampler = new ResampleLinear (*this); return; - case ResampleEngine::Cosine: resampler = new ResampleCosine (*this); return; - case ResampleEngine::Cubic: resampler = new ResampleCubic (*this); return; - case ResampleEngine::Hermite: resampler = new ResampleHermite(*this); return; - case ResampleEngine::Average: resampler = new ResampleAverage(*this); return; - case ResampleEngine::Sinc: resampler = new ResampleSinc (*this); return; - } - - throw; -} - -void DSP::setResamplerFrequency(real frequency) { - resampler->frequency = frequency; - resampler->setFrequency(); -} - -#endif diff --git a/purify/nall/emulation/super-famicom-usart.hpp b/purify/nall/emulation/super-famicom-usart.hpp deleted file mode 100644 index 68dea605..00000000 --- a/purify/nall/emulation/super-famicom-usart.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef NALL_EMULATION_SUPER_FAMICOM_USART_HPP -#define NALL_EMULATION_SUPER_FAMICOM_USART_HPP - -#include -#include -#include -#include - -#include -#include -#include - -#define usartproc dllexport - -static nall::function usart_quit; -static nall::function usart_usleep; -static nall::function usart_readable; -static nall::function usart_read; -static nall::function usart_writable; -static nall::function usart_write; - -extern "C" usartproc void usart_init( - nall::function quit, - nall::function usleep, - nall::function readable, - nall::function read, - nall::function writable, - nall::function write -) { - usart_quit = quit; - usart_usleep = usleep; - usart_readable = readable; - usart_read = read; - usart_writable = writable; - usart_write = write; -} - -extern "C" usartproc void usart_main(int, char**); - -// - -static nall::serial usart; -static bool usart_is_virtual = true; -static bool usart_sigint = false; - -static bool usart_virtual() { - return usart_is_virtual; -} - -// - -static bool usarthw_quit() { - return usart_sigint; -} - -static void usarthw_usleep(unsigned milliseconds) { - usleep(milliseconds); -} - -static bool usarthw_readable() { - return usart.readable(); -} - -static uint8_t usarthw_read() { - while(true) { - uint8_t buffer[1]; - signed length = usart.read((uint8_t*)&buffer, 1); - if(length > 0) return buffer[0]; - } -} - -static bool usarthw_writable() { - return usart.writable(); -} - -static void usarthw_write(uint8_t data) { - uint8_t buffer[1] = { data }; - usart.write((uint8_t*)&buffer, 1); -} - -static void sigint(int) { - signal(SIGINT, SIG_DFL); - usart_sigint = true; -} - -int main(int argc, char **argv) { - setpriority(PRIO_PROCESS, 0, -20); //requires superuser privileges; otherwise priority = +0 - signal(SIGINT, sigint); - - if(usart.open("/dev/ttyACM0", 57600, true) == false) { - printf("error: unable to open USART hardware device\n"); - return 0; - } - - usart_is_virtual = false; - usart_init(usarthw_quit, usarthw_usleep, usarthw_readable, usarthw_read, usarthw_writable, usarthw_write); - usart_main(argc, argv); - usart.close(); - - return 0; -} - -#endif diff --git a/purify/nall/endian.hpp b/purify/nall/endian.hpp deleted file mode 100644 index 1f834b5b..00000000 --- a/purify/nall/endian.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_ENDIAN_HPP -#define NALL_ENDIAN_HPP - -#include - -#if defined(ENDIAN_LSB) - //little-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201 - #define order_lsb2(a,b) a,b - #define order_lsb3(a,b,c) a,b,c - #define order_lsb4(a,b,c,d) a,b,c,d - #define order_lsb5(a,b,c,d,e) a,b,c,d,e - #define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h - #define order_msb2(a,b) b,a - #define order_msb3(a,b,c) c,b,a - #define order_msb4(a,b,c,d) d,c,b,a - #define order_msb5(a,b,c,d,e) e,d,c,b,a - #define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a -#elif defined(ENDIAN_MSB) - //big-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304 - #define order_lsb2(a,b) b,a - #define order_lsb3(a,b,c) c,b,a - #define order_lsb4(a,b,c,d) d,c,b,a - #define order_lsb5(a,b,c,d,e) e,d,c,b,a - #define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a - #define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a - #define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a - #define order_msb2(a,b) a,b - #define order_msb3(a,b,c) a,b,c - #define order_msb4(a,b,c,d) a,b,c,d - #define order_msb5(a,b,c,d,e) a,b,c,d,e - #define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f - #define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g - #define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h -#else - #error "Unknown endian. Please specify in nall/intrinsics.hpp" -#endif - -#endif diff --git a/purify/nall/file.hpp b/purify/nall/file.hpp deleted file mode 100644 index 80b918a8..00000000 --- a/purify/nall/file.hpp +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef NALL_FILE_HPP -#define NALL_FILE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - inline FILE* fopen_utf8(const string &utf8_filename, const char *mode) { - #if !defined(_WIN32) - return fopen(utf8_filename, mode); - #else - return _wfopen(utf16_t(utf8_filename), utf16_t(mode)); - #endif - } - - struct file { - enum class mode : unsigned { read, write, modify, append, readwrite = modify, writeread = append }; - enum class index : unsigned { absolute, relative }; - enum class time : unsigned { create, modify, access }; - - static bool copy(const string &sourcename, const string &targetname) { - file rd, wr; - if(rd.open(sourcename, mode::read) == false) return false; - if(wr.open(targetname, mode::write) == false) return false; - for(unsigned n = 0; n < rd.size(); n++) wr.write(rd.read()); - return true; - } - - static bool move(const string &sourcename, const string &targetname) { - #if !defined(_WIN32) - return rename(sourcename, targetname) == 0; - #else - return _wrename(utf16_t(sourcename), utf16_t(targetname)) == 0; - #endif - } - - static bool remove(const string &filename) { - return unlink(filename) == 0; - } - - static bool truncate(const string &filename, unsigned size) { - #if !defined(_WIN32) - return truncate(filename, size) == 0; - #else - bool result = false; - FILE *fp = fopen(filename, "rb+"); - if(fp) { - result = _chsize(fileno(fp), size) == 0; - fclose(fp); - } - return result; - #endif - } - - static vector read(const string &filename) { - vector memory; - file fp; - if(fp.open(filename, mode::read)) { - memory.resize(fp.size()); - fp.read(memory.data(), memory.size()); - } - return memory; - } - - static bool read(const string &filename, uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::read) == false) return false; - fp.read(data, size); - fp.close(); - return true; - } - - static bool write(const string &filename, const string &text) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.print(text); - fp.close(); - return true; - } - - static bool write(const string &filename, const vector &buffer) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.write(buffer.data(), buffer.size()); - fp.close(); - return true; - } - - static bool write(const string &filename, const uint8_t *data, unsigned size) { - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.write(data, size); - fp.close(); - return true; - } - - static bool create(const string &filename) { - //create an empty file (will replace existing files) - file fp; - if(fp.open(filename, mode::write) == false) return false; - fp.close(); - return true; - } - - static string sha256(const string &filename) { - auto buffer = read(filename); - return nall::sha256(buffer.data(), buffer.size()); - } - - uint8_t read() { - if(!fp) return 0xff; //file not open - if(file_mode == mode::write) return 0xff; //reads not permitted - if(file_offset >= file_size) return 0xff; //cannot read past end of file - buffer_sync(); - return buffer[(file_offset++) & buffer_mask]; - } - - uintmax_t readl(unsigned length = 1) { - uintmax_t data = 0; - for(int i = 0; i < length; i++) { - data |= (uintmax_t)read() << (i << 3); - } - return data; - } - - uintmax_t readm(unsigned length = 1) { - uintmax_t data = 0; - while(length--) { - data <<= 8; - data |= read(); - } - return data; - } - - void read(uint8_t *buffer, unsigned length) { - while(length--) *buffer++ = read(); - } - - void write(uint8_t data) { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //writes not permitted - buffer_sync(); - buffer[(file_offset++) & buffer_mask] = data; - buffer_dirty = true; - if(file_offset > file_size) file_size = file_offset; - } - - void writel(uintmax_t data, unsigned length = 1) { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) { - for(int i = length - 1; i >= 0; i--) { - write(data >> (i << 3)); - } - } - - void write(const uint8_t *buffer, unsigned length) { - while(length--) write(*buffer++); - } - - template void print(Args... args) { - string data(args...); - const char *p = data; - while(*p) write(*p++); - } - - void flush() { - buffer_flush(); - fflush(fp); - } - - void seek(int offset, index index_ = index::absolute) { - if(!fp) return; //file not open - buffer_flush(); - - uintmax_t req_offset = file_offset; - switch(index_) { - case index::absolute: req_offset = offset; break; - case index::relative: req_offset += offset; break; - } - - if(req_offset < 0) req_offset = 0; //cannot seek before start of file - if(req_offset > file_size) { - if(file_mode == mode::read) { //cannot seek past end of file - req_offset = file_size; - } else { //pad file to requested location - file_offset = file_size; - while(file_size < req_offset) write(0x00); - } - } - - file_offset = req_offset; - } - - unsigned offset() const { - if(!fp) return 0; //file not open - return file_offset; - } - - unsigned size() const { - if(!fp) return 0; //file not open - return file_size; - } - - bool truncate(unsigned size) { - if(!fp) return false; //file not open - #if !defined(_WIN32) - return ftruncate(fileno(fp), size) == 0; - #else - return _chsize(fileno(fp), size) == 0; - #endif - } - - bool end() { - if(!fp) return true; //file not open - return file_offset >= file_size; - } - - static bool exists(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - return stat64(filename, &data) == 0; - #else - struct __stat64 data; - return _wstat64(utf16_t(filename), &data) == 0; - #endif - } - - static uintmax_t size(const string &filename) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - return S_ISREG(data.st_mode) ? data.st_size : 0u; - } - - static time_t timestamp(const string &filename, file::time mode = file::time::create) { - #if !defined(_WIN32) - struct stat64 data; - stat64(filename, &data); - #else - struct __stat64 data; - _wstat64(utf16_t(filename), &data); - #endif - switch(mode) { default: - case file::time::create: return data.st_ctime; - case file::time::modify: return data.st_mtime; - case file::time::access: return data.st_atime; - } - } - - bool open() const { - return fp; - } - - bool open(const string &filename, mode mode_) { - if(fp) return false; - - switch(file_mode = mode_) { - #if !defined(_WIN32) - case mode::read: fp = fopen(filename, "rb" ); break; - case mode::write: fp = fopen(filename, "wb+"); break; //need read permission for buffering - case mode::readwrite: fp = fopen(filename, "rb+"); break; - case mode::writeread: fp = fopen(filename, "wb+"); break; - #else - case mode::read: fp = _wfopen(utf16_t(filename), L"rb" ); break; - case mode::write: fp = _wfopen(utf16_t(filename), L"wb+"); break; - case mode::readwrite: fp = _wfopen(utf16_t(filename), L"rb+"); break; - case mode::writeread: fp = _wfopen(utf16_t(filename), L"wb+"); break; - #endif - } - if(!fp) return false; - buffer_offset = -1; //invalidate buffer - file_offset = 0; - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - return true; - } - - void close() { - if(!fp) return; - buffer_flush(); - fclose(fp); - fp = 0; - } - - file() { - memset(buffer, 0, sizeof buffer); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - fp = 0; - file_offset = 0; - file_size = 0; - file_mode = mode::read; - } - - ~file() { - close(); - } - - file& operator=(const file&) = delete; - file(const file&) = delete; - - private: - enum { buffer_size = 1 << 12, buffer_mask = buffer_size - 1 }; - char buffer[buffer_size]; - int buffer_offset; - bool buffer_dirty; - FILE *fp; - unsigned file_offset; - unsigned file_size; - mode file_mode; - - void buffer_sync() { - if(!fp) return; //file not open - if(buffer_offset != (file_offset & ~buffer_mask)) { - buffer_flush(); - buffer_offset = file_offset & ~buffer_mask; - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fread(buffer, 1, length, fp); - } - } - - void buffer_flush() { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //buffer cannot be written to - if(buffer_offset < 0) return; //buffer unused - if(buffer_dirty == false) return; //buffer unmodified since read - fseek(fp, buffer_offset, SEEK_SET); - unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); - if(length) unsigned unused = fwrite(buffer, 1, length, fp); - buffer_offset = -1; //invalidate buffer - buffer_dirty = false; - } - }; -} - -#endif diff --git a/purify/nall/filemap.hpp b/purify/nall/filemap.hpp deleted file mode 100644 index f57d933c..00000000 --- a/purify/nall/filemap.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifndef NALL_FILEMAP_HPP -#define NALL_FILEMAP_HPP - -#include -#include -#include - -#include -#include -#if defined(_WIN32) - #include -#else - #include - #include - #include - #include - #include -#endif - -namespace nall { - class filemap { - public: - enum class mode : unsigned { read, write, readwrite, writeread }; - - bool open() const { return p_open(); } - bool open(const char *filename, mode mode_) { return p_open(filename, mode_); } - void close() { return p_close(); } - unsigned size() const { return p_size; } - uint8_t* data() { return p_handle; } - const uint8_t* data() const { return p_handle; } - filemap() : p_size(0), p_handle(0) { p_ctor(); } - filemap(const char *filename, mode mode_) : p_size(0), p_handle(0) { p_ctor(); p_open(filename, mode_); } - ~filemap() { p_dtor(); } - - private: - unsigned p_size; - uint8_t *p_handle; - - #if defined(_WIN32) - //============= - //MapViewOfFile - //============= - - HANDLE p_filehandle, p_maphandle; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int desired_access, creation_disposition, flprotect, map_access; - - switch(mode_) { - default: return false; - case mode::read: - desired_access = GENERIC_READ; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READONLY; - map_access = FILE_MAP_READ; - break; - case mode::write: - //write access requires read access - desired_access = GENERIC_WRITE; - creation_disposition = CREATE_ALWAYS; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::readwrite: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = OPEN_EXISTING; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - case mode::writeread: - desired_access = GENERIC_READ | GENERIC_WRITE; - creation_disposition = CREATE_NEW; - flprotect = PAGE_READWRITE; - map_access = FILE_MAP_ALL_ACCESS; - break; - } - - p_filehandle = CreateFileW(utf16_t(filename), desired_access, FILE_SHARE_READ, NULL, - creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL); - if(p_filehandle == INVALID_HANDLE_VALUE) return false; - - p_size = GetFileSize(p_filehandle, NULL); - - p_maphandle = CreateFileMapping(p_filehandle, NULL, flprotect, 0, p_size, NULL); - if(p_maphandle == INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - return false; - } - - p_handle = (uint8_t*)MapViewOfFile(p_maphandle, map_access, 0, 0, p_size); - return p_handle; - } - - void p_close() { - if(p_handle) { - UnmapViewOfFile(p_handle); - p_handle = 0; - } - - if(p_maphandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_maphandle); - p_maphandle = INVALID_HANDLE_VALUE; - } - - if(p_filehandle != INVALID_HANDLE_VALUE) { - CloseHandle(p_filehandle); - p_filehandle = INVALID_HANDLE_VALUE; - } - } - - void p_ctor() { - p_filehandle = INVALID_HANDLE_VALUE; - p_maphandle = INVALID_HANDLE_VALUE; - } - - void p_dtor() { - close(); - } - - #else - //==== - //mmap - //==== - - int p_fd; - - bool p_open() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { - if(file::exists(filename) && file::size(filename) == 0) { - p_handle = 0; - p_size = 0; - return true; - } - - int open_flags, mmap_flags; - - switch(mode_) { - default: return false; - case mode::read: - open_flags = O_RDONLY; - mmap_flags = PROT_READ; - break; - case mode::write: - open_flags = O_RDWR | O_CREAT; //mmap() requires read access - mmap_flags = PROT_WRITE; - break; - case mode::readwrite: - open_flags = O_RDWR; - mmap_flags = PROT_READ | PROT_WRITE; - break; - case mode::writeread: - open_flags = O_RDWR | O_CREAT; - mmap_flags = PROT_READ | PROT_WRITE; - break; - } - - p_fd = ::open(filename, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); - if(p_fd < 0) return false; - - struct stat p_stat; - fstat(p_fd, &p_stat); - p_size = p_stat.st_size; - - p_handle = (uint8_t*)mmap(0, p_size, mmap_flags, MAP_SHARED, p_fd, 0); - if(p_handle == MAP_FAILED) { - p_handle = 0; - ::close(p_fd); - p_fd = -1; - return false; - } - - return p_handle; - } - - void p_close() { - if(p_handle) { - munmap(p_handle, p_size); - p_handle = 0; - } - - if(p_fd >= 0) { - ::close(p_fd); - p_fd = -1; - } - } - - void p_ctor() { - p_fd = -1; - } - - void p_dtor() { - p_close(); - } - - #endif - }; -} - -#endif diff --git a/purify/nall/function.hpp b/purify/nall/function.hpp deleted file mode 100644 index ca574b8c..00000000 --- a/purify/nall/function.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef NALL_FUNCTION_HPP -#define NALL_FUNCTION_HPP - -namespace nall { - template class function; - - template class function { - struct container { - virtual R operator()(P... p) const = 0; - virtual container* copy() const = 0; - virtual ~container() {} - } *callback; - - struct global : container { - R (*function)(P...); - R operator()(P... p) const { return function(std::forward

(p)...); } - container* copy() const { return new global(function); } - global(R (*function)(P...)) : function(function) {} - }; - - template struct member : container { - R (C::*function)(P...); - C *object; - R operator()(P... p) const { return (object->*function)(std::forward

(p)...); } - container* copy() const { return new member(function, object); } - member(R (C::*function)(P...), C *object) : function(function), object(object) {} - }; - - template struct lambda : container { - mutable L object; - R operator()(P... p) const { return object(std::forward

(p)...); } - container* copy() const { return new lambda(object); } - lambda(const L& object) : object(object) {} - }; - - public: - operator bool() const { return callback; } - R operator()(P... p) const { return (*callback)(std::forward

(p)...); } - void reset() { if(callback) { delete callback; callback = nullptr; } } - - function& operator=(const function &source) { - if(this != &source) { - if(callback) { delete callback; callback = nullptr; } - if(source.callback) callback = source.callback->copy(); - } - return *this; - } - - function(const function &source) : callback(nullptr) { operator=(source); } - function() : callback(nullptr) {} - function(void *function) : callback(nullptr) { if(function) callback = new global((R (*)(P...))function); } - function(R (*function)(P...)) { callback = new global(function); } - template function(R (C::*function)(P...), C *object) { callback = new member(function, object); } - template function(R (C::*function)(P...) const, C *object) { callback = new member((R (C::*)(P...))function, object); } - template function(const L& object) { callback = new lambda(object); } - ~function() { if(callback) delete callback; } - }; -} - -#endif diff --git a/purify/nall/gzip.hpp b/purify/nall/gzip.hpp deleted file mode 100644 index a72a3faf..00000000 --- a/purify/nall/gzip.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef NALL_GZIP_HPP -#define NALL_GZIP_HPP - -#include -#include - -namespace nall { - -struct gzip { - string filename; - uint8_t *data; - unsigned size; - - inline bool decompress(const string &filename); - inline bool decompress(const uint8_t *data, unsigned size); - - inline gzip(); - inline ~gzip(); -}; - -bool gzip::decompress(const string &filename) { - if(auto memory = file::read(filename)) { - return decompress(memory.data(), memory.size()); - } - return false; -} - -bool gzip::decompress(const uint8_t *data, unsigned size) { - if(size < 18) return false; - if(data[0] != 0x1f) return false; - if(data[1] != 0x8b) return false; - unsigned cm = data[2]; - unsigned flg = data[3]; - unsigned mtime = data[4]; - mtime |= data[5] << 8; - mtime |= data[6] << 16; - mtime |= data[7] << 24; - unsigned xfl = data[8]; - unsigned os = data[9]; - unsigned p = 10; - unsigned isize = data[size - 4]; - isize |= data[size - 3] << 8; - isize |= data[size - 2] << 16; - isize |= data[size - 1] << 24; - filename = ""; - - if(flg & 0x04) { //FEXTRA - unsigned xlen = data[p + 0]; - xlen |= data[p + 1] << 8; - p += 2 + xlen; - } - - if(flg & 0x08) { //FNAME - char buffer[PATH_MAX]; - for(unsigned n = 0; n < PATH_MAX; n++, p++) { - buffer[n] = data[p]; - if(data[p] == 0) break; - } - if(data[p++]) return false; - filename = buffer; - } - - if(flg & 0x10) { //FCOMMENT - while(data[p++]); - } - - if(flg & 0x02) { //FHCRC - p += 2; - } - - this->size = isize; - this->data = new uint8_t[this->size]; - return inflate(this->data, this->size, data + p, size - p - 8); -} - -gzip::gzip() : data(nullptr) { -} - -gzip::~gzip() { - if(data) delete[] data; -} - -} - -#endif diff --git a/purify/nall/http.hpp b/purify/nall/http.hpp deleted file mode 100644 index 48aeb097..00000000 --- a/purify/nall/http.hpp +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef NALL_HTTP_HPP -#define NALL_HTTP_HPP - -#if !defined(_WIN32) - #include - #include - #include - #include -#else - #include - #include - #include -#endif - -#include -#include - -namespace nall { - -struct http { - string hostname; - addrinfo *serverinfo; - int serversocket; - string header; - - inline void download(const string &path, uint8_t *&data, unsigned &size) { - data = 0; - size = 0; - - send({ - "GET ", path, " HTTP/1.1\r\n" - "Host: ", hostname, "\r\n" - "Connection: close\r\n" - "\r\n" - }); - - header = downloadHeader(); - downloadContent(data, size); - } - - inline bool connect(string host, unsigned port) { - hostname = host; - - addrinfo hints; - memset(&hints, 0, sizeof(addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - - int status = getaddrinfo(hostname, string(port), &hints, &serverinfo); - if(status != 0) return false; - - serversocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); - if(serversocket == -1) return false; - - int result = ::connect(serversocket, serverinfo->ai_addr, serverinfo->ai_addrlen); - if(result == -1) return false; - - return true; - } - - inline bool send(const string &data) { - return send((const uint8_t*)(const char*)data, data.length()); - } - - inline bool send(const uint8_t *data, unsigned size) { - while(size) { - int length = ::send(serversocket, (const char*)data, size, 0); - if(length == -1) return false; - data += length; - size -= length; - } - return true; - } - - inline string downloadHeader() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n\r\n") == false); - return output; - } - - inline string downloadChunkLength() { - string output; - do { - char buffer[2]; - int length = recv(serversocket, buffer, 1, 0); - if(length <= 0) return output; - buffer[1] = 0; - output.append(buffer); - } while(output.endswith("\r\n") == false); - return output; - } - - inline void downloadContent(uint8_t *&data, unsigned &size) { - unsigned capacity = 0; - - if(header.iposition("\r\nTransfer-Encoding: chunked\r\n")) { - while(true) { - unsigned length = hex(downloadChunkLength()); - if(length == 0) break; - capacity += length; - data = (uint8_t*)realloc(data, capacity); - - char buffer[length]; - while(length) { - int packetlength = recv(serversocket, buffer, length, 0); - if(packetlength <= 0) break; - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } - } else if(auto position = header.iposition("\r\nContent-Length: ")) { - unsigned length = decimal((const char*)header + position() + 18); - while(length) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, min(256, length), 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - length -= packetlength; - } - } else { - while(true) { - char buffer[256]; - int packetlength = recv(serversocket, buffer, 256, 0); - if(packetlength <= 0) break; - capacity += packetlength; - data = (uint8_t*)realloc(data, capacity); - memcpy(data + size, buffer, packetlength); - size += packetlength; - } - } - - data = (uint8_t*)realloc(data, capacity + 1); - data[capacity] = 0; - } - - inline void disconnect() { - close(serversocket); - freeaddrinfo(serverinfo); - serverinfo = 0; - serversocket = -1; - } - - #ifdef _WIN32 - inline int close(int sock) { - return closesocket(sock); - } - - inline http() { - int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) { - WSADATA wsaData; - if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - WSACleanup(); - return; - } - } else { - close(sock); - } - } - #endif -}; - -} - -#endif diff --git a/purify/nall/image.hpp b/purify/nall/image.hpp deleted file mode 100644 index e334b6e0..00000000 --- a/purify/nall/image.hpp +++ /dev/null @@ -1,539 +0,0 @@ -#ifndef NALL_IMAGE_HPP -#define NALL_IMAGE_HPP - -#include -#include -#include -#include -#include -#include - -namespace nall { - -struct image { - uint8_t *data; - unsigned width; - unsigned height; - unsigned pitch; - - bool endian; //0 = little, 1 = big - unsigned depth; - unsigned stride; - - struct Channel { - uint64_t mask; - unsigned depth; - unsigned shift; - - inline bool operator==(const Channel &source) { - return mask == source.mask && depth == source.depth && shift == source.shift; - } - - inline bool operator!=(const Channel &source) { - return !operator==(source); - } - } alpha, red, green, blue; - - typedef double (*interpolation)(double, double, double, double, double); - static inline unsigned bitDepth(uint64_t color); - static inline unsigned bitShift(uint64_t color); - static inline uint64_t normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth); - - inline bool operator==(const image &source); - inline bool operator!=(const image &source); - - inline image& operator=(const image &source); - inline image& operator=(image &&source); - inline image(const image &source); - inline image(image &&source); - inline image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline image(const string &filename); - inline image(const uint8_t *data, unsigned size); - inline image(); - inline ~image(); - - inline uint64_t read(const uint8_t *data) const; - inline void write(uint8_t *data, uint64_t value) const; - - inline void free(); - inline bool empty() const; - inline void allocate(unsigned width, unsigned height); - inline void clear(uint64_t color); - inline bool load(const string &filename); -//inline bool loadBMP(const uint8_t *data, unsigned size); - inline bool loadPNG(const uint8_t *data, unsigned size); - inline void scale(unsigned width, unsigned height, interpolation op); - inline void transform(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); - inline void alphaBlend(uint64_t alphaColor); - -protected: - inline uint64_t interpolate(double mu, const uint64_t *s, interpolation op); - inline void scaleX(unsigned width, interpolation op); - inline void scaleY(unsigned height, interpolation op); - inline bool loadBMP(const string &filename); - inline bool loadPNG(const string &filename); -}; - -//static - -unsigned image::bitDepth(uint64_t color) { - unsigned depth = 0; - if(color) while((color & 1) == 0) color >>= 1; - while((color & 1) == 1) { color >>= 1; depth++; } - return depth; -} - -unsigned image::bitShift(uint64_t color) { - unsigned shift = 0; - if(color) while((color & 1) == 0) { color >>= 1; shift++; } - return shift; -} - -uint64_t image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) { - while(sourceDepth < targetDepth) { - color = (color << sourceDepth) | color; - sourceDepth += sourceDepth; - } - if(targetDepth < sourceDepth) color >>= (sourceDepth - targetDepth); - return color; -} - -//public - -bool image::operator==(const image &source) { - if(width != source.width) return false; - if(height != source.height) return false; - if(pitch != source.pitch) return false; - - if(endian != source.endian) return false; - if(stride != source.stride) return false; - - if(alpha != source.alpha) return false; - if(red != source.red) return false; - if(green != source.green) return false; - if(blue != source.blue) return false; - - return memcmp(data, source.data, width * height * stride) == 0; -} - -bool image::operator!=(const image &source) { - return !operator==(source); -} - -image& image::operator=(const image &source) { - free(); - - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = new uint8_t[width * height * stride]; - memcpy(data, source.data, width * height * stride); - return *this; -} - -image& image::operator=(image &&source) { - free(); - - width = source.width; - height = source.height; - pitch = source.pitch; - - endian = source.endian; - stride = source.stride; - - alpha = source.alpha; - red = source.red; - green = source.green; - blue = source.blue; - - data = source.data; - source.data = nullptr; - return *this; -} - -image::image(const image &source) : data(nullptr) { - operator=(source); -} - -image::image(image &&source) : data(nullptr) { - operator=(std::forward(source)); -} - -image::image(bool endian, unsigned depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = endian; - this->depth = depth; - this->stride = (depth / 8) + ((depth & 7) > 0); - - alpha.mask = alphaMask, red.mask = redMask, green.mask = greenMask, blue.mask = blueMask; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::image(const string &filename) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - load(filename); -} - -image::image(const uint8_t *data, unsigned size) : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); - - loadPNG(data, size); -} - -image::image() : data(nullptr) { - width = 0, height = 0, pitch = 0; - - this->endian = 0; - this->depth = 32; - this->stride = 4; - - alpha.mask = 255u << 24, red.mask = 255u << 16, green.mask = 255u << 8, blue.mask = 255u << 0; - alpha.depth = bitDepth(alpha.mask), alpha.shift = bitShift(alpha.mask); - red.depth = bitDepth(red.mask), red.shift = bitShift(red.mask); - green.depth = bitDepth(green.mask), green.shift = bitShift(green.mask); - blue.depth = bitDepth(blue.mask), blue.shift = bitShift(blue.mask); -} - -image::~image() { - free(); -} - -uint64_t image::read(const uint8_t *data) const { - uint64_t result = 0; - if(endian == 0) { - for(signed n = stride - 1; n >= 0; n--) result = (result << 8) | data[n]; - } else { - for(signed n = 0; n < stride; n++) result = (result << 8) | data[n]; - } - return result; -} - -void image::write(uint8_t *data, uint64_t value) const { - if(endian == 0) { - for(signed n = 0; n < stride; n++) { data[n] = value; value >>= 8; } - } else { - for(signed n = stride - 1; n >= 0; n--) { data[n] = value; value >>= 8; } - } -} - -void image::free() { - if(data) delete[] data; - data = nullptr; -} - -bool image::empty() const { - if(data == nullptr) return true; - if(width == 0 || height == 0) return true; - return false; -} - -void image::allocate(unsigned width, unsigned height) { - if(data != nullptr && this->width == width && this->height == height) return; - free(); - data = new uint8_t[width * height * stride](); - pitch = width * stride; - this->width = width; - this->height = height; -} - -void image::clear(uint64_t color) { - uint8_t *dp = data; - for(unsigned n = 0; n < width * height; n++) { - write(dp, color); - dp += stride; - } -} - -bool image::load(const string &filename) { - if(loadBMP(filename) == true) return true; - if(loadPNG(filename) == true) return true; - return false; -} - -void image::scale(unsigned outputWidth, unsigned outputHeight, interpolation op) { - if(width != outputWidth) scaleX(outputWidth, op); - if(height != outputHeight) scaleY(outputHeight, op); -} - -void image::transform(bool outputEndian, unsigned outputDepth, uint64_t outputAlphaMask, uint64_t outputRedMask, uint64_t outputGreenMask, uint64_t outputBlueMask) { - image output(outputEndian, outputDepth, outputAlphaMask, outputRedMask, outputGreenMask, outputBlueMask); - output.allocate(width, height); - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = output.data + output.pitch * y; - uint8_t *sp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(sp); - sp += stride; - - uint64_t a = (color & alpha.mask) >> alpha.shift; - uint64_t r = (color & red.mask) >> red.shift; - uint64_t g = (color & green.mask) >> green.shift; - uint64_t b = (color & blue.mask) >> blue.shift; - - a = normalize(a, alpha.depth, output.alpha.depth); - r = normalize(r, red.depth, output.red.depth); - g = normalize(g, green.depth, output.green.depth); - b = normalize(b, blue.depth, output.blue.depth); - - output.write(dp, (a << output.alpha.shift) | (r << output.red.shift) | (g << output.green.shift) | (b << output.blue.shift)); - dp += output.stride; - } - } - - operator=(std::move(output)); -} - -void image::alphaBlend(uint64_t alphaColor) { - uint64_t alphaR = (alphaColor & red.mask) >> red.shift; - uint64_t alphaG = (alphaColor & green.mask) >> green.shift; - uint64_t alphaB = (alphaColor & blue.mask) >> blue.shift; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = data + pitch * y; - for(unsigned x = 0; x < width; x++) { - uint64_t color = read(dp); - - uint64_t colorA = (color & alpha.mask) >> alpha.shift; - uint64_t colorR = (color & red.mask) >> red.shift; - uint64_t colorG = (color & green.mask) >> green.shift; - uint64_t colorB = (color & blue.mask) >> blue.shift; - double alphaScale = (double)colorA / (double)((1 << alpha.depth) - 1); - - colorA = (1 << alpha.depth) - 1; - colorR = (colorR * alphaScale) + (alphaR * (1.0 - alphaScale)); - colorG = (colorG * alphaScale) + (alphaG * (1.0 - alphaScale)); - colorB = (colorB * alphaScale) + (alphaB * (1.0 - alphaScale)); - - write(dp, (colorA << alpha.shift) | (colorR << red.shift) | (colorG << green.shift) | (colorB << blue.shift)); - dp += stride; - } - } -} - -//protected - -uint64_t image::interpolate(double mu, const uint64_t *s, double (*op)(double, double, double, double, double)) { - uint64_t aa = (s[0] & alpha.mask) >> alpha.shift, ar = (s[0] & red.mask) >> red.shift, - ag = (s[0] & green.mask) >> green.shift, ab = (s[0] & blue.mask) >> blue.shift; - uint64_t ba = (s[1] & alpha.mask) >> alpha.shift, br = (s[1] & red.mask) >> red.shift, - bg = (s[1] & green.mask) >> green.shift, bb = (s[1] & blue.mask) >> blue.shift; - uint64_t ca = (s[2] & alpha.mask) >> alpha.shift, cr = (s[2] & red.mask) >> red.shift, - cg = (s[2] & green.mask) >> green.shift, cb = (s[2] & blue.mask) >> blue.shift; - uint64_t da = (s[3] & alpha.mask) >> alpha.shift, dr = (s[3] & red.mask) >> red.shift, - dg = (s[3] & green.mask) >> green.shift, db = (s[3] & blue.mask) >> blue.shift; - - int64_t A = op(mu, aa, ba, ca, da); - int64_t R = op(mu, ar, br, cr, dr); - int64_t G = op(mu, ag, bg, cg, dg); - int64_t B = op(mu, ab, bb, cb, db); - - A = max(0, min(A, (1 << alpha.depth) - 1)); - R = max(0, min(R, (1 << red.depth) - 1)); - G = max(0, min(G, (1 << green.depth) - 1)); - B = max(0, min(B, (1 << blue.depth) - 1)); - - return (A << alpha.shift) | (R << red.shift) | (G << green.shift) | (B << blue.shift); -} - -void image::scaleX(unsigned outputWidth, interpolation op) { - uint8_t *outputData = new uint8_t[outputWidth * height * stride]; - unsigned outputPitch = outputWidth * stride; - double step = (double)width / (double)outputWidth; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - uint8_t *dp = outputData + outputPitch * y; - uint8_t *sp = data + pitch * y; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; //B,C (0,1) = center of kernel { 0, 0, 1, 2 } - s[1] = s[0]; - s[2] = sp + stride < terminal ? read(sp += stride) : s[1]; - s[3] = sp + stride < terminal ? read(sp += stride) : s[2]; - - for(unsigned x = 0; x < width; x++) { - while(fraction <= 1.0) { - if(dp >= outputData + outputPitch * height) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += stride; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + stride < terminal) s[3] = read(sp += stride); - fraction -= 1.0; - } - } - - free(); - data = outputData; - width = outputWidth; - pitch = width * stride; -} - -void image::scaleY(unsigned outputHeight, interpolation op) { - uint8_t *outputData = new uint8_t[width * outputHeight * stride]; - double step = (double)height / (double)outputHeight; - const uint8_t *terminal = data + pitch * height; - - #pragma omp parallel for - for(unsigned x = 0; x < width; x++) { - uint8_t *dp = outputData + stride * x; - uint8_t *sp = data + stride * x; - - double fraction = 0.0; - uint64_t s[4] = { sp < terminal ? read(sp) : 0 }; - s[1] = s[0]; - s[2] = sp + pitch < terminal ? read(sp += pitch) : s[1]; - s[3] = sp + pitch < terminal ? read(sp += pitch) : s[2]; - - for(unsigned y = 0; y < height; y++) { - while(fraction <= 1.0) { - if(dp >= outputData + pitch * outputHeight) break; - write(dp, interpolate(fraction, (const uint64_t*)&s, op)); - dp += pitch; - fraction += step; - } - - s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; - if(sp + pitch < terminal) s[3] = read(sp += pitch); - fraction -= 1.0; - } - } - - free(); - data = outputData; - height = outputHeight; -} - -bool image::loadBMP(const string &filename) { - uint32_t *outputData; - unsigned outputWidth, outputHeight; - if(bmp::read(filename, outputData, outputWidth, outputHeight) == false) return false; - - allocate(outputWidth, outputHeight); - const uint32_t *sp = outputData; - uint8_t *dp = data; - - for(unsigned y = 0; y < outputHeight; y++) { - for(unsigned x = 0; x < outputWidth; x++) { - uint32_t color = *sp++; - uint64_t a = normalize((uint8_t)(color >> 24), 8, alpha.depth); - uint64_t r = normalize((uint8_t)(color >> 16), 8, red.depth); - uint64_t g = normalize((uint8_t)(color >> 8), 8, green.depth); - uint64_t b = normalize((uint8_t)(color >> 0), 8, blue.depth); - write(dp, (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift)); - dp += stride; - } - } - - delete[] outputData; - return true; -} - -bool image::loadPNG(const uint8_t *pngData, unsigned pngSize) { - png source; - if(source.decode(pngData, pngSize) == false) return false; - - allocate(source.info.width, source.info.height); - const uint8_t *sp = source.data; - uint8_t *dp = data; - - auto decode = [&]() -> uint64_t { - uint64_t p, r, g, b, a; - - switch(source.info.colorType) { - case 0: //L - r = g = b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 2: //R,G,B - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = (1 << source.info.bitDepth) - 1; - break; - case 3: //P - p = source.readbits(sp); - r = source.info.palette[p][0]; - g = source.info.palette[p][1]; - b = source.info.palette[p][2]; - a = (1 << source.info.bitDepth) - 1; - break; - case 4: //L,A - r = g = b = source.readbits(sp); - a = source.readbits(sp); - break; - case 6: //R,G,B,A - r = source.readbits(sp); - g = source.readbits(sp); - b = source.readbits(sp); - a = source.readbits(sp); - break; - } - - a = normalize(a, source.info.bitDepth, alpha.depth); - r = normalize(r, source.info.bitDepth, red.depth); - g = normalize(g, source.info.bitDepth, green.depth); - b = normalize(b, source.info.bitDepth, blue.depth); - - return (a << alpha.shift) | (r << red.shift) | (g << green.shift) | (b << blue.shift); - }; - - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - write(dp, decode()); - dp += stride; - } - } - - return true; -} - -bool image::loadPNG(const string &filename) { - filemap map; - if(map.open(filename, filemap::mode::read) == false) return false; - return loadPNG(map.data(), map.size()); -} - -} - -#endif diff --git a/purify/nall/inflate.hpp b/purify/nall/inflate.hpp deleted file mode 100644 index cbbf6d29..00000000 --- a/purify/nall/inflate.hpp +++ /dev/null @@ -1,358 +0,0 @@ -#ifndef NALL_INFLATE_HPP -#define NALL_INFLATE_HPP - -#include - -namespace nall { - -namespace puff { - inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen - ); -} - -inline bool inflate( - uint8_t *target, unsigned targetLength, - const uint8_t *source, unsigned sourceLength -) { - unsigned long tl = targetLength, sl = sourceLength; - int result = puff::puff((unsigned char*)target, &tl, (unsigned char*)source, &sl); - return result == 0; -} - -namespace puff { - -//zlib/contrib/puff.c -//version 2.1* -//author: Mark Adler -//license: zlib -//ported by: byuu - -//* I have corrected a bug in fixed(), where it was accessing uninitialized -// memory: calling construct() with lencode prior to initializing lencode.count - -enum { - MAXBITS = 15, - MAXLCODES = 286, - MAXDCODES = 30, - FIXLCODES = 288, - MAXCODES = MAXLCODES + MAXDCODES, -}; - -struct state { - unsigned char *out; - unsigned long outlen; - unsigned long outcnt; - - unsigned char *in; - unsigned long inlen; - unsigned long incnt; - int bitbuf; - int bitcnt; - - jmp_buf env; -}; - -struct huffman { - short *count; - short *symbol; -}; - -inline int bits(state *s, int need) { - long val; - - val = s->bitbuf; - while(s->bitcnt < need) { - if(s->incnt == s->inlen) longjmp(s->env, 1); - val |= (long)(s->in[s->incnt++]) << s->bitcnt; - s->bitcnt += 8; - } - - s->bitbuf = (int)(val >> need); - s->bitcnt -= need; - - return (int)(val & ((1L << need) - 1)); -} - -inline int stored(state *s) { - unsigned len; - - s->bitbuf = 0; - s->bitcnt = 0; - - if(s->incnt + 4 > s->inlen) return 2; - len = s->in[s->incnt++]; - len |= s->in[s->incnt++] << 8; - if(s->in[s->incnt++] != (~len & 0xff) || - s->in[s->incnt++] != ((~len >> 8) & 0xff) - ) return 2; - - if(s->incnt + len > s->inlen) return 2; - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) s->out[s->outcnt++] = s->in[s->incnt++]; - } else { - s->outcnt += len; - s->incnt += len; - } - - return 0; -} - -inline int decode(state *s, huffman *h) { - int len, code, first, count, index, bitbuf, left; - short *next; - - bitbuf = s->bitbuf; - left = s->bitcnt; - code = first = index = 0; - len = 1; - next = h->count + 1; - while(true) { - while(left--) { - code |= bitbuf & 1; - bitbuf >>= 1; - count = *next++; - if(code - count < first) { - s->bitbuf = bitbuf; - s->bitcnt = (s->bitcnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS + 1) - len; - if(left == 0) break; - if(s->incnt == s->inlen) longjmp(s->env, 1); - bitbuf = s->in[s->incnt++]; - if(left > 8) left = 8; - } - - return -10; -} - -inline int construct(huffman *h, short *length, int n) { - int symbol, len, left; - short offs[MAXBITS + 1]; - - for(len = 0; len <= MAXBITS; len++) h->count[len] = 0; - for(symbol = 0; symbol < n; symbol++) h->count[length[symbol]]++; - if(h->count[0] == n) return 0; - - left = 1; - for(len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= h->count[len]; - if(left < 0) return left; - } - - offs[1] = 0; - for(len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; - - for(symbol = 0; symbol < n; symbol++) { - if(length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; - } - - return left; -} - -inline int codes(state *s, huffman *lencode, huffman *distcode) { - int symbol, len; - unsigned dist; - static const short lens[29] = { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 - }; - static const short lext[29] = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 - }; - static const short dists[30] = { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577 - }; - static const short dext[30] = { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13 - }; - - do { - symbol = decode(s, lencode); - if(symbol < 0) return symbol; - if(symbol < 256) { - if(s->out != 0) { - if(s->outcnt == s->outlen) return 1; - s->out[s->outcnt] = symbol; - } - s->outcnt++; - } else if(symbol > 256) { - symbol -= 257; - if(symbol >= 29) return -10; - len = lens[symbol] + bits(s, lext[symbol]); - - symbol = decode(s, distcode); - if(symbol < 0) return symbol; - dist = dists[symbol] + bits(s, dext[symbol]); - #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - if(dist > s->outcnt) return -11; - #endif - - if(s->out != 0) { - if(s->outcnt + len > s->outlen) return 1; - while(len--) { - s->out[s->outcnt] = - #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOO_FAR - dist > s->outcnt ? 0 : - #endif - s->out[s->outcnt - dist]; - s->outcnt++; - } - } else { - s->outcnt += len; - } - } - } while(symbol != 256); - - return 0; -} - -inline int fixed(state *s) { - static int virgin = 1; - static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; - static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - static huffman lencode, distcode; - - if(virgin) { - int symbol = 0; - short lengths[FIXLCODES]; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - for(; symbol < 144; symbol++) lengths[symbol] = 8; - for(; symbol < 256; symbol++) lengths[symbol] = 9; - for(; symbol < 280; symbol++) lengths[symbol] = 7; - for(; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; - construct(&lencode, lengths, FIXLCODES); - - for(symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; - construct(&distcode, lengths, MAXDCODES); - - virgin = 0; - } - - return codes(s, &lencode, &distcode); -} - -inline int dynamic(state *s) { - int nlen, ndist, ncode, index, err; - short lengths[MAXCODES]; - short lencnt[MAXBITS + 1], lensym[MAXLCODES]; - short distcnt[MAXBITS + 1], distsym[MAXDCODES]; - huffman lencode, distcode; - static const short order[19] = { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 - }; - - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - nlen = bits(s, 5) + 257; - ndist = bits(s, 5) + 1; - ncode = bits(s, 4) + 4; - if(nlen > MAXLCODES || ndist > MAXDCODES) return -3; - - for(index = 0; index < ncode; index++) lengths[order[index]] = bits(s, 3); - for(; index < 19; index++) lengths[order[index]] = 0; - - err = construct(&lencode, lengths, 19); - if(err != 0) return -4; - - index = 0; - while(index < nlen + ndist) { - int symbol, len; - - symbol = decode(s, &lencode); - if(symbol < 16) { - lengths[index++] = symbol; - } else { - len = 0; - if(symbol == 16) { - if(index == 0) return -5; - len = lengths[index - 1]; - symbol = 3 + bits(s, 2); - } else if(symbol == 17) { - symbol = 3 + bits(s, 3); - } else { - symbol = 11 + bits(s, 7); - } - if(index + symbol > nlen + ndist) return -6; - while(symbol--) lengths[index++] = len; - } - } - - if(lengths[256] == 0) return -9; - - err = construct(&lencode, lengths, nlen); - if(err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) return -7; - - err = construct(&distcode, lengths + nlen, ndist); - if(err < 0 || (err > 0 && ndist - distcode.count[0] != 1)) return -8; - - return codes(s, &lencode, &distcode); -} - -inline int puff( - unsigned char *dest, unsigned long *destlen, - unsigned char *source, unsigned long *sourcelen -) { - state s; - int last, type, err; - - s.out = dest; - s.outlen = *destlen; - s.outcnt = 0; - - s.in = source; - s.inlen = *sourcelen; - s.incnt = 0; - s.bitbuf = 0; - s.bitcnt = 0; - - if(setjmp(s.env) != 0) { - err = 2; - } else { - do { - last = bits(&s, 1); - type = bits(&s, 2); - err = type == 0 ? stored(&s) - : type == 1 ? fixed(&s) - : type == 2 ? dynamic(&s) - : -1; - if(err != 0) break; - } while(!last); - } - - if(err <= 0) { - *destlen = s.outcnt; - *sourcelen = s.incnt; - } - - return err; -} - -} - -} - -#endif diff --git a/purify/nall/input.hpp b/purify/nall/input.hpp deleted file mode 100644 index cd765393..00000000 --- a/purify/nall/input.hpp +++ /dev/null @@ -1,386 +0,0 @@ -#ifndef NALL_INPUT_HPP -#define NALL_INPUT_HPP - -#include -#include -#include - -#include -#include - -namespace nall { - -struct Keyboard; -Keyboard& keyboard(unsigned = 0); - -static const char KeyboardScancodeName[][64] = { - "Escape", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", - "PrintScreen", "ScrollLock", "Pause", "Tilde", - "Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num0", - "Dash", "Equal", "Backspace", - "Insert", "Delete", "Home", "End", "PageUp", "PageDown", - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", - "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "LeftBracket", "RightBracket", "Backslash", "Semicolon", "Apostrophe", "Comma", "Period", "Slash", - "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9", "Keypad0", - "Point", "Enter", "Add", "Subtract", "Multiply", "Divide", - "NumLock", "CapsLock", - "Up", "Down", "Left", "Right", - "Tab", "Return", "Spacebar", "Menu", - "Shift", "Control", "Alt", "Super", -}; - -struct Keyboard { - const unsigned ID; - enum { Base = 1 }; - enum { Count = 8, Size = 128 }; - - enum Scancode { - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, Tilde, - Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9, Num0, - Dash, Equal, Backspace, - Insert, Delete, Home, End, PageUp, PageDown, - A, B, C, D, E, F, G, H, I, J, K, L, M, - N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - LeftBracket, RightBracket, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - Point, Enter, Add, Subtract, Multiply, Divide, - NumLock, CapsLock, - Up, Down, Left, Right, - Tab, Return, Spacebar, Menu, - Shift, Control, Alt, Super, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed keyDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return scancode - keyboard(i).key(Escape); - } - return -1; - } - - static signed modifierDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return scancode - keyboard(i).key(Shift); - } - return -1; - } - - static bool isAnyKey(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isKey(scancode)) return true; - } - return false; - } - - static bool isAnyModifier(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(keyboard(i).isModifier(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "KB")) return 0; - s.ltrim("KB"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == KeyboardScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "KB", ID, "::", KeyboardScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t key(unsigned id) const { return Base + Size * ID + id; } - bool isKey(unsigned id) const { return id >= key(Escape) && id <= key(Menu); } - bool isModifier(unsigned id) const { return id >= key(Shift) && id <= key(Super); } - bool belongsTo(uint16_t scancode) const { return isKey(scancode) || isModifier(scancode); } - - Keyboard(unsigned ID_) : ID(ID_) {} -}; - -inline Keyboard& keyboard(unsigned id) { - static Keyboard kb0(0), kb1(1), kb2(2), kb3(3), kb4(4), kb5(5), kb6(6), kb7(7); - switch(id) { default: - case 0: return kb0; case 1: return kb1; case 2: return kb2; case 3: return kb3; - case 4: return kb4; case 5: return kb5; case 6: return kb6; case 7: return kb7; - } -} - -static const char MouseScancodeName[][64] = { - "Xaxis", "Yaxis", "Zaxis", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", -}; - -struct Mouse; -Mouse& mouse(unsigned = 0); - -struct Mouse { - const unsigned ID; - enum { Base = Keyboard::Base + Keyboard::Size * Keyboard::Count }; - enum { Count = 8, Size = 16 }; - enum { Axes = 3, Buttons = 8 }; - - enum Scancode { - Xaxis, Yaxis, Zaxis, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Limit, - }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return scancode - mouse(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return scancode - mouse(i).button(0); - } - return -1; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(mouse(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "MS")) return 0; - s.ltrim("MS"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == MouseScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - break; - } - } - return { "MS", ID, "::", MouseScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Xaxis + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(2); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(7); } - bool belongsTo(uint16_t scancode) const { return isAxis(scancode) || isButton(scancode); } - - Mouse(unsigned ID_) : ID(ID_) {} -}; - -inline Mouse& mouse(unsigned id) { - static Mouse ms0(0), ms1(1), ms2(2), ms3(3), ms4(4), ms5(5), ms6(6), ms7(7); - switch(id) { default: - case 0: return ms0; case 1: return ms1; case 2: return ms2; case 3: return ms3; - case 4: return ms4; case 5: return ms5; case 6: return ms6; case 7: return ms7; - } -} - -static const char JoypadScancodeName[][64] = { - "Hat0", "Hat1", "Hat2", "Hat3", "Hat4", "Hat5", "Hat6", "Hat7", - "Axis0", "Axis1", "Axis2", "Axis3", "Axis4", "Axis5", "Axis6", "Axis7", - "Axis8", "Axis9", "Axis10", "Axis11", "Axis12", "Axis13", "Axis14", "Axis15", - "Button0", "Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", - "Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15", - "Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23", - "Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31", -}; - -struct Joypad; -Joypad& joypad(unsigned = 0); - -struct Joypad { - const unsigned ID; - enum { Base = Mouse::Base + Mouse::Size * Mouse::Count }; - enum { Count = 8, Size = 64 }; - enum { Hats = 8, Axes = 16, Buttons = 32 }; - - enum Scancode { - Hat0, Hat1, Hat2, Hat3, Hat4, Hat5, Hat6, Hat7, - Axis0, Axis1, Axis2, Axis3, Axis4, Axis5, Axis6, Axis7, - Axis8, Axis9, Axis10, Axis11, Axis12, Axis13, Axis14, Axis15, - Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, - Button8, Button9, Button10, Button11, Button12, Button13, Button14, Button15, - Button16, Button17, Button18, Button19, Button20, Button21, Button22, Button23, - Button24, Button25, Button26, Button27, Button28, Button29, Button30, Button31, - Limit, - }; - - enum Hat { HatCenter = 0, HatUp = 1, HatRight = 2, HatDown = 4, HatLeft = 8 }; - - static signed numberDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).belongsTo(scancode)) return i; - } - return -1; - } - - static signed hatDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return scancode - joypad(i).hat(0); - } - return -1; - } - - static signed axisDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return scancode - joypad(i).axis(0); - } - return -1; - } - - static signed buttonDecode(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return scancode - joypad(i).button(0); - } - return -1; - } - - static bool isAnyHat(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isHat(scancode)) return true; - } - return false; - } - - static bool isAnyAxis(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isAxis(scancode)) return true; - } - return false; - } - - static bool isAnyButton(uint16_t scancode) { - for(unsigned i = 0; i < Count; i++) { - if(joypad(i).isButton(scancode)) return true; - } - return false; - } - - static uint16_t decode(const char *name) { - string s(name); - if(!strbegin(name, "JP")) return 0; - s.ltrim("JP"); - unsigned id = decimal(s); - auto pos = strpos(s, "::"); - if(!pos) return 0; - s = substr(s, pos() + 2); - for(unsigned i = 0; i < Limit; i++) { - if(s == JoypadScancodeName[i]) return Base + Size * id + i; - } - return 0; - } - - string encode(uint16_t code) const { - unsigned index = 0; - for(unsigned i = 0; i < Count; i++) { - if(code >= Base + Size * i && code < Base + Size * (i + 1)) { - index = code - (Base + Size * i); - } - } - return { "JP", ID, "::", JoypadScancodeName[index] }; - } - - uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } - uint16_t hat(unsigned id) const { return Base + Size * ID + Hat0 + id; } - uint16_t axis(unsigned id) const { return Base + Size * ID + Axis0 + id; } - uint16_t button(unsigned id) const { return Base + Size * ID + Button0 + id; } - bool isHat(unsigned id) const { return id >= hat(0) && id <= hat(7); } - bool isAxis(unsigned id) const { return id >= axis(0) && id <= axis(15); } - bool isButton(unsigned id) const { return id >= button(0) && id <= button(31); } - bool belongsTo(uint16_t scancode) const { return isHat(scancode) || isAxis(scancode) || isButton(scancode); } - - Joypad(unsigned ID_) : ID(ID_) {} -}; - -inline Joypad& joypad(unsigned id) { - static Joypad jp0(0), jp1(1), jp2(2), jp3(3), jp4(4), jp5(5), jp6(6), jp7(7); - switch(id) { default: - case 0: return jp0; case 1: return jp1; case 2: return jp2; case 3: return jp3; - case 4: return jp4; case 5: return jp5; case 6: return jp6; case 7: return jp7; - } -} - -struct Scancode { - enum { None = 0, Limit = Joypad::Base + Joypad::Size * Joypad::Count }; - - static uint16_t decode(const char *name) { - uint16_t code; - code = Keyboard::decode(name); - if(code) return code; - code = Mouse::decode(name); - if(code) return code; - code = Joypad::decode(name); - if(code) return code; - return None; - } - - static string encode(uint16_t code) { - for(unsigned i = 0; i < Keyboard::Count; i++) { - if(keyboard(i).belongsTo(code)) return keyboard(i).encode(code); - } - for(unsigned i = 0; i < Mouse::Count; i++) { - if(mouse(i).belongsTo(code)) return mouse(i).encode(code); - } - for(unsigned i = 0; i < Joypad::Count; i++) { - if(joypad(i).belongsTo(code)) return joypad(i).encode(code); - } - return "None"; - } -}; - -} - -#endif diff --git a/purify/nall/interpolation.hpp b/purify/nall/interpolation.hpp deleted file mode 100644 index afc7108b..00000000 --- a/purify/nall/interpolation.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NALL_INTERPOLATION_HPP -#define NALL_INTERPOLATION_HPP - -namespace nall { - -struct Interpolation { - static inline double Nearest(double mu, double a, double b, double c, double d) { - return (mu <= 0.5 ? b : c); - } - - static inline double Sublinear(double mu, double a, double b, double c, double d) { - mu = ((mu - 0.5) * 2.0) + 0.5; - if(mu < 0) mu = 0; - if(mu > 1) mu = 1; - return b * (1.0 - mu) + c * mu; - } - - static inline double Linear(double mu, double a, double b, double c, double d) { - return b * (1.0 - mu) + c * mu; - } - - static inline double Cosine(double mu, double a, double b, double c, double d) { - mu = (1.0 - cos(mu * 3.14159265)) / 2.0; - return b * (1.0 - mu) + c * mu; - } - - static inline double Cubic(double mu, double a, double b, double c, double d) { - double A = d - c - a + b; - double B = a - b - A; - double C = c - a; - double D = b; - return A * (mu * mu * mu) + B * (mu * mu) + C * mu + D; - } - - static inline double 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.0 + bias) * (1.0 - tension) / 2.0; - m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0; - m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0; - m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0; - - 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); - } -}; - -} - -#endif diff --git a/purify/nall/intrinsics.hpp b/purify/nall/intrinsics.hpp deleted file mode 100644 index 413ef593..00000000 --- a/purify/nall/intrinsics.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef NALL_INTRINSICS_HPP -#define NALL_INTRINSICS_HPP - -struct Intrinsics { - enum class Compiler : unsigned { GCC, VisualC, Unknown }; - enum class Platform : unsigned { X, OSX, Windows, Unknown }; - enum class Endian : unsigned { LSB, MSB, Unknown }; - - static inline Compiler compiler(); - static inline Platform platform(); - static inline Endian endian(); -}; - -/* Compiler detection */ - -#if defined(__GNUC__) - #define COMPILER_GCC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::GCC; } -#elif defined(_MSC_VER) - #define COMPILER_VISUALC - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::VisualC; } -#else - #warning "unable to detect compiler" - #define COMPILER_UNKNOWN - Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Unknown; } -#endif - -/* Platform detection */ - -#if defined(linux) || defined(__sun__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define PLATFORM_X - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::X; } -#elif defined(__APPLE__) - #define PLATFORM_OSX - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::OSX; } -#elif defined(_WIN32) - #define PLATFORM_WINDOWS - #define PLATFORM_WIN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; } -#else - #warning "unable to detect platform" - #define PLATFORM_UNKNOWN - Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Unknown; } -#endif - -/* Endian detection */ - -#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64) - #define ENDIAN_LSB - #define ARCH_LSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; } -#elif defined(__powerpc__) || defined(_M_PPC) || defined(__BIG_ENDIAN__) - #define ENDIAN_MSB - #define ARCH_MSB - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::MSB; } -#else - #warning "unable to detect endian" - #define ENDIAN_UNKNOWN - #define ARCH_UNKNOWN - Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::Unknown; } -#endif - -#endif diff --git a/purify/nall/invoke.hpp b/purify/nall/invoke.hpp deleted file mode 100644 index 9dfb7d0b..00000000 --- a/purify/nall/invoke.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef NALL_INVOKE_HPP -#define NALL_INVOKE_HPP - -//void invoke(const string &name, const string& args...); -//if a program is specified, it is executed with the arguments provided -//if a file is specified, the file is opened using the program associated with said file type -//if a folder is specified, the folder is opened using the associated file explorer -//if a URL is specified, the default web browser is opened and pointed at the URL requested -//path environment variable is always consulted -//execution is asynchronous (non-blocking); use system() for synchronous execution - -#include -#ifdef _WIN32 - #include -#endif - -namespace nall { - -#ifdef _WIN32 - -template -inline void invoke(const string &name, Args&&... args) { - lstring argl(std::forward(args)...); - for(auto &arg : argl) if(arg.position(" ")) arg = {"\"", arg, "\""}; - string arguments = argl.concatenate(" "); - ShellExecuteW(NULL, NULL, utf16_t(name), utf16_t(arguments), NULL, SW_SHOWNORMAL); -} - -#else - -template -inline void invoke(const string &name, Args&&... args) { - pid_t pid = fork(); - if(pid == 0) { - const char *argv[1 + sizeof...(args) + 1], **argp = argv; - lstring argl(std::forward(args)...); - *argp++ = (const char*)name; - for(auto &arg : argl) *argp++ = (const char*)arg; - *argp++ = nullptr; - - if(execvp(name, (char* const*)argv) < 0) { - execlp("xdg-open", "xdg-open", (const char*)name, nullptr); - } - exit(0); - } -} - -#endif - -} - -#endif diff --git a/purify/nall/ips.hpp b/purify/nall/ips.hpp deleted file mode 100644 index 473d74c5..00000000 --- a/purify/nall/ips.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef NALL_IPS_HPP -#define NALL_IPS_HPP - -#include -#include -#include - -namespace nall { - -struct ips { - inline bool apply(); - inline void source(const uint8_t *data, unsigned size); - inline void modify(const uint8_t *data, unsigned size); - inline ips(); - inline ~ips(); - - uint8_t *data; - unsigned size; - const uint8_t *sourceData; - unsigned sourceSize; - const uint8_t *modifyData; - unsigned modifySize; -}; - -bool ips::apply() { - if(modifySize < 8) return false; - if(modifyData[0] != 'P') return false; - if(modifyData[1] != 'A') return false; - if(modifyData[2] != 'T') return false; - if(modifyData[3] != 'C') return false; - if(modifyData[4] != 'H') return false; - - if(data) delete[] data; - data = new uint8_t[16 * 1024 * 1024 + 65536](); //maximum size of IPS patch + single-tag padding - size = sourceSize; - memcpy(data, sourceData, sourceSize); - unsigned offset = 5; - - while(true) { - unsigned address, length; - - if(offset > modifySize - 3) break; - address = modifyData[offset++] << 16; - address |= modifyData[offset++] << 8; - address |= modifyData[offset++] << 0; - - if(address == 0x454f46) { //EOF - if(offset == modifySize) return true; - if(offset == modifySize - 3) { - size = modifyData[offset++] << 16; - size |= modifyData[offset++] << 8; - size |= modifyData[offset++] << 0; - return true; - } - } - - if(offset > modifySize - 2) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - - if(length) { //Copy - if(offset > modifySize - length) break; - while(length--) data[address++] = modifyData[offset++]; - } else { //RLE - if(offset > modifySize - 3) break; - length = modifyData[offset++] << 8; - length |= modifyData[offset++] << 0; - if(length == 0) break; //illegal - while(length--) data[address++] = modifyData[offset]; - offset++; - } - - size = max(size, address); - } - - delete[] data; - data = nullptr; - return false; -} - -void ips::source(const uint8_t *data, unsigned size) { - sourceData = data, sourceSize = size; -} - -void ips::modify(const uint8_t *data, unsigned size) { - modifyData = data, modifySize = size; -} - -ips::ips() : data(nullptr), sourceData(nullptr), modifyData(nullptr) { -} - -ips::~ips() { - if(data) delete[] data; - if(sourceData) delete[] sourceData; - if(modifyData) delete[] modifyData; -} - -} - -#endif diff --git a/purify/nall/lzss.hpp b/purify/nall/lzss.hpp deleted file mode 100644 index fb3e0ba6..00000000 --- a/purify/nall/lzss.hpp +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef NALL_LZSS_HPP -#define NALL_LZSS_HPP - -#include -#include -#include -#include - -namespace nall { - -//19:5 pulldown -//8:1 marker: d7-d0 -//length: { 4 - 35 }, offset: { 1 - 0x80000 } -//4-byte file size header -//little-endian encoding -struct lzss { - inline void source(const uint8_t *data, unsigned size); - inline bool source(const string &filename); - inline unsigned size() const; - inline bool compress(const string &filename); - inline bool decompress(uint8_t *targetData, unsigned targetSize); - inline bool decompress(const string &filename); - -protected: - struct Node { - unsigned offset; - Node *next; - inline Node() : offset(0), next(nullptr) {} - inline ~Node() { if(next) delete next; } - } *tree[65536]; - - filemap sourceFile; - const uint8_t *sourceData; - unsigned sourceSize; - -public: - inline lzss() : sourceData(nullptr), sourceSize(0) {} -}; - -void lzss::source(const uint8_t *data, unsigned size) { - sourceData = data; - sourceSize = size; -} - -bool lzss::source(const string &filename) { - if(sourceFile.open(filename, filemap::mode::read) == false) return false; - sourceData = sourceFile.data(); - sourceSize = sourceFile.size(); - return true; -} - -unsigned lzss::size() const { - unsigned size = 0; - if(sourceSize < 4) return size; - for(unsigned n = 0; n < 32; n += 8) size |= sourceData[n >> 3] << n; - return size; -} - -bool lzss::compress(const string &filename) { - file targetFile; - if(targetFile.open(filename, file::mode::write) == false) return false; - - for(unsigned n = 0; n < 32; n += 8) targetFile.write(sourceSize >> n); - for(unsigned n = 0; n < 65536; n++) tree[n] = 0; - - uint8_t buffer[25]; - unsigned sourceOffset = 0; - - while(sourceOffset < sourceSize) { - uint8_t mask = 0x00; - unsigned bufferOffset = 1; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - uint16_t symbol = sourceData[sourceOffset + 0]; - if(sourceOffset < sourceSize - 1) symbol |= sourceData[sourceOffset + 1] << 8; - Node *node = tree[symbol]; - unsigned maxLength = 0, maxOffset = 0; - - while(node) { - if(node->offset < sourceOffset - 0x80000) { - //out-of-range: all subsequent nodes will also be, so free up their memory - if(node->next) { delete node->next; node->next = 0; } - break; - } - - unsigned length = 0, x = sourceOffset, y = node->offset; - while(length < 35 && x < sourceSize && sourceData[x++] == sourceData[y++]) length++; - if(length > maxLength) maxLength = length, maxOffset = node->offset; - if(length == 35) break; - - node = node->next; - } - - //attach current symbol to top of tree for subsequent searches - node = new Node; - node->offset = sourceOffset; - node->next = tree[symbol]; - tree[symbol] = node; - - if(maxLength < 4) { - buffer[bufferOffset++] = sourceData[sourceOffset++]; - } else { - unsigned output = ((maxLength - 4) << 19) | (sourceOffset - 1 - maxOffset); - for(unsigned n = 0; n < 24; n += 8) buffer[bufferOffset++] = output >> n; - mask |= 0x80 >> iteration; - sourceOffset += maxLength; - } - } - - buffer[0] = mask; - targetFile.write(buffer, bufferOffset); - } - - sourceFile.close(); - targetFile.close(); - return true; -} - -bool lzss::decompress(uint8_t *targetData, unsigned targetSize) { - if(targetSize < size()) return false; - - unsigned sourceOffset = 4, targetOffset = 0; - while(sourceOffset < sourceSize) { - uint8_t mask = sourceData[sourceOffset++]; - - for(unsigned iteration = 0; iteration < 8; iteration++) { - if(sourceOffset >= sourceSize) break; - - if((mask & (0x80 >> iteration)) == 0) { - targetData[targetOffset++] = sourceData[sourceOffset++]; - } else { - unsigned code = 0; - for(unsigned n = 0; n < 24; n += 8) code |= sourceData[sourceOffset++] << n; - unsigned length = (code >> 19) + 4; - unsigned offset = targetOffset - 1 - (code & 0x7ffff); - while(length--) targetData[targetOffset++] = targetData[offset++]; - } - } - } -} - -bool lzss::decompress(const string &filename) { - if(sourceSize < 4) return false; - unsigned targetSize = size(); - - file fp; - if(fp.open(filename, file::mode::write) == false) return false; - fp.truncate(targetSize); - fp.close(); - - filemap targetFile; - if(targetFile.open(filename, filemap::mode::readwrite) == false) return false; - uint8_t *targetData = targetFile.data(); - - bool result = decompress(targetData, targetSize); - sourceFile.close(); - targetFile.close(); - return result; -} - -} - -#endif diff --git a/purify/nall/map.hpp b/purify/nall/map.hpp deleted file mode 100644 index 938f0c2d..00000000 --- a/purify/nall/map.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef NALL_MAP_HPP -#define NALL_MAP_HPP - -#include - -namespace nall { - -template -struct map { - struct pair { - LHS name; - RHS data; - }; - - inline void reset() { - list.reset(); - } - - inline unsigned size() const { - return list.size(); - } - - //O(log n) find - inline optional find(const LHS &name) const { - signed first = 0, last = size() - 1; - while(first <= last) { - signed middle = (first + last) / 2; - if(name < list[middle].name) last = middle - 1; //search lower half - else if(list[middle].name < name) first = middle + 1; //search upper half - else return { true, (unsigned)middle }; //match found - } - return { false, 0u }; - } - - //O(n) insert + O(log n) find - inline RHS& insert(const LHS &name, const RHS &data) { - if(auto position = find(name)) { - list[position()].data = data; - return list[position()].data; - } - signed offset = size(); - for(unsigned n = 0; n < size(); n++) { - if(name < list[n].name) { offset = n; break; } - } - list.insert(offset, { name, data }); - return list[offset].data; - } - - //O(log n) find - inline void modify(const LHS &name, const RHS &data) { - if(auto position = find(name)) list[position()].data = data; - } - - //O(n) remove + O(log n) find - inline void remove(const LHS &name) { - if(auto position = find(name)) list.remove(position()); - } - - //O(log n) find - inline RHS& operator[](const LHS &name) { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline const RHS& operator[](const LHS &name) const { - if(auto position = find(name)) return list[position()].data; - throw; - } - - inline RHS& operator()(const LHS &name) { - if(auto position = find(name)) return list[position()].data; - return insert(name, RHS()); - } - - inline const RHS& operator()(const LHS &name, const RHS &data) const { - if(auto position = find(name)) return list[position()].data; - return data; - } - - inline pair* begin() { return list.begin(); } - inline pair* end() { return list.end(); } - inline const pair* begin() const { return list.begin(); } - inline const pair* end() const { return list.end(); } - -protected: - vector list; -}; - -template -struct bidirectional_map { - const map &lhs; - const map &rhs; - - inline void reset() { - llist.reset(); - rlist.reset(); - } - - inline unsigned size() const { - return llist.size(); - } - - inline void insert(const LHS &ldata, const RHS &rdata) { - llist.insert(ldata, rdata); - rlist.insert(rdata, ldata); - } - - inline bidirectional_map() : lhs(llist), rhs(rlist) {} - -protected: - map llist; - map rlist; -}; - -} - -#endif diff --git a/purify/nall/mosaic.hpp b/purify/nall/mosaic.hpp deleted file mode 100644 index 16fd0bfd..00000000 --- a/purify/nall/mosaic.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef NALL_MOSAIC_HPP -#define NALL_MOSAIC_HPP - -#define NALL_MOSAIC_INTERNAL_HPP -#include -#include -#include -#undef NALL_MOSAIC_INTERNAL_HPP - -#endif diff --git a/purify/nall/mosaic/bitstream.hpp b/purify/nall/mosaic/bitstream.hpp deleted file mode 100644 index e2cb3bc5..00000000 --- a/purify/nall/mosaic/bitstream.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct bitstream { - filemap fp; - uint8_t *data; - unsigned size; - bool readonly; - bool endian; - - inline bool read(uint64_t addr) const { - if(data == nullptr || (addr >> 3) >= size) return 0; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - return data[addr >> 3] & mask; - } - - inline void write(uint64_t addr, bool value) { - if(data == nullptr || readonly == true || (addr >> 3) >= size) return; - unsigned mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7)); - if(value == 0) data[addr >> 3] &= ~mask; - if(value == 1) data[addr >> 3] |= mask; - } - - inline bool open(const string &filename) { - readonly = false; - if(fp.open(filename, filemap::mode::readwrite) == false) { - readonly = true; - if(fp.open(filename, filemap::mode::read) == false) { - return false; - } - } - data = fp.data(); - size = fp.size(); - return true; - } - - inline void close() { - fp.close(); - data = nullptr; - } - - inline bitstream() : data(nullptr), endian(1) { - } - - inline ~bitstream() { - close(); - } -}; - -} -} - -#endif diff --git a/purify/nall/mosaic/context.hpp b/purify/nall/mosaic/context.hpp deleted file mode 100644 index bc7a518a..00000000 --- a/purify/nall/mosaic/context.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct context { - unsigned offset; - unsigned width; - unsigned height; - unsigned count; - - bool endian; //0 = lsb, 1 = msb - bool order; //0 = linear, 1 = planar - unsigned depth; //1 - 24bpp - - unsigned blockWidth; - unsigned blockHeight; - unsigned blockStride; - unsigned blockOffset; - vector block; - - unsigned tileWidth; - unsigned tileHeight; - unsigned tileStride; - unsigned tileOffset; - vector tile; - - unsigned mosaicWidth; - unsigned mosaicHeight; - unsigned mosaicStride; - unsigned mosaicOffset; - vector mosaic; - - unsigned paddingWidth; - unsigned paddingHeight; - unsigned paddingColor; - vector palette; - - inline unsigned objectWidth() const { return blockWidth * tileWidth * mosaicWidth + paddingWidth; } - inline unsigned objectHeight() const { return blockHeight * tileHeight * mosaicHeight + paddingHeight; } - inline unsigned objectSize() const { - unsigned size = blockStride * tileWidth * tileHeight * mosaicWidth * mosaicHeight - + blockOffset * tileHeight * mosaicWidth * mosaicHeight - + tileStride * mosaicWidth * mosaicHeight - + tileOffset * mosaicHeight; - return max(1u, size); - } - - inline unsigned eval(const string &expression) { - intmax_t result; - if(fixedpoint::eval(expression, result) == false) return 0u; - return result; - } - - inline void eval(vector &buffer, const string &expression_) { - string expression = expression_; - bool function = false; - for(auto &c : expression) { - if(c == '(') function = true; - if(c == ')') function = false; - if(c == ',' && function == true) c = ';'; - } - - lstring list = expression.split(","); - for(auto &item : list) { - item.trim(); - if(item.wildcard("f(?*) ?*")) { - item.ltrim<1>("f("); - lstring part = item.split<1>(") "); - lstring args = part[0].split<3>(";"); - for(auto &item : args) item.trim(); - - unsigned length = eval(args(0, "0")); - unsigned offset = eval(args(1, "0")); - unsigned stride = eval(args(2, "0")); - if(args.size() < 2) offset = buffer.size(); - if(args.size() < 3) stride = 1; - - for(unsigned n = 0; n < length; n++) { - string fn = part[1]; - fn.replace("n", decimal(n)); - fn.replace("o", decimal(offset)); - fn.replace("p", decimal(buffer.size())); - buffer.resize(offset + 1); - buffer[offset] = eval(fn); - offset += stride; - } - } else if(item.wildcard("base64*")) { - unsigned offset = 0; - item.ltrim<1>("base64"); - if(item.wildcard("(?*) *")) { - item.ltrim<1>("("); - lstring part = item.split<1>(") "); - offset = eval(part[0]); - item = part(1, ""); - } - item.trim(); - for(auto &c : item) { - if(c >= 'A' && c <= 'Z') buffer.append(offset + c - 'A' + 0); - if(c >= 'a' && c <= 'z') buffer.append(offset + c - 'a' + 26); - if(c >= '0' && c <= '9') buffer.append(offset + c - '0' + 52); - if(c == '-') buffer.append(offset + 62); - if(c == '_') buffer.append(offset + 63); - } - } else if(item.wildcard("file *")) { - item.ltrim<1>("file "); - item.trim(); - //... - } else if(item.empty() == false) { - buffer.append(eval(item)); - } - } - } - - inline void parse(const string &data) { - reset(); - - lstring lines = data.split("\n"); - for(auto &line : lines) { - lstring part = line.split<1>(":"); - if(part.size() != 2) continue; - part[0].trim(); - part[1].trim(); - - if(part[0] == "offset") offset = eval(part[1]); - if(part[0] == "width") width = eval(part[1]); - if(part[0] == "height") height = eval(part[1]); - if(part[0] == "count") count = eval(part[1]); - - if(part[0] == "endian") endian = eval(part[1]); - if(part[0] == "order") order = eval(part[1]); - if(part[0] == "depth") depth = eval(part[1]); - - if(part[0] == "blockWidth") blockWidth = eval(part[1]); - if(part[0] == "blockHeight") blockHeight = eval(part[1]); - if(part[0] == "blockStride") blockStride = eval(part[1]); - if(part[0] == "blockOffset") blockOffset = eval(part[1]); - if(part[0] == "block") eval(block, part[1]); - - if(part[0] == "tileWidth") tileWidth = eval(part[1]); - if(part[0] == "tileHeight") tileHeight = eval(part[1]); - if(part[0] == "tileStride") tileStride = eval(part[1]); - if(part[0] == "tileOffset") tileOffset = eval(part[1]); - if(part[0] == "tile") eval(tile, part[1]); - - if(part[0] == "mosaicWidth") mosaicWidth = eval(part[1]); - if(part[0] == "mosaicHeight") mosaicHeight = eval(part[1]); - if(part[0] == "mosaicStride") mosaicStride = eval(part[1]); - if(part[0] == "mosaicOffset") mosaicOffset = eval(part[1]); - if(part[0] == "mosaic") eval(mosaic, part[1]); - - if(part[0] == "paddingWidth") paddingWidth = eval(part[1]); - if(part[0] == "paddingHeight") paddingHeight = eval(part[1]); - if(part[0] == "paddingColor") paddingColor = eval(part[1]); - if(part[0] == "palette") eval(palette, part[1]); - } - - sanitize(); - } - - inline bool load(const string &filename) { - string filedata; - if(filedata.readfile(filename) == false) return false; - parse(filedata); - return true; - } - - inline void sanitize() { - if(depth < 1) depth = 1; - if(depth > 24) depth = 24; - - if(blockWidth < 1) blockWidth = 1; - if(blockHeight < 1) blockHeight = 1; - - if(tileWidth < 1) tileWidth = 1; - if(tileHeight < 1) tileHeight = 1; - - if(mosaicWidth < 1) mosaicWidth = 1; - if(mosaicHeight < 1) mosaicHeight = 1; - } - - inline void reset() { - offset = 0; - width = 0; - height = 0; - count = 0; - - endian = 1; - order = 0; - depth = 1; - - blockWidth = 1; - blockHeight = 1; - blockStride = 0; - blockOffset = 0; - block.reset(); - - tileWidth = 1; - tileHeight = 1; - tileStride = 0; - tileOffset = 0; - tile.reset(); - - mosaicWidth = 1; - mosaicHeight = 1; - mosaicStride = 0; - mosaicOffset = 0; - mosaic.reset(); - - paddingWidth = 0; - paddingHeight = 0; - paddingColor = 0x000000; - palette.reset(); - } - - inline context() { - reset(); - } -}; - -} -} - -#endif diff --git a/purify/nall/mosaic/parser.hpp b/purify/nall/mosaic/parser.hpp deleted file mode 100644 index b2c0b8ef..00000000 --- a/purify/nall/mosaic/parser.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifdef NALL_MOSAIC_INTERNAL_HPP - -namespace nall { -namespace mosaic { - -struct parser { - image canvas; - - //export from bitstream to canvas - inline void load(bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - canvas.allocate(width, height); - canvas.clear(ctx.paddingColor); - parse(1, stream, offset, ctx, width, height); - } - - //import from canvas to bitstream - inline bool save(bitstream &stream, uint64_t offset, context &ctx) { - if(stream.readonly) return false; - parse(0, stream, offset, ctx, canvas.width, canvas.height); - return true; - } - - inline parser() : canvas(0, 32, 0u, 255u << 16, 255u << 8, 255u << 0) { - } - -private: - inline uint32_t read(unsigned x, unsigned y) const { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return 0u; - uint32_t *buffer = (uint32_t*)canvas.data; - return buffer[addr]; - } - - inline void write(unsigned x, unsigned y, uint32_t data) { - unsigned addr = y * canvas.width + x; - if(addr >= canvas.width * canvas.height) return; - uint32_t *buffer = (uint32_t*)canvas.data; - buffer[addr] = data; - } - - inline void parse(bool load, bitstream &stream, uint64_t offset, context &ctx, unsigned width, unsigned height) { - stream.endian = ctx.endian; - unsigned canvasWidth = width / (ctx.mosaicWidth * ctx.tileWidth * ctx.blockWidth + ctx.paddingWidth); - unsigned canvasHeight = height / (ctx.mosaicHeight * ctx.tileHeight * ctx.blockHeight + ctx.paddingHeight); - unsigned bitsPerBlock = ctx.depth * ctx.blockWidth * ctx.blockHeight; - - unsigned objectOffset = 0; - for(unsigned objectY = 0; objectY < canvasHeight; objectY++) { - for(unsigned objectX = 0; objectX < canvasWidth; objectX++) { - if(objectOffset >= ctx.count && ctx.count > 0) break; - unsigned objectIX = objectX * ctx.objectWidth(); - unsigned objectIY = objectY * ctx.objectHeight(); - objectOffset++; - - unsigned mosaicOffset = 0; - for(unsigned mosaicY = 0; mosaicY < ctx.mosaicHeight; mosaicY++) { - for(unsigned mosaicX = 0; mosaicX < ctx.mosaicWidth; mosaicX++) { - unsigned mosaicData = ctx.mosaic(mosaicOffset, mosaicOffset); - unsigned mosaicIX = (mosaicData % ctx.mosaicWidth) * (ctx.tileWidth * ctx.blockWidth); - unsigned mosaicIY = (mosaicData / ctx.mosaicWidth) * (ctx.tileHeight * ctx.blockHeight); - mosaicOffset++; - - unsigned tileOffset = 0; - for(unsigned tileY = 0; tileY < ctx.tileHeight; tileY++) { - for(unsigned tileX = 0; tileX < ctx.tileWidth; tileX++) { - unsigned tileData = ctx.tile(tileOffset, tileOffset); - unsigned tileIX = (tileData % ctx.tileWidth) * ctx.blockWidth; - unsigned tileIY = (tileData / ctx.tileWidth) * ctx.blockHeight; - tileOffset++; - - unsigned blockOffset = 0; - for(unsigned blockY = 0; blockY < ctx.blockHeight; blockY++) { - for(unsigned blockX = 0; blockX < ctx.blockWidth; blockX++) { - if(load) { - unsigned palette = 0; - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - palette |= stream.read(offset + ctx.block(index, index)) << n; - } - - write( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY, - ctx.palette(palette, palette) - ); - } else /* save */ { - uint32_t palette = read( - objectIX + mosaicIX + tileIX + blockX, - objectIY + mosaicIY + tileIY + blockY - ); - - for(unsigned n = 0; n < ctx.depth; n++) { - unsigned index = blockOffset++; - if(ctx.order == 1) index = (index % ctx.depth) * ctx.blockWidth * ctx.blockHeight + (index / ctx.depth); - stream.write(offset + ctx.block(index, index), palette & 1); - palette >>= 1; - } - } - } //blockX - } //blockY - - offset += ctx.blockStride; - } //tileX - - offset += ctx.blockOffset; - } //tileY - - offset += ctx.tileStride; - } //mosaicX - - offset += ctx.tileOffset; - } //mosaicY - - offset += ctx.mosaicStride; - } //objectX - - offset += ctx.mosaicOffset; - } //objectY - } -}; - -} -} - -#endif diff --git a/purify/nall/nall.hpp b/purify/nall/nall.hpp deleted file mode 100644 index a7887695..00000000 --- a/purify/nall/nall.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NALL_HPP -#define NALL_HPP - -//include the most common nall headers with one statement -//does not include the most obscure components with high cost and low usage - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(PLATFORM_WINDOWS) - #include - #include -#endif - -#if defined(PLATFORM_X) - #include -#endif - -#endif diff --git a/purify/nall/platform.hpp b/purify/nall/platform.hpp deleted file mode 100644 index a45a6723..00000000 --- a/purify/nall/platform.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef NALL_PLATFORM_HPP -#define NALL_PLATFORM_HPP - -#if defined(_WIN32) - //minimum version needed for _wstat64, etc - #undef __MSVCRT_VERSION__ - #define __MSVCRT_VERSION__ 0x0601 - #include -#endif - -//========================= -//standard platform headers -//========================= - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#if defined(_WIN32) - #include - #include - #include - #include - #undef interface - #define dllexport __declspec(dllexport) -#else - #include - #include - #define dllexport -#endif - -//================== -//warning supression -//================== - -//Visual C++ -#if defined(_MSC_VER) - //disable libc "deprecation" warnings - #pragma warning(disable:4996) -#endif - -//================ -//POSIX compliance -//================ - -#if defined(_MSC_VER) - #define PATH_MAX _MAX_PATH - #define va_copy(dest, src) ((dest) = (src)) -#endif - -#if defined(_WIN32) - #define getcwd _getcwd - #define putenv _putenv - #define vsnprintf _vsnprintf - inline void usleep(unsigned milliseconds) { Sleep(milliseconds / 1000); } -#endif - -//================ -//inline expansion -//================ - -#if defined(__GNUC__) - #define noinline __attribute__((noinline)) - #define inline inline - #define alwaysinline inline __attribute__((always_inline)) -#elif defined(_MSC_VER) - #define noinline __declspec(noinline) - #define inline inline - #define alwaysinline inline __forceinline -#else - #define noinline - #define inline inline - #define alwaysinline inline -#endif - -#endif diff --git a/purify/nall/png.hpp b/purify/nall/png.hpp deleted file mode 100644 index f5ebaab4..00000000 --- a/purify/nall/png.hpp +++ /dev/null @@ -1,337 +0,0 @@ -#ifndef NALL_PNG_HPP -#define NALL_PNG_HPP - -//PNG image decoder -//author: byuu - -#include -#include - -namespace nall { - -struct png { - //colorType: - //0 = L - //2 = R,G,B - //3 = P - //4 = L,A - //6 = R,G,B,A - struct Info { - unsigned width; - unsigned height; - unsigned bitDepth; - unsigned colorType; - unsigned compressionMethod; - unsigned filterType; - unsigned interlaceMethod; - - unsigned bytesPerPixel; - unsigned pitch; - - uint8_t palette[256][3]; - } info; - - uint8_t *data; - unsigned size; - - inline bool decode(const string &filename); - inline bool decode(const uint8_t *sourceData, unsigned sourceSize); - inline unsigned readbits(const uint8_t *&data); - unsigned bitpos; - - inline png(); - inline ~png(); - -protected: - enum class FourCC : unsigned { - IHDR = 0x49484452, - PLTE = 0x504c5445, - IDAT = 0x49444154, - IEND = 0x49454e44, - }; - - inline unsigned interlace(unsigned pass, unsigned index); - inline unsigned inflateSize(); - inline bool deinterlace(const uint8_t *&inputData, unsigned pass); - inline bool filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height); - inline unsigned read(const uint8_t *data, unsigned length); -}; - -bool png::decode(const string &filename) { - if(auto memory = file::read(filename)) { - return decode(memory.data(), memory.size()); - } - return false; -} - -bool png::decode(const uint8_t *sourceData, unsigned sourceSize) { - if(sourceSize < 8) return false; - if(read(sourceData + 0, 4) != 0x89504e47) return false; - if(read(sourceData + 4, 4) != 0x0d0a1a0a) return false; - - uint8_t *compressedData = 0; - unsigned compressedSize = 0; - - unsigned offset = 8; - while(offset < sourceSize) { - unsigned length = read(sourceData + offset + 0, 4); - unsigned fourCC = read(sourceData + offset + 4, 4); - unsigned checksum = read(sourceData + offset + 8 + length, 4); - - if(fourCC == (unsigned)FourCC::IHDR) { - info.width = read(sourceData + offset + 8, 4); - info.height = read(sourceData + offset + 12, 4); - info.bitDepth = read(sourceData + offset + 16, 1); - info.colorType = read(sourceData + offset + 17, 1); - info.compressionMethod = read(sourceData + offset + 18, 1); - info.filterType = read(sourceData + offset + 19, 1); - info.interlaceMethod = read(sourceData + offset + 20, 1); - - if(info.bitDepth == 0 || info.bitDepth > 16) return false; - if(info.bitDepth & (info.bitDepth - 1)) return false; //not a power of two - if(info.compressionMethod != 0) return false; - if(info.filterType != 0) return false; - if(info.interlaceMethod != 0 && info.interlaceMethod != 1) return false; - - switch(info.colorType) { - case 0: info.bytesPerPixel = info.bitDepth * 1; break; //L - case 2: info.bytesPerPixel = info.bitDepth * 3; break; //R,G,B - case 3: info.bytesPerPixel = info.bitDepth * 1; break; //P - case 4: info.bytesPerPixel = info.bitDepth * 2; break; //L,A - case 6: info.bytesPerPixel = info.bitDepth * 4; break; //R,G,B,A - default: return false; - } - - if(info.colorType == 2 || info.colorType == 4 || info.colorType == 6) - if(info.bitDepth != 8 && info.bitDepth != 16) return false; - if(info.colorType == 3 && info.bitDepth == 16) return false; - - info.bytesPerPixel = (info.bytesPerPixel + 7) / 8; - info.pitch = (int)info.width * info.bytesPerPixel; - } - - if(fourCC == (unsigned)FourCC::PLTE) { - if(length % 3) return false; - for(unsigned n = 0, p = offset + 8; n < length / 3; n++) { - info.palette[n][0] = sourceData[p++]; - info.palette[n][1] = sourceData[p++]; - info.palette[n][2] = sourceData[p++]; - } - } - - if(fourCC == (unsigned)FourCC::IDAT) { - compressedData = (uint8_t*)realloc(compressedData, compressedSize + length); - memcpy(compressedData + compressedSize, sourceData + offset + 8, length); - compressedSize += length; - } - - if(fourCC == (unsigned)FourCC::IEND) { - break; - } - - offset += 4 + 4 + length + 4; - } - - unsigned interlacedSize = inflateSize(); - uint8_t *interlacedData = new uint8_t[interlacedSize]; - - bool result = inflate(interlacedData, interlacedSize, compressedData + 2, compressedSize - 6); - delete[] compressedData; - - if(result == false) { - delete[] interlacedData; - return false; - } - - size = info.width * info.height * info.bytesPerPixel; - data = new uint8_t[size]; - - if(info.interlaceMethod == 0) { - if(filter(data, interlacedData, info.width, info.height) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } else { - const uint8_t *passData = interlacedData; - for(unsigned pass = 0; pass < 7; pass++) { - if(deinterlace(passData, pass) == false) { - delete[] interlacedData; - delete[] data; - data = 0; - return false; - } - } - } - - delete[] interlacedData; - return true; -} - -unsigned png::interlace(unsigned pass, unsigned index) { - static const unsigned data[7][4] = { - //x-distance, y-distance, x-origin, y-origin - { 8, 8, 0, 0 }, - { 8, 8, 4, 0 }, - { 4, 8, 0, 4 }, - { 4, 4, 2, 0 }, - { 2, 4, 0, 2 }, - { 2, 2, 1, 0 }, - { 1, 2, 0, 1 }, - }; - return data[pass][index]; -} - -unsigned png::inflateSize() { - if(info.interlaceMethod == 0) { - return info.width * info.height * info.bytesPerPixel + info.height; - } - - unsigned size = 0; - for(unsigned pass = 0; pass < 7; pass++) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) continue; - size += width * height * info.bytesPerPixel + height; - } - return size; -} - -bool png::deinterlace(const uint8_t *&inputData, unsigned pass) { - unsigned xd = interlace(pass, 0), yd = interlace(pass, 1); - unsigned xo = interlace(pass, 2), yo = interlace(pass, 3); - unsigned width = (info.width + (xd - xo - 1)) / xd; - unsigned height = (info.height + (yd - yo - 1)) / yd; - if(width == 0 || height == 0) return true; - - unsigned outputSize = width * height * info.bytesPerPixel; - uint8_t *outputData = new uint8_t[outputSize]; - bool result = filter(outputData, inputData, width, height); - - const uint8_t *rd = outputData; - for(unsigned y = yo; y < info.height; y += yd) { - uint8_t *wr = data + y * info.pitch; - for(unsigned x = xo; x < info.width; x += xd) { - for(unsigned b = 0; b < info.bytesPerPixel; b++) { - wr[x * info.bytesPerPixel + b] = *rd++; - } - } - } - - inputData += outputSize + height; - delete[] outputData; - return result; -} - -bool png::filter(uint8_t *outputData, const uint8_t *inputData, unsigned width, unsigned height) { - uint8_t *wr = outputData; - const uint8_t *rd = inputData; - int bpp = info.bytesPerPixel, pitch = width * bpp; - for(int y = 0; y < height; y++) { - uint8_t filter = *rd++; - - switch(filter) { - case 0x00: //None - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x]; - } - break; - - case 0x01: //Subtract - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (x - bpp < 0 ? 0 : wr[x - bpp]); - } - break; - - case 0x02: //Above - for(int x = 0; x < pitch; x++) { - wr[x] = rd[x] + (y - 1 < 0 ? 0 : wr[x - pitch]); - } - break; - - case 0x03: //Average - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - - wr[x] = rd[x] + (uint8_t)((a + b) / 2); - } - break; - - case 0x04: //Paeth - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - short c = x - bpp < 0 || y - 1 < 0 ? 0 : wr[x - pitch - bpp]; - - short p = a + b - c; - short pa = p > a ? p - a : a - p; - short pb = p > b ? p - b : b - p; - short pc = p > c ? p - c : c - p; - - uint8_t paeth = (uint8_t)((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); - - wr[x] = rd[x] + paeth; - } - break; - - default: //Invalid - return false; - } - - rd += pitch; - wr += pitch; - } - - return true; -} - -unsigned png::read(const uint8_t *data, unsigned length) { - unsigned result = 0; - while(length--) result = (result << 8) | (*data++); - return result; -} - -unsigned png::readbits(const uint8_t *&data) { - unsigned result = 0; - switch(info.bitDepth) { - case 1: - result = (*data >> bitpos) & 1; - bitpos++; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 2: - result = (*data >> bitpos) & 3; - bitpos += 2; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 4: - result = (*data >> bitpos) & 15; - bitpos += 4; - if(bitpos == 8) { data++; bitpos = 0; } - break; - case 8: - result = *data++; - break; - case 16: - result = (data[0] << 8) | (data[1] << 0); - data += 2; - break; - } - return result; -} - -png::png() : data(nullptr) { - bitpos = 0; -} - -png::~png() { - if(data) delete[] data; -} - -} - -#endif diff --git a/purify/nall/priority-queue.hpp b/purify/nall/priority-queue.hpp deleted file mode 100644 index 1aedc6f1..00000000 --- a/purify/nall/priority-queue.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef NALL_PRIORITY_QUEUE_HPP -#define NALL_PRIORITY_QUEUE_HPP - -#include -#include -#include -#include - -namespace nall { - template void priority_queue_nocallback(type_t) {} - - //priority queue implementation using binary min-heap array; - //does not require normalize() function. - //O(1) find (tick) - //O(log n) append (enqueue) - //O(log n) remove (dequeue) - template class priority_queue { - public: - inline void tick(unsigned ticks) { - basecounter += ticks; - while(heapsize && gte(basecounter, heap[0].counter)) callback(dequeue()); - } - - //counter is relative to current time (eg enqueue(64, ...) fires in 64 ticks); - //counter cannot exceed std::numeric_limits::max() >> 1. - void enqueue(unsigned counter, type_t event) { - unsigned child = heapsize++; - counter += basecounter; - - while(child) { - unsigned parent = (child - 1) >> 1; - if(gte(counter, heap[parent].counter)) break; - - heap[child].counter = heap[parent].counter; - heap[child].event = heap[parent].event; - child = parent; - } - - heap[child].counter = counter; - heap[child].event = event; - } - - type_t dequeue() { - type_t event(heap[0].event); - unsigned parent = 0; - unsigned counter = heap[--heapsize].counter; - - while(true) { - unsigned child = (parent << 1) + 1; - if(child >= heapsize) break; - if(child + 1 < heapsize && gte(heap[child].counter, heap[child + 1].counter)) child++; - if(gte(heap[child].counter, counter)) break; - - heap[parent].counter = heap[child].counter; - heap[parent].event = heap[child].event; - parent = child; - } - - heap[parent].counter = counter; - heap[parent].event = heap[heapsize].event; - return event; - } - - void reset() { - basecounter = 0; - heapsize = 0; - } - - void serialize(serializer &s) { - s.integer(basecounter); - s.integer(heapsize); - for(unsigned n = 0; n < heapcapacity; n++) { - s.integer(heap[n].counter); - s.integer(heap[n].event); - } - } - - priority_queue(unsigned size, function callback_ = &priority_queue_nocallback) - : callback(callback_) { - heap = new heap_t[size]; - heapcapacity = size; - reset(); - } - - ~priority_queue() { - delete[] heap; - } - - priority_queue& operator=(const priority_queue&) = delete; - priority_queue(const priority_queue&) = delete; - - private: - function callback; - unsigned basecounter; - unsigned heapsize; - unsigned heapcapacity; - struct heap_t { - unsigned counter; - type_t event; - } *heap; - - //return true if x is greater than or equal to y - inline bool gte(unsigned x, unsigned y) { - return x - y < (std::numeric_limits::max() >> 1); - } - }; -} - -#endif diff --git a/purify/nall/property.hpp b/purify/nall/property.hpp deleted file mode 100644 index 1ddb5c9b..00000000 --- a/purify/nall/property.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef NALL_PROPERTY_HPP -#define NALL_PROPERTY_HPP - -//nall::property implements ownership semantics into container classes -//example: property::readonly implies that only owner has full -//access to type; and all other code has readonly access. -// -//property can be used either of two ways: -//struct foo { -// property::readonly x; -// property::readwrite y; -//}; -//-or- -//struct foo : property { -// readonly x; -// readwrite y; -//}; - -//return types are const T& (byref) instead of T (byval) to avoid major speed -//penalties for objects with expensive copy constructors - -//operator-> provides access to underlying object type: -//readonly foo; -//foo->bar(); -//... will call Object::bar(); - -//operator='s reference is constant so as to avoid leaking a reference handle -//that could bypass access restrictions - -//both constant and non-constant operators are provided, though it may be -//necessary to cast first, for instance: -//struct foo : property { readonly bar; } object; -//int main() { int value = const_cast(object); } - -//writeonly is useful for objects that have non-const reads, but const writes. -//however, to avoid leaking handles, the interface is very restricted. the only -//way to write is via operator=, which requires conversion via eg copy -//constructor. example: -//struct foo { -// foo(bool value) { ... } -//}; -//writeonly bar; -//bar = true; - -namespace nall { - template struct property { - template struct readonly { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - private: - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - friend C; - }; - - template struct writeonly { - void operator=(const T& value_) { value = value_; } - private: - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - T value; - friend C; - }; - - template struct readwrite { - const T* operator->() const { return &value; } - const T& operator()() const { return value; } - operator const T&() const { return value; } - T* operator->() { return &value; } - operator T&() { return value; } - const T& operator=(const T& value_) { return value = value_; } - T value; - }; - }; -} - -#endif diff --git a/purify/nall/public-cast.hpp b/purify/nall/public-cast.hpp deleted file mode 100644 index 331800e1..00000000 --- a/purify/nall/public-cast.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_PUBLIC_CAST_HPP -#define NALL_PUBLIC_CAST_HPP - -//this is a proof-of-concept-*only* C++ access-privilege elevation exploit. -//this code is 100% legal C++, per C++98 section 14.7.2 paragraph 8: -//"access checking rules do not apply to names in explicit instantiations." -//usage example: - -//struct N { typedef void (Class::*)(); }; -//template class public_cast; -//(class.*public_cast::value); - -//Class::Reference may be public, protected or private -//Class::Reference may be a function, object or variable - -namespace nall { - template struct public_cast; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value; - - template struct public_cast { - static typename T::type value; - }; - - template typename T::type public_cast::value = public_cast::value = P; -} - -#endif diff --git a/purify/nall/random.hpp b/purify/nall/random.hpp deleted file mode 100644 index 409c4561..00000000 --- a/purify/nall/random.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_RANDOM_HPP -#define NALL_RANDOM_HPP - -namespace nall { - //pseudo-random number generator - inline unsigned prng() { - static unsigned n = 0; - return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320); - } - - struct random_lfsr { - inline void seed(unsigned seed__) { - seed_ = seed__; - } - - inline unsigned operator()() { - return seed_ = (seed_ >> 1) ^ (((seed_ & 1) - 1) & 0xedb88320); - } - - random_lfsr() : seed_(0) { - } - - private: - unsigned seed_; - }; -} - -#endif diff --git a/purify/nall/serial.hpp b/purify/nall/serial.hpp deleted file mode 100644 index da87ae50..00000000 --- a/purify/nall/serial.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef NALL_SERIAL_HPP -#define NALL_SERIAL_HPP - -#include -#include -#include -#include - -#include - -namespace nall { - struct serial { - bool readable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, &fdset, nullptr, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes read - int read(uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::read(port, (void*)data, length); - } - - bool writable() { - if(port_open == false) return false; - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(port, &fdset); - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - int result = select(FD_SETSIZE, nullptr, &fdset, nullptr, &timeout); - if(result < 1) return false; - return FD_ISSET(port, &fdset); - } - - //-1 on error, otherwise return bytes written - int write(const uint8_t *data, unsigned length) { - if(port_open == false) return -1; - return ::write(port, (void*)data, length); - } - - bool open(const char *portname, unsigned rate, bool flowcontrol) { - close(); - - port = ::open(portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); - if(port == -1) return false; - - if(ioctl(port, TIOCEXCL) == -1) { close(); return false; } - if(fcntl(port, F_SETFL, 0) == -1) { close(); return false; } - if(tcgetattr(port, &original_attr) == -1) { close(); return false; } - - termios attr = original_attr; - cfmakeraw(&attr); - cfsetspeed(&attr, rate); - - attr.c_lflag &=~ (ECHO | ECHONL | ISIG | ICANON | IEXTEN); - attr.c_iflag &=~ (BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY); - attr.c_iflag |= (IGNBRK | IGNPAR); - attr.c_oflag &=~ (OPOST); - attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB | CLOCAL); - attr.c_cflag |= (CS8 | CREAD); - if(flowcontrol == false) { - attr.c_cflag &= ~CRTSCTS; - } else { - attr.c_cflag |= CRTSCTS; - } - attr.c_cc[VTIME] = attr.c_cc[VMIN] = 0; - - if(tcsetattr(port, TCSANOW, &attr) == -1) { close(); return false; } - return port_open = true; - } - - void close() { - if(port != -1) { - tcdrain(port); - if(port_open == true) { - tcsetattr(port, TCSANOW, &original_attr); - port_open = false; - } - ::close(port); - port = -1; - } - } - - serial() { - port = -1; - port_open = false; - } - - ~serial() { - close(); - } - - private: - int port; - bool port_open; - termios original_attr; - }; -} - -#endif diff --git a/purify/nall/serializer.hpp b/purify/nall/serializer.hpp deleted file mode 100644 index fcb39456..00000000 --- a/purify/nall/serializer.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef NALL_SERIALIZER_HPP -#define NALL_SERIALIZER_HPP - -#include -#include -#include -#include - -namespace nall { - //serializer: a class designed to save and restore the state of classes. - // - //benefits: - //- data() will be portable in size (it is not necessary to specify type sizes.) - //- data() will be portable in endianness (always stored internally as little-endian.) - //- one serialize function can both save and restore class states. - // - //caveats: - //- only plain-old-data can be stored. complex classes must provide serialize(serializer&); - //- floating-point usage is not portable across platforms - - class serializer { - public: - enum mode_t { Load, Save, Size }; - - mode_t mode() const { - return imode; - } - - const uint8_t* data() const { - return idata; - } - - unsigned size() const { - return isize; - } - - unsigned capacity() const { - return icapacity; - } - - template void floatingpoint(T &value) { - enum { size = sizeof(T) }; - //this is rather dangerous, and not cross-platform safe; - //but there is no standardized way to export FP-values - uint8_t *p = (uint8_t*)&value; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = p[n]; - } else if(imode == Load) { - for(unsigned n = 0; n < size; n++) p[n] = idata[isize++]; - } else { - isize += size; - } - } - - template void integer(T &value) { - enum { size = std::is_same::value ? 1 : sizeof(T) }; - if(imode == Save) { - for(unsigned n = 0; n < size; n++) idata[isize++] = (uintmax_t)value >> (n << 3); - } else if(imode == Load) { - value = 0; - for(unsigned n = 0; n < size; n++) value |= (uintmax_t)idata[isize++] << (n << 3); - } else if(imode == Size) { - isize += size; - } - } - - template void array(T &array) { - enum { size = sizeof(T) / sizeof(typename std::remove_extent::type) }; - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - template void array(T array, unsigned size) { - for(unsigned n = 0; n < size; n++) integer(array[n]); - } - - //copy - serializer& operator=(const serializer &s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = new uint8_t[s.icapacity]; - isize = s.isize; - icapacity = s.icapacity; - - memcpy(idata, s.idata, s.icapacity); - return *this; - } - - serializer(const serializer &s) : idata(0) { - operator=(s); - } - - //move - serializer& operator=(serializer &&s) { - if(idata) delete[] idata; - - imode = s.imode; - idata = s.idata; - isize = s.isize; - icapacity = s.icapacity; - - s.idata = 0; - return *this; - } - - serializer(serializer &&s) { - operator=(std::move(s)); - } - - //construction - serializer() { - imode = Size; - idata = 0; - isize = 0; - icapacity = 0; - } - - serializer(unsigned capacity) { - imode = Save; - idata = new uint8_t[capacity](); - isize = 0; - icapacity = capacity; - } - - serializer(const uint8_t *data, unsigned capacity) { - imode = Load; - idata = new uint8_t[capacity]; - isize = 0; - icapacity = capacity; - memcpy(idata, data, capacity); - } - - ~serializer() { - if(idata) delete[] idata; - } - - private: - mode_t imode; - uint8_t *idata; - unsigned isize; - unsigned icapacity; - }; - -}; - -#endif diff --git a/purify/nall/set.hpp b/purify/nall/set.hpp deleted file mode 100644 index c6d3d06e..00000000 --- a/purify/nall/set.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef NALL_SET_HPP -#define NALL_SET_HPP - -//set -//* unordered -//* intended for unique items -//* dynamic growth -//* reference-based variant - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - -template struct set; - -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - T *pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } -}; - -//reference set -template struct set::value>::type> { - struct exception_out_of_bounds{}; - -protected: - typedef typename std::remove_reference::type T; - T **pool; - unsigned poolsize, objectsize; - -public: - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - void reset() { - if(pool) free(pool); - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - if(size == poolsize) return; - pool = (T**)realloc(pool, sizeof(T*) * size); - poolsize = size; - objectsize = min(objectsize, size); - } - - void resize(unsigned size) { - if(size > poolsize) reserve(bit::round(size)); //amortize growth - objectsize = size; - } - - bool append(T& data) { - if(find(data)) return false; - unsigned offset = objectsize++; - if(offset >= poolsize) resize(offset + 1); - pool[offset] = &data; - return true; - } - - template - bool append(T& data, Args&&... args) { - bool result = append(data); - append(std::forward(args)...); - return result; - } - - bool remove(T& data) { - if(auto position = find(data)) { - for(signed i = position(); i < objectsize - 1; i++) pool[i] = pool[i + 1]; - resize(objectsize - 1); - return true; - } - return false; - } - - optional find(const T& data) { - for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return {true, n}; - return {false, 0u}; - } - - template set(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) { - construct(std::forward(args)...); - } - - ~set() { - reset(); - } - - set& operator=(const set &source) { - if(&source == this) return *this; - if(pool) free(pool); - objectsize = source.objectsize; - poolsize = source.poolsize; - pool = (T**)malloc(sizeof(T*) * poolsize); - memcpy(pool, source.pool, sizeof(T*) * objectsize); - return *this; - } - - set& operator=(const set &&source) { - if(&source == this) return *this; - if(pool) free(pool); - pool = source.pool; - poolsize = source.poolsize; - objectsize = source.objectsize; - source.pool = nullptr; - source.reset(); - return *this; - } - - T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return *pool[position]; - } - - struct iterator { - bool operator!=(const iterator &source) const { return position != source.position; } - T& operator*() { return source.operator[](position); } - iterator& operator++() { position++; return *this; } - iterator(const set &source, unsigned position) : source(source), position(position) {} - private: - const set &source; - unsigned position; - }; - - iterator begin() { return iterator(*this, 0); } - iterator end() { return iterator(*this, objectsize); } - const iterator begin() const { return iterator(*this, 0); } - const iterator end() const { return iterator(*this, objectsize); } - -private: - void construct() {} - void construct(const set &source) { operator=(source); } - void construct(const set &&source) { operator=(std::move(source)); } - template void construct(T& data, Args&&... args) { - append(data); - construct(std::forward(args)...); - } -}; - -} - -#endif diff --git a/purify/nall/sha256.hpp b/purify/nall/sha256.hpp deleted file mode 100644 index c63367a7..00000000 --- a/purify/nall/sha256.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef NALL_SHA256_HPP -#define NALL_SHA256_HPP - -//author: vladitx - -#include - -namespace nall { - #define PTR(t, a) ((t*)(a)) - - #define SWAP32(x) ((uint32_t)( \ - (((uint32_t)(x) & 0x000000ff) << 24) | \ - (((uint32_t)(x) & 0x0000ff00) << 8) | \ - (((uint32_t)(x) & 0x00ff0000) >> 8) | \ - (((uint32_t)(x) & 0xff000000) >> 24) \ - )) - - #define ST32(a, d) *PTR(uint32_t, a) = (d) - #define ST32BE(a, d) ST32(a, SWAP32(d)) - - #define LD32(a) *PTR(uint32_t, a) - #define LD32BE(a) SWAP32(LD32(a)) - - #define LSL32(x, n) ((uint32_t)(x) << (n)) - #define LSR32(x, n) ((uint32_t)(x) >> (n)) - #define ROR32(x, n) (LSR32(x, n) | LSL32(x, 32 - (n))) - - //first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19 - static const uint32_t T_H[8] = { - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, - }; - - //first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311 - static const uint32_t T_K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, - }; - - struct sha256_ctx { - uint8_t in[64]; - unsigned inlen; - - uint32_t w[64]; - uint32_t h[8]; - uint64_t len; - }; - - inline void sha256_init(sha256_ctx *p) { - memset(p, 0, sizeof(sha256_ctx)); - memcpy(p->h, T_H, sizeof(T_H)); - } - - static void sha256_block(sha256_ctx *p) { - unsigned i; - uint32_t s0, s1; - uint32_t a, b, c, d, e, f, g, h; - uint32_t t1, t2, maj, ch; - - for(i = 0; i < 16; i++) p->w[i] = LD32BE(p->in + i * 4); - - for(i = 16; i < 64; i++) { - s0 = ROR32(p->w[i - 15], 7) ^ ROR32(p->w[i - 15], 18) ^ LSR32(p->w[i - 15], 3); - s1 = ROR32(p->w[i - 2], 17) ^ ROR32(p->w[i - 2], 19) ^ LSR32(p->w[i - 2], 10); - p->w[i] = p->w[i - 16] + s0 + p->w[i - 7] + s1; - } - - a = p->h[0]; b = p->h[1]; c = p->h[2]; d = p->h[3]; - e = p->h[4]; f = p->h[5]; g = p->h[6]; h = p->h[7]; - - for(i = 0; i < 64; i++) { - s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22); - maj = (a & b) ^ (a & c) ^ (b & c); - t2 = s0 + maj; - s1 = ROR32(e, 6) ^ ROR32(e, 11) ^ ROR32(e, 25); - ch = (e & f) ^ (~e & g); - t1 = h + s1 + ch + T_K[i] + p->w[i]; - - h = g; g = f; f = e; e = d + t1; - d = c; c = b; b = a; a = t1 + t2; - } - - p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d; - p->h[4] += e; p->h[5] += f; p->h[6] += g; p->h[7] += h; - - //next block - p->inlen = 0; - } - - inline void sha256_chunk(sha256_ctx *p, const uint8_t *s, unsigned len) { - unsigned l; - p->len += len; - - while(len) { - l = 64 - p->inlen; - l = (len < l) ? len : l; - - memcpy(p->in + p->inlen, s, l); - s += l; - p->inlen += l; - len -= l; - - if(p->inlen == 64) sha256_block(p); - } - } - - inline void sha256_final(sha256_ctx *p) { - uint64_t len; - p->in[p->inlen++] = 0x80; - - if(p->inlen > 56) { - memset(p->in + p->inlen, 0, 64 - p->inlen); - sha256_block(p); - } - - memset(p->in + p->inlen, 0, 56 - p->inlen); - - len = p->len << 3; - ST32BE(p->in + 56, len >> 32); - ST32BE(p->in + 60, len); - sha256_block(p); - } - - inline void sha256_hash(sha256_ctx *p, uint8_t *s) { - uint32_t *t = (uint32_t*)s; - for(unsigned i = 0; i < 8; i++) ST32BE(t++, p->h[i]); - } - - #undef PTR - #undef SWAP32 - #undef ST32 - #undef ST32BE - #undef LD32 - #undef LD32BE - #undef LSL32 - #undef LSR32 - #undef ROR32 -} - -#endif diff --git a/purify/nall/sort.hpp b/purify/nall/sort.hpp deleted file mode 100644 index 8326ab1d..00000000 --- a/purify/nall/sort.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef NALL_SORT_HPP -#define NALL_SORT_HPP - -#include -#include - -//class: merge sort -//average: O(n log n) -//worst: O(n log n) -//memory: O(n) -//stack: O(log n) -//stable?: yes - -//note: merge sort was chosen over quick sort, because: -//* it is a stable sort -//* it lacks O(n^2) worst-case overhead - -#define NALL_SORT_INSERTION -//#define NALL_SORT_SELECTION - -namespace nall { - template - void sort(T list[], unsigned size, const Comparator &lessthan) { - if(size <= 1) return; //nothing to sort - - //use insertion sort to quickly sort smaller blocks - if(size < 64) { - #if defined(NALL_SORT_INSERTION) - for(signed i = 1, j; i < size; i++) { - T copy = std::move(list[i]); - for(j = i - 1; j >= 0; j--) { - if(!lessthan(copy, list[j])) break; - list[j + 1] = std::move(list[j]); - } - list[j + 1] = std::move(copy); - } - #elif defined(NALL_SORT_SELECTION) - for(unsigned i = 0; i < size; i++) { - unsigned min = i; - for(unsigned j = i + 1; j < size; j++) { - if(lessthan(list[j], list[min])) min = j; - } - if(min != i) std::swap(list[i], list[min]); - } - #endif - return; - } - - //split list in half and recursively sort both - unsigned middle = size / 2; - sort(list, middle, lessthan); - sort(list + middle, size - middle, lessthan); - - //left and right are sorted here; perform merge sort - T *buffer = new T[size]; - unsigned offset = 0, left = 0, right = middle; - while(left < middle && right < size) { - if(!lessthan(list[right], list[left])) { - buffer[offset++] = std::move(list[left++]); - } else { - buffer[offset++] = std::move(list[right++]); - } - } - while(left < middle) buffer[offset++] = std::move(list[left++]); - while(right < size) buffer[offset++] = std::move(list[right++]); - - for(unsigned i = 0; i < size; i++) list[i] = std::move(buffer[i]); - delete[] buffer; - } - - template - void sort(T list[], unsigned size) { - return sort(list, size, [](const T &l, const T &r) { return l < r; }); - } -} - -#endif diff --git a/purify/nall/stdint.hpp b/purify/nall/stdint.hpp deleted file mode 100644 index c63f5912..00000000 --- a/purify/nall/stdint.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STDINT_HPP -#define NALL_STDINT_HPP - -#if defined(_MSC_VER) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef signed long long int64_t; - typedef int64_t intmax_t; - #if defined(_WIN64) - typedef int64_t intptr_t; - #else - typedef int32_t intptr_t; - #endif - - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; - typedef unsigned long long uint64_t; - typedef uint64_t uintmax_t; - #if defined(_WIN64) - typedef uint64_t uintptr_t; - #else - typedef uint32_t uintptr_t; - #endif -#else - #include -#endif - -namespace nall { - static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size"); - - static_assert(sizeof(uint8_t) == 1, "int8_t is not of the correct size" ); - static_assert(sizeof(uint16_t) == 2, "int16_t is not of the correct size"); - static_assert(sizeof(uint32_t) == 4, "int32_t is not of the correct size"); - static_assert(sizeof(uint64_t) == 8, "int64_t is not of the correct size"); -} - -#endif diff --git a/purify/nall/stream.hpp b/purify/nall/stream.hpp deleted file mode 100644 index 586ccda7..00000000 --- a/purify/nall/stream.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NALL_STREAM_HPP -#define NALL_STREAM_HPP - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define NALL_STREAM_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STREAM_INTERNAL_HPP - -#endif diff --git a/purify/nall/stream/auto.hpp b/purify/nall/stream/auto.hpp deleted file mode 100644 index d1b6e2ba..00000000 --- a/purify/nall/stream/auto.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NALL_STREAM_AUTO_HPP -#define NALL_STREAM_AUTO_HPP - -namespace nall { - -#define autostream(...) (*makestream(__VA_ARGS__)) - -inline std::unique_ptr makestream(const string &path) { - if(path.ibeginswith("http://")) return std::unique_ptr(new httpstream(path, 80)); - if(path.iendswith(".gz")) return std::unique_ptr(new gzipstream(filestream{path})); - if(path.iendswith(".zip")) return std::unique_ptr(new zipstream(filestream{path})); - return std::unique_ptr(new mmapstream(path)); -} - -inline std::unique_ptr makestream(uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -inline std::unique_ptr makestream(const uint8_t *data, unsigned size) { - return std::unique_ptr(new memorystream(data, size)); -} - -} - -#endif diff --git a/purify/nall/stream/file.hpp b/purify/nall/stream/file.hpp deleted file mode 100644 index 878418cf..00000000 --- a/purify/nall/stream/file.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_FILE_HPP -#define NALL_STREAM_FILE_HPP - -#include - -namespace nall { - -struct filestream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return false; } - - unsigned size() const { return pfile.size(); } - unsigned offset() const { return pfile.offset(); } - void seek(unsigned offset) const { pfile.seek(offset); } - - uint8_t read() const { return pfile.read(); } - void write(uint8_t data) const { pfile.write(data); } - - filestream(const string &filename) { - pfile.open(filename, file::mode::readwrite); - pwritable = pfile.open(); - if(!pwritable) pfile.open(filename, file::mode::read); - } - - filestream(const string &filename, file::mode mode) { - pfile.open(filename, mode); - pwritable = mode == file::mode::write || mode == file::mode::readwrite; - } - -private: - mutable file pfile; - bool pwritable; -}; - -} - -#endif diff --git a/purify/nall/stream/gzip.hpp b/purify/nall/stream/gzip.hpp deleted file mode 100644 index 0c270a72..00000000 --- a/purify/nall/stream/gzip.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NALL_STREAM_GZIP_HPP -#define NALL_STREAM_GZIP_HPP - -#include - -namespace nall { - -struct gzipstream : memorystream { - using stream::read; - using stream::write; - - gzipstream(const stream &stream) { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - gzip archive; - bool result = archive.decompress(data, size); - delete[] data; - if(result == false) return; - - psize = archive.size; - pdata = new uint8_t[psize]; - memcpy(pdata, archive.data, psize); - } - - ~gzipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/purify/nall/stream/http.hpp b/purify/nall/stream/http.hpp deleted file mode 100644 index 2f9e45dd..00000000 --- a/purify/nall/stream/http.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef NALL_STREAM_HTTP_HPP -#define NALL_STREAM_HTTP_HPP - -#include - -namespace nall { - -struct httpstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return true; } - bool randomaccess() const { return true; } - - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - httpstream(const string &url, unsigned port) : pdata(nullptr), psize(0), poffset(0) { - string uri = url; - uri.ltrim<1>("http://"); - lstring part = uri.split<1>("/"); - part[1] = { "/", part[1] }; - - http connection; - if(connection.connect(part[0], port) == false) return; - connection.download(part[1], pdata, psize); - } - - ~httpstream() { - if(pdata) delete[] pdata; - } - -private: - mutable uint8_t *pdata; - mutable unsigned psize, poffset; -}; - -} - -#endif diff --git a/purify/nall/stream/memory.hpp b/purify/nall/stream/memory.hpp deleted file mode 100644 index cf49b3b2..00000000 --- a/purify/nall/stream/memory.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef NALL_STREAM_MEMORY_HPP -#define NALL_STREAM_MEMORY_HPP - -#include - -namespace nall { - -struct memorystream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t *data() const { return pdata; } - unsigned size() const { return psize; } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - memorystream() : pdata(nullptr), psize(0), poffset(0), pwritable(true) {} - - memorystream(uint8_t *data, unsigned size) { - pdata = data, psize = size, poffset = 0; - pwritable = true; - } - - memorystream(const uint8_t *data, unsigned size) { - pdata = (uint8_t*)data, psize = size, poffset = 0; - pwritable = false; - } - -protected: - mutable uint8_t *pdata; - mutable unsigned psize, poffset, pwritable; -}; - -} - -#endif diff --git a/purify/nall/stream/mmap.hpp b/purify/nall/stream/mmap.hpp deleted file mode 100644 index ce30f810..00000000 --- a/purify/nall/stream/mmap.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef NALL_STREAM_MMAP_HPP -#define NALL_STREAM_MMAP_HPP - -#include - -namespace nall { - -struct mmapstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - unsigned size() const { return pmmap.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return pdata[poffset++]; } - void write(uint8_t data) const { pdata[poffset++] = data; } - - uint8_t read(unsigned offset) const { return pdata[offset]; } - void write(unsigned offset, uint8_t data) const { pdata[offset] = data; } - - mmapstream(const string &filename) { - pmmap.open(filename, filemap::mode::readwrite); - pwritable = pmmap.open(); - if(!pwritable) pmmap.open(filename, filemap::mode::read); - pdata = pmmap.data(), poffset = 0; - } - -private: - mutable filemap pmmap; - mutable uint8_t *pdata; - mutable unsigned pwritable, poffset; -}; - -} - -#endif diff --git a/purify/nall/stream/stream.hpp b/purify/nall/stream/stream.hpp deleted file mode 100644 index 043eecba..00000000 --- a/purify/nall/stream/stream.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef NALL_STREAM_STREAM_HPP -#define NALL_STREAM_STREAM_HPP - -namespace nall { - -struct stream { - virtual bool seekable() const = 0; - virtual bool readable() const = 0; - virtual bool writable() const = 0; - virtual bool randomaccess() const = 0; - - virtual uint8_t* data() const { return nullptr; } - virtual unsigned size() const = 0; - virtual unsigned offset() const = 0; - virtual void seek(unsigned offset) const = 0; - - virtual uint8_t read() const = 0; - virtual void write(uint8_t data) const = 0; - - virtual uint8_t read(unsigned) const { return 0; } - virtual void write(unsigned, uint8_t) const {} - - operator bool() const { - return size(); - } - - bool empty() const { - return size() == 0; - } - - bool end() const { - return offset() >= size(); - } - - uintmax_t readl(unsigned length = 1) const { - uintmax_t data = 0, shift = 0; - while(length--) { data |= read() << shift; shift += 8; } - return data; - } - - uintmax_t readm(unsigned length = 1) const { - uintmax_t data = 0; - while(length--) data = (data << 8) | read(); - return data; - } - - void read(uint8_t *data, unsigned length) const { - while(length--) *data++ = read(); - } - - string text() const { - string buffer; - buffer.resize(size() + 1); - buffer[size()] = 0; - seek(0); - read((uint8_t*)buffer(), size()); - return buffer; - } - - void writel(uintmax_t data, unsigned length = 1) const { - while(length--) { - write(data); - data >>= 8; - } - } - - void writem(uintmax_t data, unsigned length = 1) const { - uintmax_t shift = 8 * length; - while(length--) { - shift -= 8; - write(data >> shift); - } - } - - void write(const uint8_t *data, unsigned length) const { - while(length--) write(*data++); - } - - struct byte { - operator uint8_t() const { return s.read(offset); } - byte& operator=(uint8_t data) { s.write(offset, data); return *this; } - byte(const stream &s, unsigned offset) : s(s), offset(offset) {} - - private: - const stream &s; - const unsigned offset; - }; - - byte operator[](unsigned offset) const { - return byte(*this, offset); - } - - stream() {} - virtual ~stream() {} - stream(const stream&) = delete; - stream& operator=(const stream&) = delete; -}; - -} - -#endif diff --git a/purify/nall/stream/vector.hpp b/purify/nall/stream/vector.hpp deleted file mode 100644 index 59f36c02..00000000 --- a/purify/nall/stream/vector.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef NALL_STREAM_VECTOR_HPP -#define NALL_STREAM_VECTOR_HPP - -#include -#include - -namespace nall { - -struct vectorstream : stream { - using stream::read; - using stream::write; - - bool seekable() const { return true; } - bool readable() const { return true; } - bool writable() const { return pwritable; } - bool randomaccess() const { return true; } - - uint8_t* data() const { return memory.data(); } - unsigned size() const { return memory.size(); } - unsigned offset() const { return poffset; } - void seek(unsigned offset) const { poffset = offset; } - - uint8_t read() const { return memory[poffset++]; } - void write(uint8_t data) const { memory[poffset++] = data; } - - uint8_t read(unsigned offset) const { return memory[offset]; } - void write(unsigned offset, uint8_t data) const { memory[offset] = data; } - - vectorstream(vector &memory) : memory(memory), poffset(0), pwritable(true) {} - vectorstream(const vector &memory) : memory((vector&)memory), poffset(0), pwritable(false) {} - -protected: - vector &memory; - mutable unsigned poffset, pwritable; -}; - -} - -#endif diff --git a/purify/nall/stream/zip.hpp b/purify/nall/stream/zip.hpp deleted file mode 100644 index 94aa3992..00000000 --- a/purify/nall/stream/zip.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef NALL_STREAM_ZIP_HPP -#define NALL_STREAM_ZIP_HPP - -#include - -namespace nall { - -struct zipstream : memorystream { - using stream::read; - using stream::write; - - zipstream(const stream &stream, const string &filter = "*") { - unsigned size = stream.size(); - uint8_t *data = new uint8_t[size]; - stream.read(data, size); - - unzip archive; - if(archive.open(data, size) == false) return; - delete[] data; - - for(auto &file : archive.file) { - if(file.name.wildcard(filter)) { - auto buffer = archive.extract(file); - psize = buffer.size(); - pdata = buffer.move(); - return; - } - } - } - - ~zipstream() { - if(pdata) delete[] pdata; - } -}; - -} - -#endif diff --git a/purify/nall/string.hpp b/purify/nall/string.hpp deleted file mode 100644 index 82b7cde4..00000000 --- a/purify/nall/string.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef NALL_STRING_HPP -#define NALL_STRING_HPP - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define NALL_STRING_INTERNAL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#undef NALL_STRING_INTERNAL_HPP - -#endif diff --git a/purify/nall/string/base.hpp b/purify/nall/string/base.hpp deleted file mode 100644 index d5f85ca4..00000000 --- a/purify/nall/string/base.hpp +++ /dev/null @@ -1,229 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - struct cstring; - struct string; - struct lstring; - template inline const char* to_string(T); - - struct cstring { - inline operator const char*() const; - inline unsigned length() const; - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline cstring& operator=(const char *data); - inline cstring(const char *data); - inline cstring(); - - protected: - const char *data; - }; - - struct string { - inline static string read(const string &filename); - - inline static string date(); - inline static string time(); - inline static string datetime(); - - inline void reserve(unsigned); - inline void resize(unsigned); - inline void clear(char); - inline bool empty() const; - - template inline string& assign(Args&&... args); - template inline string& append(Args&&... args); - - inline bool readfile(const string&); - - template inline string& replace(const char*, const char*); - template inline string& ireplace(const char*, const char*); - template inline string& qreplace(const char*, const char*); - template inline string& iqreplace(const char*, const char*); - - inline unsigned length() const; - inline unsigned capacity() const; - - template inline lstring split(const char*) const; - template inline lstring isplit(const char*) const; - template inline lstring qsplit(const char*) const; - template inline lstring iqsplit(const char*) const; - - inline bool equals(const char*) const; - inline bool iequals(const char*) const; - - inline bool wildcard(const char*) const; - inline bool iwildcard(const char*) const; - - inline bool beginswith(const char*) const; - inline bool ibeginswith(const char*) const; - inline bool endswith(const char*) const; - inline bool iendswith(const char*) const; - - inline string& lower(); - inline string& upper(); - inline string& qlower(); - inline string& qupper(); - inline string& transform(const char *before, const char *after); - inline string& reverse(); - - template inline string& ltrim(const char *key = " "); - template inline string& rtrim(const char *key = " "); - template inline string& trim(const char *key = " ", const char *rkey = 0); - inline string& strip(); - - inline optional position(const char *key) const; - inline optional iposition(const char *key) const; - inline optional qposition(const char *key) const; - inline optional iqposition(const char *key) const; - - inline operator const char*() const; - inline char* operator()(); - inline char& operator[](int); - - inline bool operator==(const char*) const; - inline bool operator!=(const char*) const; - inline bool operator< (const char*) const; - inline bool operator<=(const char*) const; - inline bool operator> (const char*) const; - inline bool operator>=(const char*) const; - - inline string& operator=(const string&); - inline string& operator=(string&&); - - template inline string(Args&&... args); - inline string(const string&); - inline string(string&&); - inline ~string(); - - inline char* begin() { return &data[0]; } - inline char* end() { return &data[length()]; } - inline const char* begin() const { return &data[0]; } - inline const char* end() const { return &data[length()]; } - - //internal functions - inline string& assign_(const char*); - inline string& append_(const char*); - - protected: - char *data; - unsigned size; - - template inline string& ureplace(const char*, const char*); - - #if defined(QSTRING_H) - public: - inline operator QString() const; - #endif - }; - - struct lstring : vector { - inline optional find(const char*) const; - inline string concatenate(const char*) const; - inline void append() {} - inline void isort(); - template inline void append(const string&, Args&&...); - - template inline lstring& split(const char*, const char*); - template inline lstring& isplit(const char*, const char*); - template inline lstring& qsplit(const char*, const char*); - template inline lstring& iqsplit(const char*, const char*); - - inline bool operator==(const lstring&) const; - inline bool operator!=(const lstring&) const; - - inline lstring& operator=(const lstring&); - inline lstring& operator=(lstring&); - inline lstring& operator=(lstring&&); - - template inline lstring(Args&&... args); - inline lstring(const lstring&); - inline lstring(lstring&); - inline lstring(lstring&&); - - protected: - template inline lstring& usplit(const char*, const char*); - }; - - //compare.hpp - inline char chrlower(char c); - inline char chrupper(char c); - inline int istrcmp(const char *str1, const char *str2); - inline bool strbegin(const char *str, const char *key); - inline bool istrbegin(const char *str, const char *key); - inline bool strend(const char *str, const char *key); - inline bool istrend(const char *str, const char *key); - - //convert.hpp - inline char* strlower(char *str); - inline char* strupper(char *str); - inline char* qstrlower(char *str); - inline char* qstrupper(char *str); - inline char* strtr(char *dest, const char *before, const char *after); - - //format.hpp - template inline string format(const string &value); - template inline string hex(uintmax_t value); - template inline string octal(uintmax_t value); - template inline string binary(uintmax_t value); - - //math.hpp - inline bool strint(const char *str, int &result); - inline bool strmath(const char *str, int &result); - - //platform.hpp - inline string activepath(); - inline string realpath(const string &name); - inline string userpath(); - inline string configpath(); - inline string temppath(); - - //strm.hpp - inline unsigned strmcpy(char *target, const char *source, unsigned length); - inline unsigned strmcat(char *target, const char *source, unsigned length); - inline bool strccpy(char *target, const char *source, unsigned length); - inline bool strccat(char *target, const char *source, unsigned length); - inline void strpcpy(char *&target, const char *source, unsigned &length); - - //strpos.hpp - inline optional strpos(const char *str, const char *key); - inline optional istrpos(const char *str, const char *key); - inline optional qstrpos(const char *str, const char *key); - inline optional iqstrpos(const char *str, const char *key); - template inline optional ustrpos(const char *str, const char *key); - - //trim.hpp - template inline char* ltrim(char *str, const char *key = " "); - template inline char* rtrim(char *str, const char *key = " "); - template inline char* trim(char *str, const char *key = " ", const char *rkey = 0); - inline char* strip(char *s); - - //utility.hpp - template alwaysinline bool chrequal(char x, char y); - template alwaysinline bool quoteskip(T *&p); - template alwaysinline bool quotecopy(char *&t, T *&p); - inline string substr(const char *src, unsigned start = 0, unsigned length = ~0u); - inline string sha256(const uint8_t *data, unsigned size); - - inline char* integer(char *result, intmax_t value); - inline char* decimal(char *result, uintmax_t value); - - //these functions are deprecated, use format() instead: - template inline string integer(intmax_t value); - template inline string linteger(intmax_t value); - template inline string decimal(uintmax_t value); - template inline string ldecimal(uintmax_t value); - inline unsigned fp(char *str, long double value); - inline string fp(long double value); - - //variadic.hpp - template inline void print(Args&&... args); - - //wildcard.hpp - inline bool wildcard(const char *str, const char *pattern); - inline bool iwildcard(const char *str, const char *pattern); -}; - -#endif diff --git a/purify/nall/string/bsv.hpp b/purify/nall/string/bsv.hpp deleted file mode 100644 index d9415d53..00000000 --- a/purify/nall/string/bsv.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BSV v1.0 parser -//revision 0.02 - -namespace nall { - -struct BSV { - static inline string decode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '}' ) return ""; - if(*input == '\r') return ""; - if(*input == '\n') return ""; - - //normal characters - if(*input != '{') { output[offset++] = *input++; continue; } - - //entities - if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; } - if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; } - if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; } - - //illegal entities - return ""; - } - output[offset] = 0; - return output; - } - - static inline string encode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '\r') return ""; - - if(*input == '\n') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'f'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '{') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '}') { - output[offset++] = '{'; - output[offset++] = 'r'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - output[offset++] = *input++; - } - output[offset] = 0; - return output; - } -}; - -} - -#endif diff --git a/purify/nall/string/cast.hpp b/purify/nall/string/cast.hpp deleted file mode 100644 index 7c7e276b..00000000 --- a/purify/nall/string/cast.hpp +++ /dev/null @@ -1,185 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//convert any (supported) type to a const char* without constructing a new nall::string -//this is used inside istring(...) to build nall::string values -template struct stringify; - -// base types - -template<> struct stringify { - bool value; - operator const char*() const { return value ? "true" : "false"; } - stringify(bool value) : value(value) {} -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(char value) { integer(data, value); } -}; - -// signed integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed char value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed short value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed int value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long value) { integer(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(signed long long value) { integer(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(int_t value) { integer(data, value); } -}; - -// unsigned integers - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned char value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned short value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned int value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long value) { decimal(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(unsigned long long value) { decimal(data, value); } -}; - -template struct stringify> { - char data[256]; - operator const char*() const { return data; } - stringify(uint_t value) { decimal(data, value); } -}; - -// floating-point - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(float value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(double value) { fp(data, value); } -}; - -template<> struct stringify { - char data[256]; - operator const char*() const { return data; } - stringify(long double value) { fp(data, value); } -}; - -// strings - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(char *value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const char *value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const string &value; - operator const char*() const { return value; } - stringify(const string &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -template<> struct stringify { - const char *value; - operator const char*() const { return value; } - stringify(const cstring &value) : value(value) {} -}; - -#if defined(QSTRING_H) - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -template<> struct stringify { - const QString &value; - operator const char*() const { return value.toUtf8().constData(); } - stringify(const QString &value) : value(value) {} -}; - -string::operator QString() const { - return QString::fromUtf8(*this); -} - -#endif - -// - -template stringify make_string(T value) { - return stringify(std::forward(value)); -} - -} - -#endif diff --git a/purify/nall/string/compare.hpp b/purify/nall/string/compare.hpp deleted file mode 100644 index 941c8e67..00000000 --- a/purify/nall/string/compare.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char chrlower(char c) { - return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; -} - -char chrupper(char c) { - return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; -} - -int istrcmp(const char *str1, const char *str2) { - while(*str1) { - if(chrlower(*str1) != chrlower(*str2)) break; - str1++, str2++; - } - return (int)chrlower(*str1) - (int)chrlower(*str2); -} - -bool strbegin(const char *str, const char *key) { - int i, ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str, key, ksl)); -} - -bool istrbegin(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = 0; i < ksl; i++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[i] && str[i]+0x20 != key[i])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[i] && str[i]-0x20 != key[i])return false; - } else { - if(str[i] != key[i])return false; - } - } - return true; -} - -bool strend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - return (!memcmp(str + ssl - ksl, key, ksl)); -} - -bool istrend(const char *str, const char *key) { - int ssl = strlen(str), ksl = strlen(key); - - if(ksl > ssl) return false; - for(int i = ssl - ksl, z = 0; i < ssl; i++, z++) { - if(str[i] >= 'A' && str[i] <= 'Z') { - if(str[i] != key[z] && str[i]+0x20 != key[z])return false; - } else if(str[i] >= 'a' && str[i] <= 'z') { - if(str[i] != key[z] && str[i]-0x20 != key[z])return false; - } else { - if(str[i] != key[z])return false; - } - } - return true; -} - -} - -#endif diff --git a/purify/nall/string/convert.hpp b/purify/nall/string/convert.hpp deleted file mode 100644 index f5a2a780..00000000 --- a/purify/nall/string/convert.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -char* strlower(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrlower(str[i]); - i++; - } - return str; -} - -char* strupper(char *str) { - if(!str) return 0; - int i = 0; - while(str[i]) { - str[i] = chrupper(str[i]); - i++; - } - return str; -} - -char* qstrlower(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'A' && *s <= 'Z') *s += 0x20; - s++; - } -} - -char* qstrupper(char *s) { - if(!s) return 0; - bool quoted = false; - while(*s) { - if(*s == '\"' || *s == '\'') quoted ^= 1; - if(quoted == false && *s >= 'a' && *s <= 'z') *s -= 0x20; - s++; - } -} - -char* strtr(char *dest, const char *before, const char *after) { - if(!dest || !before || !after) return dest; - int sl = strlen(dest), bsl = strlen(before), asl = strlen(after); - - if(bsl != asl || bsl == 0) return dest; //patterns must be the same length for 1:1 replace - for(unsigned i = 0; i < sl; i++) { - for(unsigned l = 0; l < bsl; l++) { - if(dest[i] == before[l]) { - dest[i] = after[l]; - break; - } - } - } - - return dest; -} - -} - -#endif diff --git a/purify/nall/string/core.hpp b/purify/nall/string/core.hpp deleted file mode 100644 index 64c9250d..00000000 --- a/purify/nall/string/core.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -static void istring(string &output) { -} - -template -static void istring(string &output, const T &value, Args&&... args) { - output.append_(make_string(value)); - istring(output, std::forward(args)...); -} - -void string::reserve(unsigned size_) { - if(size_ > size) resize(size_); -} - -void string::resize(unsigned size_) { - size = size_; - data = (char*)realloc(data, size + 1); - data[size] = 0; -} - -void string::clear(char c) { - for(unsigned n = 0; n < size; n++) data[n] = c; - data[size] = 0; -} - -bool string::empty() const { - return !*data; -} - -template string& string::assign(Args&&... args) { - *data = 0; - istring(*this, std::forward(args)...); - return *this; -} - -template string& string::append(Args&&... args) { - istring(*this, std::forward(args)...); - return *this; -} - -string& string::assign_(const char *s) { - unsigned length = strlen(s); - reserve(length); - strcpy(data, s); - return *this; -} - -string& string::append_(const char *s) { - unsigned length = strlen(data) + strlen(s); - reserve(length); - strcat(data, s); - return *this; -} - -string::operator const char*() const { - return data; -} - -char* string::operator()() { - return data; -} - -char& string::operator[](int index) { - reserve(index); - return data[index]; -} - -bool string::operator==(const char *str) const { return strcmp(data, str) == 0; } -bool string::operator!=(const char *str) const { return strcmp(data, str) != 0; } -bool string::operator< (const char *str) const { return strcmp(data, str) < 0; } -bool string::operator<=(const char *str) const { return strcmp(data, str) <= 0; } -bool string::operator> (const char *str) const { return strcmp(data, str) > 0; } -bool string::operator>=(const char *str) const { return strcmp(data, str) >= 0; } - -string& string::operator=(const string &value) { - if(&value == this) return *this; - assign(value); - return *this; -} - -string& string::operator=(string &&source) { - if(&source == this) return *this; - if(data) free(data); - size = source.size; - data = source.data; - source.data = nullptr; - source.size = 0; - return *this; -} - -template string::string(Args&&... args) { - size = 64; - data = (char*)malloc(size + 1); - *data = 0; - istring(*this, std::forward(args)...); -} - -string::string(const string &value) { - if(&value == this) return; - size = strlen(value); - data = strdup(value); -} - -string::string(string &&source) { - if(&source == this) return; - size = source.size; - data = source.data; - source.data = nullptr; -} - -string::~string() { - if(data) free(data); -} - -bool string::readfile(const string &filename) { - assign(""); - - #if !defined(_WIN32) - FILE *fp = fopen(filename, "rb"); - #else - FILE *fp = _wfopen(utf16_t(filename), L"rb"); - #endif - if(!fp) return false; - - fseek(fp, 0, SEEK_END); - unsigned size = ftell(fp); - rewind(fp); - char *fdata = new char[size + 1]; - unsigned unused = fread(fdata, 1, size, fp); - fclose(fp); - fdata[size] = 0; - assign(fdata); - delete[] fdata; - - return true; -} - -optional lstring::find(const char *key) const { - for(unsigned i = 0; i < size(); i++) { - if(operator[](i) == key) return { true, i }; - } - return { false, 0 }; -} - -string lstring::concatenate(const char *separator) const { - string output; - for(unsigned i = 0; i < size(); i++) { - output.append(operator[](i), i < size() - 1 ? separator : ""); - } - return output; -} - -template void lstring::append(const string &data, Args&&... args) { - vector::append(data); - append(std::forward(args)...); -} - -void lstring::isort() { - nall::sort(pool, objectsize, [](const string &x, const string &y) { - return istrcmp(x, y) < 0; - }); -} - -bool lstring::operator==(const lstring &source) const { - if(this == &source) return true; - if(size() != source.size()) return false; - for(unsigned n = 0; n < size(); n++) { - if(operator[](n) != source[n]) return false; - } - return true; -} - -bool lstring::operator!=(const lstring &source) const { - return !operator==(source); -} - -lstring& lstring::operator=(const lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &source) { - vector::operator=(source); - return *this; -} - -lstring& lstring::operator=(lstring &&source) { - vector::operator=(std::move(source)); - return *this; -} - -template lstring::lstring(Args&&... args) { - append(std::forward(args)...); -} - -lstring::lstring(const lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &source) { - vector::operator=(source); -} - -lstring::lstring(lstring &&source) { - vector::operator=(std::move(source)); -} - -} - -#endif diff --git a/purify/nall/string/cstring.hpp b/purify/nall/string/cstring.hpp deleted file mode 100644 index 13b508ff..00000000 --- a/purify/nall/string/cstring.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//const string: -//bind a const char* pointer to an object that has various testing functionality; -//yet lacks the memory allocation and modification functionality of the string class - -namespace nall { - -cstring::operator const char*() const { return data; } -unsigned cstring::length() const { return strlen(data); } -bool cstring::operator==(const char *s) const { return !strcmp(data, s); } -bool cstring::operator!=(const char *s) const { return strcmp(data, s); } -optional cstring::position (const char *key) const { return strpos(data, key); } -optional cstring::iposition(const char *key) const { return istrpos(data, key); } -cstring& cstring::operator=(const char *data) { this->data = data; return *this; } -cstring::cstring(const char *data) : data(data) {} -cstring::cstring() : data("") {} - -} - -#endif diff --git a/purify/nall/string/datetime.hpp b/purify/nall/string/datetime.hpp deleted file mode 100644 index 5382fdfd..00000000 --- a/purify/nall/string/datetime.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string string::date() { - time_t timestamp = ::time(0); - tm *info = localtime(×tamp); - return { - decimal<4, '0'>(1900 + info->tm_year), "-", - decimal<2, '0'>(1 + info->tm_mon), "-", - decimal<2, '0'>(info->tm_mday) - }; -} - -string string::time() { - time_t timestamp = ::time(0); - tm *info = localtime(×tamp); - return { - decimal<2, '0'>(info->tm_hour), ":", - decimal<2, '0'>(info->tm_min), ":", - decimal<2, '0'>(info->tm_sec) - }; -} - -string string::datetime() { - return {string::date(), " ", string::time()}; -} - -} - -#endif diff --git a/purify/nall/string/filename.hpp b/purify/nall/string/filename.hpp deleted file mode 100644 index 19b5f117..00000000 --- a/purify/nall/string/filename.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// "/foo/bar.c" -> "/foo/" -// "/foo/" -> "/foo/" -// "bar.c" -> "./" -inline string dir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - name[i + 1] = 0; - break; - } - if(i == 0) name = "./"; - } - return name; -} - -// "/foo/bar.c" -> "bar.c" -// "/foo/" -> "" -// "bar.c" -> "bar.c" -inline string notdir(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') { - return (const char*)name + i + 1; - } - } - return name; -} - -// "/foo/bar/baz" -> "/foo/bar/" -// "/foo/bar/" -> "/foo/" -// "/foo/bar" -> "/foo/" -inline string parentdir(string name) { - unsigned length = name.length(), paths = 0, prev, last; - for(unsigned i = 0; i < length; i++) { - if(name[i] == '/' || name[i] == '\\') { - paths++; - prev = last; - last = i; - } - } - if(last + 1 == length) last = prev; //if name ends in slash; use previous slash - if(paths > 1) name[last + 1] = 0; - return name; -} - -// "/foo/bar.c" -> "/foo/bar" -inline string basename(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') break; //file has no extension - if(name[i] == '.') { - name[i] = 0; - break; - } - } - return name; -} - -// "/foo/bar.c" -> "c" -// "/foo/bar" -> "" -inline string extension(string name) { - for(signed i = name.length(); i >= 0; i--) { - if(name[i] == '/' || name[i] == '\\') return ""; //file has no extension - if(name[i] == '.') { - return (const char*)name + i + 1; - } - } - return name; -} - -} - -#endif diff --git a/purify/nall/string/format.hpp b/purify/nall/string/format.hpp deleted file mode 100644 index 599021d1..00000000 --- a/purify/nall/string/format.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template string format(const string &value) { - if(precision == 0) return value; - - bool padright = precision >= 0; - unsigned padding = abs(precision); - - unsigned length = value.length(); - if(padding <= length) { - if(padright) return substr(value, length - padding); - else return substr(value, 0, padding); - } - - string buffer; - buffer.resize(padding); - buffer.clear(padchar); - - memcpy(buffer() + (padright ? padding - length : 0), value, length); - return buffer; -} - -template string hex(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 2); - - unsigned size = 0; - do { - unsigned n = value & 15; - buffer[size++] = n < 10 ? '0' + n : 'a' + n - 10; - value >>= 4; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -template string octal(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 3); - - unsigned size = 0; - do { - buffer[size++] = '0' + (value & 7); - value >>= 3; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -template string binary(uintmax_t value) { - string buffer; - buffer.resize(sizeof(uintmax_t) * 8); - - unsigned size = 0; - do { - buffer[size++] = '0' + (value & 1); - value >>= 1; - } while(value); - buffer[size] = 0; - buffer.reverse(); - - return format(buffer); -} - -} - -#endif diff --git a/purify/nall/string/markup/bml.hpp b/purify/nall/string/markup/bml.hpp deleted file mode 100644 index 338ca406..00000000 --- a/purify/nall/string/markup/bml.hpp +++ /dev/null @@ -1,147 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//BML v1.0 parser -//revision 0.02 - -namespace nall { -namespace BML { - -struct Node : Markup::Node { -protected: - //test to verify if a valid character for a node name - bool valid(char p) const { //A-Z, a-z, 0-9, -./ - return p - 'A' < 26u || p - 'a' < 26u || p - '0' < 10u || p - '-' < 3u; - } - - //determine indentation level, without incrementing pointer - unsigned readDepth(const char *p) { - unsigned depth = 0; - while(p[depth] == '\t' || p[depth] == ' ') depth++; - return depth; - } - - //determine indentation level - unsigned parseDepth(const char *&p) { - unsigned depth = readDepth(p); - p += depth; - return depth; - } - - //read name - void parseName(const char *&p) { - unsigned length = 0; - while(valid(p[length])) length++; - if(length == 0) throw "Invalid node name"; - name = substr(p, 0, length); - p += length; - } - - void parseData(const char *&p) { - if(*p == '=' && *(p + 1) == '\"') { - unsigned length = 2; - while(p[length] && p[length] != '\n' && p[length] != '\"') length++; - if(p[length] != '\"') throw "Unescaped value"; - data = substr(p, 2, length - 2); - p += length + 1; - } else if(*p == '=') { - unsigned length = 1; - while(p[length] && p[length] != '\n' && p[length] != '\"' && p[length] != ' ') length++; - if(p[length] == '\"') throw "Illegal character in value"; - data = substr(p, 1, length - 1); - p += length; - } else if(*p == ':') { - unsigned length = 1; - while(p[length] && p[length] != '\n') length++; - data = {substr(p, 1, length - 1), "\n"}; - p += length; - } - } - - //read all attributes for a node - void parseAttributes(const char *&p) { - while(*p && *p != '\n') { - if(*p != ' ') throw "Invalid node name"; - while(*p == ' ') p++; //skip excess spaces - - Node node; - node.attribute = true; - unsigned length = 0; - while(valid(p[length])) length++; - if(length == 0) throw "Invalid attribute name"; - node.name = substr(p, 0, length); - node.parseData(p += length); - children.append(node); - } - } - - //read a node and all of its children nodes - void parseNode(const char *&p) { - level = parseDepth(p); - parseName(p); - parseData(p); - parseAttributes(p); - if(*p++ != '\n') throw "Missing line feed"; - - while(*p) { - if(*p == '\n') { p++; continue; } - - unsigned depth = readDepth(p); - if(depth <= level) break; - - if(p[depth] == ':') { - p += depth; - unsigned length = 0; - while(p[length] && p[length] != '\n') length++; - data.append(substr(p, 1, length - 1), "\n"); - p += length; - continue; - } - - Node node; - node.parseNode(p); - children.append(node); - } - - data.rtrim<1>("\n"); - } - - //read top-level nodes - void parse(const char *p) { - while(*p) { - Node node; - node.parseNode(p); - if(node.level > 0) throw "Root nodes cannot be indented"; - children.append(node); - } - } - - friend class Document; -}; - -struct Document : Node { - string error; - - bool load(string document) { - name = "{root}", data = ""; - - try { - document.replace("\r", ""); - while(document.position("\n\n")) document.replace("\n\n", "\n"); - parse(document); - } catch(const char *perror) { - error = perror; - children.reset(); - return false; - } - return true; - } - - Document(const string &document = "") { - load(document); - } -}; - -} -} - -#endif diff --git a/purify/nall/string/markup/document.hpp b/purify/nall/string/markup/document.hpp deleted file mode 100644 index 34465a4f..00000000 --- a/purify/nall/string/markup/document.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { -namespace Markup { - -inline Node Document(const string &markup) { - if(markup.beginswith("<")) return XML::Document(markup); - return BML::Document(markup); -} - -} -} - -#endif diff --git a/purify/nall/string/markup/node.hpp b/purify/nall/string/markup/node.hpp deleted file mode 100644 index 77822373..00000000 --- a/purify/nall/string/markup/node.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//note: specific markups inherit from Markup::Node -//vector will slice any data; so derived nodes must not contain data nor virtual functions -//vector would incur a large performance penalty and greatly increased complexity - -namespace nall { -namespace Markup { - -struct Node { - string name; - string data; - bool attribute; - - bool exists() const { - return !name.empty(); - } - - string text() const { - return string{data}.strip(); - } - - intmax_t integer() const { - return numeral(text()); - } - - uintmax_t decimal() const { - return numeral(text()); - } - - void reset() { - children.reset(); - } - - bool evaluate(const string &query) const { - if(query.empty()) return true; - lstring rules = string{query}.replace(" ", "").split(","); - - for(auto &rule : rules) { - enum class Comparator : unsigned { ID, EQ, NE, LT, LE, GT, GE }; - auto comparator = Comparator::ID; - if(rule.wildcard("*!=*")) comparator = Comparator::NE; - else if(rule.wildcard("*<=*")) comparator = Comparator::LE; - else if(rule.wildcard("*>=*")) comparator = Comparator::GE; - else if(rule.wildcard ("*=*")) comparator = Comparator::EQ; - else if(rule.wildcard ("*<*")) comparator = Comparator::LT; - else if(rule.wildcard ("*>*")) comparator = Comparator::GT; - - if(comparator == Comparator::ID) { - if(find(rule).size()) continue; - return false; - } - - lstring side; - switch(comparator) { - case Comparator::EQ: side = rule.split<1> ("="); break; - case Comparator::NE: side = rule.split<1>("!="); break; - case Comparator::LT: side = rule.split<1> ("<"); break; - case Comparator::LE: side = rule.split<1>("<="); break; - case Comparator::GT: side = rule.split<1> (">"); break; - case Comparator::GE: side = rule.split<1>(">="); break; - } - - string data = text(); - if(side(0).empty() == false) { - auto result = find(side(0)); - if(result.size() == 0) return false; - data = result(0).data; - } - - switch(comparator) { - case Comparator::EQ: if(data.wildcard(side(1)) == true) continue; break; - case Comparator::NE: if(data.wildcard(side(1)) == false) continue; break; - case Comparator::LT: if(numeral(data) < numeral(side(1))) continue; break; - case Comparator::LE: if(numeral(data) <= numeral(side(1))) continue; break; - case Comparator::GT: if(numeral(data) > numeral(side(1))) continue; break; - case Comparator::GE: if(numeral(data) >= numeral(side(1))) continue; break; - } - - return false; - } - - return true; - } - - vector find(const string &query) const { - vector result; - - lstring path = query.split("/"); - string name = path.take(0), rule; - unsigned lo = 0u, hi = ~0u; - - if(name.wildcard("*[*]")) { - lstring side = name.split<1>("["); - name = side(0); - side = side(1).rtrim<1>("]").split<1>("-"); - lo = side(0).empty() ? 0u : numeral(side(0)); - hi = side(1).empty() ? ~0u : numeral(side(1)); - } - - if(name.wildcard("*(*)")) { - lstring side = name.split<1>("("); - name = side(0); - rule = side(1).rtrim<1>(")"); - } - - unsigned position = 0; - for(auto &node : children) { - if(node.name.wildcard(name) == false) continue; - if(node.evaluate(rule) == false) continue; - - bool inrange = position >= lo && position <= hi; - position++; - if(inrange == false) continue; - - if(path.size() == 0) result.append(node); - else { - auto list = node.find(path.concatenate("/")); - for(auto &item : list) result.append(item); - } - } - - return result; - } - - Node operator[](const string &query) const { - auto result = find(query); - return result(0); - } - - Node* begin() { return children.begin(); } - Node* end() { return children.end(); } - const Node* begin() const { return children.begin(); } - const Node* end() const { return children.end(); } - - Node() : attribute(false), level(0) {} - -protected: - unsigned level; - vector children; -}; - -} -} - -#endif diff --git a/purify/nall/string/markup/xml.hpp b/purify/nall/string/markup/xml.hpp deleted file mode 100644 index d3a3e15a..00000000 --- a/purify/nall/string/markup/xml.hpp +++ /dev/null @@ -1,218 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//XML v1.0 subset parser -//revision 0.03 - -namespace nall { -namespace XML { - -struct Node : Markup::Node { -protected: - inline string escape() const { - string result = data; - result.replace("&", "&"); - result.replace("<", "<"); - result.replace(">", ">"); - if(attribute == false) return result; - result.replace("\'", "'"); - result.replace("\"", """); - return result; - } - - inline bool isName(char c) const { - if(c >= 'A' && c <= 'Z') return true; - if(c >= 'a' && c <= 'z') return true; - if(c >= '0' && c <= '9') return true; - if(c == '.' || c == '_') return true; - if(c == '?') return true; - return false; - } - - inline bool isWhitespace(char c) const { - if(c == ' ' || c == '\t') return true; - if(c == '\r' || c == '\n') return true; - return false; - } - - //copy part of string from source document into target string; decode markup while copying - inline void copy(string &target, const char *source, unsigned length) { - target.reserve(length + 1); - - #if defined(NALL_XML_LITERAL) - memcpy(target(), source, length); - target[length] = 0; - return; - #endif - - char *output = target(); - while(length) { - if(*source == '&') { - if(!memcmp(source, "<", 4)) { *output++ = '<'; source += 4; length -= 4; continue; } - if(!memcmp(source, ">", 4)) { *output++ = '>'; source += 4; length -= 4; continue; } - if(!memcmp(source, "&", 5)) { *output++ = '&'; source += 5; length -= 5; continue; } - if(!memcmp(source, "'", 6)) { *output++ = '\''; source += 6; length -= 6; continue; } - if(!memcmp(source, """, 6)) { *output++ = '\"'; source += 6; length -= 6; continue; } - } - - if(attribute == false && source[0] == '<' && source[1] == '!') { - //comment - if(!memcmp(source, "", 3)) source++, length--; - source += 3, length -= 3; - continue; - } - - //CDATA - if(!memcmp(source, "", 3)) *output++ = *source++, length--; - source += 3, length -= 3; - continue; - } - } - - *output++ = *source++, length--; - } - *output = 0; - } - - inline bool parseExpression(const char *&p) { - if(*(p + 1) != '!') return false; - - //comment - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed comment"; - p += 3; - return true; - } - - //CDATA - if(!memcmp(p, "", 3)) p++; - if(!*p) throw "unclosed CDATA"; - p += 3; - return true; - } - - //DOCTYPE - if(!memcmp(p, "') counter--; - } while(counter); - return true; - } - - return false; - } - - //returns true if tag closes itself (); false if not () - inline bool parseHead(const char *&p) { - //parse name - const char *nameStart = ++p; //skip '<' - while(isName(*p)) p++; - const char *nameEnd = p; - copy(name, nameStart, nameEnd - nameStart); - if(name.empty()) throw "missing element name"; - - //parse attributes - while(*p) { - while(isWhitespace(*p)) p++; - if(!*p) throw "unclosed attribute"; - if(*p == '?' || *p == '/' || *p == '>') break; - - //parse attribute name - Node attribute; - attribute.attribute = true; - - const char *nameStart = p; - while(isName(*p)) p++; - const char *nameEnd = p; - copy(attribute.name, nameStart, nameEnd - nameStart); - if(attribute.name.empty()) throw "missing attribute name"; - - //parse attribute data - if(*p++ != '=') throw "missing attribute value"; - char terminal = *p++; - if(terminal != '\'' && terminal != '\"') throw "attribute value not quoted"; - const char *dataStart = p; - while(*p && *p != terminal) p++; - if(!*p) throw "missing attribute data terminal"; - const char *dataEnd = p++; //skip closing terminal - - copy(attribute.data, dataStart, dataEnd - dataStart); - children.append(attribute); - } - - //parse closure - if(*p == '?' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '/' && *(p + 1) == '>') { p += 2; return true; } - if(*p == '>') { p += 1; return false; } - throw "invalid element tag"; - } - - //parse element and all of its child elements - inline void parseElement(const char *&p) { - Node node; - if(node.parseHead(p) == false) node.parse(p); - children.append(node); - } - - //return true if matches this node's name - inline bool parseClosureElement(const char *&p) { - if(p[0] != '<' || p[1] != '/') return false; - p += 2; - const char *nameStart = p; - while(*p && *p != '>') p++; - if(*p != '>') throw "unclosed closure element"; - const char *nameEnd = p++; - if(memcmp(name, nameStart, nameEnd - nameStart)) throw "closure element name mismatch"; - return true; - } - - //parse contents of an element - inline void parse(const char *&p) { - const char *dataStart = p, *dataEnd = p; - - while(*p) { - while(*p && *p != '<') p++; - if(!*p) break; - dataEnd = p; - if(parseClosureElement(p) == true) break; - if(parseExpression(p) == true) continue; - parseElement(p); - } - - copy(data, dataStart, dataEnd - dataStart); - } -}; - -struct Document : Node { - string error; - - inline bool load(const char *document) { - if(document == nullptr) return false; - reset(); - try { - parse(document); - } catch(const char *error) { - reset(); - this->error = error; - return false; - } - return true; - } - - inline Document() {} - inline Document(const char *document) { load(document); } -}; - -} -} - -#endif diff --git a/purify/nall/string/math-fixed-point.hpp b/purify/nall/string/math-fixed-point.hpp deleted file mode 100644 index a61b23f3..00000000 --- a/purify/nall/string/math-fixed-point.hpp +++ /dev/null @@ -1,166 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace fixedpoint { - -static nall::function eval_fallback; - -static intmax_t eval_integer(const char *& s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - return value; - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static intmax_t eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - intmax_t value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 13); - else if(x == '~') value = ~eval(++s, 13); - else if(x == '+') value = +eval(++s, 13); - else if(x == '-') value = -eval(++s, 13); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 13) break; - if(x == '*') { value *= eval(++s, 13); continue; } - if(x == '/') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value /= result; continue; } - if(x == '%') { intmax_t result = eval(++s, 13); if(result == 0) throw "division by zero"; value %= result; continue; } - - if(depth >= 12) break; - if(x == '+') { value += eval(++s, 12); continue; } - if(x == '-') { value -= eval(++s, 12); continue; } - - if(depth >= 11) break; - if(x == '<' && y == '<') { value <<= eval(++++s, 11); continue; } - if(x == '>' && y == '>') { value >>= eval(++++s, 11); continue; } - - if(depth >= 10) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 10); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 10); continue; } - if(x == '<') { value = value < eval(++s, 10); continue; } - if(x == '>') { value = value > eval(++s, 10); continue; } - - if(depth >= 9) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 9); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 9); continue; } - - if(depth >= 8) break; - if(x == '&' && y != '&') { value = value & eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '^' && y != '^') { value = value ^ eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '|' && y != '|') { value = value | eval(++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - intmax_t lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - intmax_t rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, intmax_t &result) { - try { - result = eval(s); - return true; - } catch(const char*) { - result = 0; - return false; - } -} - -static intmax_t parse(const char *s) { - try { - intmax_t result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/purify/nall/string/math-floating-point.hpp b/purify/nall/string/math-floating-point.hpp deleted file mode 100644 index 43a2f0f4..00000000 --- a/purify/nall/string/math-floating-point.hpp +++ /dev/null @@ -1,157 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace floatingpoint { - -static nall::function eval_fallback; - -static double eval_integer(const char *&s) { - if(!*s) throw "unrecognized integer"; - intmax_t value = 0, radix = 0, x = *s, y = *(s + 1); - - //hexadecimal - if(x == '0' && (y == 'X' || y == 'x')) { - s += 2; - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 16 + (*s++ - '0'); continue; } - if(*s >= 'A' && *s <= 'F') { value = value * 16 + (*s++ - 'A' + 10); continue; } - if(*s >= 'a' && *s <= 'f') { value = value * 16 + (*s++ - 'a' + 10); continue; } - return value; - } - } - - //binary - if(x == '0' && (y == 'B' || y == 'b')) { - s += 2; - while(true) { - if(*s == '0' || *s == '1') { value = value * 2 + (*s++ - '0'); continue; } - return value; - } - } - - //octal (or decimal '0') - if(x == '0' && y != '.') { - s += 1; - while(true) { - if(*s >= '0' && *s <= '7') { value = value * 8 + (*s++ - '0'); continue; } - return value; - } - } - - //decimal - if(x >= '0' && x <= '9') { - while(true) { - if(*s >= '0' && *s <= '9') { value = value * 10 + (*s++ - '0'); continue; } - if(*s == '.') { s++; break; } - return value; - } - //floating-point - while(true) { - if(*s >= '0' && *s <= '9') { radix = radix * 10 + (*s++ - '0'); continue; } - return atof(nall::string{ nall::decimal(value), ".", nall::decimal(radix) }); - } - } - - //char - if(x == '\'' && y != '\'') { - s += 1; - while(true) { - value = value * 256 + *s++; - if(*s == '\'') { s += 1; return value; } - if(!*s) throw "mismatched char"; - } - } - - throw "unrecognized integer"; -} - -static double eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) throw "unrecognized token"; - double value = 0, x = *s, y = *(s + 1); - - if(*s == '(') { - value = eval(++s, 1); - if(*s++ != ')') throw "mismatched group"; - } - - else if(x == '!') value = !eval(++s, 9); - else if(x == '+') value = +eval(++s, 9); - else if(x == '-') value = -eval(++s, 9); - - else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); - - else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing - - else throw "unrecognized token"; - - while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace - if(!*s) break; - x = *s, y = *(s + 1); - - if(depth >= 9) break; - if(x == '*') { value *= eval(++s, 9); continue; } - if(x == '/') { double result = eval(++s, 9); if(result == 0.0) throw "division by zero"; value /= result; continue; } - - if(depth >= 8) break; - if(x == '+') { value += eval(++s, 8); continue; } - if(x == '-') { value -= eval(++s, 8); continue; } - - if(depth >= 7) break; - if(x == '<' && y == '=') { value = value <= eval(++++s, 7); continue; } - if(x == '>' && y == '=') { value = value >= eval(++++s, 7); continue; } - if(x == '<') { value = value < eval(++s, 7); continue; } - if(x == '>') { value = value > eval(++s, 7); continue; } - - if(depth >= 6) break; - if(x == '=' && y == '=') { value = value == eval(++++s, 6); continue; } - if(x == '!' && y == '=') { value = value != eval(++++s, 6); continue; } - - if(depth >= 5) break; - if(x == '&' && y == '&') { value = eval(++++s, 5) && value; continue; } - - if(depth >= 4) break; - if(x == '^' && y == '^') { value = (!eval(++++s, 4) != !value); continue; } - - if(depth >= 3) break; - if(x == '|' && y == '|') { value = eval(++++s, 3) || value; continue; } - - if(x == '?') { - double lhs = eval(++s, 2); - if(*s != ':') throw "mismatched ternary"; - double rhs = eval(++s, 2); - value = value ? lhs : rhs; - continue; - } - if(depth >= 2) break; - - if(depth > 0 && x == ')') break; - - throw "unrecognized token"; - } - - return value; -} - -static bool eval(const char *s, double &result) { - try { - result = eval(s); - return true; - } catch(const char*e) { - result = 0; - return false; - } -} - -static double parse(const char *s) { - try { - double result = eval(s); - return result; - } catch(const char *) { - return 0; - } -} - -} - -#endif diff --git a/purify/nall/string/platform.hpp b/purify/nall/string/platform.hpp deleted file mode 100644 index 90b6d6b8..00000000 --- a/purify/nall/string/platform.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string activepath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - auto unused = _wgetcwd(path, PATH_MAX); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - auto unused = getcwd(path, PATH_MAX); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string realpath(const string &name) { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - if(::realpath(name, path)) result = path; - #endif - if(result.empty()) result = {activepath(), name}; - return result; -} - -// /home/username/ -// c:/users/username/ -string userpath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - SHGetFolderPathW(0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, 0, 0, path); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - char path[PATH_MAX] = ""; - struct passwd *userinfo = getpwuid(getuid()); - if(userinfo) strcpy(path, userinfo->pw_dir); - result = path; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -// /home/username/.config/ -// c:/users/username/appdata/roaming/ -string configpath() { - string result; - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path); - result = (const char*)utf8_t(path); - result.transform("\\", "/"); - #else - result = {userpath(), ".config/"}; - #endif - if(result.empty()) result = "."; - if(result.endswith("/") == false) result.append("/"); - return result; -} - -string temppath() { - #ifdef _WIN32 - wchar_t path[PATH_MAX] = L""; - GetTempPathW(PATH_MAX, path); - string result = (const char*)utf8_t(path); - result.transform("\\", "/"); - return result; - #else - return "/tmp/"; - #endif -} - -} - -#endif diff --git a/purify/nall/string/replace.hpp b/purify/nall/string/replace.hpp deleted file mode 100644 index 2bd1412f..00000000 --- a/purify/nall/string/replace.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -string& string::ureplace(const char *key, const char *token) { - if(!key || !*key) return *this; - enum : unsigned { limit = Limit ? Limit : ~0u }; - - const char *p = data; - unsigned counter = 0, keyLength = 0; - - while(*p) { - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter++; p += n; keyLength = n; break; } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - if(counter == 0) return *this; - if(Limit) counter = min(counter, Limit); - - char *t = data, *base; - unsigned tokenLength = strlen(token); - if(tokenLength > keyLength) { - t = base = strdup(data); - reserve((unsigned)(p - data) + ((tokenLength - keyLength) * counter)); - } - char *o = data; - - while(*t && counter) { - if(quotecopy(o, t)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { counter--; memcpy(o, token, tokenLength); t += keyLength; o += tokenLength; break; } - if(!chrequal(key[n], t[n])) { *o++ = *t++; break; } - } - } - do *o++ = *t; while(*t++); - if(tokenLength > keyLength) free(base); - - return *this; -} - -template string &string::replace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::ireplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::qreplace(const char *key, const char *token) { return ureplace(key, token); } -template string &string::iqreplace(const char *key, const char *token) { return ureplace(key, token); } - -}; - -#endif diff --git a/purify/nall/string/split.hpp b/purify/nall/string/split.hpp deleted file mode 100644 index bb12a91b..00000000 --- a/purify/nall/string/split.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template lstring& lstring::usplit(const char *key, const char *base) { - reset(); - if(!key || !*key) return *this; - - const char *p = base; - - while(*p) { - if(Limit) if(size() >= Limit) break; - if(quoteskip(p)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) { - append(substr(base, 0, p - base)); - p += n; - base = p; - break; - } - if(!chrequal(key[n], p[n])) { p++; break; } - } - } - - append(base); - return *this; -} - -template lstring& lstring::split(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::isplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::qsplit(const char *key, const char *src) { return usplit(key, src); } -template lstring& lstring::iqsplit(const char *key, const char *src) { return usplit(key, src); } - -}; - -#endif diff --git a/purify/nall/string/static.hpp b/purify/nall/string/static.hpp deleted file mode 100644 index ca521cb0..00000000 --- a/purify/nall/string/static.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -string string::read(const string &filename) { - string data; - data.readfile(filename); - return data; -} - -} - -#endif diff --git a/purify/nall/string/strm.hpp b/purify/nall/string/strm.hpp deleted file mode 100644 index 21d05652..00000000 --- a/purify/nall/string/strm.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -// -//strmcpy, strmcat created by byuu -// - -//return = strlen(target) -unsigned strmcpy(char *target, const char *source, unsigned length) { - const char *origin = target; - if(length) { - while(*source && --length) *target++ = *source++; - *target = 0; - } - return target - origin; -} - -//return = strlen(target) -unsigned strmcat(char *target, const char *source, unsigned length) { - const char *origin = target; - while(*target && length) target++, length--; - return (target - origin) + strmcpy(target, source, length); -} - -//return = true when all of source was copied -bool strccpy(char *target, const char *source, unsigned length) { - return !source[strmcpy(target, source, length)]; -} - -//return = true when all of source was copied -bool strccat(char *target, const char *source, unsigned length) { - while(*target && length) target++, length--; - return !source[strmcpy(target, source, length)]; -} - -//return = reserved for future use -void strpcpy(char *&target, const char *source, unsigned &length) { - unsigned offset = strmcpy(target, source, length); - target += offset, length -= offset; -} - -} - -#endif diff --git a/purify/nall/string/strpos.hpp b/purify/nall/string/strpos.hpp deleted file mode 100644 index fe563a6c..00000000 --- a/purify/nall/string/strpos.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -//usage example: -//if(auto position = strpos(str, key)) print(position(), "\n"); -//prints position of key within str; but only if it is found - -namespace nall { - -template -optional ustrpos(const char *str, const char *key) { - const char *base = str; - - while(*str) { - if(quoteskip(str)) continue; - for(unsigned n = 0;; n++) { - if(key[n] == 0) return { true, (unsigned)(str - base) }; - if(str[n] == 0) return { false, 0 }; - if(!chrequal(str[n], key[n])) break; - } - str++; - } - - return { false, 0 }; -} - -optional strpos(const char *str, const char *key) { return ustrpos(str, key); } -optional istrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional qstrpos(const char *str, const char *key) { return ustrpos(str, key); } -optional iqstrpos(const char *str, const char *key) { return ustrpos(str, key); } - -} - -#endif diff --git a/purify/nall/string/trim.hpp b/purify/nall/string/trim.hpp deleted file mode 100644 index 3e0c914f..00000000 --- a/purify/nall/string/trim.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -//limit defaults to zero, which will underflow on first compare; equivalent to no limit -template char* ltrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strbegin(str, key)) { - char *dest = str, *src = str + strlen(key); - while(true) { - *dest = *src++; - if(!*dest) break; - dest++; - } - if(--limit == 0) break; - } - return str; -} - -template char* rtrim(char *str, const char *key) { - unsigned limit = Limit; - if(!key || !*key) return str; - while(strend(str, key)) { - str[strlen(str) - strlen(key)] = 0; - if(--limit == 0) break; - } - return str; -} - -template char* trim(char *str, const char *key, const char *rkey) { - if(rkey) return ltrim(rtrim(str, rkey), key); - return ltrim(rtrim(str, key), key); -} - -//remove whitespace characters from both left and right sides of string -char* strip(char *s) { - signed n = 0, p = 0; - while(s[n]) { - if(s[n] != ' ' && s[n] != '\t' && s[n] != '\r' && s[n] != '\n') break; - n++; - } - while(s[n]) s[p++] = s[n++]; - s[p--] = 0; - while(p >= 0) { - if(s[p] != ' ' && s[p] != '\t' && s[p] != '\r' && s[p] != '\n') break; - p--; - } - s[++p] = 0; - return s; -} - -} - -#endif diff --git a/purify/nall/string/utf8.hpp b/purify/nall/string/utf8.hpp deleted file mode 100644 index 77397bf2..00000000 --- a/purify/nall/string/utf8.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -struct UTF8 { - unsigned size; //size of encoded codepoint - uint64_t data; //encoded codepoint - unsigned codepoint; //decoded codepoint -}; - -inline UTF8 utf8_read(const char *s) { - UTF8 utf8; - - if((*s & 0xfe) == 0xfc) utf8.size = 6; - else if((*s & 0xfc) == 0xf8) utf8.size = 5; - else if((*s & 0xf8) == 0xf0) utf8.size = 4; - else if((*s & 0xf0) == 0xe0) utf8.size = 3; - else if((*s & 0xe0) == 0xc0) utf8.size = 2; - else utf8.size = 1; - - utf8.data = 0; - for(unsigned n = 0; n < utf8.size; n++) { - utf8.data = (utf8.data << 8) | (uint8_t)s[n]; - } - - static uint8_t mask[] = { 0, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; - utf8.codepoint = s[0] & mask[utf8.size]; - for(unsigned n = 1; n < utf8.size; n++) { - utf8.codepoint = (utf8.codepoint << 6) | (s[n] & 0x3f); - } - - return utf8; -} - -inline void utf8_write(char *s, const UTF8 &utf8) { - for(signed n = utf8.size - 1, shift = 0; n >= 0; n--, shift += 8) { - s[n] = utf8.data >> shift; - } -} - -} - -#endif diff --git a/purify/nall/string/utility.hpp b/purify/nall/string/utility.hpp deleted file mode 100644 index 657383f8..00000000 --- a/purify/nall/string/utility.hpp +++ /dev/null @@ -1,242 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template -bool chrequal(char x, char y) { - if(Insensitive) return chrlower(x) == chrlower(y); - return x == y; -} - -template -bool quoteskip(T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - while(*p && *p++ != x); - } - return true; -} - -template -bool quotecopy(char *&t, T *&p) { - if(Quoted == false) return false; - if(*p != '\'' && *p != '\"') return false; - - while(*p == '\'' || *p == '\"') { - char x = *p++; - *t++ = x; - while(*p && *p != x) *t++ = *p++; - *t++ = *p++; - } - return true; -} - -string substr(const char *src, unsigned start, unsigned length) { - string dest; - if(length == ~0u) { - //copy entire string - dest.reserve(strlen(src + start) + 1); - strcpy(dest(), src + start); - } else { - //copy partial string - dest.reserve(length + 1); - strmcpy(dest(), src + start, length + 1); - } - return dest; -} - -string sha256(const uint8_t *data, unsigned size) { - sha256_ctx sha; - uint8_t hash[32]; - sha256_init(&sha); - sha256_chunk(&sha, data, size); - sha256_final(&sha); - sha256_hash(&sha, hash); - string result; - for(auto &byte : hash) result.append(hex<2>(byte)); - return result; -} - -/* cast.hpp arithmetic -> string */ - -char* integer(char *result, intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -char* decimal(char *result, uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - - for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y]; - result[size] = 0; - return result; -} - -/* general-purpose arithmetic -> string */ - -template string integer(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string linteger(intmax_t value) { - bool negative = value < 0; - if(negative) value = -value; - - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - if(negative) buffer[size++] = '-'; -//buffer[size++] = negative ? '-' : '+'; - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string decimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -template string ldecimal(uintmax_t value) { - char buffer[64]; - unsigned size = 0; - - do { - unsigned n = value % 10; - buffer[size++] = '0' + n; - value /= 10; - } while(value); - buffer[size] = 0; - - unsigned length = (length_ == 0 ? size : length_); - char result[length + 1]; - memset(result, padding, length); - result[length] = 0; - - for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) { - result[x] = buffer[y]; - } - - return (const char*)result; -} - -//using sprintf is certainly not the most ideal method to convert -//a double to a string ... but attempting to parse a double by -//hand, digit-by-digit, results in subtle rounding errors. -unsigned fp(char *str, long double value) { - char buffer[256]; - #ifdef _WIN32 - //Windows C-runtime does not support long double via sprintf() - sprintf(buffer, "%f", (double)value); - #else - sprintf(buffer, "%Lf", value); - #endif - - //remove excess 0's in fraction (2.500000 -> 2.5) - for(char *p = buffer; *p; p++) { - if(*p == '.') { - char *p = buffer + strlen(buffer) - 1; - while(*p == '0') { - if(*(p - 1) != '.') *p = 0; //... but not for eg 1.0 -> 1. - p--; - } - break; - } - } - - unsigned length = strlen(buffer); - if(str) strcpy(str, buffer); - return length + 1; -} - -string fp(long double value) { - string temp; - temp.reserve(fp(0, value)); - fp(temp(), value); - return temp; -} - -} - -#endif diff --git a/purify/nall/string/variadic.hpp b/purify/nall/string/variadic.hpp deleted file mode 100644 index c43bfe86..00000000 --- a/purify/nall/string/variadic.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -template inline void print(Args&&... args) { - printf("%s", (const char*)string(std::forward(args)...)); -} - -} - -#endif diff --git a/purify/nall/string/wildcard.hpp b/purify/nall/string/wildcard.hpp deleted file mode 100644 index 9d2359d5..00000000 --- a/purify/nall/string/wildcard.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -bool wildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && *s != *p) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || *p == *s) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -bool iwildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && chrlower(*s) != chrlower(*p)) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || chrlower(*p) == chrlower(*s)) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(const char *s, const char *p) { - while(*s) { - if(*p == '*') { - while(*s) if(tokenize(s++, p + 1)) return true; - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') p++; - return !*p; -} - -inline bool tokenize(lstring &list, const char *s, const char *p) { - while(*s) { - if(*p == '*') { - const char *b = s; - while(*s) { - if(tokenize(list, s++, p + 1)) { - list.prepend(substr(b, 0, --s - b)); - return true; - } - } - list.prepend(b); - return !*++p; - } - if(*s++ != *p++) return false; - } - while(*p == '*') { list.prepend(s); p++; } - return !*p; -} - -} - -#endif diff --git a/purify/nall/string/wrapper.hpp b/purify/nall/string/wrapper.hpp deleted file mode 100644 index 08aa98b3..00000000 --- a/purify/nall/string/wrapper.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifdef NALL_STRING_INTERNAL_HPP - -namespace nall { - -unsigned string::length() const { return strlen(data); } -unsigned string::capacity() const { return size; } - -template lstring string::split(const char *key) const { lstring result; result.split(key, data); return result; } -template lstring string::isplit(const char *key) const { lstring result; result.isplit(key, data); return result; } -template lstring string::qsplit(const char *key) const { lstring result; result.qsplit(key, data); return result; } -template lstring string::iqsplit(const char *key) const { lstring result; result.iqsplit(key, data); return result; } - -bool string::equals(const char *str) const { return !strcmp(data, str); } -bool string::iequals(const char *str) const { return !istrcmp(data, str); } - -bool string::wildcard(const char *str) const { return nall::wildcard(data, str); } -bool string::iwildcard(const char *str) const { return nall::iwildcard(data, str); } - -bool string::beginswith(const char *str) const { return strbegin(data, str); } -bool string::ibeginswith(const char *str) const { return istrbegin(data, str); } - -bool string::endswith(const char *str) const { return strend(data, str); } -bool string::iendswith(const char *str) const { return istrend(data, str); } - -string& string::lower() { nall::strlower(data); return *this; } -string& string::upper() { nall::strupper(data); return *this; } -string& string::qlower() { nall::qstrlower(data); return *this; } -string& string::qupper() { nall::qstrupper(data); return *this; } -string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } -string& string::reverse() { - unsigned length = strlen(data), pivot = length >> 1; - for(signed x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(data[x], data[y]); - return *this; -} - -template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -template string& string::trim(const char *key, const char *rkey) { nall::trim (data, key, rkey); return *this; } -string& string::strip() { nall::strip(data); return *this; } - -optional string::position(const char *key) const { return strpos(data, key); } -optional string::iposition(const char *key) const { return istrpos(data, key); } -optional string::qposition(const char *key) const { return qstrpos(data, key); } -optional string::iqposition(const char *key) const { return iqstrpos(data, key); } - -} - -#endif diff --git a/purify/nall/thread.hpp b/purify/nall/thread.hpp deleted file mode 100644 index de894f2d..00000000 --- a/purify/nall/thread.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef NALL_THREAD_HPP -#define NALL_THREAD_HPP - -#include -#include -#include - -#if defined(PLATFORM_X) || defined(PLATFORM_OSX) - #include - -namespace nall { - void* thread_entry_point(void*); - - struct thread { - thread(function entryPoint) : entryPoint(entryPoint), completed(false), dead(false) { - initialize(); - pthread_create(&pthread, NULL, thread_entry_point, (void*)this); - } - - ~thread() { - join(); - } - - bool active() const { - return completed == false; - } - - void join() { - if(dead) return; - dead = true; - pthread_join(pthread, NULL); - } - - static bool primary() { - initialize(); - return pthread_equal(primaryThread(), pthread_self()); - } - - private: - pthread_t pthread; - function entryPoint; - volatile bool completed, dead; - friend void* thread_entry_point(void*); - - static void initialize() { - static bool initialized = false; - if(initialized) return; - initialized = true; - primaryThread() = pthread_self(); - } - - static pthread_t& primaryThread() { - static pthread_t thread; - return thread; - } - }; - - void* thread_entry_point(void *parameter) { - thread *context = (thread*)parameter; - context->entryPoint(); - context->completed = true; - pthread_exit(0); - } -} -#elif defined(PLATFORM_WIN) -namespace nall { - inline DWORD WINAPI thread_entry_point(LPVOID); - - struct thread { - thread(function entryPoint) : entryPoint(entryPoint), completed(false), dead(false) { - initialize(); - hthread = CreateThread(NULL, 0, thread_entry_point, (void*)this, 0, NULL); - } - - ~thread() { - join(); - } - - bool active() const { - return completed == false; - } - - void join() { - if(dead) return; - dead = true; - WaitForSingleObject(hthread, INFINITE); - CloseHandle(hthread); - } - - static bool primary() { - initialize(); - return primaryThread() == GetCurrentThreadId(); - } - - private: - HANDLE hthread; - function entryPoint; - volatile bool completed, dead; - friend DWORD WINAPI thread_entry_point(LPVOID); - - static void initialize() { - static bool initialized = false; - if(initialized) return; - initialized = true; - primaryThread() = GetCurrentThreadId(); - } - - static DWORD& primaryThread() { - static DWORD thread; - return thread; - } - }; - - inline DWORD WINAPI thread_entry_point(LPVOID parameter) { - thread *context = (thread*)parameter; - context->entryPoint(); - context->completed = true; - return 0; - } -} -#endif - -#endif diff --git a/purify/nall/traits.hpp b/purify/nall/traits.hpp deleted file mode 100644 index 6a140c2b..00000000 --- a/purify/nall/traits.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef NALL_TRAITS_HPP -#define NALL_TRAITS_HPP - -#include - -namespace nall { - -template class has_default_constructor { - template class receive_size{}; - template static signed sfinae(receive_size*); - template static char sfinae(...); - -public: - enum : bool { value = sizeof(sfinae(0)) == sizeof(signed) }; -}; - -template struct enable_if { typedef T type; }; -template struct enable_if {}; - -template struct type_if { typedef T type; }; -template struct type_if { typedef F type; }; - -template struct static_and { enum { value = false }; }; -template<> struct static_and { enum { value = true }; }; - -template struct static_or { enum { value = false }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; -template<> struct static_or { enum { value = true }; }; - -} - -#endif diff --git a/purify/nall/udl.hpp b/purify/nall/udl.hpp deleted file mode 100644 index 30ceefb3..00000000 --- a/purify/nall/udl.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NALL_UDL_HPP -#define NALL_UDL_HPP - -//user-defined literals - -#include -#include - -namespace nall { - constexpr inline uintmax_t operator"" _b(const char *n) { return binary(n); } - - //convert to bytes - constexpr inline uintmax_t operator"" _kb(unsigned long long n) { return 1024 * n; } - constexpr inline uintmax_t operator"" _mb(unsigned long long n) { return 1024 * 1024 * n; } - constexpr inline uintmax_t operator"" _gb(unsigned long long n) { return 1024 * 1024 * 1024 * n; } - - //convert to bits - constexpr inline uintmax_t operator"" _kbit(unsigned long long n) { return 1024 * n / 8; } - constexpr inline uintmax_t operator"" _mbit(unsigned long long n) { return 1024 * 1024 * n / 8; } - constexpr inline uintmax_t operator"" _gbit(unsigned long long n) { return 1024 * 1024 * 1024 * n / 8; } - - //convert to hz - constexpr inline uintmax_t operator"" _khz(long double n) { return n * 1000; } - constexpr inline uintmax_t operator"" _mhz(long double n) { return n * 1000000; } - constexpr inline uintmax_t operator"" _ghz(long double n) { return n * 1000000000; } -} - -#endif diff --git a/purify/nall/unzip.hpp b/purify/nall/unzip.hpp deleted file mode 100644 index 5a7935f6..00000000 --- a/purify/nall/unzip.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef NALL_UNZIP_HPP -#define NALL_UNZIP_HPP - -#include -#include -#include -#include - -namespace nall { - -struct unzip { - struct File { - string name; - const uint8_t *data; - unsigned size; - unsigned csize; - unsigned cmode; //0 = uncompressed, 8 = deflate - unsigned crc32; - }; - - inline bool open(const string &filename) { - close(); - if(fm.open(filename, filemap::mode::read) == false) return false; - if(open(fm.data(), fm.size()) == false) { - fm.close(); - return false; - } - return true; - } - - inline bool open(const uint8_t *data, unsigned size) { - if(size < 22) return false; - - filedata = data; - filesize = size; - - file.reset(); - - const uint8_t *footer = data + size - 22; - while(true) { - if(footer <= data + 22) return false; - if(read(footer, 4) == 0x06054b50) { - unsigned commentlength = read(footer + 20, 2); - if(footer + 22 + commentlength == data + size) break; - } - footer--; - } - const uint8_t *directory = data + read(footer + 16, 4); - - while(true) { - unsigned signature = read(directory + 0, 4); - if(signature != 0x02014b50) break; - - File file; - file.cmode = read(directory + 10, 2); - file.crc32 = read(directory + 16, 4); - file.csize = read(directory + 20, 4); - file.size = read(directory + 24, 4); - - unsigned namelength = read(directory + 28, 2); - unsigned extralength = read(directory + 30, 2); - unsigned commentlength = read(directory + 32, 2); - - char *filename = new char[namelength + 1]; - memcpy(filename, directory + 46, namelength); - filename[namelength] = 0; - file.name = filename; - delete[] filename; - - unsigned offset = read(directory + 42, 4); - unsigned offsetNL = read(data + offset + 26, 2); - unsigned offsetEL = read(data + offset + 28, 2); - file.data = data + offset + 30 + offsetNL + offsetEL; - - directory += 46 + namelength + extralength + commentlength; - - this->file.append(file); - } - - return true; - } - - inline vector extract(File &file) { - vector buffer; - - if(file.cmode == 0) { - buffer.resize(file.size); - memcpy(buffer.data(), file.data, file.size); - } - - if(file.cmode == 8) { - buffer.resize(file.size); - if(inflate(buffer.data(), buffer.size(), file.data, file.csize) == false) { - buffer.reset(); - } - } - - return buffer; - } - - inline void close() { - if(fm.open()) fm.close(); - } - - ~unzip() { - close(); - } - -protected: - filemap fm; - const uint8_t *filedata; - unsigned filesize; - - unsigned read(const uint8_t *data, unsigned size) { - unsigned result = 0, shift = 0; - while(size--) { result |= *data++ << shift; shift += 8; } - return result; - } - -public: - vector file; -}; - -} - -#endif diff --git a/purify/nall/ups.hpp b/purify/nall/ups.hpp deleted file mode 100644 index ffcdb2d7..00000000 --- a/purify/nall/ups.hpp +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef NALL_UPS_HPP -#define NALL_UPS_HPP - -#include -#include -#include -#include - -namespace nall { - -struct ups { - enum class result : unsigned { - unknown, - success, - patch_unwritable, - patch_invalid, - source_invalid, - target_invalid, - target_too_small, - patch_checksum_invalid, - source_checksum_invalid, - target_checksum_invalid, - }; - - function progress; - - result create( - const uint8_t *sourcedata, unsigned sourcelength, - const uint8_t *targetdata, unsigned targetlength, - const char *patchfilename - ) { - source_data = (uint8_t*)sourcedata, target_data = (uint8_t*)targetdata; - source_length = sourcelength, target_length = targetlength; - source_offset = target_offset = 0; - source_checksum = target_checksum = patch_checksum = ~0; - - if(patch_file.open(patchfilename, file::mode::write) == false) return result::patch_unwritable; - - patch_write('U'); - patch_write('P'); - patch_write('S'); - patch_write('1'); - encode(source_length); - encode(target_length); - - unsigned output_length = source_length > target_length ? source_length : target_length; - unsigned relative = 0; - for(unsigned offset = 0; offset < output_length;) { - uint8_t x = source_read(); - uint8_t y = target_read(); - - if(x == y) { - offset++; - continue; - } - - encode(offset++ - relative); - patch_write(x ^ y); - - while(true) { - if(offset >= output_length) { - patch_write(0x00); - break; - } - - x = source_read(); - y = target_read(); - offset++; - patch_write(x ^ y); - if(x == y) break; - } - - relative = offset; - } - - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(source_checksum >> (i * 8)); - for(unsigned i = 0; i < 4; i++) patch_write(target_checksum >> (i * 8)); - uint32_t patch_result_checksum = ~patch_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(patch_result_checksum >> (i * 8)); - - patch_file.close(); - return result::success; - } - - result apply( - const uint8_t *patchdata, unsigned patchlength, - const uint8_t *sourcedata, unsigned sourcelength, - uint8_t *targetdata, unsigned &targetlength - ) { - patch_data = (uint8_t*)patchdata, source_data = (uint8_t*)sourcedata, target_data = targetdata; - patch_length = patchlength, source_length = sourcelength, target_length = targetlength; - patch_offset = source_offset = target_offset = 0; - patch_checksum = source_checksum = target_checksum = ~0; - - if(patch_length < 18) return result::patch_invalid; - if(patch_read() != 'U') return result::patch_invalid; - if(patch_read() != 'P') return result::patch_invalid; - if(patch_read() != 'S') return result::patch_invalid; - if(patch_read() != '1') return result::patch_invalid; - - unsigned source_read_length = decode(); - unsigned target_read_length = decode(); - - if(source_length != source_read_length && source_length != target_read_length) return result::source_invalid; - targetlength = (source_length == source_read_length ? target_read_length : source_read_length); - if(target_length < targetlength) return result::target_too_small; - target_length = targetlength; - - while(patch_offset < patch_length - 12) { - unsigned length = decode(); - while(length--) target_write(source_read()); - while(true) { - uint8_t patch_xor = patch_read(); - target_write(patch_xor ^ source_read()); - if(patch_xor == 0) break; - } - } - while(source_offset < source_length) target_write(source_read()); - while(target_offset < target_length) target_write(source_read()); - - uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0; - for(unsigned i = 0; i < 4; i++) source_read_checksum |= patch_read() << (i * 8); - for(unsigned i = 0; i < 4; i++) target_read_checksum |= patch_read() << (i * 8); - uint32_t patch_result_checksum = ~patch_checksum; - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_read_checksum |= patch_read() << (i * 8); - - if(patch_result_checksum != patch_read_checksum) return result::patch_invalid; - if(source_checksum == source_read_checksum && source_length == source_read_length) { - if(target_checksum == target_read_checksum && target_length == target_read_length) return result::success; - return result::target_invalid; - } else if(source_checksum == target_read_checksum && source_length == target_read_length) { - if(target_checksum == source_read_checksum && target_length == source_read_length) return result::success; - return result::target_invalid; - } else { - return result::source_invalid; - } - } - -private: - uint8_t *patch_data, *source_data, *target_data; - unsigned patch_length, source_length, target_length; - unsigned patch_offset, source_offset, target_offset; - unsigned patch_checksum, source_checksum, target_checksum; - file patch_file; - - uint8_t patch_read() { - if(patch_offset < patch_length) { - uint8_t n = patch_data[patch_offset++]; - patch_checksum = crc32_adjust(patch_checksum, n); - return n; - } - return 0x00; - } - - uint8_t source_read() { - if(source_offset < source_length) { - uint8_t n = source_data[source_offset++]; - source_checksum = crc32_adjust(source_checksum, n); - return n; - } - return 0x00; - } - - uint8_t target_read() { - uint8_t result = 0x00; - if(target_offset < target_length) { - result = target_data[target_offset]; - target_checksum = crc32_adjust(target_checksum, result); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - return result; - } - - void patch_write(uint8_t n) { - patch_file.write(n); - patch_checksum = crc32_adjust(patch_checksum, n); - } - - void target_write(uint8_t n) { - if(target_offset < target_length) { - target_data[target_offset] = n; - target_checksum = crc32_adjust(target_checksum, n); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - } - - void encode(uint64_t offset) { - while(true) { - uint64_t x = offset & 0x7f; - offset >>= 7; - if(offset == 0) { - patch_write(0x80 | x); - break; - } - patch_write(x); - offset--; - } - } - - uint64_t decode() { - uint64_t offset = 0, shift = 1; - while(true) { - uint8_t x = patch_read(); - offset += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - offset += shift; - } - return offset; - } -}; - -} - -#endif diff --git a/purify/nall/utility.hpp b/purify/nall/utility.hpp deleted file mode 100644 index b3c1e5aa..00000000 --- a/purify/nall/utility.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NALL_UTILITY_HPP -#define NALL_UTILITY_HPP - -#include -#include - -namespace nall { - template struct base_from_member { - T value; - base_from_member(T value_) : value(value_) {} - }; - - template class optional { - public: - bool valid; - T value; - public: - inline operator bool() const { return valid; } - inline const T& operator()() const { if(!valid) throw; return value; } - inline optional& operator=(const optional &source) { valid = source.valid; value = source.value; return *this; } - inline optional() : valid(false) {} - inline optional(bool valid, const T &value) : valid(valid), value(value) {} - }; - - template inline T* allocate(unsigned size, const T &value) { - T *array = new T[size]; - for(unsigned i = 0; i < size; i++) array[i] = value; - return array; - } -} - -#endif diff --git a/purify/nall/varint.hpp b/purify/nall/varint.hpp deleted file mode 100644 index 98e189db..00000000 --- a/purify/nall/varint.hpp +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef NALL_VARINT_HPP -#define NALL_VARINT_HPP - -#include -#include - -namespace nall { - template struct uint_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = uclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = uclip(data - 1); return r; } - inline type_t operator ++() { return data = uclip(data + 1); } - inline type_t operator --() { return data = uclip(data - 1); } - inline type_t operator =(const type_t i) { return data = uclip(i); } - inline type_t operator |=(const type_t i) { return data = uclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = uclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = uclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = uclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = uclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = uclip(data + i); } - inline type_t operator -=(const type_t i) { return data = uclip(data - i); } - inline type_t operator *=(const type_t i) { return data = uclip(data * i); } - inline type_t operator /=(const type_t i) { return data = uclip(data / i); } - inline type_t operator %=(const type_t i) { return data = uclip(data % i); } - - inline uint_t() : data(0) {} - inline uint_t(const type_t i) : data(uclip(i)) {} - - template inline type_t operator=(const uint_t &i) { return data = uclip((type_t)i); } - template inline uint_t(const uint_t &i) : data(uclip(i)) {} - }; - - template struct int_t { - private: - typedef typename type_if::type type_t; - type_t data; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = sclip(data + 1); return r; } - inline type_t operator --(int) { type_t r = data; data = sclip(data - 1); return r; } - inline type_t operator ++() { return data = sclip(data + 1); } - inline type_t operator --() { return data = sclip(data - 1); } - inline type_t operator =(const type_t i) { return data = sclip(i); } - inline type_t operator |=(const type_t i) { return data = sclip(data | i); } - inline type_t operator ^=(const type_t i) { return data = sclip(data ^ i); } - inline type_t operator &=(const type_t i) { return data = sclip(data & i); } - inline type_t operator<<=(const type_t i) { return data = sclip(data << i); } - inline type_t operator>>=(const type_t i) { return data = sclip(data >> i); } - inline type_t operator +=(const type_t i) { return data = sclip(data + i); } - inline type_t operator -=(const type_t i) { return data = sclip(data - i); } - inline type_t operator *=(const type_t i) { return data = sclip(data * i); } - inline type_t operator /=(const type_t i) { return data = sclip(data / i); } - inline type_t operator %=(const type_t i) { return data = sclip(data % i); } - - inline int_t() : data(0) {} - inline int_t(const type_t i) : data(sclip(i)) {} - - template inline type_t operator=(const int_t &i) { return data = sclip((type_t)i); } - template inline int_t(const int_t &i) : data(sclip(i)) {} - }; - - template struct varuint_t { - private: - type_t data; - type_t mask; - - public: - inline operator type_t() const { return data; } - inline type_t operator ++(int) { type_t r = data; data = (data + 1) & mask; return r; } - inline type_t operator --(int) { type_t r = data; data = (data - 1) & mask; return r; } - inline type_t operator ++() { return data = (data + 1) & mask; } - inline type_t operator --() { return data = (data - 1) & mask; } - inline type_t operator =(const type_t i) { return data = (i) & mask; } - inline type_t operator |=(const type_t i) { return data = (data | i) & mask; } - inline type_t operator ^=(const type_t i) { return data = (data ^ i) & mask; } - inline type_t operator &=(const type_t i) { return data = (data & i) & mask; } - inline type_t operator<<=(const type_t i) { return data = (data << i) & mask; } - inline type_t operator>>=(const type_t i) { return data = (data >> i) & mask; } - inline type_t operator +=(const type_t i) { return data = (data + i) & mask; } - inline type_t operator -=(const type_t i) { return data = (data - i) & mask; } - inline type_t operator *=(const type_t i) { return data = (data * i) & mask; } - inline type_t operator /=(const type_t i) { return data = (data / i) & mask; } - inline type_t operator %=(const type_t i) { return data = (data % i) & mask; } - - inline void bits(type_t bits) { mask = (1ull << (bits - 1)) + ((1ull << (bits - 1)) - 1); data &= mask; } - inline varuint_t() : data(0ull), mask((type_t)~0ull) {} - inline varuint_t(const type_t i) : data(i), mask((type_t)~0ull) {} - }; -} - -//typedefs - typedef nall::uint_t< 1> uint1_t; - typedef nall::uint_t< 2> uint2_t; - typedef nall::uint_t< 3> uint3_t; - typedef nall::uint_t< 4> uint4_t; - typedef nall::uint_t< 5> uint5_t; - typedef nall::uint_t< 6> uint6_t; - typedef nall::uint_t< 7> uint7_t; -//typedef nall::uint_t< 8> uint8_t; - - typedef nall::uint_t< 9> uint9_t; - typedef nall::uint_t<10> uint10_t; - typedef nall::uint_t<11> uint11_t; - typedef nall::uint_t<12> uint12_t; - typedef nall::uint_t<13> uint13_t; - typedef nall::uint_t<14> uint14_t; - typedef nall::uint_t<15> uint15_t; -//typedef nall::uint_t<16> uint16_t; - - typedef nall::uint_t<17> uint17_t; - typedef nall::uint_t<18> uint18_t; - typedef nall::uint_t<19> uint19_t; - typedef nall::uint_t<20> uint20_t; - typedef nall::uint_t<21> uint21_t; - typedef nall::uint_t<22> uint22_t; - typedef nall::uint_t<23> uint23_t; - typedef nall::uint_t<24> uint24_t; - typedef nall::uint_t<25> uint25_t; - typedef nall::uint_t<26> uint26_t; - typedef nall::uint_t<27> uint27_t; - typedef nall::uint_t<28> uint28_t; - typedef nall::uint_t<29> uint29_t; - typedef nall::uint_t<30> uint30_t; - typedef nall::uint_t<31> uint31_t; -//typedef nall::uint_t<32> uint32_t; - - typedef nall::int_t< 1> int1_t; - typedef nall::int_t< 2> int2_t; - typedef nall::int_t< 3> int3_t; - typedef nall::int_t< 4> int4_t; - typedef nall::int_t< 5> int5_t; - typedef nall::int_t< 6> int6_t; - typedef nall::int_t< 7> int7_t; -//typedef nall::int_t< 8> int8_t; - - typedef nall::int_t< 9> int9_t; - typedef nall::int_t<10> int10_t; - typedef nall::int_t<11> int11_t; - typedef nall::int_t<12> int12_t; - typedef nall::int_t<13> int13_t; - typedef nall::int_t<14> int14_t; - typedef nall::int_t<15> int15_t; -//typedef nall::int_t<16> int16_t; - - typedef nall::int_t<17> int17_t; - typedef nall::int_t<18> int18_t; - typedef nall::int_t<19> int19_t; - typedef nall::int_t<20> int20_t; - typedef nall::int_t<21> int21_t; - typedef nall::int_t<22> int22_t; - typedef nall::int_t<23> int23_t; - typedef nall::int_t<24> int24_t; - typedef nall::int_t<25> int25_t; - typedef nall::int_t<26> int26_t; - typedef nall::int_t<27> int27_t; - typedef nall::int_t<28> int28_t; - typedef nall::int_t<29> int29_t; - typedef nall::int_t<30> int30_t; - typedef nall::int_t<31> int31_t; -//typedef nall::int_t<32> int32_t; - -#endif diff --git a/purify/nall/vector.hpp b/purify/nall/vector.hpp deleted file mode 100644 index 6818c69d..00000000 --- a/purify/nall/vector.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef NALL_VECTOR_HPP -#define NALL_VECTOR_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall { - template struct vector { - struct exception_out_of_bounds{}; - - protected: - T *pool; - unsigned poolsize; - unsigned objectsize; - - public: - operator bool() const { return pool; } - T* data() { return pool; } - const T* data() const { return pool; } - - bool empty() const { return objectsize == 0; } - unsigned size() const { return objectsize; } - unsigned capacity() const { return poolsize; } - - T* move() { - T *result = pool; - pool = nullptr; - poolsize = 0; - objectsize = 0; - return result; - } - - void reset() { - if(pool) { - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - } - pool = nullptr; - poolsize = 0; - objectsize = 0; - } - - void reserve(unsigned size) { - unsigned outputsize = min(size, objectsize); - size = bit::round(size); //amortize growth - T *copy = (T*)calloc(size, sizeof(T)); - for(unsigned n = 0; n < outputsize; n++) new(copy + n) T(pool[n]); - for(unsigned n = 0; n < objectsize; n++) pool[n].~T(); - free(pool); - pool = copy; - poolsize = size; - objectsize = outputsize; - } - - //requires trivial constructor - void resize(unsigned size) { - if(size == objectsize) return; - if(size < objectsize) return reserve(size); - while(size > objectsize) append(T()); - } - - template - void append(const T& data, Args&&... args) { - append(data); - append(std::forward(args)...); - } - - void append(const T& data) { - if(objectsize + 1 > poolsize) reserve(objectsize + 1); - new(pool + objectsize++) T(data); - } - - bool appendonce(const T& data) { - if(find(data) == true) return false; - append(data); - return true; - } - - void insert(unsigned position, const T& data) { - append(data); - for(signed n = size() - 1; n > position; n--) pool[n] = pool[n - 1]; - pool[position] = data; - } - - void prepend(const T& data) { - insert(0, data); - } - - void remove(unsigned index = ~0u, unsigned count = 1) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - for(unsigned n = index; count + n < objectsize; n++) pool[n] = pool[count + n]; - objectsize = (count + index >= objectsize) ? index : objectsize - count; - } - - T take(unsigned index = ~0u) { - if(index == ~0) index = objectsize ? objectsize - 1 : 0; - if(index >= objectsize) throw exception_out_of_bounds(); - T item = pool[index]; - remove(index); - return item; - } - - void reverse() { - unsigned pivot = size() / 2; - for(unsigned l = 0, r = size() - 1; l < pivot; l++, r--) { - std::swap(pool[l], pool[r]); - } - } - - void sort() { - nall::sort(pool, objectsize); - } - - template void sort(const Comparator &lessthan) { - nall::sort(pool, objectsize, lessthan); - } - - optional find(const T& data) { - for(unsigned n = 0; n < size(); n++) if(pool[n] == data) return {true, n}; - return {false, 0u}; - } - - T& first() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[0]; - } - - T& last() { - if(objectsize == 0) throw exception_out_of_bounds(); - return pool[objectsize - 1]; - } - - //access - inline T& operator[](unsigned position) { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline const T& operator[](unsigned position) const { - if(position >= objectsize) throw exception_out_of_bounds(); - return pool[position]; - } - - inline T& operator()(unsigned position) { - if(position >= poolsize) reserve(position + 1); - while(position >= objectsize) append(T()); - return pool[position]; - } - - inline const T& operator()(unsigned position, const T& data) const { - if(position >= objectsize) return data; - return pool[position]; - } - - //iteration - T* begin() { return &pool[0]; } - T* end() { return &pool[objectsize]; } - const T* begin() const { return &pool[0]; } - const T* end() const { return &pool[objectsize]; } - - //copy - inline vector& operator=(const vector &source) { - reset(); - reserve(source.capacity()); - for(auto &data : source) append(data); - return *this; - } - - vector(const vector &source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(source); - } - - //move - inline vector& operator=(vector &&source) { - reset(); - pool = source.pool, poolsize = source.poolsize, objectsize = source.objectsize; - source.pool = nullptr, source.poolsize = 0, source.objectsize = 0; - return *this; - } - - vector(vector &&source) : pool(nullptr), poolsize(0), objectsize(0) { - operator=(std::move(source)); - } - - //construction - vector() : pool(nullptr), poolsize(0), objectsize(0) { - } - - vector(std::initializer_list list) : pool(nullptr), poolsize(0), objectsize(0) { - for(auto &data : list) append(data); - } - - ~vector() { - reset(); - } - }; -} - -#endif diff --git a/purify/nall/windows/detour.hpp b/purify/nall/windows/detour.hpp deleted file mode 100644 index e270f318..00000000 --- a/purify/nall/windows/detour.hpp +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef NALL_WINDOWS_DETOUR_HPP -#define NALL_WINDOWS_DETOUR_HPP - -#include -#include -#include -#include -#include - -namespace nall { - -#define Copy 0 -#define RelNear 1 - -struct detour { - static bool insert(const string &moduleName, const string &functionName, void *&source, void *target); - static bool remove(const string &moduleName, const string &functionName, void *&source); - -protected: - static unsigned length(const uint8_t *function); - static unsigned mirror(uint8_t *target, const uint8_t *source); - - struct opcode { - uint16_t prefix; - unsigned length; - unsigned mode; - uint16_t modify; - }; - static opcode opcodes[]; -}; - -//TODO: -//* fs:, gs: should force another opcode copy -//* conditional branches within +5-byte range should fail -detour::opcode detour::opcodes[] = { - { 0x50, 1 }, //push eax - { 0x51, 1 }, //push ecx - { 0x52, 1 }, //push edx - { 0x53, 1 }, //push ebx - { 0x54, 1 }, //push esp - { 0x55, 1 }, //push ebp - { 0x56, 1 }, //push esi - { 0x57, 1 }, //push edi - { 0x58, 1 }, //pop eax - { 0x59, 1 }, //pop ecx - { 0x5a, 1 }, //pop edx - { 0x5b, 1 }, //pop ebx - { 0x5c, 1 }, //pop esp - { 0x5d, 1 }, //pop ebp - { 0x5e, 1 }, //pop esi - { 0x5f, 1 }, //pop edi - { 0x64, 1 }, //fs: - { 0x65, 1 }, //gs: - { 0x68, 5 }, //push dword - { 0x6a, 2 }, //push byte - { 0x74, 2, RelNear, 0x0f84 }, //je near -> je far - { 0x75, 2, RelNear, 0x0f85 }, //jne near -> jne far - { 0x89, 2 }, //mov reg,reg - { 0x8b, 2 }, //mov reg,reg - { 0x90, 1 }, //nop - { 0xa1, 5 }, //mov eax,[dword] - { 0xeb, 2, RelNear, 0xe9 }, //jmp near -> jmp far -}; - -bool detour::insert(const string &moduleName, const string &functionName, void *&source, void *target) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - unsigned sourceLength = detour::length(sourceData); - if(sourceLength < 5) { - //unable to clone enough bytes to insert hook - #if 1 - string output = { "detour::insert(", moduleName, "::", functionName, ") failed: " }; - for(unsigned n = 0; n < 16; n++) output.append(hex<2>(sourceData[n]), " "); - output.rtrim<1>(" "); - MessageBoxA(0, output, "nall::detour", MB_OK); - #endif - return false; - } - - uint8_t *mirrorData = new uint8_t[512](); - detour::mirror(mirrorData, sourceData); - - DWORD privileges; - VirtualProtect((void*)mirrorData, 512, PAGE_EXECUTE_READWRITE, &privileges); - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - uintmax_t address = (uintmax_t)target - ((uintmax_t)sourceData + 5); - sourceData[0] = 0xe9; //jmp target - sourceData[1] = address >> 0; - sourceData[2] = address >> 8; - sourceData[3] = address >> 16; - sourceData[4] = address >> 24; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)mirrorData; - return true; -} - -bool detour::remove(const string &moduleName, const string &functionName, void *&source) { - HMODULE module = GetModuleHandleW(utf16_t(moduleName)); - if(!module) return false; - - uint8_t *sourceData = (uint8_t*)GetProcAddress(module, functionName); - if(!sourceData) return false; - - uint8_t *mirrorData = (uint8_t*)source; - if(mirrorData == sourceData) return false; //hook was never installed - - unsigned length = detour::length(256 + mirrorData); - if(length < 5) return false; - - DWORD privileges; - VirtualProtect((void*)sourceData, 256, PAGE_EXECUTE_READWRITE, &privileges); - for(unsigned n = 0; n < length; n++) sourceData[n] = mirrorData[256 + n]; - VirtualProtect((void*)sourceData, 256, privileges, &privileges); - - source = (void*)sourceData; - delete[] mirrorData; - return true; -} - -unsigned detour::length(const uint8_t *function) { - unsigned length = 0; - while(length < 5) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(function[length] == op.prefix) { - opcode = &op; - break; - } - } - if(opcode == 0) break; - length += opcode->length; - } - return length; -} - -unsigned detour::mirror(uint8_t *target, const uint8_t *source) { - const uint8_t *entryPoint = source; - for(unsigned n = 0; n < 256; n++) target[256 + n] = source[n]; - - unsigned size = detour::length(source); - while(size) { - detour::opcode *opcode = 0; - foreach(op, detour::opcodes) { - if(*source == op.prefix) { - opcode = &op; - break; - } - } - - switch(opcode->mode) { - case Copy: - for(unsigned n = 0; n < opcode->length; n++) *target++ = *source++; - break; - case RelNear: { - source++; - uintmax_t sourceAddress = (uintmax_t)source + 1 + (int8_t)*source; - *target++ = opcode->modify; - if(opcode->modify >> 8) *target++ = opcode->modify >> 8; - uintmax_t targetAddress = (uintmax_t)target + 4; - uintmax_t address = sourceAddress - targetAddress; - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - source += 2; - } break; - } - - size -= opcode->length; - } - - uintmax_t address = (entryPoint + detour::length(entryPoint)) - (target + 5); - *target++ = 0xe9; //jmp entryPoint - *target++ = address >> 0; - *target++ = address >> 8; - *target++ = address >> 16; - *target++ = address >> 24; - - return source - entryPoint; -} - -#undef Implied -#undef RelNear - -} - -#endif diff --git a/purify/nall/windows/guid.hpp b/purify/nall/windows/guid.hpp deleted file mode 100644 index 386cfc75..00000000 --- a/purify/nall/windows/guid.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NALL_WINDOWS_GUID_HPP -#define NALL_WINDOWS_GUID_HPP - -#include -#include - -namespace nall { - -//generate unique GUID -inline string guid() { - random_lfsr lfsr; - lfsr.seed(time(0)); - for(unsigned n = 0; n < 256; n++) lfsr(); - - string output; - for(unsigned n = 0; n < 4; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 2; n++) output.append(hex<2>(lfsr())); - output.append("-"); - for(unsigned n = 0; n < 6; n++) output.append(hex<2>(lfsr())); - return {"{", output, "}"}; -} - -} - -#endif diff --git a/purify/nall/windows/launcher.hpp b/purify/nall/windows/launcher.hpp deleted file mode 100644 index 914683ec..00000000 --- a/purify/nall/windows/launcher.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef NALL_WINDOWS_LAUNCHER_HPP -#define NALL_WINDOWS_LAUNCHER_HPP - -namespace nall { - -//launch a new process and inject specified DLL into it - -bool launch(const char *applicationName, const char *libraryName, uint32_t entryPoint) { - //if a launcher does not send at least one message, a wait cursor will appear - PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0); - MSG msg; - GetMessage(&msg, 0, 0, 0); - - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - memset(&si, 0, sizeof(STARTUPINFOW)); - BOOL result = CreateProcessW( - utf16_t(applicationName), GetCommandLineW(), NULL, NULL, TRUE, - DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, //do not break if application creates its own processes - NULL, NULL, &si, &pi - ); - if(result == false) return false; - - uint8_t entryData[1024], entryHook[1024] = { - 0x68, 0x00, 0x00, 0x00, 0x00, //push libraryName - 0xb8, 0x00, 0x00, 0x00, 0x00, //mov eax,LoadLibraryW - 0xff, 0xd0, //call eax - 0xcd, 0x03, //int 3 - }; - - entryHook[1] = (uint8_t)((entryPoint + 14) >> 0); - entryHook[2] = (uint8_t)((entryPoint + 14) >> 8); - entryHook[3] = (uint8_t)((entryPoint + 14) >> 16); - entryHook[4] = (uint8_t)((entryPoint + 14) >> 24); - - uint32_t pLoadLibraryW = (uint32_t)GetProcAddress(GetModuleHandleW(L"kernel32"), "LoadLibraryW"); - entryHook[6] = pLoadLibraryW >> 0; - entryHook[7] = pLoadLibraryW >> 8; - entryHook[8] = pLoadLibraryW >> 16; - entryHook[9] = pLoadLibraryW >> 24; - - utf16_t buffer = utf16_t(libraryName); - memcpy(entryHook + 14, buffer, 2 * wcslen(buffer) + 2); - - while(true) { - DEBUG_EVENT event; - WaitForDebugEvent(&event, INFINITE); - - if(event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break; - - if(event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) { - if(event.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) { - if(event.u.Exception.ExceptionRecord.ExceptionAddress == (void*)(entryPoint + 14 - 1)) { - HANDLE hProcess = OpenProcess(0, FALSE, event.dwProcessId); - HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, event.dwThreadId); - - CONTEXT context; - context.ContextFlags = CONTEXT_FULL; - GetThreadContext(hThread, &context); - - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - context.Eip = entryPoint; - SetThreadContext(hThread, &context); - - CloseHandle(hThread); - CloseHandle(hProcess); - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); - continue; - } - - if(event.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) { - ReadProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryData, sizeof entryData, NULL); - WriteProcessMemory(pi.hProcess, (void*)entryPoint, (void*)&entryHook, sizeof entryHook, NULL); - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - continue; - } - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - } - - return true; -} - -} - -#endif diff --git a/purify/nall/windows/registry.hpp b/purify/nall/windows/registry.hpp deleted file mode 100644 index 0774e04a..00000000 --- a/purify/nall/windows/registry.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef NALL_WINDOWS_REGISTRY_HPP -#define NALL_WINDOWS_REGISTRY_HPP - -#include -#include - -#include -#ifndef KEY_WOW64_64KEY - #define KEY_WOW64_64KEY 0x0100 -#endif -#ifndef KEY_WOW64_32KEY - #define KEY_WOW64_32KEY 0x0200 -#endif - -#ifndef NWR_FLAGS - #define NWR_FLAGS KEY_WOW64_64KEY -#endif - -#ifndef NWR_SIZE - #define NWR_SIZE 4096 -#endif - -namespace nall { - -struct registry { - static bool exists(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return true; - } - return false; - } - - static string read(const string &name) { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - wchar_t data[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - LONG result = RegQueryValueExW(handle, utf16_t(node), NULL, NULL, (LPBYTE)&data, (LPDWORD)&size); - RegCloseKey(handle); - if(result == ERROR_SUCCESS) return (const char*)utf8_t(data); - } - return ""; - } - - static void write(const string &name, const string &data = "") { - lstring part = name.split("/"); - HKEY handle, rootKey = root(part.take(0)); - string node = part.take(), path; - DWORD disposition; - for(unsigned n = 0; n < part.size(); n++) { - path.append(part[n]); - if(RegCreateKeyExW(rootKey, utf16_t(path), 0, NULL, 0, NWR_FLAGS | KEY_ALL_ACCESS, NULL, &handle, &disposition) == ERROR_SUCCESS) { - if(n == part.size() - 1) { - RegSetValueExW(handle, utf16_t(node), 0, REG_SZ, (BYTE*)(wchar_t*)utf16_t(data), (data.length() + 1) * sizeof(wchar_t)); - } - RegCloseKey(handle); - } - path.append("\\"); - } - } - - static bool remove(const string &name) { - lstring part = name.split("/"); - HKEY rootKey = root(part.take(0)); - string node = part.take(); - string path = part.concatenate("\\"); - if(node.empty()) return SHDeleteKeyW(rootKey, utf16_t(path)) == ERROR_SUCCESS; - return SHDeleteValueW(rootKey, utf16_t(path), utf16_t(node)) == ERROR_SUCCESS; - } - - static lstring contents(const string &name) { - lstring part = name.split("/"), result; - HKEY handle, rootKey = root(part.take(0)); - part.remove(); - string path = part.concatenate("\\"); - if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD folders, nodes; - RegQueryInfoKey(handle, NULL, NULL, NULL, &folders, NULL, NULL, &nodes, NULL, NULL, NULL, NULL); - for(unsigned n = 0; n < folders; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumKeyEx(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append({(const char*)utf8_t(name), "/"}); - } - for(unsigned n = 0; n < nodes; n++) { - wchar_t name[NWR_SIZE] = L""; - DWORD size = NWR_SIZE * sizeof(wchar_t); - RegEnumValueW(handle, n, (wchar_t*)&name, &size, NULL, NULL, NULL, NULL); - result.append((const char*)utf8_t(name)); - } - RegCloseKey(handle); - } - return result; - } - -private: - static HKEY root(const string &name) { - if(name == "HKCR") return HKEY_CLASSES_ROOT; - if(name == "HKCC") return HKEY_CURRENT_CONFIG; - if(name == "HKCU") return HKEY_CURRENT_USER; - if(name == "HKLM") return HKEY_LOCAL_MACHINE; - if(name == "HKU" ) return HKEY_USERS; - return NULL; - } -}; - -} - -#endif diff --git a/purify/nall/windows/utf8.hpp b/purify/nall/windows/utf8.hpp deleted file mode 100644 index b1374943..00000000 --- a/purify/nall/windows/utf8.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef NALL_UTF8_HPP -#define NALL_UTF8_HPP - -//UTF-8 <> UTF-16 conversion -//used only for Win32; Linux, etc use UTF-8 internally - -#if defined(_WIN32) - -#undef UNICODE -#undef _WIN32_WINNT -#undef NOMINMAX -#define UNICODE -#define _WIN32_WINNT 0x0501 -#define NOMINMAX -#include -#include -#undef interface - -namespace nall { - //UTF-8 to UTF-16 - class utf16_t { - public: - operator wchar_t*() { - return buffer; - } - - operator const wchar_t*() const { - return buffer; - } - - utf16_t(const char *s = "") { - if(!s) s = ""; - unsigned length = MultiByteToWideChar(CP_UTF8, 0, s, -1, 0, 0); - buffer = new wchar_t[length + 1](); - MultiByteToWideChar(CP_UTF8, 0, s, -1, buffer, length); - } - - ~utf16_t() { - delete[] buffer; - } - - private: - wchar_t *buffer; - }; - - //UTF-16 to UTF-8 - class utf8_t { - public: - operator char*() { - return buffer; - } - - operator const char*() const { - return buffer; - } - - utf8_t(const wchar_t *s = L"") { - if(!s) s = L""; - unsigned length = WideCharToMultiByte(CP_UTF8, 0, s, -1, 0, 0, (const char*)0, (BOOL*)0); - buffer = new char[length + 1](); - WideCharToMultiByte(CP_UTF8, 0, s, -1, buffer, length, (const char*)0, (BOOL*)0); - } - - ~utf8_t() { - delete[] buffer; - } - - utf8_t(const utf8_t&) = delete; - utf8_t& operator=(const utf8_t&) = delete; - - private: - char *buffer; - }; - - inline void utf8_args(int &argc, char **&argv) { - wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = new char*[argc]; - for(unsigned i = 0; i < argc; i++) { - argv[i] = new char[_MAX_PATH]; - strcpy(argv[i], nall::utf8_t(wargv[i])); - } - } -} - -#endif //if defined(_WIN32) - -#endif diff --git a/purify/nall/xorg/guard.hpp b/purify/nall/xorg/guard.hpp deleted file mode 100644 index a1282683..00000000 --- a/purify/nall/xorg/guard.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NALL_XORG_GUARD_HPP -#define NALL_XORG_GUARD_HPP - -#define None -#undef XlibNone -#define XlibNone 0L -#define Button1 XlibButton1 -#define Button2 XlibButton2 -#define Button3 XlibButton3 -#define Button4 XlibButton4 -#define Button5 XlibButton5 -#define Display XlibDisplay -#define Screen XlibScreen -#define Window XlibWindow - -#else -#undef NALL_XORG_GUARD_HPP - -#undef None -#undef Button1 -#undef Button2 -#undef Button3 -#undef Button4 -#undef Button5 -#undef Display -#undef Screen -#undef Window - -#endif diff --git a/purify/nall/xorg/xorg.hpp b/purify/nall/xorg/xorg.hpp deleted file mode 100644 index bcf48b46..00000000 --- a/purify/nall/xorg/xorg.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef NALL_XORG_XORG_HPP -#define NALL_XORG_XORG_HPP - -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/purify/nall/zip.hpp b/purify/nall/zip.hpp deleted file mode 100644 index 0a73ccdd..00000000 --- a/purify/nall/zip.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef NALL_ZIP_HPP -#define NALL_ZIP_HPP - -//creates uncompressed ZIP archives - -#include -#include - -namespace nall { - -struct zip { - zip(const string &filename) { - fp.open(filename, file::mode::write); - time_t currentTime = time(0); - tm *info = localtime(¤tTime); - dosTime = (info->tm_hour << 11) | (info->tm_min << 5) | (info->tm_sec >> 1); - dosDate = ((info->tm_year - 80) << 9) | ((1 + info->tm_mon) << 5) + (info->tm_mday); - } - - //append path: append("path/"); - //append file: append("path/file", data, size); - void append(string filename, const uint8_t *data = nullptr, unsigned size = 0u) { - filename.transform("\\", "/"); - uint32_t checksum = crc32_calculate(data, size); - directory.append({filename, checksum, size, fp.offset()}); - - fp.writel(0x04034b50, 4); //signature - fp.writel(0x0014, 2); //minimum version (2.0) - fp.writel(0x0000, 2); //general purpose bit flags - fp.writel(0x0000, 2); //compression method (0 = uncompressed) - fp.writel(dosTime, 2); - fp.writel(dosDate, 2); - fp.writel(checksum, 4); - fp.writel(size, 4); //compressed size - fp.writel(size, 4); //uncompressed size - fp.writel(filename.length(), 2); //file name length - fp.writel(0x0000, 2); //extra field length - fp.print(filename); //file name - - fp.write(data, size); //file data - } - - ~zip() { - //central directory - unsigned baseOffset = fp.offset(); - for(auto &entry : directory) { - fp.writel(0x02014b50, 4); //signature - fp.writel(0x0014, 2); //version made by (2.0) - fp.writel(0x0014, 2); //version needed to extract (2.0) - fp.writel(0x0000, 2); //general purpose bit flags - fp.writel(0x0000, 2); //compression method (0 = uncompressed) - fp.writel(dosTime, 2); - fp.writel(dosDate, 2); - fp.writel(entry.checksum, 4); - fp.writel(entry.size, 4); //compressed size - fp.writel(entry.size, 4); //uncompressed size - fp.writel(entry.filename.length(), 2); //file name length - fp.writel(0x0000, 2); //extra field length - fp.writel(0x0000, 2); //file comment length - fp.writel(0x0000, 2); //disk number start - fp.writel(0x0000, 2); //internal file attributes - fp.writel(0x00000000, 4); //external file attributes - fp.writel(entry.offset, 4); //relative offset of file header - fp.print(entry.filename); - } - unsigned finishOffset = fp.offset(); - - //end of central directory - fp.writel(0x06054b50, 4); //signature - fp.writel(0x0000, 2); //number of this disk - fp.writel(0x0000, 2); //disk where central directory starts - fp.writel(directory.size(), 2); //number of central directory records on this disk - fp.writel(directory.size(), 2); //total number of central directory records - fp.writel(finishOffset - baseOffset, 4); //size of central directory - fp.writel(baseOffset, 4); //offset of central directory - fp.writel(0x0000, 2); //comment length - - fp.close(); - } - -protected: - file fp; - uint16_t dosTime, dosDate; - struct entry_t { - string filename; - uint32_t checksum; - uint32_t size; - uint32_t offset; - }; - vector directory; -}; - -} - -#endif diff --git a/purify/obj/.gitignore b/purify/obj/.gitignore deleted file mode 100644 index 5761abcf..00000000 --- a/purify/obj/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.o diff --git a/purify/phoenix/Makefile b/purify/phoenix/Makefile deleted file mode 100644 index d1c9d981..00000000 --- a/purify/phoenix/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -ifeq ($(platform),x) - ifeq ($(phoenix),) - phoenix := gtk - endif - - ifeq ($(phoenix),gtk) - phoenixflags := -DPHOENIX_GTK `pkg-config --cflags gtk+-2.0` - phoenixlink := `pkg-config --libs gtk+-2.0` - endif - - ifeq ($(phoenix),qt) - phoenixflags := -DPHOENIX_QT `pkg-config --cflags QtCore QtGui` - phoenixlink := `pkg-config --libs QtCore QtGui` - endif -else ifeq ($(platform),win) - phoenixflags := -DPHOENIX_WINDOWS - phoenixlink := -lkernel32 -luser32 -lgdi32 -ladvapi32 -lole32 -lcomctl32 -lcomdlg32 -lshlwapi -else - phoenixflags := -DPHOENIX_REFERENCE - phoenixlink := -endif diff --git a/purify/phoenix/core/core.cpp b/purify/phoenix/core/core.cpp deleted file mode 100644 index a2588770..00000000 --- a/purify/phoenix/core/core.cpp +++ /dev/null @@ -1,1342 +0,0 @@ -#include "state.hpp" -#include "layout/fixed-layout.cpp" -#include "layout/horizontal-layout.cpp" -#include "layout/vertical-layout.cpp" - -#if defined(PHOENIX_WINDOWS) - #include "../windows/platform.cpp" -#elif defined(PHOENIX_QT) - #include "../qt/platform.cpp" -#elif defined(PHOENIX_GTK) - #include "../gtk/platform.cpp" -#elif defined(PHOENIX_REFERENCE) - #include "../reference/platform.cpp" -#endif - -static bool OS_quit = false; - -//Color -//===== - -uint32_t Color::rgb() const { - return (255 << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -uint32_t Color::rgba() const { - return (alpha << 24) + (red << 16) + (green << 8) + (blue << 0); -} - -//Geometry -//======== - -Position Geometry::position() const { - return { x, y }; -} - -Size Geometry::size() const { - return { width, height }; -} - -string Geometry::text() const { - return { x, ",", y, ",", width, ",", height }; -} - -Geometry::Geometry(const string &text) { - lstring part = text.split(","); - x = integer(part(0, "256")); - y = integer(part(1, "256")); - width = decimal(part(2, "256")); - height = decimal(part(3, "256")); -} - -//Font -//==== - -Geometry Font::geometry(const string &text) { - return pFont::geometry(description, text); -} - -Font::Font(const string &description): -description(description) { -} - -//Desktop -//======= - -Size Desktop::size() { - return pDesktop::size(); -} - -Geometry Desktop::workspace() { - return pDesktop::workspace(); -} - -//Keyboard -//======== - -bool Keyboard::pressed(Keyboard::Scancode scancode) { - return pKeyboard::pressed(scancode); -} - -bool Keyboard::released(Keyboard::Scancode scancode) { - return !pressed(scancode); -} - -vector Keyboard::state() { - return pKeyboard::state(); -} - -//Mouse -//===== - -Position Mouse::position() { - return pMouse::position(); -} - -bool Mouse::pressed(Mouse::Button button) { - return pMouse::pressed(button); -} - -bool Mouse::released(Mouse::Button button) { - return !pressed(button); -} - -//DialogWindow -//============ - -string DialogWindow::fileOpen_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileOpen(parent, path, filter); -} - -string DialogWindow::fileSave_(Window &parent, const string &path, const lstring &filter_) { - auto filter = filter_; - if(filter.size() == 0) filter.append("All files (*)"); - return pDialogWindow::fileSave(parent, path, filter); -} - -string DialogWindow::folderSelect(Window &parent, const string &path) { - return pDialogWindow::folderSelect(parent, path); -} - -//MessageWindow -//============= - -MessageWindow::Response MessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::information(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::question(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::warning(parent, text, buttons); -} - -MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return pMessageWindow::critical(parent, text, buttons); -} - -//Object -//====== - -Object::Object(pObject &p): -p(p) { - OS::initialize(); - p.constructor(); -} - -Object::~Object() { - p.destructor(); - delete &p; -} - -//OS -//== - -void OS::main() { - return pOS::main(); -} - -bool OS::pendingEvents() { - return pOS::pendingEvents(); -} - -void OS::processEvents() { - return pOS::processEvents(); -} - -void OS::quit() { - OS_quit = true; - return pOS::quit(); -} - -void OS::setName(const string &name) { - osState.name = name; -} - -void OS::initialize() { - static bool initialized = false; - if(initialized == false) { - initialized = true; - return pOS::initialize(); - } -} - -//Timer -//===== - -void Timer::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Timer::setInterval(unsigned milliseconds) { - state.milliseconds = milliseconds; - return p.setInterval(milliseconds); -} - -Timer::Timer(): -state(*new State), -base_from_member(*new pTimer(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Timer::~Timer() { - p.destructor(); - delete &state; -} - -//Window -//====== - -Window& Window::none() { - return pWindow::none(); -} - -void Window::append_(Layout &layout) { - if(state.layout.append(layout)) { - ((Sizable&)layout).state.window = this; - ((Sizable&)layout).state.layout = 0; - p.append(layout); - layout.synchronizeLayout(); - } -} - -void Window::append_(Menu &menu) { - if(state.menu.append(menu)) { - ((Action&)menu).state.window = this; - p.append(menu); - } -} - -void Window::append_(Widget &widget) { - if(state.widget.append(widget)) { - ((Sizable&)widget).state.window = this; - p.append(widget); - } -} - -Color Window::backgroundColor() { - return p.backgroundColor(); -} - -Geometry Window::frameGeometry() { - Geometry geometry = p.geometry(); - Geometry margin = p.frameMargin(); - return { - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height - }; -} - -Geometry Window::frameMargin() { - return p.frameMargin(); -} - -bool Window::focused() { - return p.focused(); -} - -bool Window::fullScreen() { - return state.fullScreen; -} - -Geometry Window::geometry() { - return p.geometry(); -} - -void Window::ignore() { - state.ignore = true; -} - -void Window::remove_(Layout &layout) { - if(state.layout.remove(layout)) { - p.remove(layout); - ((Sizable&)layout).state.window = 0; - } -} - -void Window::remove_(Menu &menu) { - if(state.menu.remove(menu)) { - p.remove(menu); - ((Action&)menu).state.window = 0; - } -} - -void Window::remove_(Widget &widget) { - if(state.widget.remove(widget)) { - p.remove(widget); - ((Sizable&)widget).state.window = 0; - } -} - -void Window::setBackgroundColor(const Color &color) { - state.backgroundColorOverride = true; - state.backgroundColor = color; - return p.setBackgroundColor(color); -} - -void Window::setFrameGeometry(const Geometry &geometry) { - Geometry margin = p.frameMargin(); - return setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width - margin.width, geometry.height - margin.height - }); -} - -void Window::setFocused() { - return p.setFocused(); -} - -void Window::setFullScreen(bool fullScreen) { - state.fullScreen = fullScreen; - return p.setFullScreen(fullScreen); -} - -void Window::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Window::setMenuFont(const string &font) { - state.menuFont = font; - return p.setMenuFont(font); -} - -void Window::setMenuVisible(bool visible) { - state.menuVisible = visible; - return p.setMenuVisible(visible); -} - -void Window::setModal(bool modal) { - state.modal = modal; - return p.setModal(modal); -} - -void Window::setResizable(bool resizable) { - state.resizable = resizable; - return p.setResizable(resizable); -} - -void Window::setSmartGeometry(const Geometry &geometry) { - Geometry margin = p.frameMargin(); - return setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width, geometry.height - }); -} - -void Window::setStatusFont(const string &font) { - state.statusFont = font; - return p.setStatusFont(font); -} - -void Window::setStatusText(const string &text) { - state.statusText = text; - return p.setStatusText(text); -} - -void Window::setStatusVisible(bool visible) { - state.statusVisible = visible; - return p.setStatusVisible(visible); -} - -void Window::setTitle(const string &text) { - state.title = text; - return p.setTitle(text); -} - -void Window::setVisible(bool visible) { - state.visible = visible; - synchronizeLayout(); - return p.setVisible(visible); -} - -void Window::setWidgetFont(const string &font) { - state.widgetFont = font; - return p.setWidgetFont(font); -} - -string Window::statusText() { - return state.statusText; -} - -void Window::synchronizeLayout() { - if(visible() && OS_quit == false) setGeometry(geometry()); -} - -bool Window::visible() { - return state.visible; -} - -Window::Window(): -state(*new State), -base_from_member(*new pWindow(*this)), -Object(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Window::~Window() { - p.destructor(); - delete &state; -} - -//Action -//====== - -bool Action::enabled() { - return state.enabled; -} - -void Action::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Action::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Action::visible() { - return state.visible; -} - -Action::Action(pAction &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Action::~Action() { - p.destructor(); - delete &state; -} - -//Menu -//==== - -void Menu::append(const set &list) { - for(auto &action : list) { - if(state.action.append(action)) { - action.state.menu = this; - p.append(action); - } - } -} - -void Menu::remove(const set &list) { - for(auto &action : list) { - if(state.action.remove(action)) { - action.state.menu = 0; - return p.remove(action); - } - } -} - -void Menu::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Menu::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Menu::Menu(): -state(*new State), -base_from_member(*new pMenu(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Menu::~Menu() { - p.destructor(); - delete &state; -} - -//Separator -//========= - -Separator::Separator(): -base_from_member(*new pSeparator(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Separator::~Separator() { - p.destructor(); -} - -//Item -//==== - -void Item::setImage(const image &image) { - state.image = image; - return p.setImage(image); -} - -void Item::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Item::Item(): -state(*new State), -base_from_member(*new pItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Item::~Item() { - p.destructor(); - delete &state; -} - -//CheckItem -//========= - -bool CheckItem::checked() { - return p.checked(); -} - -void CheckItem::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckItem::CheckItem(): -state(*new State), -base_from_member(*new pCheckItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckItem::~CheckItem() { - p.destructor(); - delete &state; -} - -//RadioItem -//========= - -void RadioItem::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioItem::checked() { - return p.checked(); -} - -void RadioItem::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioItem::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string RadioItem::text() { - return state.text; -} - -RadioItem::RadioItem(): -state(*new State), -base_from_member(*new pRadioItem(*this)), -Action(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioItem::~RadioItem() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//Sizable -//======= - -Layout* Sizable::layout() { - return state.layout; -} - -Window* Sizable::window() { - if(state.layout) return state.layout->window(); - return state.window; -} - -Sizable::Sizable(pSizable &p): -state(*new State), -Object(p), -p(p) { - p.constructor(); -} - -Sizable::~Sizable() { - if(layout()) layout()->remove(*this); - p.destructor(); - delete &state; -} - -//Layout -//====== - -void Layout::append(Sizable &sizable) { - sizable.state.layout = this; - sizable.state.window = 0; - - if(dynamic_cast(&sizable)) { - Layout &layout = (Layout&)sizable; - layout.synchronizeLayout(); - } - - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->append(widget); - } -} - -void Layout::remove(Sizable &sizable) { - if(dynamic_cast(&sizable)) { - Widget &widget = (Widget&)sizable; - if(sizable.window()) sizable.window()->remove(widget); - } - - sizable.state.layout = 0; - sizable.state.window = 0; -} - -Layout::Layout(): -state(*new State), -base_from_member(*new pLayout(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { -} - -Layout::Layout(pLayout &p): -state(*new State), -base_from_member(p), -Sizable(p), -p(p) { -} - -Layout::~Layout() { - if(layout()) layout()->remove(*this); - else if(window()) window()->remove(*this); - p.destructor(); - delete &state; -} - -//Widget -//====== - -bool Widget::enabled() { - return state.enabled; -} - -bool Widget::focused() { - return p.focused(); -} - -string Widget::font() { - return state.font; -} - -Geometry Widget::geometry() { - return state.geometry; -} - -Geometry Widget::minimumGeometry() { - return p.minimumGeometry(); -} - -void Widget::setEnabled(bool enabled) { - state.enabled = enabled; - return p.setEnabled(enabled); -} - -void Widget::setFocused() { - return p.setFocused(); -} - -void Widget::setFont(const string &font) { - state.font = font; - return p.setFont(font); -} - -void Widget::setGeometry(const Geometry &geometry) { - state.geometry = geometry; - return p.setGeometry(geometry); -} - -void Widget::setVisible(bool visible) { - state.visible = visible; - return p.setVisible(visible); -} - -bool Widget::visible() { - return state.visible; -} - -Widget::Widget(): -state(*new State), -base_from_member(*new pWidget(*this)), -Sizable(base_from_member::value), -p(base_from_member::value) { - state.abstract = true; - p.constructor(); -} - -Widget::Widget(pWidget &p): -state(*new State), -base_from_member(p), -Sizable(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Widget::~Widget() { - p.destructor(); - delete &state; -} - -//Button -//====== - -void Button::setImage(const image &image, Orientation orientation) { - state.image = image; - state.orientation = orientation; - return p.setImage(image, orientation); -} - -void Button::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Button::Button(): -state(*new State), -base_from_member(*new pButton(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Button::~Button() { - p.destructor(); - delete &state; -} - -//Canvas -//====== - -uint32_t* Canvas::data() { - return state.data; -} - -bool Canvas::setImage(const nall::image &image) { - if(image.data == nullptr || image.width == 0 || image.height == 0) return false; - state.width = image.width; - state.height = image.height; - setSize({ state.width, state.height }); - memcpy(state.data, image.data, state.width * state.height * sizeof(uint32_t)); - return true; -} - -void Canvas::setSize(const Size &size) { - state.width = size.width; - state.height = size.height; - delete[] state.data; - state.data = new uint32_t[size.width * size.height]; - return p.setSize(size); -} - -Size Canvas::size() { - return { state.width, state.height }; -} - -void Canvas::update() { - return p.update(); -} - -Canvas::Canvas(): -state(*new State), -base_from_member(*new pCanvas(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - state.data = new uint32_t[state.width * state.height]; - p.constructor(); -} - -Canvas::~Canvas() { - p.destructor(); - delete[] state.data; - delete &state; -} - -//CheckBox -//======== - -bool CheckBox::checked() { - return p.checked(); -} - -void CheckBox::setChecked(bool checked) { - state.checked = checked; - return p.setChecked(checked); -} - -void CheckBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -CheckBox::CheckBox(): -state(*new State), -base_from_member(*new pCheckBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -CheckBox::~CheckBox() { - p.destructor(); - delete &state; -} - -//ComboBox -//======== - -void ComboBox::append_(const lstring &list) { - for(auto &text : list) { - state.text.append(text); - p.append(text); - } -} - -void ComboBox::modify(unsigned row, const string &text) { - state.text(row) = text; - p.modify(row, text); -} - -void ComboBox::remove(unsigned row) { - state.text.remove(row); - p.remove(row); -} - -void ComboBox::reset() { - state.selection = 0; - state.text.reset(); - return p.reset(); -} - -unsigned ComboBox::selection() { - return p.selection(); -} - -void ComboBox::setSelection(unsigned row) { - state.selection = row; - return p.setSelection(row); -} - -string ComboBox::text() { - return state.text(selection()); -} - -string ComboBox::text(unsigned row) { - return state.text(row); -} - -ComboBox::ComboBox(): -state(*new State), -base_from_member(*new pComboBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ComboBox::~ComboBox() { - p.destructor(); - delete &state; -} - -//HexEdit -//======= - -void HexEdit::setColumns(unsigned columns) { - state.columns = columns; - return p.setColumns(columns); -} - -void HexEdit::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HexEdit::setOffset(unsigned offset) { - state.offset = offset; - return p.setOffset(offset); -} - -void HexEdit::setRows(unsigned rows) { - state.rows = rows; - return p.setRows(rows); -} - -void HexEdit::update() { - return p.update(); -} - -HexEdit::HexEdit(): -state(*new State), -base_from_member(*new pHexEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HexEdit::~HexEdit() { - p.destructor(); - delete &state; -} - -//HorizontalScrollBar -//=================== - -unsigned HorizontalScrollBar::length() { - return state.length; -} - -unsigned HorizontalScrollBar::position() { - return p.position(); -} - -void HorizontalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalScrollBar::HorizontalScrollBar(): -state(*new State), -base_from_member(*new pHorizontalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalScrollBar::~HorizontalScrollBar() { - p.destructor(); - delete &state; -} - -//HorizontalSlider -//================ - -unsigned HorizontalSlider::length() { - return state.length; -} - -unsigned HorizontalSlider::position() { - return p.position(); -} - -void HorizontalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void HorizontalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -HorizontalSlider::HorizontalSlider(): -state(*new State), -base_from_member(*new pHorizontalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -HorizontalSlider::~HorizontalSlider() { - p.destructor(); - delete &state; -} - -//Label -//===== - -void Label::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -Label::Label(): -state(*new State), -base_from_member(*new pLabel(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Label::~Label() { - p.destructor(); - delete &state; -} - -//LineEdit -//======== - -void LineEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void LineEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -string LineEdit::text() { - return p.text(); -} - -LineEdit::LineEdit(): -state(*new State), -base_from_member(*new pLineEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -LineEdit::~LineEdit() { - p.destructor(); - delete &state; -} - -//ListView -//======== - -void ListView::append_(const lstring &text) { - state.checked.append(false); - state.text.append(text); - return p.append(text); -} - -void ListView::autoSizeColumns() { - return p.autoSizeColumns(); -} - -bool ListView::checked(unsigned row) { - return p.checked(row); -} - -void ListView::modify_(unsigned row, const lstring &text) { - state.text[row] = text; - return p.modify(row, text); -} - -void ListView::remove(unsigned row) { - state.text.remove(row); - state.image.remove(row); - return p.remove(row); -} - -void ListView::reset() { - state.checked.reset(); - state.image.reset(); - state.text.reset(); - return p.reset(); -} - -bool ListView::selected() { - return p.selected(); -} - -unsigned ListView::selection() { - return p.selection(); -} - -void ListView::setCheckable(bool checkable) { - state.checkable = checkable; - return p.setCheckable(checkable); -} - -void ListView::setChecked(unsigned row, bool checked) { - state.checked[row] = checked; - return p.setChecked(row, checked); -} - -void ListView::setHeaderText_(const lstring &text) { - state.headerText = text; - return p.setHeaderText(text); -} - -void ListView::setHeaderVisible(bool visible) { - state.headerVisible = visible; - return p.setHeaderVisible(visible); -} - -void ListView::setImage(unsigned row, unsigned column, const nall::image &image) { - state.image(row)(column) = image; - return p.setImage(row, column, image); -} - -void ListView::setSelected(bool selected) { - state.selected = selected; - return p.setSelected(selected); -} - -void ListView::setSelection(unsigned row) { - state.selected = true; - state.selection = row; - return p.setSelection(row); -} - -ListView::ListView(): -state(*new State), -base_from_member(*new pListView(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ListView::~ListView() { - p.destructor(); - delete &state; -} - -//ProgressBar -//=========== - -void ProgressBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -ProgressBar::ProgressBar(): -state(*new State), -base_from_member(*new pProgressBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -ProgressBar::~ProgressBar() { - p.destructor(); - delete &state; -} - -//RadioBox -//======== - -void RadioBox::group(const set &list) { - for(auto &item : list) item.p.setGroup(item.state.group = list); - if(list.size()) list[0].setChecked(); -} - -bool RadioBox::checked() { - return p.checked(); -} - -void RadioBox::setChecked() { - for(auto &item : state.group) item.state.checked = false; - state.checked = true; - return p.setChecked(); -} - -void RadioBox::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -RadioBox::RadioBox(): -state(*new State), -base_from_member(*new pRadioBox(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -RadioBox::~RadioBox() { - for(auto &item : state.group) { - if(&item != this) item.state.group.remove(*this); - } - p.destructor(); - delete &state; -} - -//TextEdit -//======== - -void TextEdit::setCursorPosition(unsigned position) { - state.cursorPosition = position; - return p.setCursorPosition(position); -} - -void TextEdit::setEditable(bool editable) { - state.editable = editable; - return p.setEditable(editable); -} - -void TextEdit::setText(const string &text) { - state.text = text; - return p.setText(text); -} - -void TextEdit::setWordWrap(bool wordWrap) { - state.wordWrap = wordWrap; - return p.setWordWrap(wordWrap); -} - -string TextEdit::text() { - return p.text(); -} - -TextEdit::TextEdit(): -state(*new State), -base_from_member(*new pTextEdit(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -TextEdit::~TextEdit() { - p.destructor(); - delete &state; -} - -//VerticalScrollBar -//================= - -unsigned VerticalScrollBar::length() { - return state.length; -} - -unsigned VerticalScrollBar::position() { - return p.position(); -} - -void VerticalScrollBar::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalScrollBar::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalScrollBar::VerticalScrollBar(): -state(*new State), -base_from_member(*new pVerticalScrollBar(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalScrollBar::~VerticalScrollBar() { - p.destructor(); - delete &state; -} - -//VerticalSlider -//============== - -unsigned VerticalSlider::length() { - return state.length; -} - -unsigned VerticalSlider::position() { - return p.position(); -} - -void VerticalSlider::setLength(unsigned length) { - state.length = length; - return p.setLength(length); -} - -void VerticalSlider::setPosition(unsigned position) { - state.position = position; - return p.setPosition(position); -} - -VerticalSlider::VerticalSlider(): -state(*new State), -base_from_member(*new pVerticalSlider(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -VerticalSlider::~VerticalSlider() { - p.destructor(); - delete &state; -} - -//Viewport -//======== - -uintptr_t Viewport::handle() { - return p.handle(); -} - -Viewport::Viewport(): -base_from_member(*new pViewport(*this)), -Widget(base_from_member::value), -p(base_from_member::value) { - p.constructor(); -} - -Viewport::~Viewport() { - p.destructor(); -} diff --git a/purify/phoenix/core/core.hpp b/purify/phoenix/core/core.hpp deleted file mode 100644 index 1b329f85..00000000 --- a/purify/phoenix/core/core.hpp +++ /dev/null @@ -1,615 +0,0 @@ -struct Font; -struct Window; -struct Menu; -struct Sizable; -struct Layout; -struct Widget; - -struct pFont; -struct pObject; -struct pOS; -struct pTimer; -struct pWindow; -struct pAction; -struct pMenu; -struct pSeparator; -struct pItem; -struct pCheckItem; -struct pRadioItem; -struct pSizable; -struct pLayout; -struct pWidget; -struct pButton; -struct pCanvas; -struct pCheckBox; -struct pComboBox; -struct pHexEdit; -struct pHorizontalScrollBar; -struct pHorizontalSlider; -struct pLabel; -struct pLineEdit; -struct pListView; -struct pProgressBar; -struct pRadioBox; -struct pTextEdit; -struct pVerticalScrollBar; -struct pVerticalSlider; -struct pViewport; - -enum : unsigned { - MaximumSize = ~0u, - MinimumSize = 0u, -}; - -struct Color { - uint8_t red, green, blue, alpha; - uint32_t rgb() const; - uint32_t rgba() const; - inline Color() : red(0), green(0), blue(0), alpha(255) {} - inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) : red(red), green(green), blue(blue), alpha(alpha) {} -}; - -struct Position { - signed x, y; - inline Position() : x(0), y(0) {} - template inline Position(X x, Y y) : x(x), y(y) {} -}; - -struct Size { - unsigned width, height; - inline Size() : width(0), height(0) {} - template inline Size(W width, H height) : width(width), height(height) {} -}; - -struct Geometry { - signed x, y; - unsigned width, height; - Position position() const; - Size size() const; - nall::string text() const; - inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(const Position& position, const Size& size) : x(position.x), y(position.y), width(size.width), height(size.height) {} - template inline Geometry(X x, Y y, W width, H height) : x(x), y(y), width(width), height(height) {} - Geometry(const nall::string &text); -}; - -enum class Orientation : unsigned { Horizontal, Vertical }; - -struct Font { - nall::string description; - Geometry geometry(const nall::string &text); - Font(const nall::string &description = ""); -}; - -struct Desktop { - static Size size(); - static Geometry workspace(); - Desktop() = delete; -}; - -struct Keyboard { - #include "keyboard.hpp" - static bool pressed(Scancode scancode); - static bool released(Scancode scancode); - static nall::vector state(); - Keyboard() = delete; -}; - -struct Mouse { - enum class Button : unsigned { Left, Middle, Right }; - static Position position(); - static bool pressed(Button); - static bool released(Button); - Mouse() = delete; -}; - -struct DialogWindow { - template static nall::string fileOpen(Window &parent, const nall::string &path, const Args&... args) { return fileOpen_(parent, path, { args... }); } - template static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); } - static nall::string folderSelect(Window &parent, const nall::string &path); - DialogWindow() = delete; - -private: - static nall::string fileOpen_(Window &parent, const nall::string &path, const nall::lstring& filter); - static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter); -}; - -struct MessageWindow { - enum class Buttons : unsigned { - Ok, - OkCancel, - YesNo, - }; - - enum class Response : unsigned { - Ok, - Cancel, - Yes, - No, - }; - - static Response information(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response question(Window &parent, const nall::string &text, Buttons = Buttons::YesNo); - static Response warning(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok); - MessageWindow() = delete; -}; - -struct Object { - Object(pObject &p); - Object& operator=(const Object&) = delete; - Object(const Object&) = delete; - virtual ~Object(); - pObject &p; -}; - -struct OS { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - static void setName(const nall::string &name); - - struct State; - static void initialize(); -}; - -struct Timer : private nall::base_from_member, Object { - nall::function onTimeout; - - void setEnabled(bool enabled = true); - void setInterval(unsigned milliseconds); - - Timer(); - ~Timer(); - struct State; - State &state; - pTimer &p; -}; - -struct Window : private nall::base_from_member, Object { - nall::function onClose; - nall::function onKeyPress; - nall::function onKeyRelease; - nall::function onMove; - nall::function onSize; - - static Window& none(); - - inline void append() {} - inline void remove() {} - template void append(T &arg, Args&... args) { append_(arg); append(args...); } - template void remove(T &arg, Args&... args) { remove_(arg); remove(args...); } - - void append_(Layout &layout); - void append_(Menu &menu); - void append_(Widget &widget); - Color backgroundColor(); - Geometry frameGeometry(); - Geometry frameMargin(); - bool focused(); - bool fullScreen(); - Geometry geometry(); - void ignore(); - void remove_(Layout &layout); - void remove_(Menu &menu); - void remove_(Widget &widget); - void setBackgroundColor(const Color &color); - void setFrameGeometry(const Geometry &geometry); - void setFocused(); - void setFullScreen(bool fullScreen = true); - void setGeometry(const Geometry &geometry); - void setMenuFont(const nall::string &font); - void setMenuVisible(bool visible = true); - void setModal(bool modal = true); - void setResizable(bool resizable = true); - void setSmartGeometry(const Geometry &geometry); - void setStatusFont(const nall::string &font); - void setStatusText(const nall::string &text); - void setStatusVisible(bool visible = true); - void setTitle(const nall::string &text); - void setVisible(bool visible = true); - void setWidgetFont(const nall::string &font); - nall::string statusText(); - void synchronizeLayout(); - bool visible(); - - Window(); - ~Window(); - struct State; - State &state; - pWindow &p; -}; - -struct Action : Object { - bool enabled(); - void setEnabled(bool enabled = true); - void setVisible(bool visible = true); - bool visible(); - - Action(pAction &p); - ~Action(); - struct State; - State &state; - pAction &p; -}; - -struct Menu : private nall::base_from_member, Action { - template void append(Args&... args) { append({args...}); } - template void remove(Args&... args) { remove({args...}); } - - void append(const nall::set &list); - void remove(const nall::set &list); - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Menu(); - ~Menu(); - struct State; - State &state; - pMenu &p; -}; - -struct Separator : private nall::base_from_member, Action { - Separator(); - ~Separator(); - pSeparator &p; -}; - -struct Item : private nall::base_from_member, Action { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}); - void setText(const nall::string &text); - - Item(); - ~Item(); - struct State; - State &state; - pItem &p; -}; - -struct CheckItem : private nall::base_from_member, Action { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckItem(); - ~CheckItem(); - struct State; - State &state; - pCheckItem &p; -}; - -struct RadioItem : private nall::base_from_member, Action { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - nall::string text(); - - RadioItem(); - ~RadioItem(); - struct State; - State &state; - pRadioItem &p; -}; - -struct Sizable : Object { - virtual bool enabled() = 0; - Layout* layout(); - virtual Geometry minimumGeometry() = 0; - virtual void setEnabled(bool enabled = true) = 0; - virtual void setGeometry(const Geometry &geometry) = 0; - virtual void setVisible(bool visible = true) = 0; - virtual bool visible() = 0; - Window* window(); - - Sizable(pSizable &p); - ~Sizable(); - struct State; - State &state; - pSizable &p; -}; - -struct Layout : private nall::base_from_member, Sizable { - virtual void append(Sizable &sizable); - virtual void remove(Sizable &sizable); - virtual void reset() {} - virtual void synchronizeLayout() = 0; - - Layout(); - Layout(pLayout &p); - ~Layout(); - struct State; - State &state; - pLayout &p; -}; - -struct Widget : private nall::base_from_member, Sizable { - bool enabled(); - bool focused(); - nall::string font(); - Geometry geometry(); - Geometry minimumGeometry(); - void setEnabled(bool enabled = true); - void setFocused(); - void setFont(const nall::string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - bool visible(); - - Widget(); - Widget(pWidget &p); - ~Widget(); - struct State; - State &state; - pWidget &p; -}; - -struct Button : private nall::base_from_member, Widget { - nall::function onActivate; - - void setImage(const nall::image &image = nall::image{}, Orientation = Orientation::Horizontal); - void setText(const nall::string &text); - - Button(); - ~Button(); - struct State; - State &state; - pButton &p; -}; - -struct Canvas : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uint32_t* data(); - bool setImage(const nall::image &image); - void setSize(const Size &size); - Size size(); - void update(); - - Canvas(); - ~Canvas(); - struct State; - State &state; - pCanvas &p; -}; - -struct CheckBox : private nall::base_from_member, Widget { - nall::function onToggle; - - bool checked(); - void setChecked(bool checked = true); - void setText(const nall::string &text); - - CheckBox(); - ~CheckBox(); - struct State; - State &state; - pCheckBox &p; -}; - -struct ComboBox : private nall::base_from_member, Widget { - nall::function onChange; - - template void append(const Args&... args) { append_({args...}); } - - void append_(const nall::lstring &list); - void modify(unsigned row, const nall::string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - nall::string text(); - nall::string text(unsigned row); - - ComboBox(); - ~ComboBox(); - struct State; - State &state; - pComboBox &p; -}; - -struct HexEdit : private nall::base_from_member, Widget { - nall::function onRead; - nall::function onWrite; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - HexEdit(); - ~HexEdit(); - struct State; - State &state; - pHexEdit &p; -}; - -struct HorizontalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalScrollBar(); - ~HorizontalScrollBar(); - struct State; - State &state; - pHorizontalScrollBar &p; -}; - -struct HorizontalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - HorizontalSlider(); - ~HorizontalSlider(); - struct State; - State &state; - pHorizontalSlider &p; -}; - -struct Label : private nall::base_from_member, Widget { - void setText(const nall::string &text); - - Label(); - ~Label(); - struct State; - State &state; - pLabel &p; -}; - -struct LineEdit : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - - void setEditable(bool editable = true); - void setText(const nall::string &text); - nall::string text(); - - LineEdit(); - ~LineEdit(); - struct State; - State &state; - pLineEdit &p; -}; - -struct ListView : private nall::base_from_member, Widget { - nall::function onActivate; - nall::function onChange; - nall::function onToggle; - - template void append(const Args&... args) { append_({args...}); } - template void modify(unsigned row, const Args&... args) { modify_(row, {args...}); } - template void setHeaderText(const Args&... args) { setHeaderText_({args...}); } - - void append_(const nall::lstring &list); - void autoSizeColumns(); - bool checked(unsigned row); - void modify_(unsigned row, const nall::lstring &list); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable = true); - void setChecked(unsigned row, bool checked = true); - void setHeaderText_(const nall::lstring &list); - void setHeaderVisible(bool visible = true); - void setImage(unsigned row, unsigned column, const nall::image &image = nall::image{}); - void setSelected(bool selected = true); - void setSelection(unsigned row); - - ListView(); - ~ListView(); - struct State; - State &state; - pListView &p; -}; - -struct ProgressBar : private nall::base_from_member, Widget { - void setPosition(unsigned position); - - ProgressBar(); - ~ProgressBar(); - struct State; - State &state; - pProgressBar &p; -}; - -struct RadioBox : private nall::base_from_member, Widget { - template static void group(Args&... args) { group({args...}); } - static void group(const nall::set &list); - - nall::function onActivate; - - bool checked(); - void setChecked(); - void setText(const nall::string &text); - - RadioBox(); - ~RadioBox(); - struct State; - State &state; - pRadioBox &p; -}; - -struct TextEdit : private nall::base_from_member, Widget { - nall::function onChange; - - void setCursorPosition(unsigned position); - void setEditable(bool editable = true); - void setText(const nall::string &text); - void setWordWrap(bool wordWrap = true); - nall::string text(); - - TextEdit(); - ~TextEdit(); - struct State; - State &state; - pTextEdit &p; -}; - -struct VerticalScrollBar : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalScrollBar(); - ~VerticalScrollBar(); - struct State; - State &state; - pVerticalScrollBar &p; -}; - -struct VerticalSlider : private nall::base_from_member, Widget { - nall::function onChange; - - unsigned length(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - VerticalSlider(); - ~VerticalSlider(); - struct State; - State &state; - pVerticalSlider &p; -}; - -struct Viewport : private nall::base_from_member, Widget { - nall::function onMouseLeave; - nall::function onMouseMove; - nall::function onMousePress; - nall::function onMouseRelease; - - uintptr_t handle(); - - Viewport(); - ~Viewport(); - pViewport &p; -}; - -#include "layout/fixed-layout.hpp" -#include "layout/horizontal-layout.hpp" -#include "layout/vertical-layout.hpp" diff --git a/purify/phoenix/core/keyboard.hpp b/purify/phoenix/core/keyboard.hpp deleted file mode 100644 index ed04ec05..00000000 --- a/purify/phoenix/core/keyboard.hpp +++ /dev/null @@ -1,45 +0,0 @@ -//each code refers to a physical key -//names are taken assuming: NumLock on, CapsLock off, Shift off -//layout uses US-104 keyboard -enum class Scancode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, ScrollLock, Pause, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - - Limit, -}; - -//each enum refers to a translated scancode (eg Shift+1 = !) -enum class Keycode : unsigned { - None, - - Escape, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - PrintScreen, SysRq, ScrollLock, Pause, Break, - Insert, Delete, Home, End, PageUp, PageDown, - Up, Down, Left, Right, - - Grave, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number0, Minus, Equal, Backspace, - Tilde, Exclamation, At, Pound, Dollar, Percent, Power, Ampersand, Asterisk, ParenthesisLeft, ParenthesisRight, Underscore, Plus, - BracketLeft, BracketRight, Backslash, Semicolon, Apostrophe, Comma, Period, Slash, - BraceLeft, BraceRight, Pipe, Colon, Quote, CaretLeft, CaretRight, Question, - Tab, CapsLock, Return, ShiftLeft, ShiftRight, ControlLeft, ControlRight, SuperLeft, SuperRight, AltLeft, AltRight, Space, Menu, - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, - a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, - - NumLock, Divide, Multiply, Subtract, Add, Enter, Point, - Keypad1, Keypad2, Keypad3, Keypad4, Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, Keypad0, - KeypadInsert, KeypadDelete, KeypadHome, KeypadEnd, KeypadPageUp, KeypadPageDown, KeypadUp, KeypadDown, KeypadLeft, KeypadRight, KeypadCenter, - - Limit, -}; diff --git a/purify/phoenix/core/layout/fixed-layout.cpp b/purify/phoenix/core/layout/fixed-layout.cpp deleted file mode 100644 index 71ff3dac..00000000 --- a/purify/phoenix/core/layout/fixed-layout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -void FixedLayout::append(Sizable &sizable, const Geometry &geometry) { - children.append({ &sizable, geometry }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void FixedLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool FixedLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry FixedLayout::minimumGeometry() { - unsigned width = MinimumSize, height = MinimumSize; - for(auto &child : children) { - width = max(width, child.sizable->minimumGeometry().width); - height = max(height, child.sizable->minimumGeometry().height); - } - return { 0, 0, width, height }; -} - -void FixedLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void FixedLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void FixedLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void FixedLayout::setGeometry(const Geometry &geometry) { -} - -void FixedLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void FixedLayout::synchronizeLayout() { - for(auto &child : children) { - Layout::append(*child.sizable); - child.sizable->setGeometry(child.geometry); - } -} - -bool FixedLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -FixedLayout::FixedLayout() { - state.enabled = true; - state.visible = true; -} - -FixedLayout::~FixedLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/purify/phoenix/core/layout/fixed-layout.hpp b/purify/phoenix/core/layout/fixed-layout.hpp deleted file mode 100644 index a67f2185..00000000 --- a/purify/phoenix/core/layout/fixed-layout.hpp +++ /dev/null @@ -1,27 +0,0 @@ -struct FixedLayout : Layout { - void append(Sizable &sizable, const Geometry &geometry); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - FixedLayout(); - ~FixedLayout(); - -//private: - struct State { - bool enabled; - bool visible; - } state; - - struct Children { - Sizable *sizable; - Geometry geometry; - }; - nall::vector children; -}; diff --git a/purify/phoenix/core/layout/horizontal-layout.cpp b/purify/phoenix/core/layout/horizontal-layout.cpp deleted file mode 100644 index a1146038..00000000 --- a/purify/phoenix/core/layout/horizontal-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void HorizontalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void HorizontalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool HorizontalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry HorizontalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - width += child.spacing; - if(child.width == MinimumSize || child.width == MaximumSize) { - width += child.sizable->minimumGeometry().width; - continue; - } - width += child.width; - } - - for(auto &child : children) { - if(child.height == MinimumSize || child.height == MaximumSize) { - height = max(height, child.sizable->minimumGeometry().height); - continue; - } - height = max(height, child.height); - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void HorizontalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void HorizontalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void HorizontalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void HorizontalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void HorizontalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumWidth = 0, maximumWidthCounter = 0; - for(auto &child : children) { - if(child.width == MaximumSize) maximumWidthCounter++; - if(child.width != MaximumSize) minimumWidth += child.width; - minimumWidth += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = (geometry.width - minimumWidth) / maximumWidthCounter; - if(child.height == MaximumSize) child.height = geometry.height; - } - - unsigned maximumHeight = 0; - for(auto &child : children) maximumHeight = max(maximumHeight, child.height); - - for(auto &child : children) { - unsigned pivot = (maximumHeight - child.height) * state.alignment; - Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.x += child.width + child.spacing; - geometry.width -= child.width + child.spacing; - } -} - -void HorizontalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void HorizontalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void HorizontalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool HorizontalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -HorizontalLayout::HorizontalLayout() { - state.alignment = 0.5; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -HorizontalLayout::~HorizontalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/purify/phoenix/core/layout/horizontal-layout.hpp b/purify/phoenix/core/layout/horizontal-layout.hpp deleted file mode 100644 index 96d4f101..00000000 --- a/purify/phoenix/core/layout/horizontal-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct HorizontalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - HorizontalLayout(); - ~HorizontalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/purify/phoenix/core/layout/vertical-layout.cpp b/purify/phoenix/core/layout/vertical-layout.cpp deleted file mode 100644 index 4fd6315b..00000000 --- a/purify/phoenix/core/layout/vertical-layout.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void VerticalLayout::append(Sizable &sizable, const Size &size, unsigned spacing) { - for(auto &child : children) if(child.sizable == &sizable) return; - children.append({ &sizable, size.width, size.height, spacing }); - synchronizeLayout(); - if(window()) window()->synchronizeLayout(); -} - -void VerticalLayout::append(Sizable &sizable) { - for(auto &child : children) if(child.sizable == &sizable) return; - Layout::append(sizable); - if(window()) window()->synchronizeLayout(); -} - -bool VerticalLayout::enabled() { - if(layout()) return state.enabled && layout()->enabled(); - return state.enabled; -} - -Geometry VerticalLayout::minimumGeometry() { - unsigned width = 0, height = 0; - - for(auto &child : children) { - if(child.width == MinimumSize || child.width == MaximumSize) { - width = max(width, child.sizable->minimumGeometry().width); - continue; - } - width = max(width, child.width); - } - - for(auto &child : children) { - height += child.spacing; - if(child.height == MinimumSize || child.height == MaximumSize) { - height += child.sizable->minimumGeometry().height; - continue; - } - height += child.height; - } - - return { 0, 0, state.margin * 2 + width, state.margin * 2 + height }; -} - -void VerticalLayout::remove(Sizable &sizable) { - for(unsigned n = 0; n < children.size(); n++) { - if(children[n].sizable == &sizable) { - if(dynamic_cast(children[n].sizable)) { - Layout *layout = (Layout*)children[n].sizable; - layout->reset(); - } - children.remove(n); - Layout::remove(sizable); - if(window()) window()->synchronizeLayout(); - break; - } - } -} - -void VerticalLayout::reset() { - for(auto &child : children) { - if(window() && dynamic_cast(child.sizable)) ((Layout*)child.sizable)->reset(); - if(window() && dynamic_cast(child.sizable)) window()->remove((Widget&)*child.sizable); - } -} - -void VerticalLayout::setAlignment(double alignment) { - state.alignment = max(0.0, min(1.0, alignment)); -} - -void VerticalLayout::setEnabled(bool enabled) { - state.enabled = enabled; - for(auto &child : children) { - child.sizable->setEnabled(dynamic_cast(child.sizable) ? child.sizable->enabled() : enabled); - } -} - -void VerticalLayout::setGeometry(const Geometry &containerGeometry) { - auto children = this->children; - for(auto &child : children) { - if(child.width == MinimumSize) child.width = child.sizable->minimumGeometry().width; - if(child.height == MinimumSize) child.height = child.sizable->minimumGeometry().height; - } - - Geometry geometry = containerGeometry; - geometry.x += state.margin; - geometry.y += state.margin; - geometry.width -= state.margin * 2; - geometry.height -= state.margin * 2; - - unsigned minimumHeight = 0, maximumHeightCounter = 0; - for(auto &child : children) { - if(child.height == MaximumSize) maximumHeightCounter++; - if(child.height != MaximumSize) minimumHeight += child.height; - minimumHeight += child.spacing; - } - - for(auto &child : children) { - if(child.width == MaximumSize) child.width = geometry.width; - if(child.height == MaximumSize) child.height = (geometry.height - minimumHeight) / maximumHeightCounter; - } - - unsigned maximumWidth = 0; - for(auto &child : children) maximumWidth = max(maximumWidth, child.width); - - for(auto &child : children) { - unsigned pivot = (maximumWidth - child.width) * state.alignment; - Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height }; - child.sizable->setGeometry(childGeometry); - - geometry.y += child.height + child.spacing; - geometry.height -= child.height + child.spacing; - } -} - -void VerticalLayout::setMargin(unsigned margin) { - state.margin = margin; -} - -void VerticalLayout::setVisible(bool visible) { - state.visible = visible; - for(auto &child : children) { - child.sizable->setVisible(dynamic_cast(child.sizable) ? child.sizable->visible() : visible); - } -} - -void VerticalLayout::synchronizeLayout() { - for(auto &child : children) Layout::append(*child.sizable); -} - -bool VerticalLayout::visible() { - if(layout()) return state.visible && layout()->visible(); - return state.visible; -} - -VerticalLayout::VerticalLayout() { - state.alignment = 0.0; - state.enabled = true; - state.margin = 0; - state.visible = true; -} - -VerticalLayout::~VerticalLayout() { - while(children.size()) remove(*children[0].sizable); -} diff --git a/purify/phoenix/core/layout/vertical-layout.hpp b/purify/phoenix/core/layout/vertical-layout.hpp deleted file mode 100644 index 8273dbe2..00000000 --- a/purify/phoenix/core/layout/vertical-layout.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct VerticalLayout : public Layout { - void append(Sizable &sizable, const Size &size, unsigned spacing = 0); - void append(Sizable &sizable); - bool enabled(); - Geometry minimumGeometry(); - void remove(Sizable &sizable); - void reset(); - void setAlignment(double alignment); - void setEnabled(bool enabled = true); - void setGeometry(const Geometry &geometry); - void setMargin(unsigned margin); - void setVisible(bool visible = true); - void synchronizeLayout(); - bool visible(); - VerticalLayout(); - ~VerticalLayout(); - -//private: - struct State { - double alignment; - bool enabled; - unsigned margin; - bool visible; - } state; - - struct Children { - Sizable *sizable; - unsigned width, height, spacing; - }; - nall::vector children; -}; diff --git a/purify/phoenix/core/state.hpp b/purify/phoenix/core/state.hpp deleted file mode 100644 index a4bff751..00000000 --- a/purify/phoenix/core/state.hpp +++ /dev/null @@ -1,285 +0,0 @@ -struct OS::State { - string name; - - State() { - } -} osState; - -struct Timer::State { - bool enabled; - unsigned milliseconds; - - State() { - enabled = false; - milliseconds = 0; - } -}; - -struct Window::State { - bool backgroundColorOverride; - Color backgroundColor; - bool fullScreen; - Geometry geometry; - bool ignore; - set layout; - set menu; - string menuFont; - bool menuVisible; - bool modal; - bool resizable; - string statusFont; - string statusText; - bool statusVisible; - string title; - bool visible; - set widget; - string widgetFont; - - State() { - backgroundColorOverride = false; - backgroundColor = {0, 0, 0, 255}; - fullScreen = false; - geometry = {128, 128, 256, 256}; - ignore = false; - menuVisible = false; - modal = false; - resizable = true; - statusVisible = false; - visible = false; - } -}; - -struct Action::State { - bool enabled; - Menu *menu; - bool visible; - Window *window; - - State() { - enabled = true; - menu = 0; - visible = true; - window = 0; - } -}; - -struct Menu::State { - set action; - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Item::State { - nall::image image; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct CheckItem::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct RadioItem::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct Sizable::State { - Layout *layout; - Window *window; - - State() { - layout = 0; - window = 0; - } -}; - -struct Layout::State { - State() { - } -}; - -struct Widget::State { - bool abstract; - bool enabled; - string font; - Geometry geometry; - bool visible; - - State() { - abstract = false; - enabled = true; - geometry = {0, 0, 0, 0}; - visible = true; - } -}; - -struct Button::State { - nall::image image; - Orientation orientation; - string text; - - State() : image(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) { - } -}; - -struct Canvas::State { - uint32_t *data; - unsigned width; - unsigned height; - - State() { - data = nullptr; - width = 256; - height = 256; - } -}; - -struct CheckBox::State { - bool checked; - string text; - - State() { - checked = false; - } -}; - -struct ComboBox::State { - unsigned selection; - vector text; - - State() { - selection = 0; - } -}; - -struct HexEdit::State { - unsigned columns; - unsigned length; - unsigned offset; - unsigned rows; - - State() { - columns = 16; - length = 0; - offset = 0; - rows = 16; - } -}; - -struct HorizontalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct HorizontalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct Label::State { - string text; -}; - -struct LineEdit::State { - bool editable; - string text; - - State() { - editable = true; - } -}; - -struct ListView::State { - bool checkable; - vector checked; - lstring headerText; - bool headerVisible; - vector> image; - bool selected; - unsigned selection; - vector text; - - State() { - checkable = false; - headerVisible = false; - selected = false; - selection = 0; - } -}; - -struct ProgressBar::State { - unsigned position; - - State() { - position = 0; - } -}; - -struct RadioBox::State { - bool checked; - set group; - string text; - - State() { - checked = true; - } -}; - -struct TextEdit::State { - unsigned cursorPosition; - bool editable; - string text; - bool wordWrap; - - State() { - cursorPosition = 0; - editable = true; - wordWrap = true; - } -}; - -struct VerticalScrollBar::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; - -struct VerticalSlider::State { - unsigned length; - unsigned position; - - State() { - length = 101; - position = 0; - } -}; diff --git a/purify/phoenix/gtk/action/action.cpp b/purify/phoenix/gtk/action/action.cpp deleted file mode 100644 index 950259de..00000000 --- a/purify/phoenix/gtk/action/action.cpp +++ /dev/null @@ -1,27 +0,0 @@ -void pAction::setEnabled(bool enabled) { - gtk_widget_set_sensitive(widget, enabled); -} - -void pAction::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); -} - -void pAction::constructor() { -} - -void pAction::orphan() { -} - -//GTK+ uses _ for mnemonics, __ for _ -//transform so that & is used for mnemonics, && for & -string pAction::mnemonic(string text) { - text.transform("&_", "\x01\x02"); - text.replace("\x01\x01", "&"); - text.transform("\x01", "_"); - text.replace("\x02", "__"); - return text; -} - -void pAction::setFont(const string &font) { - pFont::setFont(widget, font); -} diff --git a/purify/phoenix/gtk/action/check-item.cpp b/purify/phoenix/gtk/action/check-item.cpp deleted file mode 100644 index 2cc182a6..00000000 --- a/purify/phoenix/gtk/action/check-item.cpp +++ /dev/null @@ -1,33 +0,0 @@ -static void CheckItem_toggle(CheckItem *self) { - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pCheckItem::setChecked(bool checked) { - locked = true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked); - locked = false; -} - -void pCheckItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pCheckItem::constructor() { - widget = gtk_check_menu_item_new_with_mnemonic(""); - setChecked(checkItem.state.checked); - setText(checkItem.state.text); - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_toggle), (gpointer)&checkItem); -} - -void pCheckItem::destructor() { - gtk_widget_destroy(widget); -} - -void pCheckItem::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/action/item.cpp b/purify/phoenix/gtk/action/item.cpp deleted file mode 100644 index afab955e..00000000 --- a/purify/phoenix/gtk/action/item.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static void Item_activate(Item *self) { - if(self->onActivate) self->onActivate(); -} - -void pItem::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pItem::constructor() { - widget = gtk_image_menu_item_new_with_mnemonic(""); - g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_activate), (gpointer)&item); - setText(item.state.text); -} - -void pItem::destructor() { - gtk_widget_destroy(widget); -} - -void pItem::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/action/menu.cpp b/purify/phoenix/gtk/action/menu.cpp deleted file mode 100644 index 92252085..00000000 --- a/purify/phoenix/gtk/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - action.state.window = this->action.state.window; - - gtk_menu_shell_append(GTK_MENU_SHELL(gtkMenu), action.p.widget); - if(action.state.window && action.state.window->state.menuFont != "") { - action.p.setFont(action.state.window->state.menuFont); - } - gtk_widget_show(action.p.widget); -} - -void pMenu::remove(Action &action) { - action.p.orphan(); - action.state.window = 0; -} - -void pMenu::setImage(const image &image) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image, true); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), (GtkWidget*)gtkImage); - } else { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), nullptr); - } -} - -void pMenu::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pMenu::constructor() { - gtkMenu = gtk_menu_new(); - widget = gtk_image_menu_item_new_with_mnemonic(""); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), gtkMenu); - setText(menu.state.text); -} - -void pMenu::destructor() { - gtk_widget_destroy(gtkMenu); - gtk_widget_destroy(widget); -} - -void pMenu::orphan() { - for(auto &action : menu.state.action) action.p.orphan(); - destructor(); - constructor(); - for(auto &action : menu.state.action) append(action); -} - -void pMenu::setFont(const string &font) { - pAction::setFont(font); - for(auto &item : menu.state.action) item.p.setFont(font); -} diff --git a/purify/phoenix/gtk/action/radio-item.cpp b/purify/phoenix/gtk/action/radio-item.cpp deleted file mode 100644 index a599d70b..00000000 --- a/purify/phoenix/gtk/action/radio-item.cpp +++ /dev/null @@ -1,48 +0,0 @@ -static void RadioItem_activate(RadioItem *self) { - for(auto &item : self->state.group) item.state.checked = (&item == self); - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true); - locked = false; -} - -void pRadioItem::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget)); - if(currentGroup != gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[n].p.widget))) { - gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(group[n].p.widget), currentGroup); - } - } -} - -void pRadioItem::setText(const string &text) { - gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text)); -} - -void pRadioItem::constructor() { - widget = gtk_radio_menu_item_new_with_mnemonic(0, ""); - setGroup(radioItem.state.group); - setText(radioItem.state.text); - for(auto &item : radioItem.state.group) { - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), item.state.checked); - } - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_activate), (gpointer)&radioItem); -} - -void pRadioItem::destructor() { - gtk_widget_destroy(widget); -} - -void pRadioItem::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/action/separator.cpp b/purify/phoenix/gtk/action/separator.cpp deleted file mode 100644 index 8b7a1a6b..00000000 --- a/purify/phoenix/gtk/action/separator.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pSeparator::constructor() { - widget = gtk_separator_menu_item_new(); -} - -void pSeparator::destructor() { - gtk_widget_destroy(widget); -} - -void pSeparator::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/desktop.cpp b/purify/phoenix/gtk/desktop.cpp deleted file mode 100644 index 2b1801ad..00000000 --- a/purify/phoenix/gtk/desktop.cpp +++ /dev/null @@ -1,36 +0,0 @@ -Size pDesktop::size() { - return { - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} - -Geometry pDesktop::workspace() { - XlibDisplay *display = XOpenDisplay(0); - int screen = DefaultScreen(display); - - static Atom atom = XlibNone; - if(atom == XlibNone) atom = XInternAtom(display, "_NET_WORKAREA", True); - - int format; - unsigned char *data = 0; - unsigned long items, after; - Atom returnAtom; - - int result = XGetWindowProperty( - display, RootWindow(display, screen), atom, 0, 4, False, XA_CARDINAL, &returnAtom, &format, &items, &after, &data - ); - - XCloseDisplay(display); - - if(result == Success && returnAtom == XA_CARDINAL && format == 32 && items == 4) { - unsigned long *workarea = (unsigned long*)data; - return { (signed)workarea[0], (signed)workarea[1], (unsigned)workarea[2], (unsigned)workarea[3] }; - } - - return { - 0, 0, - gdk_screen_get_width(gdk_screen_get_default()), - gdk_screen_get_height(gdk_screen_get_default()) - }; -} diff --git a/purify/phoenix/gtk/dialog-window.cpp b/purify/phoenix/gtk/dialog-window.cpp deleted file mode 100644 index eb04bd64..00000000 --- a/purify/phoenix/gtk/dialog-window.cpp +++ /dev/null @@ -1,69 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - save == 0 ? "Load File" : "Save File", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - save == 0 ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - for(auto &filterItem : filter) { - GtkFileFilter *gtkFilter = gtk_file_filter_new(); - gtk_file_filter_set_name(gtkFilter, filterItem); - lstring part; - part.split("(", filterItem); - part[1].rtrim<1>(")"); - lstring list; - list.split(",", part[1]); - for(auto &pattern : list) gtk_file_filter_add_pattern(gtkFilter, pattern); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), gtkFilter); - } - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(0, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(1, parent, path, filter); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - string name; - - GtkWidget *dialog = gtk_file_chooser_dialog_new( - "Select Folder", - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - (const gchar*)nullptr - ); - - if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - name = temp; - g_free(temp); - } - - gtk_widget_destroy(dialog); - if(name == "") return ""; - if(name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/purify/phoenix/gtk/font.cpp b/purify/phoenix/gtk/font.cpp deleted file mode 100644 index cb6889d1..00000000 --- a/purify/phoenix/gtk/font.cpp +++ /dev/null @@ -1,58 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - PangoFontDescription *font = create(description); - Geometry geometry = pFont::geometry(font, text); - free(font); - return geometry; -} - -PangoFontDescription* pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - PangoFontDescription *font = pango_font_description_new(); - pango_font_description_set_family(font, family); - pango_font_description_set_size(font, size * PANGO_SCALE); - pango_font_description_set_weight(font, !bold ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD); - pango_font_description_set_style(font, !italic ? PANGO_STYLE_NORMAL : PANGO_STYLE_OBLIQUE); - return font; -} - -void pFont::free(PangoFontDescription *font) { - pango_font_description_free(font); -} - -Geometry pFont::geometry(PangoFontDescription *font, const string &text) { - PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); - PangoLayout *layout = pango_layout_new(context); - pango_layout_set_font_description(layout, font); - pango_layout_set_text(layout, text, -1); - int width = 0, height = 0; - pango_layout_get_pixel_size(layout, &width, &height); - g_object_unref((gpointer)layout); - return { 0, 0, width, height }; -} - -void pFont::setFont(GtkWidget *widget, const string &font) { - auto gtkFont = pFont::create(font); - pFont::setFont(widget, (gpointer)gtkFont); - pFont::free(gtkFont); -} - -void pFont::setFont(GtkWidget *widget, gpointer font) { - if(font == 0) return; - gtk_widget_modify_font(widget, (PangoFontDescription*)font); - if(GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)pFont::setFont, font); - } -} diff --git a/purify/phoenix/gtk/keyboard.cpp b/purify/phoenix/gtk/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/purify/phoenix/gtk/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/purify/phoenix/gtk/message-window.cpp b/purify/phoenix/gtk/message-window.cpp deleted file mode 100644 index 7cd2172a..00000000 --- a/purify/phoenix/gtk/message-window.cpp +++ /dev/null @@ -1,61 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, gint response) { - if(response == GTK_RESPONSE_OK) return MessageWindow::Response::Ok; - if(response == GTK_RESPONSE_CANCEL) return MessageWindow::Response::Cancel; - if(response == GTK_RESPONSE_YES) return MessageWindow::Response::Yes; - if(response == GTK_RESPONSE_NO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - GtkButtonsType buttonsType = GTK_BUTTONS_OK; - if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL; - if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO; - GtkWidget *dialog = gtk_message_dialog_new( - &parent != &Window::none() ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)nullptr, - GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, buttonsType, "%s", (const char*)text - ); - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - return MessageWindow_response(buttons, response); -} diff --git a/purify/phoenix/gtk/mouse.cpp b/purify/phoenix/gtk/mouse.cpp deleted file mode 100644 index e00f7ff7..00000000 --- a/purify/phoenix/gtk/mouse.cpp +++ /dev/null @@ -1,20 +0,0 @@ -Position pMouse::position() { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - return { rootx, rooty }; -} - -bool pMouse::pressed(Mouse::Button button) { - XlibWindow root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - XQueryPointer(pOS::display, DefaultRootWindow(pOS::display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); - switch(button) { - case Mouse::Button::Left: return mask & Button1Mask; - case Mouse::Button::Middle: return mask & Button2Mask; - case Mouse::Button::Right: return mask & Button3Mask; - } - return false; -} diff --git a/purify/phoenix/gtk/platform.cpp b/purify/phoenix/gtk/platform.cpp deleted file mode 100644 index c6650dbb..00000000 --- a/purify/phoenix/gtk/platform.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; -Font pOS::defaultFont; - -void pOS::main() { - gtk_main(); -} - -bool pOS::pendingEvents() { - return gtk_events_pending(); -} - -void pOS::processEvents() { - while(pendingEvents()) gtk_main_iteration_do(false); -} - -void pOS::quit() { - gtk_main_quit(); -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - int argc = 1; - char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - gtk_init(&argc, &argvp); - - gtk_rc_parse_string(R"( - style "phoenix-gtk" - { - GtkWindow::resize-grip-width = 0 - GtkWindow::resize-grip-height = 0 - GtkTreeView::vertical-separator = 0 - GtkComboBox::appears-as-list = 1 - } - class "GtkWindow" style "phoenix-gtk" - class "GtkTreeView" style "phoenix-gtk" - # class "GtkComboBox" style "phoenix-gtk" - )"); - - pKeyboard::initialize(); -} diff --git a/purify/phoenix/gtk/platform.hpp b/purify/phoenix/gtk/platform.hpp deleted file mode 100644 index 01c4a223..00000000 --- a/purify/phoenix/gtk/platform.hpp +++ /dev/null @@ -1,505 +0,0 @@ -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - unsigned windowBackgroundColor; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static PangoFontDescription* create(const string &description); - static void free(PangoFontDescription *font); - static Geometry geometry(PangoFontDescription *font, const string &text); - static void setFont(GtkWidget *widget, const string &font); - static void setFont(GtkWidget *widget, gpointer font); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - static Font defaultFont; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - GtkWidget *widget; - GtkWidget *menuContainer; - GtkWidget *formContainer; - GtkWidget *statusContainer; - GtkWidget *menu; - GtkWidget *status; - GtkAllocation lastAllocation; - bool onSizePending; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - unsigned menuHeight(); - unsigned statusHeight(); -}; - -struct pAction : public pObject { - Action &action; - GtkWidget *widget; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - virtual void orphan(); - string mnemonic(string text); - virtual void setFont(const string &font); -}; - -struct pMenu : public pAction { - Menu &menu; - GtkWidget *gtkMenu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); - void orphan(); - void setFont(const string &font); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - GtkWidget *gtkWidget; - - bool enabled(); - virtual bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - virtual void setFocused(); - virtual void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public pWidget { - Button &button; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - cairo_surface_t *surface; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - unsigned itemCounter; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - GtkWidget *container; - GtkWidget *subWidget; - GtkWidget *scrollBar; - GtkTextBuffer *textBuffer; - GtkTextMark *textCursor; - - bool focused(); - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - unsigned cursorPosition(); - bool keyPress(unsigned scancode); - void scroll(unsigned position); - void setCursorPosition(unsigned position); - void setScroll(); - void updateScroll(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - GtkWidget *subWidget; - GtkListStore *store; - struct GtkColumn { - GtkTreeViewColumn *column; - GtkCellRenderer *checkbox, *icon, *text; - GtkWidget *label; - }; - vector column; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - bool focused(); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - void setFocused(); - void setFont(const string &font); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - GtkWidget *subWidget; - GtkTextBuffer *textBuffer; - - bool focused(); - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/purify/phoenix/gtk/settings.cpp b/purify/phoenix/gtk/settings.cpp deleted file mode 100644 index aeb28bba..00000000 --- a/purify/phoenix/gtk/settings.cpp +++ /dev/null @@ -1,25 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/gtk.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("gtk.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); - append(windowBackgroundColor = 0xedeceb, "windowBackgroundColor"); -} diff --git a/purify/phoenix/gtk/timer.cpp b/purify/phoenix/gtk/timer.cpp deleted file mode 100644 index d04183f8..00000000 --- a/purify/phoenix/gtk/timer.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static guint Timer_trigger(pTimer *self) { - //timer may have been disabled prior to triggering, so check state - if(self->timer.state.enabled) { - if(self->timer.onTimeout) self->timer.onTimeout(); - } - //callback may have disabled timer, so check state again - if(self->timer.state.enabled) { - g_timeout_add(self->timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)self); - } - //kill this timer instance (it is spawned above if needed again) - return false; -} - -void pTimer::setEnabled(bool enabled) { - if(enabled) { - g_timeout_add(timer.state.milliseconds, (GSourceFunc)Timer_trigger, (gpointer)this); - } -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/purify/phoenix/gtk/utility.cpp b/purify/phoenix/gtk/utility.cpp deleted file mode 100644 index 29e87bb8..00000000 --- a/purify/phoenix/gtk/utility.cpp +++ /dev/null @@ -1,200 +0,0 @@ -static GdkPixbuf* CreatePixbuf(const nall::image &image, bool scale = false) { - nall::image gdkImage = image; - gdkImage.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); - if(scale) gdkImage.scale(15, 15, Interpolation::Linear); - - GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, gdkImage.width, gdkImage.height); - memcpy(gdk_pixbuf_get_pixels(pixbuf), gdkImage.data, gdkImage.width * gdkImage.height * 4); - - return pixbuf; -} - -static GtkImage* CreateImage(const nall::image &image, bool scale = false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, scale); - GtkImage *gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); - return gtkImage; -} - -static Keyboard::Keycode Keysym(unsigned keysym) { - switch(keysym) { - case GDK_Escape: return Keyboard::Keycode::Escape; - case GDK_F1: return Keyboard::Keycode::F1; - case GDK_F2: return Keyboard::Keycode::F2; - case GDK_F3: return Keyboard::Keycode::F3; - case GDK_F4: return Keyboard::Keycode::F4; - case GDK_F5: return Keyboard::Keycode::F5; - case GDK_F6: return Keyboard::Keycode::F6; - case GDK_F7: return Keyboard::Keycode::F7; - case GDK_F8: return Keyboard::Keycode::F8; - case GDK_F9: return Keyboard::Keycode::F9; - case GDK_F10: return Keyboard::Keycode::F10; - case GDK_F11: return Keyboard::Keycode::F11; - case GDK_F12: return Keyboard::Keycode::F12; - - case GDK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case GDK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case GDK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case GDK_Insert: return Keyboard::Keycode::Insert; - case GDK_Delete: return Keyboard::Keycode::Delete; - case GDK_Home: return Keyboard::Keycode::Home; - case GDK_End: return Keyboard::Keycode::End; - case GDK_Prior: return Keyboard::Keycode::PageUp; - case GDK_Next: return Keyboard::Keycode::PageDown; - - case GDK_Up: return Keyboard::Keycode::Up; - case GDK_Down: return Keyboard::Keycode::Down; - case GDK_Left: return Keyboard::Keycode::Left; - case GDK_Right: return Keyboard::Keycode::Right; - - case GDK_grave: return Keyboard::Keycode::Grave; - case GDK_1: return Keyboard::Keycode::Number1; - case GDK_2: return Keyboard::Keycode::Number2; - case GDK_3: return Keyboard::Keycode::Number3; - case GDK_4: return Keyboard::Keycode::Number4; - case GDK_5: return Keyboard::Keycode::Number5; - case GDK_6: return Keyboard::Keycode::Number6; - case GDK_7: return Keyboard::Keycode::Number7; - case GDK_8: return Keyboard::Keycode::Number8; - case GDK_9: return Keyboard::Keycode::Number9; - case GDK_0: return Keyboard::Keycode::Number0; - case GDK_minus: return Keyboard::Keycode::Minus; - case GDK_equal: return Keyboard::Keycode::Equal; - case GDK_BackSpace: return Keyboard::Keycode::Backspace; - - case GDK_asciitilde: return Keyboard::Keycode::Tilde; - case GDK_exclam: return Keyboard::Keycode::Exclamation; - case GDK_at: return Keyboard::Keycode::At; - case GDK_numbersign: return Keyboard::Keycode::Pound; - case GDK_dollar: return Keyboard::Keycode::Dollar; - case GDK_percent: return Keyboard::Keycode::Percent; - case GDK_asciicircum: return Keyboard::Keycode::Power; - case GDK_ampersand: return Keyboard::Keycode::Ampersand; - case GDK_asterisk: return Keyboard::Keycode::Asterisk; - case GDK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case GDK_parenright: return Keyboard::Keycode::ParenthesisRight; - case GDK_underscore: return Keyboard::Keycode::Underscore; - case GDK_plus: return Keyboard::Keycode::Plus; - - case GDK_bracketleft: return Keyboard::Keycode::BracketLeft; - case GDK_bracketright: return Keyboard::Keycode::BracketRight; - case GDK_backslash: return Keyboard::Keycode::Backslash; - case GDK_semicolon: return Keyboard::Keycode::Semicolon; - case GDK_apostrophe: return Keyboard::Keycode::Apostrophe; - case GDK_comma: return Keyboard::Keycode::Comma; - case GDK_period: return Keyboard::Keycode::Period; - case GDK_slash: return Keyboard::Keycode::Slash; - - case GDK_braceleft: return Keyboard::Keycode::BraceLeft; - case GDK_braceright: return Keyboard::Keycode::BraceRight; - case GDK_bar: return Keyboard::Keycode::Pipe; - case GDK_colon: return Keyboard::Keycode::Colon; - case GDK_quotedbl: return Keyboard::Keycode::Quote; - case GDK_less: return Keyboard::Keycode::CaretLeft; - case GDK_greater: return Keyboard::Keycode::CaretRight; - case GDK_question: return Keyboard::Keycode::Question; - - case GDK_Tab: return Keyboard::Keycode::Tab; - case GDK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case GDK_Return: return Keyboard::Keycode::Return; - case GDK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case GDK_Shift_R: return Keyboard::Keycode::ShiftRight; - case GDK_Control_L: return Keyboard::Keycode::ControlLeft; - case GDK_Control_R: return Keyboard::Keycode::ControlRight; - case GDK_Super_L: return Keyboard::Keycode::SuperLeft; - case GDK_Super_R: return Keyboard::Keycode::SuperRight; - case GDK_Alt_L: return Keyboard::Keycode::AltLeft; - case GDK_Alt_R: return Keyboard::Keycode::AltRight; - case GDK_space: return Keyboard::Keycode::Space; - case GDK_Menu: return Keyboard::Keycode::Menu; - - case GDK_A: return Keyboard::Keycode::A; - case GDK_B: return Keyboard::Keycode::B; - case GDK_C: return Keyboard::Keycode::C; - case GDK_D: return Keyboard::Keycode::D; - case GDK_E: return Keyboard::Keycode::E; - case GDK_F: return Keyboard::Keycode::F; - case GDK_G: return Keyboard::Keycode::G; - case GDK_H: return Keyboard::Keycode::H; - case GDK_I: return Keyboard::Keycode::I; - case GDK_J: return Keyboard::Keycode::J; - case GDK_K: return Keyboard::Keycode::K; - case GDK_L: return Keyboard::Keycode::L; - case GDK_M: return Keyboard::Keycode::M; - case GDK_N: return Keyboard::Keycode::N; - case GDK_O: return Keyboard::Keycode::O; - case GDK_P: return Keyboard::Keycode::P; - case GDK_Q: return Keyboard::Keycode::Q; - case GDK_R: return Keyboard::Keycode::R; - case GDK_S: return Keyboard::Keycode::S; - case GDK_T: return Keyboard::Keycode::T; - case GDK_U: return Keyboard::Keycode::U; - case GDK_V: return Keyboard::Keycode::V; - case GDK_W: return Keyboard::Keycode::W; - case GDK_X: return Keyboard::Keycode::X; - case GDK_Y: return Keyboard::Keycode::Y; - case GDK_Z: return Keyboard::Keycode::Z; - - case GDK_a: return Keyboard::Keycode::a; - case GDK_b: return Keyboard::Keycode::b; - case GDK_c: return Keyboard::Keycode::c; - case GDK_d: return Keyboard::Keycode::d; - case GDK_e: return Keyboard::Keycode::e; - case GDK_f: return Keyboard::Keycode::f; - case GDK_g: return Keyboard::Keycode::g; - case GDK_h: return Keyboard::Keycode::h; - case GDK_i: return Keyboard::Keycode::i; - case GDK_j: return Keyboard::Keycode::j; - case GDK_k: return Keyboard::Keycode::k; - case GDK_l: return Keyboard::Keycode::l; - case GDK_m: return Keyboard::Keycode::m; - case GDK_n: return Keyboard::Keycode::n; - case GDK_o: return Keyboard::Keycode::o; - case GDK_p: return Keyboard::Keycode::p; - case GDK_q: return Keyboard::Keycode::q; - case GDK_r: return Keyboard::Keycode::r; - case GDK_s: return Keyboard::Keycode::s; - case GDK_t: return Keyboard::Keycode::t; - case GDK_u: return Keyboard::Keycode::u; - case GDK_v: return Keyboard::Keycode::v; - case GDK_w: return Keyboard::Keycode::w; - case GDK_x: return Keyboard::Keycode::x; - case GDK_y: return Keyboard::Keycode::y; - case GDK_z: return Keyboard::Keycode::z; - - case GDK_Num_Lock: return Keyboard::Keycode::NumLock; - case GDK_KP_Divide: return Keyboard::Keycode::Divide; - case GDK_KP_Multiply: return Keyboard::Keycode::Multiply; - case GDK_KP_Subtract: return Keyboard::Keycode::Subtract; - case GDK_KP_Add: return Keyboard::Keycode::Add; - case GDK_KP_Enter: return Keyboard::Keycode::Enter; - case GDK_KP_Decimal: return Keyboard::Keycode::Point; - - case GDK_KP_1: return Keyboard::Keycode::Keypad1; - case GDK_KP_2: return Keyboard::Keycode::Keypad2; - case GDK_KP_3: return Keyboard::Keycode::Keypad3; - case GDK_KP_4: return Keyboard::Keycode::Keypad4; - case GDK_KP_5: return Keyboard::Keycode::Keypad5; - case GDK_KP_6: return Keyboard::Keycode::Keypad6; - case GDK_KP_7: return Keyboard::Keycode::Keypad7; - case GDK_KP_8: return Keyboard::Keycode::Keypad8; - case GDK_KP_9: return Keyboard::Keycode::Keypad9; - case GDK_KP_0: return Keyboard::Keycode::Keypad0; - - case GDK_KP_Home: return Keyboard::Keycode::KeypadHome; - case GDK_KP_End: return Keyboard::Keycode::KeypadEnd; - case GDK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case GDK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case GDK_KP_Up: return Keyboard::Keycode::KeypadUp; - case GDK_KP_Down: return Keyboard::Keycode::KeypadDown; - case GDK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case GDK_KP_Right: return Keyboard::Keycode::KeypadRight; - case GDK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case GDK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case GDK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/purify/phoenix/gtk/widget/button.cpp b/purify/phoenix/gtk/widget/button.cpp deleted file mode 100644 index 6f646a25..00000000 --- a/purify/phoenix/gtk/widget/button.cpp +++ /dev/null @@ -1,53 +0,0 @@ -static void Button_activate(Button *self) { - if(self->onActivate) self->onActivate(); -} - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 24, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - if(image.empty() == false) { - GtkImage *gtkImage = CreateImage(image); - gtk_button_set_image(GTK_BUTTON(gtkWidget), (GtkWidget*)gtkImage); - } else { - gtk_button_set_image(GTK_BUTTON(gtkWidget), nullptr); - } - switch(orientation) { - case Orientation::Horizontal: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_LEFT); break; - case Orientation::Vertical: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_TOP); break; - } -} - -void pButton::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); - setFont(widget.state.font); -} - -void pButton::constructor() { - gtkWidget = gtk_button_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_activate), (gpointer)&button); - - setText(button.state.text); -} - -void pButton::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/canvas.cpp b/purify/phoenix/gtk/widget/canvas.cpp deleted file mode 100644 index 9d17dc82..00000000 --- a/purify/phoenix/gtk/widget/canvas.cpp +++ /dev/null @@ -1,70 +0,0 @@ -static gboolean Canvas_expose(GtkWidget *widget, GdkEvent *event, pCanvas *self) { - cairo_t *context = gdk_cairo_create(gtk_widget_get_window(widget)); - cairo_set_source_surface(context, self->surface, 0, 0); - cairo_paint(context); - cairo_destroy(context); - return true; -} - -static gboolean Canvas_mouseLeave(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseLeave) self->canvas.onMouseLeave(); - return true; -} - -static gboolean Canvas_mouseMove(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseMove) self->canvas.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Canvas_mousePress(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMousePress) switch(event->button) { - case 1: self->canvas.onMousePress(Mouse::Button::Left); break; - case 2: self->canvas.onMousePress(Mouse::Button::Middle); break; - case 3: self->canvas.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Canvas_mouseRelease(GtkWidget *widget, GdkEventButton *event, pCanvas *self) { - if(self->canvas.onMouseRelease) switch(event->button) { - case 1: self->canvas.onMouseRelease(Mouse::Button::Left); break; - case 2: self->canvas.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->canvas.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -void pCanvas::setSize(const Size &size) { - cairo_surface_destroy(surface); - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); -} - -void pCanvas::update() { - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - if(gtk_widget_get_realized(gtkWidget) == false) return; - gdk_window_invalidate_rect(gtk_widget_get_window(gtkWidget), 0, true); -} - -void pCanvas::constructor() { - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, canvas.state.width, canvas.state.height); - memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - gtkWidget = gtk_drawing_area_new(); - gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Canvas_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Canvas_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Canvas_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Canvas_mouseMove), (gpointer)this); -} - -void pCanvas::destructor() { - gtk_widget_destroy(gtkWidget); - cairo_surface_destroy(surface); -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/check-box.cpp b/purify/phoenix/gtk/widget/check-box.cpp deleted file mode 100644 index b6493f32..00000000 --- a/purify/phoenix/gtk/widget/check-box.cpp +++ /dev/null @@ -1,40 +0,0 @@ -static void CheckBox_toggle(CheckBox *self) { - self->state.checked = self->checked(); - if(self->p.locked == false && self->onToggle) self->onToggle(); -} - -bool pCheckBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, checkBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pCheckBox::constructor() { - gtkWidget = gtk_check_button_new_with_label(""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_toggle), (gpointer)&checkBox); - - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/combo-box.cpp b/purify/phoenix/gtk/widget/combo-box.cpp deleted file mode 100644 index 648d587f..00000000 --- a/purify/phoenix/gtk/widget/combo-box.cpp +++ /dev/null @@ -1,73 +0,0 @@ -static void ComboBox_change(ComboBox *self) { - if(self->p.locked == false) { - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -void pComboBox::append(const string &text) { - gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text); - if(itemCounter++ == 0) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &item : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(widget.state.font, item).width); - - Geometry geometry = pFont::geometry(widget.state.font, " "); - return { 0, 0, maximumWidth + 44, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkWidget), row, text); - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row); - if(position == row) gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), 0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(gtkWidget)))); - itemCounter = 0; - locked = false; -} - -unsigned pComboBox::selection() { - return gtk_combo_box_get_active(GTK_COMBO_BOX(gtkWidget)); -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), row); - locked = false; -} - -void pComboBox::constructor() { - itemCounter = 0; - gtkWidget = gtk_combo_box_new_text(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox); - - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(comboBox.state.selection); -} - -void pComboBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/hex-edit.cpp b/purify/phoenix/gtk/widget/hex-edit.cpp deleted file mode 100644 index ec10cd7c..00000000 --- a/purify/phoenix/gtk/widget/hex-edit.cpp +++ /dev/null @@ -1,268 +0,0 @@ -static bool HexEdit_keyPress(GtkWidget *widget, GdkEventKey *event, HexEdit *self) { - return self->p.keyPress(event->keyval); -} - -static bool HexEdit_scroll(GtkRange *range, GtkScrollType scroll, gdouble value, HexEdit *self) { - self->p.scroll((unsigned)value); - return false; -} - -bool pHexEdit::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pHexEdit::setColumns(unsigned columns) { - setScroll(); - update(); -} - -void pHexEdit::setLength(unsigned length) { - setScroll(); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - setScroll(); - updateScroll(); - update(); -} - -void pHexEdit::setRows(unsigned rows) { - setScroll(); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - gtk_text_buffer_set_text(textBuffer, "", -1); - return; - } - - unsigned position = cursorPosition(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - gtk_text_buffer_set_text(textBuffer, output, -1); - if(position == 0) position = 10; //start at first position where hex values can be entered - setCursorPosition(position); -} - -void pHexEdit::constructor() { - gtkWidget = gtk_hbox_new(false, 0); - - container = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(container), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(container), GTK_SHADOW_ETCHED_IN); - - subWidget = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), false); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_NONE); - gtk_container_add(GTK_CONTAINER(container), subWidget); - g_signal_connect(G_OBJECT(subWidget), "key-press-event", G_CALLBACK(HexEdit_keyPress), (gpointer)&hexEdit); - - scrollBar = gtk_vscrollbar_new((GtkAdjustment*)0); - gtk_range_set_range(GTK_RANGE(scrollBar), 0, 255); - gtk_range_set_increments(GTK_RANGE(scrollBar), 1, 16); - gtk_widget_set_sensitive(scrollBar, false); - g_signal_connect(G_OBJECT(scrollBar), "change-value", G_CALLBACK(HexEdit_scroll), (gpointer)&hexEdit); - - gtk_box_pack_start(GTK_BOX(gtkWidget), container, true, true, 0); - gtk_box_pack_start(GTK_BOX(gtkWidget), scrollBar, false, false, 1); - - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - textCursor = gtk_text_buffer_get_mark(textBuffer, "insert"); - - gtk_widget_show(scrollBar); - gtk_widget_show(subWidget); - gtk_widget_show(container); - - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - gtk_widget_destroy(scrollBar); - gtk_widget_destroy(subWidget); - gtk_widget_destroy(container); - gtk_widget_destroy(gtkWidget); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -unsigned pHexEdit::cursorPosition() { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - return gtk_text_iter_get_offset(&iter); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = cursorPosition(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - if(scancode == GDK_Home) { - setCursorPosition(cursorY * lineWidth + 10); - return true; - } - - if(scancode == GDK_End) { - setCursorPosition(cursorY * lineWidth + 10 + (hexEdit.state.columns * 3 - 1)); - return true; - } - - if(scancode == GDK_Up) { - if(cursorY != 0) return false; - - signed newOffset = hexEdit.state.offset - hexEdit.state.columns; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Down) { - if(cursorY != hexEdit.state.rows - 1) return false; - - signed newOffset = hexEdit.state.offset + hexEdit.state.columns; - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - } - return true; - } - - if(scancode == GDK_Page_Up) { - signed newOffset = hexEdit.state.offset - hexEdit.state.columns * hexEdit.state.rows; - if(newOffset >= 0) { - hexEdit.setOffset(newOffset); - } else { - hexEdit.setOffset(0); - } - update(); - return true; - } - - if(scancode == GDK_Page_Down) { - signed newOffset = hexEdit.state.offset + hexEdit.state.columns * hexEdit.state.rows; - for(unsigned n = 0; n < hexEdit.state.rows; n++) { - if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) { - hexEdit.setOffset(newOffset); - update(); - break; - } - newOffset -= hexEdit.state.columns; - } - return true; - } - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; //not a valid hex value - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - setCursorPosition(position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} - -void pHexEdit::scroll(unsigned position) { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(position >= rows) position = rows - 1; - hexEdit.setOffset(position * hexEdit.state.columns); -} - -void pHexEdit::setCursorPosition(unsigned position) { - GtkTextIter iter; - gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); - - //GTK+ will throw many errors to the terminal if you set iterator past end of buffer - GtkTextIter endIter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - unsigned endPosition = gtk_text_iter_get_offset(&iter); - - gtk_text_iter_set_offset(&iter, min(position, endPosition)); - gtk_text_buffer_place_cursor(textBuffer, &iter); -} - -void pHexEdit::setScroll() { - unsigned rows = hexEdit.state.length / hexEdit.state.columns; - if(rows) rows--; - if(rows) { - gtk_range_set_range(GTK_RANGE(scrollBar), 0, rows); - gtk_widget_set_sensitive(scrollBar, true); - } else { - gtk_widget_set_sensitive(scrollBar, false); - } -} - -void pHexEdit::updateScroll() { - unsigned row = hexEdit.state.offset / hexEdit.state.columns; - gtk_range_set_value(GTK_RANGE(scrollBar), row); -} diff --git a/purify/phoenix/gtk/widget/horizontal-scroll-bar.cpp b/purify/phoenix/gtk/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 0d765e92..00000000 --- a/purify/phoenix/gtk/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void HorizontalScrollBar_change(HorizontalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalScrollBar::constructor() { - gtkWidget = gtk_hscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar); - - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/horizontal-slider.cpp b/purify/phoenix/gtk/widget/horizontal-slider.cpp deleted file mode 100644 index 2d19bae6..00000000 --- a/purify/phoenix/gtk/widget/horizontal-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void HorizontalSlider_change(HorizontalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pHorizontalSlider::constructor() { - gtkWidget = gtk_hscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider); - - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/label.cpp b/purify/phoenix/gtk/widget/label.cpp deleted file mode 100644 index 8b5cec4f..00000000 --- a/purify/phoenix/gtk/widget/label.cpp +++ /dev/null @@ -1,24 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - gtk_label_set_text(GTK_LABEL(gtkWidget), text); -} - -void pLabel::constructor() { - gtkWidget = gtk_label_new(""); - gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5); - - setText(label.state.text); -} - -void pLabel::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/line-edit.cpp b/purify/phoenix/gtk/widget/line-edit.cpp deleted file mode 100644 index 8dbe9ef4..00000000 --- a/purify/phoenix/gtk/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -static void LineEdit_activate(LineEdit *self) { - if(self->onActivate) self->onActivate(); -} - -static void LineEdit_change(LineEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, lineEdit.state.text); - return { 0, 0, geometry.width + 10, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - gtk_editable_set_editable(GTK_EDITABLE(gtkWidget), editable); -} - -void pLineEdit::setText(const string &text) { - locked = true; - gtk_entry_set_text(GTK_ENTRY(gtkWidget), text); - locked = false; -} - -string pLineEdit::text() { - return gtk_entry_get_text(GTK_ENTRY(gtkWidget)); -} - -void pLineEdit::constructor() { - gtkWidget = gtk_entry_new(); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit); - - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/list-view.cpp b/purify/phoenix/gtk/widget/list-view.cpp deleted file mode 100644 index 10e1d439..00000000 --- a/purify/phoenix/gtk/widget/list-view.cpp +++ /dev/null @@ -1,221 +0,0 @@ -static void ListView_activate(ListView *self) { - if(self->onActivate) self->onActivate(); -} - -static void ListView_change(ListView *self) { - if(self->state.selected == false || self->state.selection != self->selection()) { - self->state.selected = true; - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); - } -} - -static void ListView_toggle(GtkCellRendererToggle *cell, gchar *path, ListView *self) { - unsigned row = decimal(path); - self->setChecked(row, !self->checked(row)); - if(self->onToggle) self->onToggle(row); -} - -void pListView::append(const lstring &text) { - GtkTreeIter iter; - gtk_list_store_append(store, &iter); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::autoSizeColumns() { - gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget)); -} - -bool pListView::checked(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - bool state; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return false; - gtk_tree_model_get(model, &iter, 0, &state, -1); - return state; -} - -bool pListView::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pListView::modify(unsigned row, const lstring &text) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - for(unsigned n = 0; n < text.size(); n++) gtk_list_store_set(store, &iter, 1 + n * 2 + 1, (const char*)text[n], -1); -} - -void pListView::remove(unsigned row) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_remove(store, &iter); -} - -void pListView::reset() { - listView.state.selected = false; - listView.state.selection = 0; - gtk_list_store_clear(GTK_LIST_STORE(store)); - gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store)); - //reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty - gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); - gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); -} - -bool pListView::selected() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - return gtk_tree_selection_get_selected(selection, 0, 0); -} - -unsigned pListView::selection() { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - if(gtk_tree_selection_get_selected(selection, 0, &iter) == false) return listView.state.selection; - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - unsigned row = decimal(path); - g_free(path); - return row; -} - -void pListView::setCheckable(bool checkable) { - gtk_cell_renderer_set_visible(column(0).checkbox, checkable); -} - -void pListView::setChecked(unsigned row, bool checked) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, checked, -1); -} - -void pListView::setHeaderText(const lstring &text) { - destructor(); - constructor(); -} - -void pListView::setHeaderVisible(bool visible) { - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model, &iter, string(row)); - if(image.empty() == false) { - GdkPixbuf *pixbuf = CreatePixbuf(image, true); - gtk_list_store_set(store, &iter, 1 + column * 2, pixbuf, -1); - } else { - gtk_list_store_set(store, &iter, 1 + column * 2, nullptr, -1); - } -} - -void pListView::setSelected(bool selected) { - if(selected == false) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - } else { - setSelection(listView.state.selection); - } -} - -void pListView::setSelection(unsigned row) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - gtk_tree_selection_unselect_all(selection); - GtkTreeIter iter; - if(gtk_tree_model_get_iter_from_string(model, &iter, string(row)) == false) return; - gtk_tree_selection_select_iter(selection, &iter); - - //scroll window to selected item - char *path = gtk_tree_model_get_string_from_iter(model, &iter); - GtkTreePath *treePath = gtk_tree_path_new_from_string(path); - gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(subWidget), treePath, nullptr, true, 0.5, 0.0); - gtk_tree_path_free(treePath); - g_free(path); -} - -void pListView::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - - lstring headerText = listView.state.headerText; - if(headerText.size() == 0) headerText.append(""); //ListView must have at least one column - - column.reset(); - vector gtype; - for(auto &text : headerText) { - GtkColumn cell; - cell.label = gtk_label_new(text); - cell.column = gtk_tree_view_column_new(); - gtk_tree_view_column_set_resizable(cell.column, true); - gtk_tree_view_column_set_title(cell.column, ""); - - if(column.size() == 0) { //first column checkbox - cell.checkbox = gtk_cell_renderer_toggle_new(); - gtk_tree_view_column_pack_start(cell.column, cell.checkbox, false); - gtk_tree_view_column_set_attributes(cell.column, cell.checkbox, "active", gtype.size(), nullptr); - gtype.append(G_TYPE_BOOLEAN); - g_signal_connect(cell.checkbox, "toggled", G_CALLBACK(ListView_toggle), (gpointer)&listView); - } - - cell.icon = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(cell.column, cell.icon, false); - gtk_tree_view_column_set_attributes(cell.column, cell.icon, "pixbuf", gtype.size(), nullptr); - gtype.append(GDK_TYPE_PIXBUF); - - cell.text = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(cell.column, cell.text, false); - gtk_tree_view_column_set_attributes(cell.column, cell.text, "text", gtype.size(), nullptr); - gtype.append(G_TYPE_STRING); - - column.append(cell); - } - - store = gtk_list_store_newv(gtype.size(), gtype.data()); - subWidget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - g_object_unref(G_OBJECT(store)); - - for(auto &cell : column) { - gtk_tree_view_column_set_widget(GTK_TREE_VIEW_COLUMN(cell.column), cell.label); - gtk_tree_view_append_column(GTK_TREE_VIEW(subWidget), cell.column); - gtk_widget_show(cell.label); - } - - gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(subWidget), headerText.size() >= 2); //two or more columns + checkbox column - gtk_tree_view_set_search_column(GTK_TREE_VIEW(subWidget), 2); - - g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView); - g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView); - - gtk_widget_show(subWidget); - - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setFocused() { - gtk_widget_grab_focus(subWidget); -} - -void pListView::setFont(const string &font) { - pFont::setFont(gtkWidget, font); - for(auto &cell : column) pFont::setFont(cell.label, font); -} diff --git a/purify/phoenix/gtk/widget/progress-bar.cpp b/purify/phoenix/gtk/widget/progress-bar.cpp deleted file mode 100644 index 972170b8..00000000 --- a/purify/phoenix/gtk/widget/progress-bar.cpp +++ /dev/null @@ -1,23 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - position = position <= 100 ? position : 0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (double)position / 100.0); -} - -void pProgressBar::constructor() { - gtkWidget = gtk_progress_bar_new(); - - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/radio-box.cpp b/purify/phoenix/gtk/widget/radio-box.cpp deleted file mode 100644 index 36aff3fa..00000000 --- a/purify/phoenix/gtk/widget/radio-box.cpp +++ /dev/null @@ -1,50 +0,0 @@ -static void RadioBox_activate(RadioBox *self) { - if(self->p.locked == false && self->checked() && self->onActivate) self->onActivate(); -} - -bool pRadioBox::checked() { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget)); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(widget.state.font, radioBox.state.text); -//Font &font = pWidget::font(); -//Geometry geometry = font.geometry(radioBox.state.text); - return { 0, 0, geometry.width + 28, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - locked = true; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), true); - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - for(unsigned n = 0; n < group.size(); n++) { - if(n == 0) continue; - GSList *currentGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(group[0].p.gtkWidget)); - if(currentGroup != gtk_radio_button_get_group(GTK_RADIO_BUTTON(gtkWidget))) { - gtk_radio_button_set_group(GTK_RADIO_BUTTON(gtkWidget), currentGroup); - } - } -} - -void pRadioBox::setText(const string &text) { - gtk_button_set_label(GTK_BUTTON(gtkWidget), text); -} - -void pRadioBox::constructor() { - gtkWidget = gtk_radio_button_new_with_label(0, ""); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_activate), (gpointer)&radioBox); - - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/text-edit.cpp b/purify/phoenix/gtk/widget/text-edit.cpp deleted file mode 100644 index 2d2b740b..00000000 --- a/purify/phoenix/gtk/widget/text-edit.cpp +++ /dev/null @@ -1,70 +0,0 @@ -static void TextEdit_change(TextEdit *self) { - self->state.text = self->text(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -bool pTextEdit::focused() { - return GTK_WIDGET_HAS_FOCUS(subWidget); -} - -void pTextEdit::setCursorPosition(unsigned position) { - GtkTextMark *mark = gtk_text_buffer_get_mark(textBuffer, "insert"); - GtkTextIter iter; - gtk_text_buffer_get_end_iter(textBuffer, &iter); - gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter))); - gtk_text_buffer_place_cursor(textBuffer, &iter); - gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(subWidget), mark); -} - -void pTextEdit::setEditable(bool editable) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable); -} - -void pTextEdit::setText(const string &text) { - locked = true; - gtk_text_buffer_set_text(textBuffer, text, -1); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), - wordWrap ? GTK_POLICY_NEVER : GTK_POLICY_ALWAYS, - GTK_POLICY_ALWAYS); -} - -string pTextEdit::text() { - GtkTextIter start, end; - gtk_text_buffer_get_start_iter(textBuffer, &start); - gtk_text_buffer_get_end_iter(textBuffer, &end); - char *temp = gtk_text_buffer_get_text(textBuffer, &start, &end, true); - string text = temp; - g_free(temp); - return text; -} - -void pTextEdit::constructor() { - gtkWidget = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN); - subWidget = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_WORD_CHAR); - gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget); - textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget)); - g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit); - gtk_widget_show(subWidget); - - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - gtk_widget_destroy(subWidget); - gtk_widget_destroy(gtkWidget); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/vertical-scroll-bar.cpp b/purify/phoenix/gtk/widget/vertical-scroll-bar.cpp deleted file mode 100644 index e3bde589..00000000 --- a/purify/phoenix/gtk/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,42 +0,0 @@ -static void VerticalScrollBar_change(VerticalScrollBar *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->p.locked == false && self->onChange) self->onChange(); -} - -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalScrollBar::setLength(unsigned length) { - locked = true; - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); - locked = false; -} - -void pVerticalScrollBar::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalScrollBar::constructor() { - gtkWidget = gtk_vscrollbar_new(0); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalScrollBar_change), (gpointer)&verticalScrollBar); - - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/vertical-slider.cpp b/purify/phoenix/gtk/widget/vertical-slider.cpp deleted file mode 100644 index 3c68489e..00000000 --- a/purify/phoenix/gtk/widget/vertical-slider.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static void VerticalSlider_change(VerticalSlider *self) { - if(self->state.position == self->position()) return; - self->state.position = self->position(); - if(self->onChange) self->onChange(); -} - -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget)); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); - gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - gtk_range_set_value(GTK_RANGE(gtkWidget), position); -} - -void pVerticalSlider::constructor() { - gtkWidget = gtk_vscale_new_with_range(0, 100, 1); - gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false); - g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider); - - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/viewport.cpp b/purify/phoenix/gtk/widget/viewport.cpp deleted file mode 100644 index e842a2e5..00000000 --- a/purify/phoenix/gtk/widget/viewport.cpp +++ /dev/null @@ -1,58 +0,0 @@ -static gboolean Viewport_mouseLeave(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseLeave) self->viewport.onMouseLeave(); - return true; -} - -static gboolean Viewport_mouseMove(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseMove) self->viewport.onMouseMove({ (signed)event->x, (signed)event->y }); - return true; -} - -static gboolean Viewport_mousePress(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMousePress) switch(event->button) { - case 1: self->viewport.onMousePress(Mouse::Button::Left); break; - case 2: self->viewport.onMousePress(Mouse::Button::Middle); break; - case 3: self->viewport.onMousePress(Mouse::Button::Right); break; - } - return true; -} - -static gboolean Viewport_mouseRelease(GtkWidget *widget, GdkEventButton *event, pViewport *self) { - if(self->viewport.onMouseRelease) switch(event->button) { - case 1: self->viewport.onMouseRelease(Mouse::Button::Left); break; - case 2: self->viewport.onMouseRelease(Mouse::Button::Middle); break; - case 3: self->viewport.onMouseRelease(Mouse::Button::Right); break; - } - return true; -} - -uintptr_t pViewport::handle() { - return GDK_WINDOW_XID(gtk_widget_get_window(gtkWidget)); -} - -void pViewport::constructor() { - gtkWidget = gtk_drawing_area_new(); -//gtk_widget_set_double_buffered(gtkWidget, false); - gtk_widget_add_events(gtkWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect(G_OBJECT(gtkWidget), "button_press_event", G_CALLBACK(Viewport_mousePress), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "button_release_event", G_CALLBACK(Viewport_mouseRelease), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "leave_notify_event", G_CALLBACK(Viewport_mouseLeave), (gpointer)this); - g_signal_connect(G_OBJECT(gtkWidget), "motion_notify_event", G_CALLBACK(Viewport_mouseMove), (gpointer)this); - - GdkColor color; - color.pixel = 0; - color.red = 0; - color.green = 0; - color.blue = 0; - gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color); -} - -void pViewport::destructor() { - gtk_widget_destroy(gtkWidget); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/widget/widget.cpp b/purify/phoenix/gtk/widget/widget.cpp deleted file mode 100644 index aa4eacfa..00000000 --- a/purify/phoenix/gtk/widget/widget.cpp +++ /dev/null @@ -1,51 +0,0 @@ -bool pWidget::enabled() { - return gtk_widget_get_sensitive(gtkWidget); -} - -bool pWidget::focused() { - return GTK_WIDGET_HAS_FOCUS(gtkWidget); -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - gtk_widget_set_sensitive(gtkWidget, enabled); -} - -void pWidget::setFocused() { - gtk_widget_grab_focus(gtkWidget); -} - -void pWidget::setFont(const string &font) { - pFont::setFont(gtkWidget, font); -} - -void pWidget::setGeometry(const Geometry &geometry) { - if(sizable.window() && sizable.window()->visible()) gtk_fixed_move(GTK_FIXED(sizable.window()->p.formContainer), gtkWidget, geometry.x, geometry.y); - unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width; - unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height; - gtk_widget_set_size_request(gtkWidget, width, height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - gtk_widget_set_visible(gtkWidget, visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) gtkWidget = gtk_label_new(""); -} - -void pWidget::destructor() { - if(widget.state.abstract) gtk_widget_destroy(gtkWidget); -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/gtk/window.cpp b/purify/phoenix/gtk/window.cpp deleted file mode 100644 index 4518c38a..00000000 --- a/purify/phoenix/gtk/window.cpp +++ /dev/null @@ -1,362 +0,0 @@ -static gint Window_close(GtkWidget *widget, GdkEvent *event, Window *window) { - window->state.ignore = false; - if(window->onClose) window->onClose(); - if(window->state.ignore == false) window->setVisible(false); - return true; -} - -static gboolean Window_expose(GtkWidget *widget, GdkEvent *event, Window *window) { - if(window->state.backgroundColorOverride == false) return false; - cairo_t *context = gdk_cairo_create(widget->window); - - Color color = window->backgroundColor(); - double red = (double)color.red / 255.0; - double green = (double)color.green / 255.0; - double blue = (double)color.blue / 255.0; - double alpha = (double)color.alpha / 255.0; - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - cairo_set_source_rgba(context, red, green, blue, alpha); - } else { - cairo_set_source_rgb(context, red, green, blue); - } - - cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); - cairo_paint(context); - cairo_destroy(context); - - return false; -} - -static gboolean Window_configure(GtkWidget *widget, GdkEvent *event, Window *window) { - if(gtk_widget_get_realized(window->p.widget) == false) return false; - if(window->visible() == false) return false; - GdkWindow *gdkWindow = gtk_widget_get_window(widget); - - GdkRectangle border, client; - gdk_window_get_frame_extents(gdkWindow, &border); - gdk_window_get_geometry(gdkWindow, 0, 0, &client.width, &client.height, 0); - gdk_window_get_origin(gdkWindow, &client.x, &client.y); - - if(window->state.fullScreen == false) { - //update geometry settings - settings->frameGeometryX = client.x - border.x; - settings->frameGeometryY = client.y - border.y; - settings->frameGeometryWidth = border.width - client.width; - settings->frameGeometryHeight = border.height - client.height; - if(window->state.backgroundColorOverride == false) { - GdkColor color = widget->style->bg[GTK_STATE_NORMAL]; - settings->windowBackgroundColor - = ((uint8_t)(color.red >> 8) << 16) - + ((uint8_t)(color.green >> 8) << 8) - + ((uint8_t)(color.blue >> 8) << 0); - } - settings->save(); - } - - Geometry geometry = { - client.x, - client.y + window->p.menuHeight(), - client.width, - client.height - window->p.menuHeight() - window->p.statusHeight() - }; - - //move - if(geometry.x != window->state.geometry.x || geometry.y != window->state.geometry.y) { - if(window->state.fullScreen == false) { - window->state.geometry.x = geometry.x; - window->state.geometry.y = geometry.y; - } - if(window->p.locked == false && window->onMove) window->onMove(); - } - - //size - if(geometry.width != window->state.geometry.width || geometry.height != window->state.geometry.height) { - window->p.onSizePending = true; - } - - return false; -} - -static gboolean Window_keyPressEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyPress) window->onKeyPress(key); - return false; -} - -static gboolean Window_keyReleaseEvent(GtkWidget *widget, GdkEventKey *event, Window *window) { - Keyboard::Keycode key = Keysym(event->keyval); - if(key != Keyboard::Keycode::None && window->onKeyRelease) window->onKeyRelease(key); - return false; -} - -static void Window_sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, Window *window) { - //size-allocate sent from gtk_fixed_move(); detect if layout unchanged and return - if(allocation->width == window->p.lastAllocation.width - && allocation->height == window->p.lastAllocation.height) return; - - window->state.geometry.width = allocation->width; - window->state.geometry.height = allocation->height; - - for(auto &layout : window->state.layout) { - Geometry geometry = window->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(window->p.onSizePending && window->p.locked == false && window->onSize) { - window->p.onSizePending = false; - window->onSize(); - } - - window->p.lastAllocation = *allocation; -} - -static void Window_sizeRequest(GtkWidget *widget, GtkRequisition *requisition, Window *window) { - requisition->width = window->state.geometry.width; - requisition->height = window->state.geometry.height; -} - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = this->geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), menu.p.widget); - gtk_widget_show(menu.p.widget); -} - -void pWindow::append(Widget &widget) { - ((Sizable&)widget).state.window = &window; - gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - return { - (uint8_t)(settings->windowBackgroundColor >> 16), - (uint8_t)(settings->windowBackgroundColor >> 8), - (uint8_t)(settings->windowBackgroundColor >> 0), - 255 - }; -} - -Geometry pWindow::frameMargin() { - if(window.state.fullScreen) return { - 0, - menuHeight(), - 0, - menuHeight() + statusHeight() - }; - - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight(), - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight() + statusHeight() - }; -} - -bool pWindow::focused() { - return gtk_window_is_active(GTK_WINDOW(widget)); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen == true) return { - 0, - menuHeight(), - Desktop::size().width, - Desktop::size().height - menuHeight() - statusHeight() - }; - - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - menu.p.orphan(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - GdkColor gdkColor; - gdkColor.pixel = (color.red << 16) | (color.green << 8) | (color.blue << 0); - gdkColor.red = (color.red << 8) | (color.red << 0); - gdkColor.green = (color.green << 8) | (color.green << 0); - gdkColor.blue = (color.blue << 8) | (color.blue << 0); - gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &gdkColor); -} - -void pWindow::setFocused() { - gtk_window_present(GTK_WINDOW(widget)); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - gtk_window_unfullscreen(GTK_WINDOW(widget)); - } else { - gtk_window_fullscreen(GTK_WINDOW(widget)); - } -} - -void pWindow::setGeometry(const Geometry &geometry) { - Geometry margin = frameMargin(); - gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y); - - GdkGeometry geom; - geom.min_width = window.state.resizable ? 1 : window.state.geometry.width; - geom.min_height = window.state.resizable ? 1 : window.state.geometry.height; - gtk_window_set_geometry_hints(GTK_WINDOW(widget), GTK_WIDGET(widget), &geom, GDK_HINT_MIN_SIZE); - -//gtk_window_set_policy(GTK_WINDOW(widget), true, true, false); - gtk_widget_set_size_request(formContainer, geometry.width, geometry.height); - gtk_window_resize(GTK_WINDOW(widget), geometry.width, geometry.height + menuHeight() + statusHeight()); -} - -void pWindow::setMenuFont(const string &font) { - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - gtk_widget_set_visible(menu, visible); -} - -void pWindow::setModal(bool modal) { - gtk_window_set_modal(GTK_WINDOW(widget), modal); -} - -void pWindow::setResizable(bool resizable) { - gtk_window_set_resizable(GTK_WINDOW(widget), resizable); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable); -} - -void pWindow::setStatusFont(const string &font) { - pFont::setFont(status, font); -} - -void pWindow::setStatusText(const string &text) { - gtk_statusbar_pop(GTK_STATUSBAR(status), 1); - gtk_statusbar_push(GTK_STATUSBAR(status), 1, text); -} - -void pWindow::setStatusVisible(bool visible) { - gtk_widget_set_visible(status, visible); -} - -void pWindow::setTitle(const string &text) { - gtk_window_set_title(GTK_WINDOW(widget), text); -} - -void pWindow::setVisible(bool visible) { - gtk_widget_set_visible(widget, visible); - if(visible) { - if(gtk_widget_get_visible(menu)) { - GtkAllocation allocation; - gtk_widget_get_allocation(menu, &allocation); - settings->menuGeometryHeight = allocation.height; - } - - if(gtk_widget_get_visible(status)) { - GtkAllocation allocation; - gtk_widget_get_allocation(status, &allocation); - settings->statusGeometryHeight = allocation.height; - } - } -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(item.state.font == "") item.setFont(font); - } -} - -void pWindow::constructor() { - lastAllocation.width = 0; - lastAllocation.height = 0; - onSizePending = false; - - widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - //if program was given a name, try and set the window taskbar icon from one of the pixmaps folders - if(osState.name.empty() == false) { - if(file::exists({"/usr/share/pixmaps/", osState.name, ".png"})) { - gtk_window_set_icon_from_file(GTK_WINDOW(widget), string{"/usr/share/pixmaps/", osState.name, ".png"}, nullptr); - } else if(file::exists({"/usr/local/share/pixmaps/", osState.name, ".png"})) { - gtk_window_set_icon_from_file(GTK_WINDOW(widget), string{"/usr/local/share/pixmaps/", osState.name, ".png"}, nullptr); - } - } - - if(gdk_screen_is_composited(gdk_screen_get_default())) { - gtk_widget_set_colormap(widget, gdk_screen_get_rgba_colormap(gdk_screen_get_default())); - } else { - gtk_widget_set_colormap(widget, gdk_screen_get_rgb_colormap(gdk_screen_get_default())); - } - - gtk_window_set_resizable(GTK_WINDOW(widget), true); - #if GTK_MAJOR_VERSION >= 3 - gtk_window_set_has_resize_grip(GTK_WINDOW(widget), false); - #endif - - gtk_widget_set_app_paintable(widget, true); - gtk_widget_add_events(widget, GDK_CONFIGURE); - - menuContainer = gtk_vbox_new(false, 0); - gtk_container_add(GTK_CONTAINER(widget), menuContainer); - gtk_widget_show(menuContainer); - - menu = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), menu, false, false, 0); - - formContainer = gtk_fixed_new(); - gtk_box_pack_start(GTK_BOX(menuContainer), formContainer, true, true, 0); - gtk_widget_show(formContainer); - - statusContainer = gtk_event_box_new(); - status = gtk_statusbar_new(); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), true); - gtk_container_add(GTK_CONTAINER(statusContainer), status); - gtk_box_pack_start(GTK_BOX(menuContainer), statusContainer, false, false, 0); - gtk_widget_show(statusContainer); - - setTitle(""); - setResizable(window.state.resizable); - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); - - g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "expose-event", G_CALLBACK(Window_expose), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(Window_keyPressEvent), (gpointer)&window); - - g_signal_connect(G_OBJECT(formContainer), "size-allocate", G_CALLBACK(Window_sizeAllocate), (gpointer)&window); - g_signal_connect(G_OBJECT(formContainer), "size-request", G_CALLBACK(Window_sizeRequest), (gpointer)&window); -} - -unsigned pWindow::menuHeight() { - return window.state.menuVisible ? settings->menuGeometryHeight : 0; -} - -unsigned pWindow::statusHeight() { - return window.state.statusVisible ? settings->statusGeometryHeight : 0; -} diff --git a/purify/phoenix/phoenix.cpp b/purify/phoenix/phoenix.cpp deleted file mode 100644 index eaa66b97..00000000 --- a/purify/phoenix/phoenix.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef PHOENIX_CPP -#define PHOENIX_CPP - -#if defined(PHOENIX_WINDOWS) - #define UNICODE - #define WINVER 0x0501 - #define _WIN32_WINNT 0x0501 - #define _WIN32_IE 0x0600 - #define __MSVCRT_VERSION__ 0x0601 - #define NOMINMAX - - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_QT) - #include - #include - #include - #define XK_MISCELLANY - #define XK_LATIN1 - #include - #include - #undef XK_MISCELLANY - #undef XK_LATIN1 - #include -#elif defined(PHOENIX_GTK) - #include - #include - #include - #include - #include - #include - #include - #include -#elif defined(PHOENIX_REFERENCE) -#else - #error "phoenix: unrecognized target" -#endif - -#include "phoenix.hpp" -using namespace nall; - -namespace phoenix { - #include "core/core.cpp" -} - -#endif diff --git a/purify/phoenix/phoenix.hpp b/purify/phoenix/phoenix.hpp deleted file mode 100644 index 8a6129c4..00000000 --- a/purify/phoenix/phoenix.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PHOENIX_HPP -#define PHOENIX_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace phoenix { - #include "core/core.hpp" -} - -#endif diff --git a/purify/phoenix/qt/action/action.cpp b/purify/phoenix/qt/action/action.cpp deleted file mode 100644 index 62efaa2a..00000000 --- a/purify/phoenix/qt/action/action.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setEnabled(enabled); - } -} - -void pAction::setFont(const string &font) { - QFont qtFont = pFont::create(font); - - if(dynamic_cast(&action)) { - ((Menu&)action).p.setFont(font); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setFont(qtFont); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setFont(qtFont); - } -} - -void pAction::setVisible(bool visible) { - if(dynamic_cast(&action)) { - ((Menu&)action).p.qtMenu->menuAction()->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Separator&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((Item&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((CheckItem&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((RadioItem&)action).p.qtAction->setVisible(visible); - } -} - -void pAction::constructor() { -} - -void pAction::destructor() { -} diff --git a/purify/phoenix/qt/action/check-item.cpp b/purify/phoenix/qt/action/check-item.cpp deleted file mode 100644 index ef451e73..00000000 --- a/purify/phoenix/qt/action/check-item.cpp +++ /dev/null @@ -1,27 +0,0 @@ -bool pCheckItem::checked() { - return qtAction->isChecked(); -} - -void pCheckItem::setChecked(bool checked) { - qtAction->setChecked(checked); -} - -void pCheckItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pCheckItem::constructor() { - qtAction = new QAction(0); - qtAction->setCheckable(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onToggle())); -} - -void pCheckItem::destructor() { - if(action.state.menu) action.state.menu->remove(checkItem); - delete qtAction; -} - -void pCheckItem::onToggle() { - checkItem.state.checked = checked(); - if(checkItem.onToggle) checkItem.onToggle(); -} diff --git a/purify/phoenix/qt/action/item.cpp b/purify/phoenix/qt/action/item.cpp deleted file mode 100644 index 7f142289..00000000 --- a/purify/phoenix/qt/action/item.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pItem::setImage(const image &image) { - qtAction->setIcon(CreateIcon(image)); -} - -void pItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pItem::constructor() { - qtAction = new QAction(0); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pItem::destructor() { - if(action.state.menu) action.state.menu->remove(item); - delete qtAction; -} - -void pItem::onActivate() { - if(item.onActivate) item.onActivate(); -} diff --git a/purify/phoenix/qt/action/menu.cpp b/purify/phoenix/qt/action/menu.cpp deleted file mode 100644 index 43d89a1e..00000000 --- a/purify/phoenix/qt/action/menu.cpp +++ /dev/null @@ -1,51 +0,0 @@ -void pMenu::append(Action &action) { - if(dynamic_cast(&action)) { - qtMenu->addMenu(((Menu&)action).p.qtMenu); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((RadioItem&)action).p.qtAction); - } -} - -void pMenu::remove(Action &action) { - if(dynamic_cast(&action)) { - //QMenu::removeMenu() does not exist - qtMenu->clear(); - for(auto &action : menu.state.action) append(action); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Separator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((Item&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->removeAction(((CheckItem&)action).p.qtAction); - } -} - -void pMenu::setFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : menu.state.action) item.p.setFont(font); -} - -void pMenu::setImage(const image &image) { - qtMenu->setIcon(CreateIcon(image)); -} - -void pMenu::setText(const string &text) { - qtMenu->setTitle(QString::fromUtf8(text)); -} - -void pMenu::constructor() { - qtMenu = new QMenu; -} - -void pMenu::destructor() { - if(action.state.menu) action.state.menu->remove(menu); - delete qtMenu; -} diff --git a/purify/phoenix/qt/action/radio-item.cpp b/purify/phoenix/qt/action/radio-item.cpp deleted file mode 100644 index 66cf6c6a..00000000 --- a/purify/phoenix/qt/action/radio-item.cpp +++ /dev/null @@ -1,41 +0,0 @@ -bool pRadioItem::checked() { - return qtAction->isChecked(); -} - -void pRadioItem::setChecked() { - locked = true; - for(auto &item : radioItem.state.group) { - bool checkState = item.p.qtAction == qtAction; - item.state.checked = checkState; - item.p.qtAction->setChecked(checkState); - } - locked = false; -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pRadioItem::constructor() { - qtAction = new QAction(0); - qtGroup = new QActionGroup(0); - qtAction->setCheckable(true); - qtAction->setActionGroup(qtGroup); - qtAction->setChecked(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onActivate())); -} - -void pRadioItem::destructor() { - if(action.state.menu) action.state.menu->remove(radioItem); - delete qtAction; -} - -void pRadioItem::onActivate() { - if(radioItem.state.checked == false) { - setChecked(); - if(locked == false && radioItem.onActivate) radioItem.onActivate(); - } -} diff --git a/purify/phoenix/qt/action/separator.cpp b/purify/phoenix/qt/action/separator.cpp deleted file mode 100644 index 95e66b6c..00000000 --- a/purify/phoenix/qt/action/separator.cpp +++ /dev/null @@ -1,9 +0,0 @@ -void pSeparator::constructor() { - qtAction = new QAction(0); - qtAction->setSeparator(true); -} - -void pSeparator::destructor() { - if(action.state.menu) action.state.menu->remove(separator); - delete qtAction; -} diff --git a/purify/phoenix/qt/desktop.cpp b/purify/phoenix/qt/desktop.cpp deleted file mode 100644 index 554106b5..00000000 --- a/purify/phoenix/qt/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - QRect rect = QApplication::desktop()->screenGeometry(); - return { rect.width(), rect.height() }; -} - -Geometry pDesktop::workspace() { - QRect rect = QApplication::desktop()->availableGeometry(); - return { rect.x(), rect.y(), rect.width(), rect.height() }; -} diff --git a/purify/phoenix/qt/dialog-window.cpp b/purify/phoenix/qt/dialog-window.cpp deleted file mode 100644 index 680a6e2e..00000000 --- a/purify/phoenix/qt/dialog-window.cpp +++ /dev/null @@ -1,57 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getOpenFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Open File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - string filterList; - for(auto &item : filter) { - filterList.append(item); - filterList.append(";;"); - } - filterList.rtrim<1>(";;"); - - //convert filter list from phoenix to Qt format, example: - //"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" - signed parenthesis = 0; - for(auto &n : filterList) { - if(n == '(') parenthesis++; - if(n == ')') parenthesis--; - if(n == ',' && parenthesis) n = ' '; - } - - QString filename = QFileDialog::getSaveFileName( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Save File", - QString::fromUtf8(path), QString::fromUtf8(filterList) - ); - return filename.toUtf8().constData(); -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - QString directory = QFileDialog::getExistingDirectory( - &parent != &Window::none() ? parent.p.qtWindow : nullptr, "Select Directory", - QString::fromUtf8(path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks - ); - string name = directory.toUtf8().constData(); - if(name != "" && name.endswith("/") == false) name.append("/"); - return name; -} diff --git a/purify/phoenix/qt/font.cpp b/purify/phoenix/qt/font.cpp deleted file mode 100644 index bb3261cd..00000000 --- a/purify/phoenix/qt/font.cpp +++ /dev/null @@ -1,40 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return pFont::geometry(pFont::create(description), text); -} - -QFont pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - QFont qtFont; - qtFont.setFamily(family); - qtFont.setPointSize(size); - if(bold) qtFont.setBold(true); - if(italic) qtFont.setItalic(true); - return qtFont; -} - -Geometry pFont::geometry(const QFont &qtFont, const string &text) { - QFontMetrics metrics(qtFont); - - lstring lines; - lines.split("\n", text); - - unsigned maxWidth = 0; - for(auto &line : lines) { - maxWidth = max(maxWidth, metrics.width(line)); - } - - return { 0, 0, maxWidth, metrics.height() * lines.size() }; -} diff --git a/purify/phoenix/qt/keyboard.cpp b/purify/phoenix/qt/keyboard.cpp deleted file mode 100644 index 5b346406..00000000 --- a/purify/phoenix/qt/keyboard.cpp +++ /dev/null @@ -1,142 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, XKeysymToKeycode(pOS::display, keysym)); - }; - - append(Keyboard::Scancode::Escape, XK_Escape); - append(Keyboard::Scancode::F1, XK_F1); - append(Keyboard::Scancode::F2, XK_F2); - append(Keyboard::Scancode::F3, XK_F3); - append(Keyboard::Scancode::F4, XK_F4); - append(Keyboard::Scancode::F5, XK_F5); - append(Keyboard::Scancode::F6, XK_F6); - append(Keyboard::Scancode::F7, XK_F7); - append(Keyboard::Scancode::F8, XK_F8); - append(Keyboard::Scancode::F9, XK_F9); - append(Keyboard::Scancode::F10, XK_F10); - append(Keyboard::Scancode::F11, XK_F11); - append(Keyboard::Scancode::F12, XK_F12); - - append(Keyboard::Scancode::PrintScreen, XK_Print); - append(Keyboard::Scancode::ScrollLock, XK_Scroll_Lock); - append(Keyboard::Scancode::Pause, XK_Pause); - - append(Keyboard::Scancode::Insert, XK_Insert); - append(Keyboard::Scancode::Delete, XK_Delete); - append(Keyboard::Scancode::Home, XK_Home); - append(Keyboard::Scancode::End, XK_End); - append(Keyboard::Scancode::PageUp, XK_Prior); - append(Keyboard::Scancode::PageDown, XK_Next); - - append(Keyboard::Scancode::Up, XK_Up); - append(Keyboard::Scancode::Down, XK_Down); - append(Keyboard::Scancode::Left, XK_Left); - append(Keyboard::Scancode::Right, XK_Right); - - append(Keyboard::Scancode::Grave, XK_asciitilde); - append(Keyboard::Scancode::Number1, XK_1); - append(Keyboard::Scancode::Number2, XK_2); - append(Keyboard::Scancode::Number3, XK_3); - append(Keyboard::Scancode::Number4, XK_4); - append(Keyboard::Scancode::Number5, XK_5); - append(Keyboard::Scancode::Number6, XK_6); - append(Keyboard::Scancode::Number7, XK_7); - append(Keyboard::Scancode::Number8, XK_8); - append(Keyboard::Scancode::Number9, XK_9); - append(Keyboard::Scancode::Number0, XK_0); - append(Keyboard::Scancode::Minus, XK_minus); - append(Keyboard::Scancode::Equal, XK_equal); - append(Keyboard::Scancode::Backspace, XK_BackSpace); - - append(Keyboard::Scancode::BracketLeft, XK_bracketleft); - append(Keyboard::Scancode::BracketRight, XK_bracketright); - append(Keyboard::Scancode::Backslash, XK_backslash); - append(Keyboard::Scancode::Semicolon, XK_semicolon); - append(Keyboard::Scancode::Apostrophe, XK_apostrophe); - append(Keyboard::Scancode::Comma, XK_comma); - append(Keyboard::Scancode::Period, XK_period); - append(Keyboard::Scancode::Slash, XK_slash); - - append(Keyboard::Scancode::Tab, XK_Tab); - append(Keyboard::Scancode::CapsLock, XK_Caps_Lock); - append(Keyboard::Scancode::Return, XK_Return); - append(Keyboard::Scancode::ShiftLeft, XK_Shift_L); - append(Keyboard::Scancode::ShiftRight, XK_Shift_R); - append(Keyboard::Scancode::ControlLeft, XK_Control_L); - append(Keyboard::Scancode::ControlRight, XK_Control_R); - append(Keyboard::Scancode::SuperLeft, XK_Super_L); - append(Keyboard::Scancode::SuperRight, XK_Super_R); - append(Keyboard::Scancode::AltLeft, XK_Alt_L); - append(Keyboard::Scancode::AltRight, XK_Alt_R); - append(Keyboard::Scancode::Space, XK_space); - append(Keyboard::Scancode::Menu, XK_Menu); - - append(Keyboard::Scancode::A, XK_A); - append(Keyboard::Scancode::B, XK_B); - append(Keyboard::Scancode::C, XK_C); - append(Keyboard::Scancode::D, XK_D); - append(Keyboard::Scancode::E, XK_E); - append(Keyboard::Scancode::F, XK_F); - append(Keyboard::Scancode::G, XK_G); - append(Keyboard::Scancode::H, XK_H); - append(Keyboard::Scancode::I, XK_I); - append(Keyboard::Scancode::J, XK_J); - append(Keyboard::Scancode::K, XK_K); - append(Keyboard::Scancode::L, XK_L); - append(Keyboard::Scancode::M, XK_M); - append(Keyboard::Scancode::N, XK_N); - append(Keyboard::Scancode::O, XK_O); - append(Keyboard::Scancode::P, XK_P); - append(Keyboard::Scancode::Q, XK_Q); - append(Keyboard::Scancode::R, XK_R); - append(Keyboard::Scancode::S, XK_S); - append(Keyboard::Scancode::T, XK_T); - append(Keyboard::Scancode::U, XK_U); - append(Keyboard::Scancode::V, XK_V); - append(Keyboard::Scancode::W, XK_W); - append(Keyboard::Scancode::X, XK_X); - append(Keyboard::Scancode::Y, XK_Y); - append(Keyboard::Scancode::Z, XK_Z); - - append(Keyboard::Scancode::NumLock, XK_Num_Lock); - append(Keyboard::Scancode::Divide, XK_KP_Divide); - append(Keyboard::Scancode::Multiply, XK_KP_Multiply); - append(Keyboard::Scancode::Subtract, XK_KP_Subtract); - append(Keyboard::Scancode::Add, XK_KP_Add); - append(Keyboard::Scancode::Enter, XK_KP_Enter); - append(Keyboard::Scancode::Point, XK_KP_Decimal); - - append(Keyboard::Scancode::Keypad1, XK_KP_1); - append(Keyboard::Scancode::Keypad2, XK_KP_2); - append(Keyboard::Scancode::Keypad3, XK_KP_3); - append(Keyboard::Scancode::Keypad4, XK_KP_4); - append(Keyboard::Scancode::Keypad5, XK_KP_5); - append(Keyboard::Scancode::Keypad6, XK_KP_6); - append(Keyboard::Scancode::Keypad7, XK_KP_7); - append(Keyboard::Scancode::Keypad8, XK_KP_8); - append(Keyboard::Scancode::Keypad9, XK_KP_9); - append(Keyboard::Scancode::Keypad0, XK_KP_0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - char state[256]; - XQueryKeymap(pOS::display, state); - unsigned id = settings->keymap.lhs[scancode]; - return state[id >> 3] & (1 << (id & 7)); -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - char state[256]; - XQueryKeymap(pOS::display, state); - for(auto &n : settings->keymap.rhs) { - if(state[n.name >> 3] & (1 << (n.name & 7))) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/purify/phoenix/qt/message-window.cpp b/purify/phoenix/qt/message-window.cpp deleted file mode 100644 index 7bceba0f..00000000 --- a/purify/phoenix/qt/message-window.cpp +++ /dev/null @@ -1,47 +0,0 @@ -static QMessageBox::StandardButtons MessageWindow_buttons(MessageWindow::Buttons buttons) { - QMessageBox::StandardButtons standardButtons = QMessageBox::NoButton; - if(buttons == MessageWindow::Buttons::Ok) standardButtons = QMessageBox::Ok; - if(buttons == MessageWindow::Buttons::OkCancel) standardButtons = QMessageBox::Ok | QMessageBox::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) standardButtons = QMessageBox::Yes | QMessageBox::No; - return standardButtons; -} - -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, QMessageBox::StandardButton response) { - if(response == QMessageBox::Ok) return MessageWindow::Response::Ok; - if(response == QMessageBox::Cancel) return MessageWindow::Response::Cancel; - if(response == QMessageBox::Yes) return MessageWindow::Response::Yes; - if(response == QMessageBox::No) return MessageWindow::Response::No; - - //MessageWindow was closed via window manager, rather than by a button; assume a cancel/no response - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::information(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::question(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::warning(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow_response( - buttons, QMessageBox::critical(&parent != &Window::none() ? parent.p.qtWindow : nullptr, " ", - QString::fromUtf8(text), MessageWindow_buttons(buttons)) - ); -} diff --git a/purify/phoenix/qt/mouse.cpp b/purify/phoenix/qt/mouse.cpp deleted file mode 100644 index 4ea06cc9..00000000 --- a/purify/phoenix/qt/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - QPoint point = QCursor::pos(); - return { point.x(), point.y() }; -} - -bool pMouse::pressed(Mouse::Button button) { - Qt::MouseButtons buttons = QApplication::mouseButtons(); - switch(button) { - case Mouse::Button::Left: return buttons & Qt::LeftButton; - case Mouse::Button::Middle: return buttons & Qt::MidButton; - case Mouse::Button::Right: return buttons & Qt::RightButton; - } - return false; -} diff --git a/purify/phoenix/qt/platform.cpp b/purify/phoenix/qt/platform.cpp deleted file mode 100644 index 86f659c8..00000000 --- a/purify/phoenix/qt/platform.cpp +++ /dev/null @@ -1,91 +0,0 @@ -//Qt 4.8.0 and earlier improperly define the QLOCATION macro -//in C++11, it is detected as a malformed user-defined literal -//below is a workaround to fix compilation errors caused by this -#undef QLOCATION -#define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__) - -#include "platform.moc.hpp" -#include "platform.moc" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -XlibDisplay* pOS::display = 0; - -void pOS::main() { - QApplication::exec(); -} - -bool pOS::pendingEvents() { - return QApplication::hasPendingEvents(); -} - -void pOS::processEvents() { - while(pendingEvents()) QApplication::processEvents(); -} - -void pOS::quit() { - QApplication::quit(); - //note: QApplication cannot be deleted; or libQtGui will crash - qtApplication = 0; -} - -void pOS::syncX() { - for(unsigned n = 0; n < 8; n++) { - QApplication::syncX(); - OS::processEvents(); - usleep(2000); - } -} - -void pOS::initialize() { - display = XOpenDisplay(0); - - settings = new Settings; - settings->load(); - - static int argc = 1; - static char *argv[2]; - argv[0] = new char[8]; - argv[1] = 0; - strcpy(argv[0], "phoenix"); - char **argvp = argv; - - qtApplication = new QApplication(argc, argvp); - - pKeyboard::initialize(); -} diff --git a/purify/phoenix/qt/platform.moc b/purify/phoenix/qt/platform.moc deleted file mode 100644 index 2a53a326..00000000 --- a/purify/phoenix/qt/platform.moc +++ /dev/null @@ -1,1105 +0,0 @@ -/**************************************************************************** -** Meta object code from reading C++ file 'platform.moc.hpp' -** -** Created: Wed Dec 26 00:12:14 2012 -** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - -#if !defined(Q_MOC_OUTPUT_REVISION) -#error "The header file 'platform.moc.hpp' doesn't include ." -#elif Q_MOC_OUTPUT_REVISION != 62 -#error "This file was generated using the moc from 4.6.3. It" -#error "cannot be used with the include files from this version of Qt." -#error "(The moc has changed too much.)" -#endif - -QT_BEGIN_MOC_NAMESPACE -static const uint qt_meta_data_pTimer[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 8, 7, 7, 7, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTimer[] = { - "pTimer\0\0onTimeout()\0" -}; - -const QMetaObject pTimer::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTimer, - qt_meta_data_pTimer, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTimer::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTimer::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTimer::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTimer)) - return static_cast(const_cast< pTimer*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pTimer*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTimer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onTimeout(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pWindow[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pWindow[] = { - "pWindow\0" -}; - -const QMetaObject pWindow::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pWindow, - qt_meta_data_pWindow, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pWindow::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pWindow::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pWindow::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pWindow)) - return static_cast(const_cast< pWindow*>(this)); - if (!strcmp(_clname, "pObject")) - return static_cast< pObject*>(const_cast< pWindow*>(this)); - return QObject::qt_metacast(_clname); -} - -int pWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 7, 6, 6, 6, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pItem[] = { - "pItem\0\0onActivate()\0" -}; - -const QMetaObject pItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pItem, - qt_meta_data_pItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pItem)) - return static_cast(const_cast< pItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCheckItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckItem[] = { - "pCheckItem\0\0onToggle()\0" -}; - -const QMetaObject pCheckItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckItem, - qt_meta_data_pCheckItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckItem)) - return static_cast(const_cast< pCheckItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pCheckItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pRadioItem[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 12, 11, 11, 11, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioItem[] = { - "pRadioItem\0\0onActivate()\0" -}; - -const QMetaObject pRadioItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioItem, - qt_meta_data_pRadioItem, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioItem::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioItem::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioItem::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioItem)) - return static_cast(const_cast< pRadioItem*>(this)); - if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pRadioItem*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pButton[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 9, 8, 8, 8, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pButton[] = { - "pButton\0\0onActivate()\0" -}; - -const QMetaObject pButton::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pButton, - qt_meta_data_pButton, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pButton::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pButton::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pButton::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pButton)) - return static_cast(const_cast< pButton*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pButton*>(this)); - return QObject::qt_metacast(_clname); -} - -int pButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pCanvas[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_pCanvas[] = { - "pCanvas\0" -}; - -const QMetaObject pCanvas::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCanvas, - qt_meta_data_pCanvas, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCanvas::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCanvas::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCanvas::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCanvas)) - return static_cast(const_cast< pCanvas*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCanvas*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCanvas::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_pCheckBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pCheckBox[] = { - "pCheckBox\0\0onToggle()\0" -}; - -const QMetaObject pCheckBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pCheckBox, - qt_meta_data_pCheckBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pCheckBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pCheckBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pCheckBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pCheckBox)) - return static_cast(const_cast< pCheckBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pCheckBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pCheckBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onToggle(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pComboBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pComboBox[] = { - "pComboBox\0\0onChange()\0" -}; - -const QMetaObject pComboBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pComboBox, - qt_meta_data_pComboBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pComboBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pComboBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pComboBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pComboBox)) - return static_cast(const_cast< pComboBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pComboBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHexEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 10, 9, 9, 9, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHexEdit[] = { - "pHexEdit\0\0onScroll()\0" -}; - -const QMetaObject pHexEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHexEdit, - qt_meta_data_pHexEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHexEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHexEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHexEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHexEdit)) - return static_cast(const_cast< pHexEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHexEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHexEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onScroll(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 22, 21, 21, 21, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalScrollBar[] = { - "pHorizontalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pHorizontalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalScrollBar, - qt_meta_data_pHorizontalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalScrollBar)) - return static_cast(const_cast< pHorizontalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pHorizontalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 19, 18, 18, 18, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pHorizontalSlider[] = { - "pHorizontalSlider\0\0onChange()\0" -}; - -const QMetaObject pHorizontalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pHorizontalSlider, - qt_meta_data_pHorizontalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pHorizontalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pHorizontalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pHorizontalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pHorizontalSlider)) - return static_cast(const_cast< pHorizontalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pHorizontalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pHorizontalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pLineEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 2, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 24, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pLineEdit[] = { - "pLineEdit\0\0onActivate()\0onChange()\0" -}; - -const QMetaObject pLineEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pLineEdit, - qt_meta_data_pLineEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pLineEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pLineEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pLineEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pLineEdit)) - return static_cast(const_cast< pLineEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pLineEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange(); break; - default: ; - } - _id -= 2; - } - return _id; -} -static const uint qt_meta_data_pListView[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 3, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - 29, 24, 10, 10, 0x0a, - 56, 24, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pListView[] = { - "pListView\0\0onActivate()\0item\0" - "onChange(QTreeWidgetItem*)\0" - "onToggle(QTreeWidgetItem*)\0" -}; - -const QMetaObject pListView::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pListView, - qt_meta_data_pListView, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pListView::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pListView::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pListView::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pListView)) - return static_cast(const_cast< pListView*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pListView*>(this)); - return QObject::qt_metacast(_clname); -} - -int pListView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - case 1: onChange((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - case 2: onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1]))); break; - default: ; - } - _id -= 3; - } - return _id; -} -static const uint qt_meta_data_pRadioBox[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pRadioBox[] = { - "pRadioBox\0\0onActivate()\0" -}; - -const QMetaObject pRadioBox::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pRadioBox, - qt_meta_data_pRadioBox, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pRadioBox::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pRadioBox::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pRadioBox::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pRadioBox)) - return static_cast(const_cast< pRadioBox*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pRadioBox*>(this)); - return QObject::qt_metacast(_clname); -} - -int pRadioBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onActivate(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pTextEdit[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pTextEdit[] = { - "pTextEdit\0\0onChange()\0" -}; - -const QMetaObject pTextEdit::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pTextEdit, - qt_meta_data_pTextEdit, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pTextEdit::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pTextEdit::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pTextEdit::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pTextEdit)) - return static_cast(const_cast< pTextEdit*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pTextEdit*>(this)); - return QObject::qt_metacast(_clname); -} - -int pTextEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalScrollBar[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 20, 19, 19, 19, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalScrollBar[] = { - "pVerticalScrollBar\0\0onChange()\0" -}; - -const QMetaObject pVerticalScrollBar::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalScrollBar, - qt_meta_data_pVerticalScrollBar, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalScrollBar::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalScrollBar::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalScrollBar::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalScrollBar)) - return static_cast(const_cast< pVerticalScrollBar*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalScrollBar*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -static const uint qt_meta_data_pVerticalSlider[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 1, 14, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - // slots: signature, parameters, type, tag, flags - 17, 16, 16, 16, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_pVerticalSlider[] = { - "pVerticalSlider\0\0onChange()\0" -}; - -const QMetaObject pVerticalSlider::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pVerticalSlider, - qt_meta_data_pVerticalSlider, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pVerticalSlider::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *pVerticalSlider::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *pVerticalSlider::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pVerticalSlider)) - return static_cast(const_cast< pVerticalSlider*>(this)); - if (!strcmp(_clname, "pWidget")) - return static_cast< pWidget*>(const_cast< pVerticalSlider*>(this)); - return QObject::qt_metacast(_clname); -} - -int pVerticalSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: onChange(); break; - default: ; - } - _id -= 1; - } - return _id; -} -QT_END_MOC_NAMESPACE diff --git a/purify/phoenix/qt/platform.moc.hpp b/purify/phoenix/qt/platform.moc.hpp deleted file mode 100644 index 6a3909bf..00000000 --- a/purify/phoenix/qt/platform.moc.hpp +++ /dev/null @@ -1,634 +0,0 @@ -static QApplication *qtApplication = nullptr; - -struct Settings : public configuration { - bidirectional_map keymap; - - unsigned frameGeometryX; - unsigned frameGeometryY; - unsigned frameGeometryWidth; - unsigned frameGeometryHeight; - unsigned menuGeometryHeight; - unsigned statusGeometryHeight; - - void load(); - void save(); - Settings(); -}; - -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static QFont create(const string &description); - static Geometry geometry(const QFont &qtFont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(false) {} - virtual ~pObject() {} - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static XlibDisplay *display; - - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); - static void syncX(); -}; - -struct pTimer : public QObject, public pObject { - Q_OBJECT - -public: - Timer &timer; - QTimer *qtTimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); - void destructor(); - -public slots: - void onTimeout(); -}; - -struct pWindow : public QObject, public pObject { - Q_OBJECT - -public: - Window &window; - struct QtWindow : public QWidget { - pWindow &self; - void closeEvent(QCloseEvent*); - void keyPressEvent(QKeyEvent*); - void keyReleaseEvent(QKeyEvent*); - void moveEvent(QMoveEvent*); - void resizeEvent(QResizeEvent*); - QSize sizeHint() const; - QtWindow(pWindow &self) : self(self) {} - } *qtWindow; - QVBoxLayout *qtLayout; - QMenuBar *qtMenu; - QStatusBar *qtStatus; - QWidget *qtContainer; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - Geometry frameMargin(); - bool focused(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateFrameGeometry(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setFont(const string &font); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); - void destructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - QMenu *qtMenu; - - void append(Action &action); - void remove(Action &action); - void setFont(const string &font); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - QAction *qtAction; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public QObject, public pAction { - Q_OBJECT - -public: - Item &item; - QAction *qtAction; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pCheckItem : public QObject, public pAction { - Q_OBJECT - -public: - CheckItem &checkItem; - QAction *qtAction; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); - -public slots: - void onToggle(); -}; - -struct pRadioItem : public QObject, public pAction { - Q_OBJECT - -public: - RadioItem &radioItem; - QAction *qtAction; - QActionGroup *qtGroup; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); - -public slots: - void onActivate(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} - - void constructor() {} - void destructor() {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} - - void constructor() {} - void destructor() {} -}; - -struct pWidget : public pSizable { - Widget &widget; - QWidget *qtWidget; - - bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); - void synchronizeState(); - void destructor(); - virtual void orphan(); -}; - -struct pButton : public QObject, public pWidget { - Q_OBJECT - -public: - Button &button; - QToolButton *qtButton; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pCanvas : public QObject, public pWidget { - Q_OBJECT - -public: - Canvas &canvas; - QImage *qtImage; - struct QtCanvas : public QWidget { - pCanvas &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - void paintEvent(QPaintEvent*); - QtCanvas(pCanvas &self); - } *qtCanvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: -}; - -struct pCheckBox : public QObject, public pWidget { - Q_OBJECT - -public: - CheckBox &checkBox; - QCheckBox *qtCheckBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onToggle(); -}; - -struct pComboBox : public QObject, public pWidget { - Q_OBJECT - -public: - ComboBox &comboBox; - QComboBox *qtComboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHexEdit : public QObject, public pWidget { - Q_OBJECT - -public: - HexEdit &hexEdit; - struct QtHexEdit : public QTextEdit { - pHexEdit &self; - void keyPressEvent(QKeyEvent*); - void keyPressEventAcknowledge(QKeyEvent*); - QtHexEdit(pHexEdit &self) : self(self) {} - } *qtHexEdit; - QHBoxLayout *qtLayout; - QScrollBar *qtScroll; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - void keyPressEvent(QKeyEvent*); - -public slots: - void onScroll(); -}; - -struct pHorizontalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalScrollBar &horizontalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pHorizontalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - HorizontalSlider &horizontalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pLabel : public pWidget { - Label &label; - QLabel *qtLabel; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public QObject, public pWidget { - Q_OBJECT - -public: - LineEdit &lineEdit; - QLineEdit *qtLineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(); -}; - -struct pListView : public QObject, public pWidget { - Q_OBJECT - -public: - ListView &listView; - QTreeWidget *qtListView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const nall::image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); - void onChange(QTreeWidgetItem *item); - void onToggle(QTreeWidgetItem *item); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - QProgressBar *qtProgressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public QObject, public pWidget { - Q_OBJECT - -public: - RadioBox &radioBox; - QRadioButton *qtRadioBox; - QButtonGroup *qtGroup; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onActivate(); -}; - -struct pTextEdit : public QObject, public pWidget { - Q_OBJECT - -public: - TextEdit &textEdit; - QTextEdit *qtTextEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalScrollBar : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalScrollBar &verticalScrollBar; - QScrollBar *qtScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pVerticalSlider : public QObject, public pWidget { - Q_OBJECT - -public: - VerticalSlider &verticalSlider; - QSlider *qtSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); - -public slots: - void onChange(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - struct QtViewport : public QWidget { - pViewport &self; - void leaveEvent(QEvent*); - void mouseMoveEvent(QMouseEvent*); - void mousePressEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - QtViewport(pViewport &self); - } *qtViewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/purify/phoenix/qt/settings.cpp b/purify/phoenix/qt/settings.cpp deleted file mode 100644 index 90d3a76e..00000000 --- a/purify/phoenix/qt/settings.cpp +++ /dev/null @@ -1,24 +0,0 @@ -static Settings *settings = nullptr; - -void Settings::load() { - string path = { userpath(), ".config/phoenix/qt.cfg" }; - configuration::load(path); -} - -void Settings::save() { - string path = { userpath(), ".config/" }; - mkdir(path, 0755); - path.append("phoenix/"); - mkdir(path, 0755); - path.append("qt.cfg"); - configuration::save(path); -} - -Settings::Settings() { - append(frameGeometryX = 4, "frameGeometryX"); - append(frameGeometryY = 24, "frameGeometryY"); - append(frameGeometryWidth = 8, "frameGeometryWidth"); - append(frameGeometryHeight = 28, "frameGeometryHeight"); - append(menuGeometryHeight = 20, "menuGeometryHeight"); - append(statusGeometryHeight = 20, "statusGeometryHeight"); -} diff --git a/purify/phoenix/qt/timer.cpp b/purify/phoenix/qt/timer.cpp deleted file mode 100644 index 61f00ba8..00000000 --- a/purify/phoenix/qt/timer.cpp +++ /dev/null @@ -1,25 +0,0 @@ -void pTimer::setEnabled(bool enabled) { - if(enabled) { - qtTimer->start(); - } else { - qtTimer->stop(); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - qtTimer->setInterval(milliseconds); -} - -void pTimer::constructor() { - qtTimer = new QTimer; - qtTimer->setInterval(0); - connect(qtTimer, SIGNAL(timeout()), SLOT(onTimeout())); -} - -void pTimer::destructor() { - delete qtTimer; -} - -void pTimer::onTimeout() { - if(timer.onTimeout) timer.onTimeout(); -} diff --git a/purify/phoenix/qt/utility.cpp b/purify/phoenix/qt/utility.cpp deleted file mode 100644 index 400df0a2..00000000 --- a/purify/phoenix/qt/utility.cpp +++ /dev/null @@ -1,190 +0,0 @@ -static QIcon CreateIcon(const nall::image &image, bool scale = false) { - nall::image qtBuffer = image; - qtBuffer.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - if(scale) qtBuffer.scale(16, 16, Interpolation::Linear); - QImage qtImage(qtBuffer.data, qtBuffer.width, qtBuffer.height, QImage::Format_ARGB32); - return QIcon(QPixmap::fromImage(qtImage)); -} - -static Keyboard::Keycode Keysym(int keysym) { - switch(keysym) { - case XK_Escape: return Keyboard::Keycode::Escape; - case XK_F1: return Keyboard::Keycode::F1; - case XK_F2: return Keyboard::Keycode::F2; - case XK_F3: return Keyboard::Keycode::F3; - case XK_F4: return Keyboard::Keycode::F4; - case XK_F5: return Keyboard::Keycode::F5; - case XK_F6: return Keyboard::Keycode::F6; - case XK_F7: return Keyboard::Keycode::F7; - case XK_F8: return Keyboard::Keycode::F8; - case XK_F9: return Keyboard::Keycode::F9; - case XK_F10: return Keyboard::Keycode::F10; - case XK_F11: return Keyboard::Keycode::F11; - case XK_F12: return Keyboard::Keycode::F12; - - case XK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case XK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case XK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case XK_Insert: return Keyboard::Keycode::Insert; - case XK_Delete: return Keyboard::Keycode::Delete; - case XK_Home: return Keyboard::Keycode::Home; - case XK_End: return Keyboard::Keycode::End; - case XK_Prior: return Keyboard::Keycode::PageUp; - case XK_Next: return Keyboard::Keycode::PageDown; - - case XK_Up: return Keyboard::Keycode::Up; - case XK_Down: return Keyboard::Keycode::Down; - case XK_Left: return Keyboard::Keycode::Left; - case XK_Right: return Keyboard::Keycode::Right; - - case XK_grave: return Keyboard::Keycode::Grave; - case XK_1: return Keyboard::Keycode::Number1; - case XK_2: return Keyboard::Keycode::Number2; - case XK_3: return Keyboard::Keycode::Number3; - case XK_4: return Keyboard::Keycode::Number4; - case XK_5: return Keyboard::Keycode::Number5; - case XK_6: return Keyboard::Keycode::Number6; - case XK_7: return Keyboard::Keycode::Number7; - case XK_8: return Keyboard::Keycode::Number8; - case XK_9: return Keyboard::Keycode::Number9; - case XK_0: return Keyboard::Keycode::Number0; - case XK_minus: return Keyboard::Keycode::Minus; - case XK_equal: return Keyboard::Keycode::Equal; - case XK_BackSpace: return Keyboard::Keycode::Backspace; - - case XK_asciitilde: return Keyboard::Keycode::Tilde; - case XK_exclam: return Keyboard::Keycode::Exclamation; - case XK_at: return Keyboard::Keycode::At; - case XK_numbersign: return Keyboard::Keycode::Pound; - case XK_dollar: return Keyboard::Keycode::Dollar; - case XK_percent: return Keyboard::Keycode::Percent; - case XK_asciicircum: return Keyboard::Keycode::Power; - case XK_ampersand: return Keyboard::Keycode::Ampersand; - case XK_asterisk: return Keyboard::Keycode::Asterisk; - case XK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case XK_parenright: return Keyboard::Keycode::ParenthesisRight; - case XK_underscore: return Keyboard::Keycode::Underscore; - case XK_plus: return Keyboard::Keycode::Plus; - - case XK_bracketleft: return Keyboard::Keycode::BracketLeft; - case XK_bracketright: return Keyboard::Keycode::BracketRight; - case XK_backslash: return Keyboard::Keycode::Backslash; - case XK_semicolon: return Keyboard::Keycode::Semicolon; - case XK_apostrophe: return Keyboard::Keycode::Apostrophe; - case XK_comma: return Keyboard::Keycode::Comma; - case XK_period: return Keyboard::Keycode::Period; - case XK_slash: return Keyboard::Keycode::Slash; - - case XK_braceleft: return Keyboard::Keycode::BraceLeft; - case XK_braceright: return Keyboard::Keycode::BraceRight; - case XK_bar: return Keyboard::Keycode::Pipe; - case XK_colon: return Keyboard::Keycode::Colon; - case XK_quotedbl: return Keyboard::Keycode::Quote; - case XK_less: return Keyboard::Keycode::CaretLeft; - case XK_greater: return Keyboard::Keycode::CaretRight; - case XK_question: return Keyboard::Keycode::Question; - - case XK_Tab: return Keyboard::Keycode::Tab; - case XK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case XK_Return: return Keyboard::Keycode::Return; - case XK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case XK_Shift_R: return Keyboard::Keycode::ShiftRight; - case XK_Control_L: return Keyboard::Keycode::ControlLeft; - case XK_Control_R: return Keyboard::Keycode::ControlRight; - case XK_Super_L: return Keyboard::Keycode::SuperLeft; - case XK_Super_R: return Keyboard::Keycode::SuperRight; - case XK_Alt_L: return Keyboard::Keycode::AltLeft; - case XK_Alt_R: return Keyboard::Keycode::AltRight; - case XK_space: return Keyboard::Keycode::Space; - case XK_Menu: return Keyboard::Keycode::Menu; - - case XK_A: return Keyboard::Keycode::A; - case XK_B: return Keyboard::Keycode::B; - case XK_C: return Keyboard::Keycode::C; - case XK_D: return Keyboard::Keycode::D; - case XK_E: return Keyboard::Keycode::E; - case XK_F: return Keyboard::Keycode::F; - case XK_G: return Keyboard::Keycode::G; - case XK_H: return Keyboard::Keycode::H; - case XK_I: return Keyboard::Keycode::I; - case XK_J: return Keyboard::Keycode::J; - case XK_K: return Keyboard::Keycode::K; - case XK_L: return Keyboard::Keycode::L; - case XK_M: return Keyboard::Keycode::M; - case XK_N: return Keyboard::Keycode::N; - case XK_O: return Keyboard::Keycode::O; - case XK_P: return Keyboard::Keycode::P; - case XK_Q: return Keyboard::Keycode::Q; - case XK_R: return Keyboard::Keycode::R; - case XK_S: return Keyboard::Keycode::S; - case XK_T: return Keyboard::Keycode::T; - case XK_U: return Keyboard::Keycode::U; - case XK_V: return Keyboard::Keycode::V; - case XK_W: return Keyboard::Keycode::W; - case XK_X: return Keyboard::Keycode::X; - case XK_Y: return Keyboard::Keycode::Y; - case XK_Z: return Keyboard::Keycode::Z; - - case XK_a: return Keyboard::Keycode::a; - case XK_b: return Keyboard::Keycode::b; - case XK_c: return Keyboard::Keycode::c; - case XK_d: return Keyboard::Keycode::d; - case XK_e: return Keyboard::Keycode::e; - case XK_f: return Keyboard::Keycode::f; - case XK_g: return Keyboard::Keycode::g; - case XK_h: return Keyboard::Keycode::h; - case XK_i: return Keyboard::Keycode::i; - case XK_j: return Keyboard::Keycode::j; - case XK_k: return Keyboard::Keycode::k; - case XK_l: return Keyboard::Keycode::l; - case XK_m: return Keyboard::Keycode::m; - case XK_n: return Keyboard::Keycode::n; - case XK_o: return Keyboard::Keycode::o; - case XK_p: return Keyboard::Keycode::p; - case XK_q: return Keyboard::Keycode::q; - case XK_r: return Keyboard::Keycode::r; - case XK_s: return Keyboard::Keycode::s; - case XK_t: return Keyboard::Keycode::t; - case XK_u: return Keyboard::Keycode::u; - case XK_v: return Keyboard::Keycode::v; - case XK_w: return Keyboard::Keycode::w; - case XK_x: return Keyboard::Keycode::x; - case XK_y: return Keyboard::Keycode::y; - case XK_z: return Keyboard::Keycode::z; - - case XK_Num_Lock: return Keyboard::Keycode::NumLock; - case XK_KP_Divide: return Keyboard::Keycode::Divide; - case XK_KP_Multiply: return Keyboard::Keycode::Multiply; - case XK_KP_Subtract: return Keyboard::Keycode::Subtract; - case XK_KP_Add: return Keyboard::Keycode::Add; - case XK_KP_Enter: return Keyboard::Keycode::Enter; - case XK_KP_Decimal: return Keyboard::Keycode::Point; - - case XK_KP_1: return Keyboard::Keycode::Keypad1; - case XK_KP_2: return Keyboard::Keycode::Keypad2; - case XK_KP_3: return Keyboard::Keycode::Keypad3; - case XK_KP_4: return Keyboard::Keycode::Keypad4; - case XK_KP_5: return Keyboard::Keycode::Keypad5; - case XK_KP_6: return Keyboard::Keycode::Keypad6; - case XK_KP_7: return Keyboard::Keycode::Keypad7; - case XK_KP_8: return Keyboard::Keycode::Keypad8; - case XK_KP_9: return Keyboard::Keycode::Keypad9; - case XK_KP_0: return Keyboard::Keycode::Keypad0; - - case XK_KP_Home: return Keyboard::Keycode::KeypadHome; - case XK_KP_End: return Keyboard::Keycode::KeypadEnd; - case XK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case XK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case XK_KP_Up: return Keyboard::Keycode::KeypadUp; - case XK_KP_Down: return Keyboard::Keycode::KeypadDown; - case XK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case XK_KP_Right: return Keyboard::Keycode::KeypadRight; - case XK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case XK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case XK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} diff --git a/purify/phoenix/qt/widget/button.cpp b/purify/phoenix/qt/widget/button.cpp deleted file mode 100644 index 0e1522b3..00000000 --- a/purify/phoenix/qt/widget/button.cpp +++ /dev/null @@ -1,52 +0,0 @@ -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 12 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - qtButton->setIconSize(QSize(image.width, image.height)); - qtButton->setIcon(CreateIcon(image)); - qtButton->setStyleSheet("text-align: top;"); - switch(orientation) { - case Orientation::Horizontal: qtButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; - case Orientation::Vertical: qtButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; - } -} - -void pButton::setText(const string &text) { - qtButton->setText(QString::fromUtf8(text)); -} - -void pButton::constructor() { - qtWidget = qtButton = new QToolButton; - qtButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - connect(qtButton, SIGNAL(released()), SLOT(onActivate())); - - pWidget::synchronizeState(); - setText(button.state.text); -} - -void pButton::destructor() { - delete qtButton; - qtWidget = qtButton = 0; -} - -void pButton::orphan() { - destructor(); - constructor(); -} - -void pButton::onActivate() { - if(button.onActivate) button.onActivate(); -} diff --git a/purify/phoenix/qt/widget/canvas.cpp b/purify/phoenix/qt/widget/canvas.cpp deleted file mode 100644 index 245c1e9f..00000000 --- a/purify/phoenix/qt/widget/canvas.cpp +++ /dev/null @@ -1,73 +0,0 @@ -void pCanvas::setSize(const Size &size) { - delete qtImage; - qtImage = new QImage(size.width, size.height, QImage::Format_ARGB32); -} - -void pCanvas::update() { - uint32_t *dp = (uint32_t*)qtImage->bits(), *sp = (uint32_t*)canvas.state.data; - for(unsigned n = 0; n < canvas.state.width * canvas.state.height; n++) *dp++ = 0xff000000 | *sp++; - qtCanvas->update(); -} - -void pCanvas::constructor() { - qtWidget = qtCanvas = new QtCanvas(*this); - qtCanvas->setMouseTracking(true); - qtImage = new QImage(canvas.state.width, canvas.state.height, QImage::Format_ARGB32); - memcpy(qtImage->bits(), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - - pWidget::synchronizeState(); - update(); -} - -void pCanvas::destructor() { - delete qtCanvas; - delete qtImage; - qtWidget = qtCanvas = 0; - qtImage = 0; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::QtCanvas::leaveEvent(QEvent *event) { - if(self.canvas.onMouseLeave) self.canvas.onMouseLeave(); -} - -void pCanvas::QtCanvas::mouseMoveEvent(QMouseEvent *event) { - if(self.canvas.onMouseMove) self.canvas.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pCanvas::QtCanvas::mousePressEvent(QMouseEvent *event) { - if(self.canvas.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMousePress(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::mouseReleaseEvent(QMouseEvent *event) { - if(self.canvas.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.canvas.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.canvas.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.canvas.onMouseRelease(Mouse::Button::Right); break; - } -} - -void pCanvas::QtCanvas::paintEvent(QPaintEvent *event) { - QPainter painter(self.qtCanvas); - painter.drawImage(0, 0, *self.qtImage); - -//this will scale the source image to fit the target widget size (nearest-neighbor): -//painter.drawImage( -// QRect(0, 0, geometry().width(), geometry().height()), -// *self.qtImage, -// QRect(0, 0, self.canvas.state.width, self.canvas.state.height) -//); -} - -pCanvas::QtCanvas::QtCanvas(pCanvas &self) : self(self) { -} diff --git a/purify/phoenix/qt/widget/check-box.cpp b/purify/phoenix/qt/widget/check-box.cpp deleted file mode 100644 index c45bb326..00000000 --- a/purify/phoenix/qt/widget/check-box.cpp +++ /dev/null @@ -1,42 +0,0 @@ -bool pCheckBox::checked() { - return qtCheckBox->isChecked(); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), checkBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pCheckBox::setChecked(bool checked) { - locked = true; - qtCheckBox->setChecked(checked); - locked = false; -} - -void pCheckBox::setText(const string &text) { - qtCheckBox->setText(QString::fromUtf8(text)); -} - -void pCheckBox::constructor() { - qtWidget = qtCheckBox = new QCheckBox; - connect(qtCheckBox, SIGNAL(stateChanged(int)), SLOT(onToggle())); - - pWidget::synchronizeState(); - setChecked(checkBox.state.checked); - setText(checkBox.state.text); -} - -void pCheckBox::destructor() { - delete qtCheckBox; - qtWidget = qtCheckBox = 0; -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} - -void pCheckBox::onToggle() { - checkBox.state.checked = checked(); - if(locked == false && checkBox.onToggle) checkBox.onToggle(); -} diff --git a/purify/phoenix/qt/widget/combo-box.cpp b/purify/phoenix/qt/widget/combo-box.cpp deleted file mode 100644 index 1dfa609d..00000000 --- a/purify/phoenix/qt/widget/combo-box.cpp +++ /dev/null @@ -1,68 +0,0 @@ -void pComboBox::append(const string &text) { - locked = true; - qtComboBox->addItem(QString::fromUtf8(text)); - locked = false; -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(qtWidget->font(), text).width); - Geometry geometry = pFont::geometry(qtWidget->font(), " "); - return { 0, 0, maximumWidth + 32, geometry.height + 12 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - qtComboBox->setItemText(row, text); -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - qtComboBox->removeItem(row); - if(position == row) qtComboBox->setCurrentIndex(0); - locked = false; -} - -void pComboBox::reset() { - locked = true; - while(qtComboBox->count()) qtComboBox->removeItem(0); - locked = false; -} - -unsigned pComboBox::selection() { - signed index = qtComboBox->currentIndex(); - return index >= 0 ? index : 0; -} - -void pComboBox::setSelection(unsigned row) { - locked = true; - qtComboBox->setCurrentIndex(row); - locked = false; -} - -void pComboBox::constructor() { - qtWidget = qtComboBox = new QComboBox; - connect(qtComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - unsigned selection = comboBox.state.selection; - locked = true; - for(auto &text : comboBox.state.text) append(text); - locked = false; - setSelection(selection); -} - -void pComboBox::destructor() { - delete qtComboBox; - qtWidget = qtComboBox = 0; -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::onChange() { - comboBox.state.selection = selection(); - if(locked == false && comboBox.onChange) comboBox.onChange(); -} diff --git a/purify/phoenix/qt/widget/hex-edit.cpp b/purify/phoenix/qt/widget/hex-edit.cpp deleted file mode 100644 index fdeebe4a..00000000 --- a/purify/phoenix/qt/widget/hex-edit.cpp +++ /dev/null @@ -1,191 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - //add one if last row is not equal to column length (eg only part of the row is present) - bool indivisible = hexEdit.state.columns == 0 || (hexEdit.state.length % hexEdit.state.columns) != 0; - qtScroll->setRange(0, hexEdit.state.length / hexEdit.state.columns + indivisible - hexEdit.state.rows); - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - locked = true; - qtScroll->setSliderPosition(hexEdit.state.offset / hexEdit.state.columns); - locked = false; - update(); -} - -void pHexEdit::setRows(unsigned rows) { - qtScroll->setPageStep(hexEdit.state.rows); - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - qtHexEdit->setPlainText(""); - return; - } - - unsigned cursorPosition = qtHexEdit->textCursor().position(); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\n"); - } - - qtHexEdit->setPlainText(QString::fromUtf8(output)); - QTextCursor cursor = qtHexEdit->textCursor(); - cursor.setPosition(cursorPosition); - qtHexEdit->setTextCursor(cursor); -} - -void pHexEdit::constructor() { - qtWidget = qtHexEdit = new QtHexEdit(*this); - - qtHexEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - qtHexEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - qtLayout = new QHBoxLayout; - qtLayout->setAlignment(Qt::AlignRight); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtHexEdit->setLayout(qtLayout); - - qtScroll = new QScrollBar(Qt::Vertical); - qtScroll->setSingleStep(1); - qtLayout->addWidget(qtScroll); - - connect(qtScroll, SIGNAL(actionTriggered(int)), SLOT(onScroll())); - - pWidget::synchronizeState(); - setColumns(hexEdit.state.columns); - setRows(hexEdit.state.rows); - setLength(hexEdit.state.length); - setOffset(hexEdit.state.offset); - update(); -} - -void pHexEdit::destructor() { - delete qtScroll; - delete qtLayout; - delete qtHexEdit; - qtWidget = qtHexEdit = 0; - qtLayout = 0; - qtScroll = 0; -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -void pHexEdit::keyPressEvent(QKeyEvent *event) { - if(!hexEdit.onRead) return; - - QTextCursor cursor = qtHexEdit->textCursor(); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1; - unsigned cursorY = cursor.position() / lineWidth; - unsigned cursorX = cursor.position() % lineWidth; - - unsigned nibble; - switch(event->key()) { - case Qt::Key_0: nibble = 0; break; - case Qt::Key_1: nibble = 1; break; - case Qt::Key_2: nibble = 2; break; - case Qt::Key_3: nibble = 3; break; - case Qt::Key_4: nibble = 4; break; - case Qt::Key_5: nibble = 5; break; - case Qt::Key_6: nibble = 6; break; - case Qt::Key_7: nibble = 7; break; - case Qt::Key_8: nibble = 8; break; - case Qt::Key_9: nibble = 9; break; - case Qt::Key_A: nibble = 10; break; - case Qt::Key_B: nibble = 11; break; - case Qt::Key_C: nibble = 12; break; - case Qt::Key_D: nibble = 13; break; - case Qt::Key_E: nibble = 14; break; - case Qt::Key_F: nibble = 15; break; - default: { - //allow navigation keys to move cursor, but block text input - qtHexEdit->setTextInteractionFlags(Qt::TextInteractionFlags( - Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse - )); - qtHexEdit->keyPressEventAcknowledge(event); - qtHexEdit->setTextInteractionFlags(Qt::TextEditorInteraction); - return; - } - } - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return; //do not edit past end of file - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (nibble << 0); - } else { - data = (data & 0x0f) | (nibble << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble/byte - unsigned step = 1; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) step = 2; - cursor.setPosition(cursor.position() + step); - qtHexEdit->setTextCursor(cursor); - - //refresh output to reflect modified data - update(); - } - } - } -} - -void pHexEdit::onScroll() { - if(locked) return; - unsigned offset = qtScroll->sliderPosition(); - hexEdit.state.offset = offset * hexEdit.state.columns; - update(); -} - -void pHexEdit::QtHexEdit::keyPressEvent(QKeyEvent *event) { - self.keyPressEvent(event); -} - -void pHexEdit::QtHexEdit::keyPressEventAcknowledge(QKeyEvent *event) { - QTextEdit::keyPressEvent(event); -} diff --git a/purify/phoenix/qt/widget/horizontal-scroll-bar.cpp b/purify/phoenix/qt/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 6127c301..00000000 --- a/purify/phoenix/qt/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 15 }; -} - -unsigned pHorizontalScrollBar::position() { - return qtScrollBar->value(); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pHorizontalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Horizontal); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalScrollBar.state.length); - setPosition(horizontalScrollBar.state.position); -} - -void pHorizontalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pHorizontalScrollBar::onChange() { - horizontalScrollBar.state.position = position(); - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); -} diff --git a/purify/phoenix/qt/widget/horizontal-slider.cpp b/purify/phoenix/qt/widget/horizontal-slider.cpp deleted file mode 100644 index 5401aae1..00000000 --- a/purify/phoenix/qt/widget/horizontal-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 20 }; -} - -unsigned pHorizontalSlider::position() { - return qtSlider->value(); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pHorizontalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pHorizontalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Horizontal); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(horizontalSlider.state.length); - setPosition(horizontalSlider.state.position); -} - -void pHorizontalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} - -void pHorizontalSlider::onChange() { - horizontalSlider.state.position = position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); -} diff --git a/purify/phoenix/qt/widget/label.cpp b/purify/phoenix/qt/widget/label.cpp deleted file mode 100644 index 8dd86eb6..00000000 --- a/purify/phoenix/qt/widget/label.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - qtLabel->setText(QString::fromUtf8(text)); -} - -void pLabel::constructor() { - qtWidget = qtLabel = new QLabel; - - pWidget::synchronizeState(); - setText(label.state.text); -} - -void pLabel::destructor() { - delete qtLabel; - qtWidget = qtLabel = 0; -} - -void pLabel::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/qt/widget/line-edit.cpp b/purify/phoenix/qt/widget/line-edit.cpp deleted file mode 100644 index a13f3b81..00000000 --- a/purify/phoenix/qt/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 12 }; -} - -void pLineEdit::setEditable(bool editable) { - qtLineEdit->setReadOnly(!editable); -} - -void pLineEdit::setText(const string &text) { - qtLineEdit->setText(QString::fromUtf8(text)); -} - -string pLineEdit::text() { - return qtLineEdit->text().toUtf8().constData(); -} - -void pLineEdit::constructor() { - qtWidget = qtLineEdit = new QLineEdit; - connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate())); - connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); -} - -void pLineEdit::destructor() { - delete qtLineEdit; - qtWidget = qtLineEdit = 0; -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} - -void pLineEdit::onActivate() { - if(lineEdit.onActivate) lineEdit.onActivate(); -} - -void pLineEdit::onChange() { - lineEdit.state.text = text(); - if(lineEdit.onChange) lineEdit.onChange(); -} diff --git a/purify/phoenix/qt/widget/list-view.cpp b/purify/phoenix/qt/widget/list-view.cpp deleted file mode 100644 index a81c092d..00000000 --- a/purify/phoenix/qt/widget/list-view.cpp +++ /dev/null @@ -1,164 +0,0 @@ -void pListView::append(const lstring &text) { - locked = true; - auto items = qtListView->findItems("", Qt::MatchContains); - QTreeWidgetItem *item = new QTreeWidgetItem(qtListView); - - item->setData(0, Qt::UserRole, (unsigned)items.size()); - if(listView.state.checkable) item->setCheckState(0, Qt::Unchecked); - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::autoSizeColumns() { - for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n); -} - -bool pListView::checked(unsigned row) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - return item ? item->checkState(0) == Qt::Checked : false; -} - -void pListView::modify(unsigned row, const lstring &text) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - for(unsigned n = 0; n < text.size(); n++) { - item->setText(n, QString::fromUtf8(text[n])); - } - locked = false; -} - -void pListView::remove(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item == nullptr) return; - delete item; - locked = false; -} - -void pListView::reset() { - qtListView->clear(); -} - -bool pListView::selected() { - QTreeWidgetItem *item = qtListView->currentItem(); - return (item && item->isSelected() == true); -} - -unsigned pListView::selection() { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item == 0) return 0; - return item->data(0, Qt::UserRole).toUInt(); -} - -void pListView::setCheckable(bool checkable) { - if(checkable) { - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) items[n]->setCheckState(0, Qt::Unchecked); - } -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) item->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); - locked = false; -} - -void pListView::setHeaderText(const lstring &text) { - QStringList labels; - for(auto &column : text) labels << QString::fromUtf8(column); - - qtListView->setColumnCount(text.size()); - qtListView->setAlternatingRowColors(text.size() >= 2); - qtListView->setHeaderLabels(labels); - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - qtListView->setHeaderHidden(!visible); - autoSizeColumns(); -} - -void pListView::setImage(unsigned row, unsigned column, const nall::image &image) { - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(item) { - if(image.empty() == 0) item->setIcon(column, CreateIcon(image)); - if(image.empty() == 1) item->setIcon(column, QIcon()); - } -} - -void pListView::setSelected(bool selected) { - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(selected); -} - -void pListView::setSelection(unsigned row) { - locked = true; - QTreeWidgetItem *item = qtListView->currentItem(); - if(item) item->setSelected(false); - qtListView->setCurrentItem(0); - auto items = qtListView->findItems("", Qt::MatchContains); - for(unsigned n = 0; n < items.size(); n++) { - if(items[n]->data(0, Qt::UserRole).toUInt() == row) { - qtListView->setCurrentItem(items[n]); - break; - } - } - locked = false; -} - -void pListView::constructor() { - qtWidget = qtListView = new QTreeWidget; - qtListView->setAllColumnsShowFocus(true); - qtListView->setRootIsDecorated(false); - - connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate())); - connect(qtListView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(onChange(QTreeWidgetItem*))); - connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*))); - - pWidget::synchronizeState(); - setCheckable(listView.state.checkable); - setHeaderText(listView.state.headerText.size() ? listView.state.headerText : lstring{ " " }); - setHeaderVisible(listView.state.headerVisible); - for(auto &row : listView.state.text) append(row); - if(listView.state.checkable) { - for(unsigned n = 0; n < listView.state.checked.size(); n++) { - setChecked(n, listView.state.checked[n]); - } - } - setSelected(listView.state.selected); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); -} - -void pListView::destructor() { - delete qtListView; - qtWidget = qtListView = 0; -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::onActivate() { - if(locked == false && listView.onActivate) listView.onActivate(); -} - -void pListView::onChange(QTreeWidgetItem *item) { - //Qt bug workaround: clicking items with mouse does not mark items as selected - if(item) item->setSelected(true); - listView.state.selected = selected(); - if(listView.state.selected) listView.state.selection = selection(); - if(locked == false && listView.onChange) listView.onChange(); -} - -void pListView::onToggle(QTreeWidgetItem *item) { - unsigned row = item->data(0, Qt::UserRole).toUInt(); - bool checkState = checked(row); - listView.state.checked[row] = checkState; - if(locked == false && listView.onToggle) listView.onToggle(row); -} diff --git a/purify/phoenix/qt/widget/progress-bar.cpp b/purify/phoenix/qt/widget/progress-bar.cpp deleted file mode 100644 index 8178bb66..00000000 --- a/purify/phoenix/qt/widget/progress-bar.cpp +++ /dev/null @@ -1,26 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -void pProgressBar::setPosition(unsigned position) { - qtProgressBar->setValue(position); -} - -void pProgressBar::constructor() { - qtWidget = qtProgressBar = new QProgressBar; - qtProgressBar->setRange(0, 100); - qtProgressBar->setTextVisible(false); - - pWidget::synchronizeState(); - setPosition(progressBar.state.position); -} - -void pProgressBar::destructor() { - delete qtProgressBar; - qtWidget = qtProgressBar = 0; -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/qt/widget/radio-box.cpp b/purify/phoenix/qt/widget/radio-box.cpp deleted file mode 100644 index bf640fd2..00000000 --- a/purify/phoenix/qt/widget/radio-box.cpp +++ /dev/null @@ -1,64 +0,0 @@ -bool pRadioBox::checked() { - return qtRadioBox->isChecked(); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(qtWidget->font(), radioBox.state.text); - return { 0, 0, geometry.width + 26, geometry.height + 6 }; -} - -void pRadioBox::setChecked() { - locked = true; - for(auto &item : radioBox.state.group) { - bool checkState = item.p.qtRadioBox == qtRadioBox; - item.state.checked = checkState; - item.p.qtRadioBox->setChecked(checkState); - } - locked = false; -} - -void pRadioBox::setGroup(const set &group) { - locked = true; - if(qtGroup) { - delete qtGroup; - qtGroup = 0; - } - if(group.size() > 0 && qtRadioBox == group[0].p.qtRadioBox) { - qtGroup = new QButtonGroup; - for(auto &item : group) qtGroup->addButton(item.p.qtRadioBox); - setChecked(); - } - locked = false; -} - -void pRadioBox::setText(const string &text) { - qtRadioBox->setText(QString::fromUtf8(text)); -} - -void pRadioBox::constructor() { - qtWidget = qtRadioBox = new QRadioButton; - qtGroup = new QButtonGroup; - qtGroup->addButton(qtRadioBox); - qtRadioBox->setChecked(true); - connect(qtRadioBox, SIGNAL(toggled(bool)), SLOT(onActivate())); - - pWidget::synchronizeState(); - setGroup(radioBox.state.group); - setText(radioBox.state.text); -} - -void pRadioBox::destructor() { - delete qtGroup; - delete qtRadioBox; - qtWidget = qtRadioBox = 0; - qtGroup = 0; -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} - -void pRadioBox::onActivate() { - if(locked == false && checked() && radioBox.onActivate) radioBox.onActivate(); -} diff --git a/purify/phoenix/qt/widget/text-edit.cpp b/purify/phoenix/qt/widget/text-edit.cpp deleted file mode 100644 index 8cdbe573..00000000 --- a/purify/phoenix/qt/widget/text-edit.cpp +++ /dev/null @@ -1,50 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - QTextCursor cursor = qtTextEdit->textCursor(); - unsigned lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData()); - cursor.setPosition(min(position, lastCharacter)); - qtTextEdit->setTextCursor(cursor); -} - -void pTextEdit::setEditable(bool editable) { - qtTextEdit->setReadOnly(!editable); -} - -void pTextEdit::setText(const string &text) { - qtTextEdit->setPlainText(QString::fromUtf8(text)); -} - -void pTextEdit::setWordWrap(bool wordWrap) { - qtTextEdit->setWordWrapMode(wordWrap ? QTextOption::WordWrap : QTextOption::NoWrap); - qtTextEdit->setHorizontalScrollBarPolicy(wordWrap ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn); - qtTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); -} - -string pTextEdit::text() { - return qtTextEdit->toPlainText().toUtf8().constData(); -} - -void pTextEdit::constructor() { - qtWidget = qtTextEdit = new QTextEdit; - connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange())); - - pWidget::synchronizeState(); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - setWordWrap(textEdit.state.wordWrap); -} - -void pTextEdit::destructor() { - if(sizable.state.layout) sizable.state.layout->remove(textEdit); - delete qtTextEdit; - qtWidget = qtTextEdit = 0; -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} - -void pTextEdit::onChange() { - textEdit.state.text = text(); - if(textEdit.onChange) textEdit.onChange(); -} diff --git a/purify/phoenix/qt/widget/vertical-scroll-bar.cpp b/purify/phoenix/qt/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 74d68ca6..00000000 --- a/purify/phoenix/qt/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 15, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return qtScrollBar->value(); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += length == 0; - qtScrollBar->setRange(0, length - 1); - qtScrollBar->setPageStep(length >> 3); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - qtScrollBar->setValue(position); -} - -void pVerticalScrollBar::constructor() { - qtWidget = qtScrollBar = new QScrollBar(Qt::Vertical); - qtScrollBar->setRange(0, 100); - qtScrollBar->setPageStep(101 >> 3); - connect(qtScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalScrollBar.state.length); - setPosition(verticalScrollBar.state.position); -} - -void pVerticalScrollBar::destructor() { - delete qtScrollBar; - qtWidget = qtScrollBar = 0; -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} - -void pVerticalScrollBar::onChange() { - verticalScrollBar.state.position = position(); - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); -} diff --git a/purify/phoenix/qt/widget/vertical-slider.cpp b/purify/phoenix/qt/widget/vertical-slider.cpp deleted file mode 100644 index 500adb07..00000000 --- a/purify/phoenix/qt/widget/vertical-slider.cpp +++ /dev/null @@ -1,43 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 20, 0 }; -} - -unsigned pVerticalSlider::position() { - return qtSlider->value(); -} - -void pVerticalSlider::setLength(unsigned length) { - length += length == 0; - qtSlider->setRange(0, length - 1); - qtSlider->setPageStep(length >> 3); -} - -void pVerticalSlider::setPosition(unsigned position) { - qtSlider->setValue(position); -} - -void pVerticalSlider::constructor() { - qtWidget = qtSlider = new QSlider(Qt::Vertical); - qtSlider->setRange(0, 100); - qtSlider->setPageStep(101 >> 3); - connect(qtSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); - - pWidget::synchronizeState(); - setLength(verticalSlider.state.length); - setPosition(verticalSlider.state.position); -} - -void pVerticalSlider::destructor() { - delete qtSlider; - qtWidget = qtSlider = 0; -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} - -void pVerticalSlider::onChange() { - verticalSlider.state.position = position(); - if(verticalSlider.onChange) verticalSlider.onChange(); -} diff --git a/purify/phoenix/qt/widget/viewport.cpp b/purify/phoenix/qt/widget/viewport.cpp deleted file mode 100644 index 1b67d776..00000000 --- a/purify/phoenix/qt/widget/viewport.cpp +++ /dev/null @@ -1,51 +0,0 @@ -uintptr_t pViewport::handle() { - return (uintptr_t)qtViewport->winId(); -} - -void pViewport::constructor() { - qtWidget = qtViewport = new QtViewport(*this); - qtViewport->setMouseTracking(true); - qtViewport->setAttribute(Qt::WA_PaintOnScreen, true); - qtViewport->setStyleSheet("background: #000000"); - - pWidget::synchronizeState(); -} - -void pViewport::destructor() { - delete qtViewport; - qtWidget = qtViewport = nullptr; -} - -void pViewport::orphan() { - destructor(); - constructor(); -} - -void pViewport::QtViewport::leaveEvent(QEvent *event) { - if(self.viewport.onMouseLeave) self.viewport.onMouseLeave(); -} - -void pViewport::QtViewport::mouseMoveEvent(QMouseEvent *event) { - if(self.viewport.onMouseMove) self.viewport.onMouseMove({ event->pos().x(), event->pos().y() }); -} - -void pViewport::QtViewport::mousePressEvent(QMouseEvent *event) { - if(self.viewport.onMousePress == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMousePress(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMousePress(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMousePress(Mouse::Button::Right); break; - } -} - -void pViewport::QtViewport::mouseReleaseEvent(QMouseEvent *event) { - if(self.viewport.onMouseRelease == false) return; - switch(event->button()) { - case Qt::LeftButton: self.viewport.onMouseRelease(Mouse::Button::Left); break; - case Qt::MidButton: self.viewport.onMouseRelease(Mouse::Button::Middle); break; - case Qt::RightButton: self.viewport.onMouseRelease(Mouse::Button::Right); break; - } -} - -pViewport::QtViewport::QtViewport(pViewport &self) : self(self) { -} diff --git a/purify/phoenix/qt/widget/widget.cpp b/purify/phoenix/qt/widget/widget.cpp deleted file mode 100644 index 27d23354..00000000 --- a/purify/phoenix/qt/widget/widget.cpp +++ /dev/null @@ -1,56 +0,0 @@ -bool pWidget::focused() { - return qtWidget->hasFocus(); -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - qtWidget->setEnabled(enabled); -} - -void pWidget::setFocused() { - qtWidget->setFocus(Qt::OtherFocusReason); -} - -void pWidget::setFont(const string &font) { - qtWidget->setFont(pFont::create(font)); -} - -void pWidget::setGeometry(const Geometry &geometry) { - qtWidget->setGeometry(geometry.x, geometry.y, geometry.width, geometry.height); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout == 0) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - qtWidget->setVisible(visible); -} - -void pWidget::constructor() { - if(widget.state.abstract) qtWidget = new QWidget; -} - -//pWidget::constructor() called before p{Derived}::constructor(); ergo qtWidget is not yet valid -//pWidget::synchronizeState() is called to finish construction of p{Derived}::constructor() -void pWidget::synchronizeState() { - setEnabled(widget.state.enabled); - setFont(widget.state.font); -//setVisible(widget.state.visible); -} - -void pWidget::destructor() { - if(widget.state.abstract) { - delete qtWidget; - qtWidget = 0; - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/qt/window.cpp b/purify/phoenix/qt/window.cpp deleted file mode 100644 index dac311ee..00000000 --- a/purify/phoenix/qt/window.cpp +++ /dev/null @@ -1,297 +0,0 @@ -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geometry = window.state.geometry; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); -} - -void pWindow::append(Menu &menu) { - if(window.state.menuFont != "") menu.p.setFont(window.state.menuFont); - else menu.p.setFont("Sans, 8"); - qtMenu->addMenu(menu.p.qtMenu); -} - -void pWindow::append(Widget &widget) { - if(widget.state.font == "") { - if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Sans, 8"); - } - widget.p.qtWidget->setParent(qtContainer); - widget.setVisible(widget.visible()); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - QColor color = qtWindow->palette().color(QPalette::ColorRole::Window); - return { (uint8_t)color.red(), (uint8_t)color.green(), (uint8_t)color.blue(), (uint8_t)color.alpha() }; -} - -Geometry pWindow::frameMargin() { - unsigned menuHeight = window.state.menuVisible ? settings->menuGeometryHeight : 0; - unsigned statusHeight = window.state.statusVisible ? settings->statusGeometryHeight : 0; - if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight }; - return { - settings->frameGeometryX, - settings->frameGeometryY + menuHeight, - settings->frameGeometryWidth, - settings->frameGeometryHeight + menuHeight + statusHeight - }; -} - -bool pWindow::focused() { - return qtWindow->isActiveWindow() && !qtWindow->isMinimized(); -} - -Geometry pWindow::geometry() { - if(window.state.fullScreen) { - unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; - unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; - return { 0, menuHeight, Desktop::size().width, Desktop::size().height - menuHeight - statusHeight }; - } - return window.state.geometry; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - //QMenuBar::removeMenu() does not exist - qtMenu->clear(); - for(auto &menu : window.state.menu) append(menu); -} - -void pWindow::remove(Widget &widget) { - //bugfix: orphan() destroys and recreates widgets (to disassociate them from their parent); - //attempting to create widget again after QApplication::quit() crashes libQtGui - if(qtApplication) widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - QPalette palette; - palette.setColor(QPalette::Window, QColor(color.red, color.green, color.blue, color.alpha)); - qtContainer->setPalette(palette); - qtContainer->setAutoFillBackground(true); - qtWindow->setAttribute(Qt::WA_TranslucentBackground, color.alpha != 255); -} - -void pWindow::setFocused() { - qtWindow->raise(); - qtWindow->activateWindow(); -} - -void pWindow::setFullScreen(bool fullScreen) { - if(fullScreen == false) { - setResizable(window.state.resizable); - qtWindow->showNormal(); - qtWindow->adjustSize(); - } else { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setFixedSize(Desktop::size().width - frameMargin().width, Desktop::size().height - frameMargin().height); - qtWindow->showFullScreen(); - } -} - -void pWindow::setGeometry(const Geometry &geometry_) { - locked = true; - OS::processEvents(); - QApplication::syncX(); - Geometry geometry = geometry_, margin = frameMargin(); - - setResizable(window.state.resizable); - qtWindow->move(geometry.x - frameMargin().x, geometry.y - frameMargin().y); - //qtWindow->adjustSize() fails if larger than 2/3rds screen size - qtWindow->resize(qtWindow->sizeHint()); - qtWindow->setMinimumSize(1, 1); - qtContainer->setMinimumSize(1, 1); - - for(auto &layout : window.state.layout) { - geometry = geometry_; - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { - qtMenu->setFont(pFont::create(font)); - for(auto &item : window.state.menu) item.p.setFont(font); -} - -void pWindow::setMenuVisible(bool visible) { - qtMenu->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setModal(bool modal) { - qtWindow->setWindowModality(modal ? Qt::ApplicationModal : Qt::NonModal); -} - -void pWindow::setResizable(bool resizable) { - if(resizable) { - qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setMinimumSize(window.state.geometry.width, window.state.geometry.height); - } else { - qtLayout->setSizeConstraint(QLayout::SetFixedSize); - qtContainer->setFixedSize(window.state.geometry.width, window.state.geometry.height); - } - qtStatus->setSizeGripEnabled(resizable); -} - -void pWindow::setStatusFont(const string &font) { - qtStatus->setFont(pFont::create(font)); -} - -void pWindow::setStatusText(const string &text) { - qtStatus->showMessage(QString::fromUtf8(text), 0); -} - -void pWindow::setStatusVisible(bool visible) { - qtStatus->setVisible(visible); - setGeometry(window.state.geometry); -} - -void pWindow::setTitle(const string &text) { - qtWindow->setWindowTitle(QString::fromUtf8(text)); -} - -void pWindow::setVisible(bool visible) { - locked = true; - qtWindow->setVisible(visible); - if(visible) { - updateFrameGeometry(); - setGeometry(window.state.geometry); - } - locked = false; -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &item : window.state.widget) { - if(!item.state.font) item.setFont(font); - } -} - -void pWindow::constructor() { - qtWindow = new QtWindow(*this); - qtWindow->setWindowTitle(" "); - - //if program was given a name, try and set the window taskbar icon to a matching pixmap image - if(osState.name.empty() == false) { - if(file::exists({"/usr/share/pixmaps/", osState.name, ".png"})) { - qtWindow->setWindowIcon(QIcon(string{"/usr/share/pixmaps/", osState.name, ".png"})); - } else if(file::exists({"/usr/local/share/pixmaps/", osState.name, ".png"})) { - qtWindow->setWindowIcon(QIcon(string{"/usr/local/share/pixmaps/", osState.name, ".png"})); - } - } - - qtLayout = new QVBoxLayout(qtWindow); - qtLayout->setMargin(0); - qtLayout->setSpacing(0); - qtWindow->setLayout(qtLayout); - - qtMenu = new QMenuBar(qtWindow); - qtMenu->setVisible(false); - qtLayout->addWidget(qtMenu); - - qtContainer = new QWidget(qtWindow); - qtContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - qtContainer->setVisible(true); - qtLayout->addWidget(qtContainer); - - qtStatus = new QStatusBar(qtWindow); - qtStatus->setSizeGripEnabled(true); - qtStatus->setVisible(false); - qtLayout->addWidget(qtStatus); - - setGeometry(window.state.geometry); - setMenuFont("Sans, 8"); - setStatusFont("Sans, 8"); -} - -void pWindow::destructor() { - delete qtStatus; - delete qtContainer; - delete qtMenu; - delete qtLayout; - delete qtWindow; -} - -void pWindow::updateFrameGeometry() { - pOS::syncX(); - QRect border = qtWindow->frameGeometry(); - QRect client = qtWindow->geometry(); - - settings->frameGeometryX = client.x() - border.x(); - settings->frameGeometryY = client.y() - border.y(); - settings->frameGeometryWidth = border.width() - client.width(); - settings->frameGeometryHeight = border.height() - client.height(); - - if(window.state.menuVisible) { - pOS::syncX(); - settings->menuGeometryHeight = qtMenu->height(); - } - - if(window.state.statusVisible) { - pOS::syncX(); - settings->statusGeometryHeight = qtStatus->height(); - } - - settings->save(); -} - -void pWindow::QtWindow::closeEvent(QCloseEvent *event) { - self.window.state.ignore = false; - event->ignore(); - if(self.window.onClose) self.window.onClose(); - if(self.window.state.ignore == false) hide(); -} - -void pWindow::QtWindow::moveEvent(QMoveEvent *event) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.x += event->pos().x() - event->oldPos().x(); - self.window.state.geometry.y += event->pos().y() - event->oldPos().y(); - } - - if(self.locked == false) { - if(self.window.onMove) self.window.onMove(); - } -} - -void pWindow::QtWindow::keyPressEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym); -} - -void pWindow::QtWindow::keyReleaseEvent(QKeyEvent *event) { - Keyboard::Keycode sym = Keysym(event->nativeVirtualKey()); - if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym); -} - -void pWindow::QtWindow::resizeEvent(QResizeEvent*) { - if(self.locked == false && self.window.state.fullScreen == false && self.qtWindow->isVisible() == true) { - self.window.state.geometry.width = self.qtContainer->geometry().width(); - self.window.state.geometry.height = self.qtContainer->geometry().height(); - } - - for(auto &layout : self.window.state.layout) { - Geometry geometry = self.geometry(); - geometry.x = geometry.y = 0; - layout.setGeometry(geometry); - } - - if(self.locked == false) { - if(self.window.onSize) self.window.onSize(); - } -} - -QSize pWindow::QtWindow::sizeHint() const { - unsigned width = self.window.state.geometry.width; - unsigned height = self.window.state.geometry.height; - if(self.window.state.menuVisible) height += settings->menuGeometryHeight; - if(self.window.state.statusVisible) height += settings->statusGeometryHeight; - return QSize(width, height); -} diff --git a/purify/phoenix/reference/action/action.cpp b/purify/phoenix/reference/action/action.cpp deleted file mode 100644 index 0bc6bc3f..00000000 --- a/purify/phoenix/reference/action/action.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pAction::setEnabled(bool enabled) { -} - -void pAction::setVisible(bool visible) { -} - -void pAction::constructor() { -} diff --git a/purify/phoenix/reference/action/check-item.cpp b/purify/phoenix/reference/action/check-item.cpp deleted file mode 100644 index 26970fc8..00000000 --- a/purify/phoenix/reference/action/check-item.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pCheckItem::checked() { - return false; -} - -void pCheckItem::setChecked(bool checked) { -} - -void pCheckItem::setText(const string &text) { -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { -} diff --git a/purify/phoenix/reference/action/item.cpp b/purify/phoenix/reference/action/item.cpp deleted file mode 100644 index 438ed32f..00000000 --- a/purify/phoenix/reference/action/item.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pItem::setImage(const image &image) { -} - -void pItem::setText(const string &text) { -} - -void pItem::constructor() { -} - -void pItem::destructor() { -} diff --git a/purify/phoenix/reference/action/menu.cpp b/purify/phoenix/reference/action/menu.cpp deleted file mode 100644 index 4f0a65a8..00000000 --- a/purify/phoenix/reference/action/menu.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pMenu::append(Action &action) { -} - -void pMenu::remove(Action &action) { -} - -void pMenu::setImage(const image &image) { -} - -void pMenu::setText(const string &text) { -} - -void pMenu::constructor() { -} - -void pMenu::destructor() { -} diff --git a/purify/phoenix/reference/action/radio-item.cpp b/purify/phoenix/reference/action/radio-item.cpp deleted file mode 100644 index e87a4deb..00000000 --- a/purify/phoenix/reference/action/radio-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pRadioItem::checked() { - return false; -} - -void pRadioItem::setChecked() { -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { -} diff --git a/purify/phoenix/reference/action/separator.cpp b/purify/phoenix/reference/action/separator.cpp deleted file mode 100644 index 24a45c04..00000000 --- a/purify/phoenix/reference/action/separator.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { -} diff --git a/purify/phoenix/reference/desktop.cpp b/purify/phoenix/reference/desktop.cpp deleted file mode 100644 index a96eb1f0..00000000 --- a/purify/phoenix/reference/desktop.cpp +++ /dev/null @@ -1,8 +0,0 @@ -Size pDesktop::size() { - return { 0, 0 }; -} - -Geometry pDesktop::workspace() { - return { 0, 0, 0, 0 }; -} - diff --git a/purify/phoenix/reference/dialog-window.cpp b/purify/phoenix/reference/dialog-window.cpp deleted file mode 100644 index c7d089ae..00000000 --- a/purify/phoenix/reference/dialog-window.cpp +++ /dev/null @@ -1,11 +0,0 @@ -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return ""; -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - return ""; -} diff --git a/purify/phoenix/reference/font.cpp b/purify/phoenix/reference/font.cpp deleted file mode 100644 index bfda5c06..00000000 --- a/purify/phoenix/reference/font.cpp +++ /dev/null @@ -1,3 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - return { 0, 0, 0, 0 }; -} diff --git a/purify/phoenix/reference/keyboard.cpp b/purify/phoenix/reference/keyboard.cpp deleted file mode 100644 index 40b3a1a7..00000000 --- a/purify/phoenix/reference/keyboard.cpp +++ /dev/null @@ -1,10 +0,0 @@ -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return false; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - return output; -} diff --git a/purify/phoenix/reference/message-window.cpp b/purify/phoenix/reference/message-window.cpp deleted file mode 100644 index 84a287f5..00000000 --- a/purify/phoenix/reference/message-window.cpp +++ /dev/null @@ -1,15 +0,0 @@ -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - return MessageWindow::Response::Ok; -} diff --git a/purify/phoenix/reference/mouse.cpp b/purify/phoenix/reference/mouse.cpp deleted file mode 100644 index f103a15a..00000000 --- a/purify/phoenix/reference/mouse.cpp +++ /dev/null @@ -1,7 +0,0 @@ -Position pMouse::position() { - return { 0, 0 }; -} - -bool pMouse::pressed(Mouse::Button button) { - return false; -} diff --git a/purify/phoenix/reference/platform.cpp b/purify/phoenix/reference/platform.cpp deleted file mode 100644 index e64f7eab..00000000 --- a/purify/phoenix/reference/platform.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "platform.hpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -void pOS::main() { -} - -bool pOS::pendingEvents() { - return false; -} - -void pOS::processEvents() { -} - -void pOS::quit() { -} - -void pOS::initialize() { -} diff --git a/purify/phoenix/reference/platform.hpp b/purify/phoenix/reference/platform.hpp deleted file mode 100644 index cd9e4152..00000000 --- a/purify/phoenix/reference/platform.hpp +++ /dev/null @@ -1,384 +0,0 @@ -struct pFont; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -struct pFont { - static Geometry geometry(const string &description, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - Object &object; - bool locked; - - pObject(Object &object) : object(object), locked(locked) {} - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - Window &window; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); -}; - -struct pAction : public pObject { - Action &action; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu) {} - void constructor(); - void destructor(); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item) {} - void constructor(); - void destructor(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - - bool enabled(); - bool focused(); - Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) {} - void constructor(); -}; - -struct pButton : public pWidget { - Button &button; - - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button) {} - void constructor(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); -}; - -struct pLabel : public pWidget { - Label &label; - - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); -}; - -struct pListView : public pWidget { - ListView &listView; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView) {} - void constructor(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); -}; diff --git a/purify/phoenix/reference/timer.cpp b/purify/phoenix/reference/timer.cpp deleted file mode 100644 index 6cbe571a..00000000 --- a/purify/phoenix/reference/timer.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pTimer::setEnabled(bool enabled) { -} - -void pTimer::setInterval(unsigned milliseconds) { -} - -void pTimer::constructor() { -} diff --git a/purify/phoenix/reference/widget/button.cpp b/purify/phoenix/reference/widget/button.cpp deleted file mode 100644 index fc06c371..00000000 --- a/purify/phoenix/reference/widget/button.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pButton::setImage(const image &image, Orientation orientation) { -} - -void pButton::setText(const string &text) { -} - -void pButton::constructor() { -} diff --git a/purify/phoenix/reference/widget/canvas.cpp b/purify/phoenix/reference/widget/canvas.cpp deleted file mode 100644 index 953cfa77..00000000 --- a/purify/phoenix/reference/widget/canvas.cpp +++ /dev/null @@ -1,8 +0,0 @@ -void pCanvas::setSize(const Size &size) { -} - -void pCanvas::update() { -} - -void pCanvas::constructor() { -} diff --git a/purify/phoenix/reference/widget/check-box.cpp b/purify/phoenix/reference/widget/check-box.cpp deleted file mode 100644 index c5aec216..00000000 --- a/purify/phoenix/reference/widget/check-box.cpp +++ /dev/null @@ -1,12 +0,0 @@ -bool pCheckBox::checked() { - return false; -} - -void pCheckBox::setChecked(bool checked) { -} - -void pCheckBox::setText(const string &text) { -} - -void pCheckBox::constructor() { -} diff --git a/purify/phoenix/reference/widget/combo-box.cpp b/purify/phoenix/reference/widget/combo-box.cpp deleted file mode 100644 index 297d7369..00000000 --- a/purify/phoenix/reference/widget/combo-box.cpp +++ /dev/null @@ -1,21 +0,0 @@ -void pComboBox::append(const string &text) { -} - -void pComboBox::modify(unsigned row, const string &text) { -} - -void pComboBox::remove(unsigned row) { -} - -void pComboBox::reset() { -} - -unsigned pComboBox::selection() { - return 0; -} - -void pComboBox::setSelection(unsigned row) { -} - -void pComboBox::constructor() { -} diff --git a/purify/phoenix/reference/widget/hex-edit.cpp b/purify/phoenix/reference/widget/hex-edit.cpp deleted file mode 100644 index 40bf9f5d..00000000 --- a/purify/phoenix/reference/widget/hex-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pHexEdit::setColumns(unsigned columns) { -} - -void pHexEdit::setLength(unsigned length) { -} - -void pHexEdit::setOffset(unsigned offset) { -} - -void pHexEdit::setRows(unsigned rows) { -} - -void pHexEdit::update() { -} - -void pHexEdit::constructor() { -} diff --git a/purify/phoenix/reference/widget/horizontal-scroll-bar.cpp b/purify/phoenix/reference/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 352b3393..00000000 --- a/purify/phoenix/reference/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalScrollBar::position() { - return 0; -} - -void pHorizontalScrollBar::setLength(unsigned length) { -} - -void pHorizontalScrollBar::setPosition(unsigned position) { -} - -void pHorizontalScrollBar::constructor() { -} diff --git a/purify/phoenix/reference/widget/horizontal-slider.cpp b/purify/phoenix/reference/widget/horizontal-slider.cpp deleted file mode 100644 index 0a4a8392..00000000 --- a/purify/phoenix/reference/widget/horizontal-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pHorizontalSlider::position() { - return 0; -} - -void pHorizontalSlider::setLength(unsigned length) { -} - -void pHorizontalSlider::setPosition(unsigned position) { -} - -void pHorizontalSlider::constructor() { -} diff --git a/purify/phoenix/reference/widget/label.cpp b/purify/phoenix/reference/widget/label.cpp deleted file mode 100644 index 25600d2a..00000000 --- a/purify/phoenix/reference/widget/label.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pLabel::setText(const string &text) { -} - -void pLabel::constructor() { -} diff --git a/purify/phoenix/reference/widget/line-edit.cpp b/purify/phoenix/reference/widget/line-edit.cpp deleted file mode 100644 index 96b9ac6c..00000000 --- a/purify/phoenix/reference/widget/line-edit.cpp +++ /dev/null @@ -1,11 +0,0 @@ -void pLineEdit::setEditable(bool editable) { -} - -void pLineEdit::setText(const string &text) { -} - -string pLineEdit::text() { -} - -void pLineEdit::constructor() { -} diff --git a/purify/phoenix/reference/widget/list-view.cpp b/purify/phoenix/reference/widget/list-view.cpp deleted file mode 100644 index 6e90e0a3..00000000 --- a/purify/phoenix/reference/widget/list-view.cpp +++ /dev/null @@ -1,49 +0,0 @@ -void pListView::append(const lstring &text) { -} - -void pListView::autoSizeColumns() { -} - -bool pListView::checked(unsigned row) { -} - -void pListView::modify(unsigned row, const lstring &text) { -} - -void pListView::remove(unsigned row) { -} - -void pListView::reset() { -} - -bool pListView::selected() { - return false; -} - -unsigned pListView::selection() { - return 0; -} - -void pListView::setCheckable(bool checkable) { -} - -void pListView::setChecked(unsigned row, bool checked) { -} - -void pListView::setHeaderText(const lstring &text) { -} - -void pListView::setHeaderVisible(bool visible) { -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { -} - -void pListView::setSelected(bool selected) { -} - -void pListView::setSelection(unsigned row) { -} - -void pListView::constructor() { -} diff --git a/purify/phoenix/reference/widget/progress-bar.cpp b/purify/phoenix/reference/widget/progress-bar.cpp deleted file mode 100644 index b4905a85..00000000 --- a/purify/phoenix/reference/widget/progress-bar.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pProgressBar::setPosition(unsigned position) { -} - -void pProgressBar::constructor() { -} diff --git a/purify/phoenix/reference/widget/radio-box.cpp b/purify/phoenix/reference/widget/radio-box.cpp deleted file mode 100644 index f6aebcbe..00000000 --- a/purify/phoenix/reference/widget/radio-box.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pRadioBox::checked() { - return false; -} - -void pRadioBox::setChecked() { -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { -} - -void pRadioBox::constructor() { -} diff --git a/purify/phoenix/reference/widget/text-edit.cpp b/purify/phoenix/reference/widget/text-edit.cpp deleted file mode 100644 index 74121b2d..00000000 --- a/purify/phoenix/reference/widget/text-edit.cpp +++ /dev/null @@ -1,17 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { -} - -void pTextEdit::setEditable(bool editable) { -} - -void pTextEdit::setText(const string &text) { -} - -void pTextEdit::setWordWrap(bool wordWrap) { -} - -string pTextEdit::text() { -} - -void pTextEdit::constructor() { -} diff --git a/purify/phoenix/reference/widget/vertical-scroll-bar.cpp b/purify/phoenix/reference/widget/vertical-scroll-bar.cpp deleted file mode 100644 index 26795248..00000000 --- a/purify/phoenix/reference/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalScrollBar::position() { - return 0; -} - -void pVerticalScrollBar::setLength(unsigned length) { -} - -void pVerticalScrollBar::setPosition(unsigned position) { -} - -void pVerticalScrollBar::constructor() { -} diff --git a/purify/phoenix/reference/widget/vertical-slider.cpp b/purify/phoenix/reference/widget/vertical-slider.cpp deleted file mode 100644 index a6d8ae00..00000000 --- a/purify/phoenix/reference/widget/vertical-slider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -unsigned pVerticalSlider::position() { - return 0; -} - -void pVerticalSlider::setLength(unsigned length) { -} - -void pVerticalSlider::setPosition(unsigned position) { -} - -void pVerticalSlider::constructor() { -} diff --git a/purify/phoenix/reference/widget/viewport.cpp b/purify/phoenix/reference/widget/viewport.cpp deleted file mode 100644 index 9d398438..00000000 --- a/purify/phoenix/reference/widget/viewport.cpp +++ /dev/null @@ -1,6 +0,0 @@ -uintptr_t pViewport::handle() { - return 0; -} - -void pViewport::constructor() { -} diff --git a/purify/phoenix/reference/widget/widget.cpp b/purify/phoenix/reference/widget/widget.cpp deleted file mode 100644 index d9c86478..00000000 --- a/purify/phoenix/reference/widget/widget.cpp +++ /dev/null @@ -1,29 +0,0 @@ -bool pWidget::enabled() { - return false; -} - -bool pWidget::focused() { - return false; -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { -} - -void pWidget::setFocused() { -} - -void pWidget::setFont(const string &font) { -} - -void pWidget::setGeometry(const Geometry &geometry) { -} - -void pWidget::setVisible(bool visible) { -} - -void pWidget::constructor() { -} diff --git a/purify/phoenix/reference/window.cpp b/purify/phoenix/reference/window.cpp deleted file mode 100644 index aca2cc2d..00000000 --- a/purify/phoenix/reference/window.cpp +++ /dev/null @@ -1,84 +0,0 @@ -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { -} - -void pWindow::append(Menu &menu) { -} - -void pWindow::append(Widget &widget) { -} - -Color pWindow::backgroundColor() { - return {0, 0, 0, 255}; -} - -bool pWindow::focused() { - return false; -} - -Geometry pWindow::frameMargin() { - return {0, 0, 0, 0}; -} - -Geometry pWindow::geometry() { - return {0, 0, 0, 0}; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { -} - -void pWindow::remove(Widget &widget) { -} - -void pWindow::setBackgroundColor(const Color &color) { -} - -void pWindow::setFocused() { -} - -void pWindow::setFullScreen(bool fullScreen) { -} - -void pWindow::setGeometry(const Geometry &geometry) { -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { -} - -void pWindow::setModal(bool modal) { -} - -void pWindow::setResizable(bool resizable) { -} - -void pWindow::setStatusFont(const string &font) { -} - -void pWindow::setStatusText(const string &text) { -} - -void pWindow::setStatusVisible(bool visible) { -} - -void pWindow::setTitle(const string &text) { -} - -void pWindow::setVisible(bool visible) { -} - -void pWindow::setWidgetFont(const string &font) { -} - -void pWindow::constructor() { -} diff --git a/purify/phoenix/sync.sh b/purify/phoenix/sync.sh deleted file mode 100644 index 40ee3d98..00000000 --- a/purify/phoenix/sync.sh +++ /dev/null @@ -1,9 +0,0 @@ -synchronize() { - if [ -d ../"$1" ]; then - test -d "$1" && rm -r "$1" - cp -r ../"$1" ./"$1" - fi -} - -synchronize "nall" -rm -r nall/test diff --git a/purify/phoenix/windows/action/action.cpp b/purify/phoenix/windows/action/action.cpp deleted file mode 100644 index b80208d1..00000000 --- a/purify/phoenix/windows/action/action.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pAction::setEnabled(bool enabled) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::setVisible(bool visible) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pAction::constructor() { - parentMenu = 0; - parentWindow = 0; -} diff --git a/purify/phoenix/windows/action/check-item.cpp b/purify/phoenix/windows/action/check-item.cpp deleted file mode 100644 index 195deabd..00000000 --- a/purify/phoenix/windows/action/check-item.cpp +++ /dev/null @@ -1,18 +0,0 @@ -bool pCheckItem::checked() { - return checkItem.state.checked; -} - -void pCheckItem::setChecked(bool checked) { - if(parentMenu) CheckMenuItem(parentMenu->p.hmenu, id, checked ? MF_CHECKED : MF_UNCHECKED); -} - -void pCheckItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pCheckItem::constructor() { -} - -void pCheckItem::destructor() { - if(parentMenu) parentMenu->remove(checkItem); -} diff --git a/purify/phoenix/windows/action/item.cpp b/purify/phoenix/windows/action/item.cpp deleted file mode 100644 index 2804bfcb..00000000 --- a/purify/phoenix/windows/action/item.cpp +++ /dev/null @@ -1,29 +0,0 @@ -void pItem::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pItem::constructor() { - createBitmap(); -} - -void pItem::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) parentMenu->remove(item); -} - -void pItem::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(item.state.image.width && item.state.image.height) { - nall::image nallImage = item.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} diff --git a/purify/phoenix/windows/action/menu.cpp b/purify/phoenix/windows/action/menu.cpp deleted file mode 100644 index 5d9da04e..00000000 --- a/purify/phoenix/windows/action/menu.cpp +++ /dev/null @@ -1,109 +0,0 @@ -void pMenu::append(Action &action) { - action.p.parentMenu = &menu; - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::remove(Action &action) { - if(parentWindow) parentWindow->p.updateMenu(); - action.p.parentMenu = 0; -} - -void pMenu::setImage(const image &image) { - createBitmap(); - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenu::constructor() { - hmenu = 0; - createBitmap(); -} - -void pMenu::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(parentMenu) { - parentMenu->remove(menu); - } else if(parentWindow) { - //belongs to window's main menubar - parentWindow->remove(menu); - } -} - -void pMenu::createBitmap() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - - if(menu.state.image.width && menu.state.image.height) { - nall::image nallImage = menu.state.image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - nallImage.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline) - nallImage.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear); - hbitmap = CreateBitmap(nallImage); - } -} - -//Windows actions lack the ability to toggle visibility. -//To support this, menus must be destroyed and recreated when toggling any action's visibility. -void pMenu::update(Window &parentWindow, Menu *parentMenu) { - this->parentMenu = parentMenu; - this->parentWindow = &parentWindow; - - if(hmenu) DestroyMenu(hmenu); - hmenu = CreatePopupMenu(); - - for(auto &action : menu.state.action) { - action.p.parentMenu = &menu; - action.p.parentWindow = &parentWindow; - - unsigned enabled = action.state.enabled ? 0 : MF_GRAYED; - if(dynamic_cast(&action)) { - Menu &item = (Menu&)action; - if(action.state.visible) { - item.p.update(parentWindow, &menu); - AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, (UINT_PTR)item.p.hmenu, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - Separator &item = (Separator&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L""); - } - } else if(dynamic_cast(&action)) { - Item &item = (Item&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - - if(item.state.image.width && item.state.image.height) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - //Windows XP and below displays MIIM_BITMAP + hbmpItem in its own column (separate from check/radio marks) - //this causes too much spacing, so use a custom checkmark image instead - mii.fMask = MIIM_CHECKMARKS; - mii.hbmpUnchecked = item.p.hbitmap; - SetMenuItemInfo(hmenu, item.p.id, FALSE, &mii); - } - } - } else if(dynamic_cast(&action)) { - CheckItem &item = (CheckItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } else if(dynamic_cast(&action)) { - RadioItem &item = (RadioItem&)action; - if(action.state.visible) { - AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } - if(item.state.checked) item.setChecked(); - } - } -} diff --git a/purify/phoenix/windows/action/radio-item.cpp b/purify/phoenix/windows/action/radio-item.cpp deleted file mode 100644 index 6b4f3a31..00000000 --- a/purify/phoenix/windows/action/radio-item.cpp +++ /dev/null @@ -1,26 +0,0 @@ -bool pRadioItem::checked() { - return radioItem.state.checked; -} - -void pRadioItem::setChecked() { - for(auto &item : radioItem.state.group) { - //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi - //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) - //to check id, we use: lo == hi == id (only ID, but in range) - if(item.p.parentMenu) CheckMenuRadioItem(item.p.parentMenu->p.hmenu, item.p.id, item.p.id, item.p.id + (id != item.p.id), MF_BYCOMMAND); - } -} - -void pRadioItem::setGroup(const set &group) { -} - -void pRadioItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pRadioItem::constructor() { -} - -void pRadioItem::destructor() { - if(parentMenu) parentMenu->remove(radioItem); -} diff --git a/purify/phoenix/windows/action/separator.cpp b/purify/phoenix/windows/action/separator.cpp deleted file mode 100644 index fac38eca..00000000 --- a/purify/phoenix/windows/action/separator.cpp +++ /dev/null @@ -1,6 +0,0 @@ -void pSeparator::constructor() { -} - -void pSeparator::destructor() { - if(parentMenu) parentMenu->remove(separator); -} diff --git a/purify/phoenix/windows/desktop.cpp b/purify/phoenix/windows/desktop.cpp deleted file mode 100644 index 956ba521..00000000 --- a/purify/phoenix/windows/desktop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -Size pDesktop::size() { - return { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) }; -} - -Geometry pDesktop::workspace() { - RECT rc; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top }; -} diff --git a/purify/phoenix/windows/dialog-window.cpp b/purify/phoenix/windows/dialog-window.cpp deleted file mode 100644 index 5ef21153..00000000 --- a/purify/phoenix/windows/dialog-window.cpp +++ /dev/null @@ -1,98 +0,0 @@ -static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { - string dir = path; - dir.replace("/", "\\"); - - string filterList; - for(auto &filterItem : filter) { - lstring part; - part.split("(", filterItem); - if(part.size() != 2) continue; - part[1].rtrim<1>(")"); - part[1].replace(" ", ""); - part[1].transform(",", ";"); - filterList.append(string(filterItem, "\t", part[1], "\t")); - } - - utf16_t wfilter(filterList); - utf16_t wdir(dir); - wchar_t wfilename[PATH_MAX + 1] = L""; - - wchar_t *p = wfilter; - while(*p != L'\0') { - if(*p == L'\t') *p = L'\0'; - p++; - } - - if(path.empty() == false) { - //clear COMDLG32 MRU (most recently used) file list - //this is required in order for lpstrInitialDir to be honored in Windows 7 and above - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/LastVisitedPidlMRU/"); - registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/OpenSavePidlMRU/"); - } - - OPENFILENAME ofn; - memset(&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - ofn.lpstrFilter = wfilter; - ofn.lpstrInitialDir = wdir; - ofn.lpstrFile = wfilename; - ofn.nMaxFile = PATH_MAX; - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - ofn.lpstrDefExt = L""; - - bool result = (save == false ? GetOpenFileName(&ofn) : GetSaveFileName(&ofn)); - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - name.transform("\\", "/"); - return name; -} - -string pDialogWindow::fileOpen(Window &parent, const string &path, const lstring &filter) { - return FileDialog(false, parent, path, filter); -} - -string pDialogWindow::fileSave(Window &parent, const string &path, const lstring &filter) { - return FileDialog(true, parent, path, filter); -} - -static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpdata) { - if(msg == BFFM_INITIALIZED) { - if(lpdata) SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpdata); - } - - return 0; -} - -string pDialogWindow::folderSelect(Window &parent, const string &path) { - wchar_t wfilename[PATH_MAX + 1] = L""; - utf16_t wpath(string{path}.transform("/", "\\")); - - BROWSEINFO bi; - bi.hwndOwner = &parent != &Window::none() ? parent.p.hwnd : 0; - bi.pidlRoot = NULL; - bi.pszDisplayName = wfilename; - bi.lpszTitle = L""; - bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS; - bi.lpfn = BrowseCallbackProc; - bi.lParam = (LPARAM)(wchar_t*)wpath; - bi.iImage = 0; - bool result = false; - LPITEMIDLIST pidl = SHBrowseForFolder(&bi); - if(pidl) { - if(SHGetPathFromIDList(pidl, wfilename)) { - result = true; - IMalloc *imalloc = 0; - if(SUCCEEDED(SHGetMalloc(&imalloc))) { - imalloc->Free(pidl); - imalloc->Release(); - } - } - } - if(result == false) return ""; - string name = (const char*)utf8_t(wfilename); - if(name == "") return ""; - name.transform("\\", "/"); - if(name.endswith("/") == false) name.append("/"); - return name; -} \ No newline at end of file diff --git a/purify/phoenix/windows/font.cpp b/purify/phoenix/windows/font.cpp deleted file mode 100644 index de42f24d..00000000 --- a/purify/phoenix/windows/font.cpp +++ /dev/null @@ -1,44 +0,0 @@ -Geometry pFont::geometry(const string &description, const string &text) { - HFONT hfont = pFont::create(description); - Geometry geometry = pFont::geometry(hfont, text); - pFont::free(hfont); - return geometry; -} - -HFONT pFont::create(const string &description) { - lstring part; - part.split(",", description); - for(auto &item : part) item.trim(" "); - - string family = "Sans"; - unsigned size = 8u; - bool bold = false; - bool italic = false; - - if(part[0] != "") family = part[0]; - if(part.size() >= 2) size = decimal(part[1]); - if(part.size() >= 3) bold = part[2].position("Bold"); - if(part.size() >= 3) italic = part[2].position("Italic"); - - return CreateFont( - -(size * 96.0 / 72.0 + 0.5), - 0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, 0, 0, 0, 0, 0, 0, 0, - utf16_t(family) - ); -} - -void pFont::free(HFONT hfont) { - DeleteObject(hfont); -} - -Geometry pFont::geometry(HFONT hfont, const string &text_) { - //temporary fix: empty text string returns height of zero; bad for eg Button height - string text = (text_ == "" ? " " : text_); - - HDC hdc = GetDC(0); - SelectObject(hdc, hfont); - RECT rc = { 0, 0, 0, 0 }; - DrawText(hdc, utf16_t(text), -1, &rc, DT_CALCRECT); - ReleaseDC(0, hdc); - return { 0, 0, rc.right, rc.bottom }; -} diff --git a/purify/phoenix/windows/keyboard.cpp b/purify/phoenix/windows/keyboard.cpp deleted file mode 100644 index 1edffcb3..00000000 --- a/purify/phoenix/windows/keyboard.cpp +++ /dev/null @@ -1,137 +0,0 @@ -void pKeyboard::initialize() { - auto append = [](Keyboard::Scancode scancode, unsigned keysym) { - settings->keymap.insert(scancode, keysym); - }; - - append(Keyboard::Scancode::Escape, VK_ESCAPE); - append(Keyboard::Scancode::F1, VK_F1); - append(Keyboard::Scancode::F2, VK_F2); - append(Keyboard::Scancode::F3, VK_F3); - append(Keyboard::Scancode::F4, VK_F4); - append(Keyboard::Scancode::F5, VK_F5); - append(Keyboard::Scancode::F6, VK_F6); - append(Keyboard::Scancode::F7, VK_F7); - append(Keyboard::Scancode::F8, VK_F8); - append(Keyboard::Scancode::F9, VK_F9); - append(Keyboard::Scancode::F10, VK_F10); - append(Keyboard::Scancode::F11, VK_F11); - append(Keyboard::Scancode::F12, VK_F12); - - append(Keyboard::Scancode::PrintScreen, VK_SNAPSHOT); - append(Keyboard::Scancode::ScrollLock, VK_SCROLL); - append(Keyboard::Scancode::Pause, VK_PAUSE); - - append(Keyboard::Scancode::Insert, VK_INSERT); - append(Keyboard::Scancode::Delete, VK_DELETE); - append(Keyboard::Scancode::Home, VK_HOME); - append(Keyboard::Scancode::End, VK_END); - append(Keyboard::Scancode::PageUp, VK_PRIOR); - append(Keyboard::Scancode::PageDown, VK_NEXT); - - append(Keyboard::Scancode::Up, VK_UP); - append(Keyboard::Scancode::Down, VK_DOWN); - append(Keyboard::Scancode::Left, VK_LEFT); - append(Keyboard::Scancode::Right, VK_RIGHT); - - append(Keyboard::Scancode::Grave, VK_OEM_3); - append(Keyboard::Scancode::Number1, '1'); - append(Keyboard::Scancode::Number2, '2'); - append(Keyboard::Scancode::Number3, '3'); - append(Keyboard::Scancode::Number4, '4'); - append(Keyboard::Scancode::Number5, '5'); - append(Keyboard::Scancode::Number6, '6'); - append(Keyboard::Scancode::Number7, '7'); - append(Keyboard::Scancode::Number8, '8'); - append(Keyboard::Scancode::Number9, '9'); - append(Keyboard::Scancode::Number0, '0'); - append(Keyboard::Scancode::Minus, VK_OEM_MINUS); - append(Keyboard::Scancode::Equal, VK_OEM_PLUS); - append(Keyboard::Scancode::Backspace, VK_BACK); - - append(Keyboard::Scancode::BracketLeft, VK_OEM_4); - append(Keyboard::Scancode::BracketRight, VK_OEM_6); - append(Keyboard::Scancode::Backslash, VK_OEM_5); - append(Keyboard::Scancode::Semicolon, VK_OEM_1); - append(Keyboard::Scancode::Apostrophe, VK_OEM_7); - append(Keyboard::Scancode::Comma, VK_OEM_COMMA); - append(Keyboard::Scancode::Period, VK_OEM_PERIOD); - append(Keyboard::Scancode::Slash, VK_OEM_2); - - append(Keyboard::Scancode::Tab, VK_TAB); - append(Keyboard::Scancode::CapsLock, VK_CAPITAL); - append(Keyboard::Scancode::Return, VK_RETURN); - append(Keyboard::Scancode::ShiftLeft, VK_LSHIFT); - append(Keyboard::Scancode::ShiftRight, VK_RSHIFT); - append(Keyboard::Scancode::ControlLeft, VK_LCONTROL); - append(Keyboard::Scancode::ControlRight, VK_RCONTROL); - append(Keyboard::Scancode::SuperLeft, VK_LWIN); - append(Keyboard::Scancode::SuperRight, VK_RWIN); - append(Keyboard::Scancode::AltLeft, VK_LMENU); - append(Keyboard::Scancode::AltRight, VK_RMENU); - append(Keyboard::Scancode::Space, VK_SPACE); - append(Keyboard::Scancode::Menu, VK_APPS); - - append(Keyboard::Scancode::A, 'A'); - append(Keyboard::Scancode::B, 'B'); - append(Keyboard::Scancode::C, 'C'); - append(Keyboard::Scancode::D, 'D'); - append(Keyboard::Scancode::E, 'E'); - append(Keyboard::Scancode::F, 'F'); - append(Keyboard::Scancode::G, 'G'); - append(Keyboard::Scancode::H, 'H'); - append(Keyboard::Scancode::I, 'I'); - append(Keyboard::Scancode::J, 'J'); - append(Keyboard::Scancode::K, 'K'); - append(Keyboard::Scancode::L, 'L'); - append(Keyboard::Scancode::M, 'M'); - append(Keyboard::Scancode::N, 'N'); - append(Keyboard::Scancode::O, 'O'); - append(Keyboard::Scancode::P, 'P'); - append(Keyboard::Scancode::Q, 'Q'); - append(Keyboard::Scancode::R, 'R'); - append(Keyboard::Scancode::S, 'S'); - append(Keyboard::Scancode::T, 'T'); - append(Keyboard::Scancode::U, 'U'); - append(Keyboard::Scancode::V, 'V'); - append(Keyboard::Scancode::W, 'W'); - append(Keyboard::Scancode::X, 'X'); - append(Keyboard::Scancode::Y, 'Y'); - append(Keyboard::Scancode::Z, 'Z'); - - append(Keyboard::Scancode::NumLock, VK_NUMLOCK); - append(Keyboard::Scancode::Divide, VK_DIVIDE); - append(Keyboard::Scancode::Multiply, VK_MULTIPLY); - append(Keyboard::Scancode::Subtract, VK_SUBTRACT); - append(Keyboard::Scancode::Add, VK_ADD); -//append(Keyboard::Scancode::Enter, ...); - append(Keyboard::Scancode::Point, VK_DECIMAL); - - append(Keyboard::Scancode::Keypad1, VK_NUMPAD1); - append(Keyboard::Scancode::Keypad2, VK_NUMPAD2); - append(Keyboard::Scancode::Keypad3, VK_NUMPAD3); - append(Keyboard::Scancode::Keypad4, VK_NUMPAD4); - append(Keyboard::Scancode::Keypad5, VK_NUMPAD5); - append(Keyboard::Scancode::Keypad6, VK_NUMPAD6); - append(Keyboard::Scancode::Keypad7, VK_NUMPAD7); - append(Keyboard::Scancode::Keypad8, VK_NUMPAD8); - append(Keyboard::Scancode::Keypad9, VK_NUMPAD9); - append(Keyboard::Scancode::Keypad0, VK_NUMPAD0); -} - -bool pKeyboard::pressed(Keyboard::Scancode scancode) { - return GetAsyncKeyState(settings->keymap.lhs[scancode]) & 0x8000; -} - -vector pKeyboard::state() { - vector output; - output.resize((unsigned)Keyboard::Scancode::Limit); - for(auto &n : output) n = false; - - for(auto &n : settings->keymap.rhs) { - if(GetAsyncKeyState(n.name) & 0x8000) { - output[(unsigned)n.data] = true; - } - } - - return output; -} diff --git a/purify/phoenix/windows/message-window.cpp b/purify/phoenix/windows/message-window.cpp deleted file mode 100644 index fca126f4..00000000 --- a/purify/phoenix/windows/message-window.cpp +++ /dev/null @@ -1,41 +0,0 @@ -static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons buttons, UINT response) { - if(response == IDOK) return MessageWindow::Response::Ok; - if(response == IDCANCEL) return MessageWindow::Response::Cancel; - if(response == IDYES) return MessageWindow::Response::Yes; - if(response == IDNO) return MessageWindow::Response::No; - if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel; - if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No; - return MessageWindow::Response::Ok; -} - -MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONINFORMATION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONQUESTION; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONWARNING; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} - -MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { - UINT flags = MB_ICONERROR; - if(buttons == MessageWindow::Buttons::Ok) flags |= MB_OK; - if(buttons == MessageWindow::Buttons::OkCancel) flags |= MB_OKCANCEL; - if(buttons == MessageWindow::Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::none() ? parent.p.hwnd : 0, utf16_t(text), L"", flags)); -} diff --git a/purify/phoenix/windows/mouse.cpp b/purify/phoenix/windows/mouse.cpp deleted file mode 100644 index e5004645..00000000 --- a/purify/phoenix/windows/mouse.cpp +++ /dev/null @@ -1,14 +0,0 @@ -Position pMouse::position() { - POINT point = { 0 }; - GetCursorPos(&point); - return { point.x, point.y }; -} - -bool pMouse::pressed(Mouse::Button button) { - switch(button) { - case Mouse::Button::Left: return GetAsyncKeyState(VK_LBUTTON) & 0x8000; - case Mouse::Button::Middle: return GetAsyncKeyState(VK_MBUTTON) & 0x8000; - case Mouse::Button::Right: return GetAsyncKeyState(VK_RBUTTON) & 0x8000; - } - return false; -} \ No newline at end of file diff --git a/purify/phoenix/windows/object.cpp b/purify/phoenix/windows/object.cpp deleted file mode 100644 index 78811d79..00000000 --- a/purify/phoenix/windows/object.cpp +++ /dev/null @@ -1,13 +0,0 @@ -vector pObject::objects; - -pObject::pObject(Object &object) : object(object) { - static unsigned uniqueId = 100; - objects.append(this); - id = uniqueId++; - locked = false; -} - -pObject* pObject::find(unsigned id) { - for(auto &item : objects) if(item->id == id) return item; - return 0; -} diff --git a/purify/phoenix/windows/phoenix.Manifest b/purify/phoenix/windows/phoenix.Manifest deleted file mode 100644 index 45fbb4cd..00000000 --- a/purify/phoenix/windows/phoenix.Manifest +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - true - - - diff --git a/purify/phoenix/windows/phoenix.rc b/purify/phoenix/windows/phoenix.rc deleted file mode 100644 index 89fb8dc2..00000000 --- a/purify/phoenix/windows/phoenix.rc +++ /dev/null @@ -1 +0,0 @@ -1 24 "phoenix.Manifest" diff --git a/purify/phoenix/windows/platform.cpp b/purify/phoenix/windows/platform.cpp deleted file mode 100644 index 1214f2c2..00000000 --- a/purify/phoenix/windows/platform.cpp +++ /dev/null @@ -1,479 +0,0 @@ -#include "platform.hpp" -#include "utility.cpp" -#include "settings.cpp" - -#include "desktop.cpp" -#include "keyboard.cpp" -#include "mouse.cpp" -#include "dialog-window.cpp" -#include "message-window.cpp" - -#include "object.cpp" -#include "font.cpp" -#include "timer.cpp" -#include "window.cpp" - -#include "action/action.cpp" -#include "action/menu.cpp" -#include "action/separator.cpp" -#include "action/item.cpp" -#include "action/check-item.cpp" -#include "action/radio-item.cpp" - -#include "widget/widget.cpp" -#include "widget/button.cpp" -#include "widget/canvas.cpp" -#include "widget/check-box.cpp" -#include "widget/combo-box.cpp" -#include "widget/hex-edit.cpp" -#include "widget/horizontal-scroll-bar.cpp" -#include "widget/horizontal-slider.cpp" -#include "widget/label.cpp" -#include "widget/line-edit.cpp" -#include "widget/list-view.cpp" -#include "widget/progress-bar.cpp" -#include "widget/radio-box.cpp" -#include "widget/text-edit.cpp" -#include "widget/vertical-scroll-bar.cpp" -#include "widget/vertical-slider.cpp" -#include "widget/viewport.cpp" - -static bool OS_keyboardProc(HWND, UINT, WPARAM, LPARAM); -static void OS_processDialogMessage(MSG&); -static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM); - -void pOS::main() { - MSG msg; - while(GetMessage(&msg, 0, 0, 0)) { - OS_processDialogMessage(msg); - } -} - -bool pOS::pendingEvents() { - MSG msg; - return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); -} - -void pOS::processEvents() { - while(pendingEvents()) { - MSG msg; - if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { - OS_processDialogMessage(msg); - } - } -} - -void OS_processDialogMessage(MSG &msg) { - if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP - || msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) { - if(OS_keyboardProc(msg.hwnd, msg.message, msg.wParam, msg.lParam)) { - DispatchMessage(&msg); - return; - } - } - - if(!IsDialogMessage(GetForegroundWindow(), &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -void pOS::quit() { - osQuit = true; - PostQuitMessage(0); -} - -void pOS::initialize() { - CoInitialize(0); - InitCommonControls(); - - WNDCLASS wc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(2)); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = OS_windowProc; - wc.lpszClassName = L"phoenix_window"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Canvas_windowProc; - wc.lpszClassName = L"phoenix_canvas"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Label_windowProc; - wc.lpszClassName = L"phoenix_label"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hInstance = GetModuleHandle(0); - wc.lpfnWndProc = Viewport_windowProc; - wc.lpszClassName = L"phoenix_viewport"; - wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - settings = new Settings; - pKeyboard::initialize(); -} - -static bool OS_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - if(msg != WM_KEYDOWN && msg != WM_SYSKEYDOWN && msg != WM_KEYUP && msg != WM_SYSKEYUP) return false; - - GUITHREADINFO info; - memset(&info, 0, sizeof(GUITHREADINFO)); - info.cbSize = sizeof(GUITHREADINFO); - GetGUIThreadInfo(GetCurrentThreadId(), &info); - Object *object = (Object*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA); - if(object == nullptr) return false; - - if(dynamic_cast(object)) { - Window &window = (Window&)*object; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) return false; - Keyboard::Keycode keysym = Keysym(wparam, lparam); - if(keysym != Keyboard::Keycode::None) { - if((msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) && window.onKeyPress) window.onKeyPress(keysym); - if((msg == WM_KEYUP || msg == WM_SYSKEYUP) && window.onKeyRelease) window.onKeyRelease(keysym); - } - return false; - } - - if(msg == WM_KEYDOWN) { - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - if(wparam == VK_RETURN) { - if(listView.onActivate) listView.onActivate(); - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(wparam == VK_RETURN) { - if(lineEdit.onActivate) lineEdit.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(wparam == 'A' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+A = select all text - //note: this is not a standard accelerator on Windows - Edit_SetSel(textEdit.p.hwnd, 0, ~0); - return true; - } else if(wparam == 'V' && GetKeyState(VK_CONTROL) < 0) { - //Ctrl+V = paste text - //note: this formats Unix (LF) and OS9 (CR) line-endings to Windows (CR+LF) line-endings - //this is necessary as the EDIT control only supports Windows line-endings - OpenClipboard(hwnd); - HANDLE handle = GetClipboardData(CF_UNICODETEXT); - if(handle) { - wchar_t *text = (wchar_t*)GlobalLock(handle); - if(text) { - string data = (const char*)utf8_t(text); - data.replace("\r\n", "\n"); - data.replace("\r", "\n"); - data.replace("\n", "\r\n"); - GlobalUnlock(handle); - utf16_t output(data); - HGLOBAL resource = GlobalAlloc(GMEM_MOVEABLE, (wcslen(output) + 1) * sizeof(wchar_t)); - if(resource) { - wchar_t *write = (wchar_t*)GlobalLock(resource); - if(write) { - wcscpy(write, output); - GlobalUnlock(write); - if(SetClipboardData(CF_UNICODETEXT, resource) == FALSE) { - GlobalFree(resource); - } - } - } - } - } - CloseClipboard(); - return false; - } - } - } - - return false; -} - -static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!object || !dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Window &window = (Window&)*object; - - bool process = true; - if(pWindow::modal.size() > 0 && !pWindow::modal.find(&window.p)) process = false; - if(osQuit) process = false; - - if(process) switch(msg) { - case WM_CLOSE: { - window.state.ignore = false; - if(window.onClose) window.onClose(); - if(window.state.ignore == false) { - window.setVisible(false); - window.setModal(false); - } - return TRUE; - } - - case WM_MOVE: { - if(window.p.locked) break; - - Geometry geometry = window.geometry(); - window.state.geometry.x = geometry.x; - window.state.geometry.y = geometry.y; - - if(window.onMove) window.onMove(); - break; - } - - case WM_SIZE: { - if(window.p.locked) break; - SetWindowPos(window.p.hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - - Geometry geometry = window.geometry(); - window.state.geometry.width = geometry.width; - window.state.geometry.height = geometry.height; - - for(auto &layout : window.state.layout) { - Geometry geom = window.geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - - if(window.onSize) window.onSize(); - break; - } - - case WM_GETMINMAXINFO: { - MINMAXINFO *mmi = (MINMAXINFO*)lparam; - //mmi->ptMinTrackSize.x = 256 + window.p.frameMargin().width; - //mmi->ptMinTrackSize.y = 256 + window.p.frameMargin().height; - //return TRUE; - break; - } - - case WM_ERASEBKGND: { - if(window.p.brush == 0) break; - RECT rc; - GetClientRect(window.p.hwnd, &rc); - PAINTSTRUCT ps; - BeginPaint(window.p.hwnd, &ps); - FillRect(ps.hdc, &rc, window.p.brush); - EndPaint(window.p.hwnd, &ps); - return TRUE; - } - - case WM_CTLCOLORBTN: - case WM_CTLCOLORSTATIC: { - Object *object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - if(object && window.p.brush) { - HDC hdc = (HDC)wparam; - SetBkColor((HDC)wparam, window.p.brushColor); - return (INT_PTR)window.p.brush; - } - break; - } - - case WM_COMMAND: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) { - pObject *object = (pObject*)pObject::find(id); - if(!object) break; - if(dynamic_cast(object)) { - Item &item = ((pItem*)object)->item; - if(item.onActivate) item.onActivate(); - } else if(dynamic_cast(object)) { - CheckItem &checkItem = ((pCheckItem*)object)->checkItem; - checkItem.setChecked(!checkItem.state.checked); - if(checkItem.onToggle) checkItem.onToggle(); - } else if(dynamic_cast(object)) { - RadioItem &radioItem = ((pRadioItem*)object)->radioItem; - if(radioItem.state.checked == false) { - radioItem.setChecked(); - if(radioItem.onActivate) radioItem.onActivate(); - } - } - } else { - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(!object) break; - if(dynamic_cast(object)) { - Button &button = (Button&)*object; - if(button.onActivate) button.onActivate(); - } else if(dynamic_cast(object)) { - CheckBox &checkBox = (CheckBox&)*object; - checkBox.setChecked(!checkBox.state.checked); - if(checkBox.onToggle) checkBox.onToggle(); - } else if(dynamic_cast(object)) { - ComboBox &comboBox = (ComboBox&)*object; - if(HIWORD(wparam) == CBN_SELCHANGE) { - if(comboBox.state.selection != comboBox.selection()) { - comboBox.state.selection = comboBox.selection(); - if(comboBox.onChange) comboBox.onChange(); - } - } - } else if(dynamic_cast(object)) { - LineEdit &lineEdit = (LineEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(lineEdit.p.locked == false && lineEdit.onChange) lineEdit.onChange(); - } - } else if(dynamic_cast(object)) { - RadioBox &radioBox = (RadioBox&)*object; - if(radioBox.state.checked == false) { - radioBox.setChecked(); - if(radioBox.onActivate) radioBox.onActivate(); - } - } else if(dynamic_cast(object)) { - TextEdit &textEdit = (TextEdit&)*object; - if(HIWORD(wparam) == EN_CHANGE) { - if(textEdit.p.locked == false && textEdit.onChange) textEdit.onChange(); - } - } - } - break; - } - - case WM_NOTIFY: { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - Object *object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - if(object == 0) break; - if(dynamic_cast(object)) { - ListView &listView = (ListView&)*object; - LPNMHDR nmhdr = (LPNMHDR)lparam; - LPNMLISTVIEW nmlistview = (LPNMLISTVIEW)lparam; - - if(nmhdr->code == LVN_ITEMCHANGED && (nmlistview->uChanged & LVIF_STATE)) { - unsigned imagemask = ((nmlistview->uNewState & LVIS_STATEIMAGEMASK) >> 12) - 1; - if(imagemask == 0 || imagemask == 1) { - if(listView.p.locked == false && listView.onToggle) listView.onToggle(nmlistview->iItem); - } else if((nmlistview->uOldState & LVIS_FOCUSED) && !(nmlistview->uNewState & LVIS_FOCUSED)) { - listView.p.lostFocus = true; - } else if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) { - listView.p.lostFocus = false; - listView.state.selected = true; - listView.state.selection = listView.selection(); - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } else if(listView.p.lostFocus == false && listView.selected() == false) { - listView.p.lostFocus = false; - listView.state.selected = false; - listView.state.selection = 0; - if(listView.p.locked == false && listView.onChange) listView.onChange(); - } - } else if(nmhdr->code == LVN_ITEMACTIVATE) { - if(listView.onActivate) listView.onActivate(); - } else if(nmhdr->code == NM_CUSTOMDRAW) { - LPNMLVCUSTOMDRAW lvcd = (LPNMLVCUSTOMDRAW)nmhdr; - switch(lvcd->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - return CDRF_NOTIFYITEMDRAW; - case CDDS_ITEMPREPAINT: - if(listView.state.headerText.size() >= 2) { - //draw alternating row colors of there are two or more columns - if(lvcd->nmcd.dwItemSpec % 2) lvcd->clrTextBk = GetSysColor(COLOR_WINDOW) ^ 0x070707; - } - return CDRF_DODEFAULT; - default: - return CDRF_DODEFAULT; - } - } - } - break; - } - - case WM_HSCROLL: - case WM_VSCROLL: { - Object *object = 0; - if(lparam) { - object = (Object*)GetWindowLongPtr((HWND)lparam, GWLP_USERDATA); - } else { - unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.p.hwnd, id); - if(control == 0) break; - object = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); - } - if(object == 0) break; - - if(dynamic_cast(object) - || dynamic_cast(object)) { - SCROLLINFO info; - memset(&info, 0, sizeof(SCROLLINFO)); - info.cbSize = sizeof(SCROLLINFO); - info.fMask = SIF_ALL; - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - switch(LOWORD(wparam)) { - case SB_LEFT: info.nPos = info.nMin; break; - case SB_RIGHT: info.nPos = info.nMax; break; - case SB_LINELEFT: info.nPos--; break; - case SB_LINERIGHT: info.nPos++; break; - case SB_PAGELEFT: info.nPos -= info.nMax >> 3; break; - case SB_PAGERIGHT: info.nPos += info.nMax >> 3; break; - case SB_THUMBTRACK: info.nPos = info.nTrackPos; break; - } - - info.fMask = SIF_POS; - SetScrollInfo((HWND)lparam, SB_CTL, &info, TRUE); - - //Windows may clamp position to scrollbar range - GetScrollInfo((HWND)lparam, SB_CTL, &info); - - if(dynamic_cast(object)) { - HorizontalScrollBar &horizontalScrollBar = (HorizontalScrollBar&)*object; - if(horizontalScrollBar.state.position != info.nPos) { - horizontalScrollBar.state.position = info.nPos; - if(horizontalScrollBar.onChange) horizontalScrollBar.onChange(); - } - } else { - VerticalScrollBar &verticalScrollBar = (VerticalScrollBar&)*object; - if(verticalScrollBar.state.position != info.nPos) { - verticalScrollBar.state.position = info.nPos; - if(verticalScrollBar.onChange) verticalScrollBar.onChange(); - } - } - - return TRUE; - } - - if(dynamic_cast(object)) { - HorizontalSlider &horizontalSlider = (HorizontalSlider&)*object; - if(horizontalSlider.state.position != horizontalSlider.position()) { - horizontalSlider.state.position = horizontalSlider.position(); - if(horizontalSlider.onChange) horizontalSlider.onChange(); - } - } else if(dynamic_cast(object)) { - VerticalSlider &verticalSlider = (VerticalSlider&)*object; - if(verticalSlider.state.position != verticalSlider.position()) { - verticalSlider.state.position = verticalSlider.position(); - if(verticalSlider.onChange) verticalSlider.onChange(); - } - } - - break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/purify/phoenix/windows/platform.hpp b/purify/phoenix/windows/platform.hpp deleted file mode 100644 index d14685b2..00000000 --- a/purify/phoenix/windows/platform.hpp +++ /dev/null @@ -1,484 +0,0 @@ -struct Settings { - bidirectional_map keymap; -}; - -struct pFont; -struct pObject; -struct pWindow; -struct pMenu; -struct pLayout; -struct pWidget; - -static bool osQuit = false; - -struct pFont { - static Geometry geometry(const string &description, const string &text); - - static HFONT create(const string &description); - static void free(HFONT hfont); - static Geometry geometry(HFONT hfont, const string &text); -}; - -struct pDesktop { - static Size size(); - static Geometry workspace(); -}; - -struct pKeyboard { - static bool pressed(Keyboard::Scancode scancode); - static vector state(); - - static void initialize(); -}; - -struct pMouse { - static Position position(); - static bool pressed(Mouse::Button button); -}; - -struct pDialogWindow { - static string fileOpen(Window &parent, const string &path, const lstring &filter); - static string fileSave(Window &parent, const string &path, const lstring &filter); - static string folderSelect(Window &parent, const string &path); -}; - -struct pMessageWindow { - static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons); - static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons); -}; - -struct pObject { - static vector objects; - - Object &object; - uintptr_t id; - bool locked; - - pObject(Object &object); - static pObject* find(unsigned id); - virtual ~pObject() {} - - void constructor() {} - void destructor() {} -}; - -struct pOS : public pObject { - static void main(); - static bool pendingEvents(); - static void processEvents(); - static void quit(); - - static void initialize(); -}; - -struct pTimer : public pObject { - Timer &timer; - UINT_PTR htimer; - - void setEnabled(bool enabled); - void setInterval(unsigned milliseconds); - - pTimer(Timer &timer) : pObject(timer), timer(timer) {} - void constructor(); -}; - -struct pWindow : public pObject { - static vector modal; - static void updateModality(); - - Window &window; - HWND hwnd; - HMENU hmenu; - HWND hstatus; - HFONT hstatusfont; - HBRUSH brush; - COLORREF brushColor; - - static Window& none(); - - void append(Layout &layout); - void append(Menu &menu); - void append(Widget &widget); - Color backgroundColor(); - bool focused(); - Geometry frameMargin(); - Geometry geometry(); - void remove(Layout &layout); - void remove(Menu &menu); - void remove(Widget &widget); - void setBackgroundColor(const Color &color); - void setFocused(); - void setFullScreen(bool fullScreen); - void setGeometry(const Geometry &geometry); - void setMenuFont(const string &font); - void setMenuVisible(bool visible); - void setModal(bool modal); - void setResizable(bool resizable); - void setStatusFont(const string &font); - void setStatusText(const string &text); - void setStatusVisible(bool visible); - void setTitle(const string &text); - void setVisible(bool visible); - void setWidgetFont(const string &font); - - pWindow(Window &window) : pObject(window), window(window) {} - void constructor(); - void destructor(); - void updateMenu(); -}; - -struct pAction : public pObject { - Action &action; - Menu *parentMenu; - Window *parentWindow; - - void setEnabled(bool enabled); - void setVisible(bool visible); - - pAction(Action &action) : pObject(action), action(action) {} - void constructor(); -}; - -struct pMenu : public pAction { - Menu &menu; - HMENU hmenu; - HBITMAP hbitmap; - - void append(Action &action); - void remove(Action &action); - void setImage(const image &image); - void setText(const string &text); - - pMenu(Menu &menu) : pAction(menu), menu(menu), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); - void update(Window &parentWindow, Menu *parentMenu = 0); -}; - -struct pSeparator : public pAction { - Separator &separator; - - pSeparator(Separator &separator) : pAction(separator), separator(separator) {} - void constructor(); - void destructor(); -}; - -struct pItem : public pAction { - Item &item; - HBITMAP hbitmap; - - void setImage(const image &image); - void setText(const string &text); - - pItem(Item &item) : pAction(item), item(item), hbitmap(0) {} - void constructor(); - void destructor(); - void createBitmap(); -}; - -struct pCheckItem : public pAction { - CheckItem &checkItem; - - bool checked(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} - void constructor(); - void destructor(); -}; - -struct pRadioItem : public pAction { - RadioItem &radioItem; - - bool checked(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} - void constructor(); - void destructor(); -}; - -struct pSizable : public pObject { - Sizable &sizable; - - pSizable(Sizable &sizable) : pObject(sizable), sizable(sizable) {} -}; - -struct pLayout : public pSizable { - Layout &layout; - - pLayout(Layout &layout) : pSizable(layout), layout(layout) {} -}; - -struct pWidget : public pSizable { - Widget &widget; - Window *parentWindow; - HWND hwnd; - HFONT hfont; - - bool enabled(); - bool focused(); - virtual Geometry minimumGeometry(); - void setEnabled(bool enabled); - void setFocused(); - void setFont(const string &font); - virtual void setGeometry(const Geometry &geometry); - void setVisible(bool visible); - - pWidget(Widget &widget) : pSizable(widget), widget(widget) { parentWindow = &Window::none(); } - void constructor(); - void destructor(); - virtual void orphan(); - void setDefaultFont(); - void synchronize(); -}; - -struct pButton : public pWidget { - Button &button; - HBITMAP hbitmap; - HIMAGELIST himagelist; - - Geometry minimumGeometry(); - void setImage(const image &image, Orientation orientation); - void setText(const string &text); - - pButton(Button &button) : pWidget(button), button(button), hbitmap(0), himagelist(0) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pCanvas : public pWidget { - Canvas &canvas; - uint32_t *data; - - void setSize(const Size &size); - void update(); - - pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {} - void constructor(); - void destructor(); - void orphan(); - void paint(); -}; - -struct pCheckBox : public pWidget { - CheckBox &checkBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(bool checked); - void setText(const string &text); - - pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pComboBox : public pWidget { - ComboBox &comboBox; - - void append(const string &text); - void modify(unsigned row, const string &text); - void remove(unsigned row); - Geometry minimumGeometry(); - void reset(); - unsigned selection(); - void setSelection(unsigned row); - - pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); -}; - -struct pHexEdit : public pWidget { - HexEdit &hexEdit; - LRESULT CALLBACK (*windowProc)(HWND, UINT, LPARAM, WPARAM); - - void setColumns(unsigned columns); - void setLength(unsigned length); - void setOffset(unsigned offset); - void setRows(unsigned rows); - void update(); - - pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {} - void constructor(); - void destructor(); - void orphan(); - bool keyPress(unsigned key); -}; - -struct pHorizontalScrollBar : public pWidget { - HorizontalScrollBar &horizontalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalScrollBar(HorizontalScrollBar &horizontalScrollBar) : pWidget(horizontalScrollBar), horizontalScrollBar(horizontalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pHorizontalSlider : public pWidget { - HorizontalSlider &horizontalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLabel : public pWidget { - Label &label; - - Geometry minimumGeometry(); - void setText(const string &text); - - pLabel(Label &label) : pWidget(label), label(label) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pLineEdit : public pWidget { - LineEdit &lineEdit; - - Geometry minimumGeometry(); - void setEditable(bool editable); - void setText(const string &text); - string text(); - - pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pListView : public pWidget { - ListView &listView; - HIMAGELIST imageList; - vector> imageMap; - vector images; - bool lostFocus; - - void append(const lstring &text); - void autoSizeColumns(); - bool checked(unsigned row); - void modify(unsigned row, const lstring &text); - void remove(unsigned row); - void reset(); - bool selected(); - unsigned selection(); - void setCheckable(bool checkable); - void setChecked(unsigned row, bool checked); - void setHeaderText(const lstring &text); - void setHeaderVisible(bool visible); - void setImage(unsigned row, unsigned column, const image &image); - void setSelected(bool selected); - void setSelection(unsigned row); - - pListView(ListView &listView) : pWidget(listView), listView(listView), imageList(nullptr) {} - void constructor(); - void destructor(); - void orphan(); - void setGeometry(const Geometry &geometry); - void buildImageList(); -}; - -struct pProgressBar : public pWidget { - ProgressBar &progressBar; - - Geometry minimumGeometry(); - void setPosition(unsigned position); - - pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pRadioBox : public pWidget { - RadioBox &radioBox; - - bool checked(); - Geometry minimumGeometry(); - void setChecked(); - void setGroup(const set &group); - void setText(const string &text); - - pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pTextEdit : public pWidget { - TextEdit &textEdit; - - void setCursorPosition(unsigned position); - void setEditable(bool editable); - void setText(const string &text); - void setWordWrap(bool wordWrap); - string text(); - - pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalScrollBar : public pWidget { - VerticalScrollBar &verticalScrollBar; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalScrollBar(VerticalScrollBar &verticalScrollBar) : pWidget(verticalScrollBar), verticalScrollBar(verticalScrollBar) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pVerticalSlider : public pWidget { - VerticalSlider &verticalSlider; - - Geometry minimumGeometry(); - unsigned position(); - void setLength(unsigned length); - void setPosition(unsigned position); - - pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {} - void constructor(); - void destructor(); - void orphan(); -}; - -struct pViewport : public pWidget { - Viewport &viewport; - - uintptr_t handle(); - - pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {} - void constructor(); - void destructor(); - void orphan(); -}; diff --git a/purify/phoenix/windows/settings.cpp b/purify/phoenix/windows/settings.cpp deleted file mode 100644 index 343fc9fb..00000000 --- a/purify/phoenix/windows/settings.cpp +++ /dev/null @@ -1 +0,0 @@ -static Settings *settings = nullptr; \ No newline at end of file diff --git a/purify/phoenix/windows/timer.cpp b/purify/phoenix/windows/timer.cpp deleted file mode 100644 index 99fb5c00..00000000 --- a/purify/phoenix/windows/timer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -static vector timers; - -static void CALLBACK Timer_timeoutProc(HWND hwnd, UINT msg, UINT_PTR timerID, DWORD time) { - for(auto &timer : timers) { - if(timer->htimer == timerID) { - if(timer->timer.onTimeout) timer->timer.onTimeout(); - return; - } - } -} - -void pTimer::setEnabled(bool enabled) { - if(htimer) { - KillTimer(NULL, htimer); - htimer = 0; - } - - if(enabled == true) { - htimer = SetTimer(NULL, 0U, timer.state.milliseconds, Timer_timeoutProc); - } -} - -void pTimer::setInterval(unsigned milliseconds) { - //destroy and recreate timer if interval changed - setEnabled(timer.state.enabled); -} - -void pTimer::constructor() { - timers.append(this); - htimer = 0; -} diff --git a/purify/phoenix/windows/utility.cpp b/purify/phoenix/windows/utility.cpp deleted file mode 100644 index c247d5cc..00000000 --- a/purify/phoenix/windows/utility.cpp +++ /dev/null @@ -1,150 +0,0 @@ -static const unsigned Windows2000 = 0x0500; -static const unsigned WindowsXP = 0x0501; -static const unsigned WindowsVista = 0x0600; -static const unsigned Windows7 = 0x0601; - -static unsigned OsVersion() { - OSVERSIONINFO versionInfo = { 0 }; - versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&versionInfo); - return (versionInfo.dwMajorVersion << 8) + (versionInfo.dwMajorVersion << 0); -} - -static HBITMAP CreateBitmap(const image &image) { - HDC hdc = GetDC(0); - BITMAPINFO bitmapInfo; - memset(&bitmapInfo, 0, sizeof(BITMAPINFO)); - bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bitmapInfo.bmiHeader.biWidth = image.width; - bitmapInfo.bmiHeader.biHeight = -image.height; //bitmaps are stored upside down unless we negate height - bitmapInfo.bmiHeader.biPlanes = 1; - bitmapInfo.bmiHeader.biBitCount = 32; - bitmapInfo.bmiHeader.biCompression = BI_RGB; - bitmapInfo.bmiHeader.biSizeImage = image.width * image.height * 4; - void *bits = nullptr; - HBITMAP hbitmap = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0); - if(bits) memcpy(bits, image.data, image.width * image.height * 4); - ReleaseDC(0, hdc); - return hbitmap; -} - -static Keyboard::Keycode Keysym(unsigned keysym, unsigned keyflags) { - #define pressed(keysym) (GetAsyncKeyState(keysym) & 0x8000) - #define enabled(keysym) (GetKeyState(keysym)) - #define shifted() (pressed(VK_LSHIFT) || pressed(VK_RSHIFT)) - #define extended() (keyflags & (1 << 24)) - - switch(keysym) { - case VK_ESCAPE: return Keyboard::Keycode::Escape; - case VK_F1: return Keyboard::Keycode::F1; - case VK_F2: return Keyboard::Keycode::F2; - case VK_F3: return Keyboard::Keycode::F3; - case VK_F4: return Keyboard::Keycode::F4; - case VK_F5: return Keyboard::Keycode::F5; - case VK_F6: return Keyboard::Keycode::F6; - case VK_F7: return Keyboard::Keycode::F7; - case VK_F8: return Keyboard::Keycode::F8; - case VK_F9: return Keyboard::Keycode::F9; - //Keyboard::Keycode::F10 (should be captured under VK_MENU from WM_SYSKEY(UP,DOWN); but this is not working...) - case VK_F11: return Keyboard::Keycode::F11; - case VK_F12: return Keyboard::Keycode::F12; - - //Keyboard::Keycode::PrintScreen - //Keyboard::Keycode::SysRq - case VK_SCROLL: return Keyboard::Keycode::ScrollLock; - case VK_PAUSE: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case VK_INSERT: return extended() ? Keyboard::Keycode::Insert : Keyboard::Keycode::KeypadInsert; - case VK_DELETE: return extended() ? Keyboard::Keycode::Delete : Keyboard::Keycode::KeypadDelete; - case VK_HOME: return extended() ? Keyboard::Keycode::Home : Keyboard::Keycode::KeypadHome; - case VK_END: return extended() ? Keyboard::Keycode::End : Keyboard::Keycode::KeypadEnd; - case VK_PRIOR: return extended() ? Keyboard::Keycode::PageUp : Keyboard::Keycode::KeypadPageUp; - case VK_NEXT: return extended() ? Keyboard::Keycode::PageDown : Keyboard::Keycode::KeypadPageDown; - - case VK_UP: return extended() ? Keyboard::Keycode::Up : Keyboard::Keycode::KeypadUp; - case VK_DOWN: return extended() ? Keyboard::Keycode::Down : Keyboard::Keycode::KeypadDown; - case VK_LEFT: return extended() ? Keyboard::Keycode::Left : Keyboard::Keycode::KeypadLeft; - case VK_RIGHT: return extended() ? Keyboard::Keycode::Right : Keyboard::Keycode::KeypadRight; - - case VK_OEM_3: return !shifted() ? Keyboard::Keycode::Grave : Keyboard::Keycode::Tilde; - case '1': return !shifted() ? Keyboard::Keycode::Number1 : Keyboard::Keycode::Exclamation; - case '2': return !shifted() ? Keyboard::Keycode::Number2 : Keyboard::Keycode::At; - case '3': return !shifted() ? Keyboard::Keycode::Number3 : Keyboard::Keycode::Pound; - case '4': return !shifted() ? Keyboard::Keycode::Number4 : Keyboard::Keycode::Dollar; - case '5': return !shifted() ? Keyboard::Keycode::Number5 : Keyboard::Keycode::Percent; - case '6': return !shifted() ? Keyboard::Keycode::Number6 : Keyboard::Keycode::Power; - case '7': return !shifted() ? Keyboard::Keycode::Number7 : Keyboard::Keycode::Ampersand; - case '8': return !shifted() ? Keyboard::Keycode::Number8 : Keyboard::Keycode::Asterisk; - case '9': return !shifted() ? Keyboard::Keycode::Number9 : Keyboard::Keycode::ParenthesisLeft; - case '0': return !shifted() ? Keyboard::Keycode::Number0 : Keyboard::Keycode::ParenthesisRight; - case VK_OEM_MINUS: return !shifted() ? Keyboard::Keycode::Minus : Keyboard::Keycode::Underscore; - case VK_OEM_PLUS: return !shifted() ? Keyboard::Keycode::Equal : Keyboard::Keycode::Plus; - case VK_BACK: return Keyboard::Keycode::Backspace; - - case VK_OEM_4: return !shifted() ? Keyboard::Keycode::BracketLeft : Keyboard::Keycode::BraceLeft; - case VK_OEM_6: return !shifted() ? Keyboard::Keycode::BracketRight : Keyboard::Keycode::BraceRight; - case VK_OEM_5: return !shifted() ? Keyboard::Keycode::Backslash : Keyboard::Keycode::Pipe; - case VK_OEM_1: return !shifted() ? Keyboard::Keycode::Semicolon : Keyboard::Keycode::Colon; - case VK_OEM_7: return !shifted() ? Keyboard::Keycode::Apostrophe : Keyboard::Keycode::Quote; - case VK_OEM_COMMA: return !shifted() ? Keyboard::Keycode::Comma : Keyboard::Keycode::CaretLeft; - case VK_OEM_PERIOD: return !shifted() ? Keyboard::Keycode::Period : Keyboard::Keycode::CaretRight; - case VK_OEM_2: return !shifted() ? Keyboard::Keycode::Slash : Keyboard::Keycode::Question; - - case VK_TAB: return Keyboard::Keycode::Tab; - case VK_CAPITAL: return Keyboard::Keycode::CapsLock; - case VK_RETURN: return !extended() ? Keyboard::Keycode::Return : Keyboard::Keycode::Enter; - case VK_SHIFT: return !pressed(VK_RSHIFT) ? Keyboard::Keycode::ShiftLeft : Keyboard::Keycode::ShiftRight; - case VK_CONTROL: return !pressed(VK_RCONTROL) ? Keyboard::Keycode::ControlLeft : Keyboard::Keycode::ControlRight; - case VK_LWIN: return Keyboard::Keycode::SuperLeft; - case VK_RWIN: return Keyboard::Keycode::SuperRight; - case VK_MENU: - if(keyflags & (1 << 24)) return Keyboard::Keycode::AltRight; - return Keyboard::Keycode::AltLeft; - case VK_SPACE: return Keyboard::Keycode::Space; - case VK_APPS: return Keyboard::Keycode::Menu; - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': - case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': - if(enabled(VK_CAPITAL)) { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } - } else { - if(shifted()) { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::A + keysym - 'A'); - } else { - return (Keyboard::Keycode)((unsigned)Keyboard::Keycode::a + keysym - 'A'); - } - } - break; - - case VK_NUMLOCK: return Keyboard::Keycode::NumLock; - case VK_DIVIDE: return Keyboard::Keycode::Divide; - case VK_MULTIPLY: return Keyboard::Keycode::Multiply; - case VK_SUBTRACT: return Keyboard::Keycode::Subtract; - case VK_ADD: return Keyboard::Keycode::Add; - case VK_DECIMAL: return Keyboard::Keycode::Point; - case VK_NUMPAD1: return Keyboard::Keycode::Keypad1; - case VK_NUMPAD2: return Keyboard::Keycode::Keypad2; - case VK_NUMPAD3: return Keyboard::Keycode::Keypad3; - case VK_NUMPAD4: return Keyboard::Keycode::Keypad4; - case VK_NUMPAD5: return Keyboard::Keycode::Keypad5; - case VK_NUMPAD6: return Keyboard::Keycode::Keypad6; - case VK_NUMPAD7: return Keyboard::Keycode::Keypad7; - case VK_NUMPAD8: return Keyboard::Keycode::Keypad8; - case VK_NUMPAD9: return Keyboard::Keycode::Keypad9; - case VK_NUMPAD0: return Keyboard::Keycode::Keypad0; - - case VK_CLEAR: return Keyboard::Keycode::KeypadCenter; - } - - return Keyboard::Keycode::None; - - #undef pressed - #undef enabled - #undef shifted - #undef extended -} diff --git a/purify/phoenix/windows/widget/button.cpp b/purify/phoenix/windows/widget/button.cpp deleted file mode 100644 index 12cacbe5..00000000 --- a/purify/phoenix/windows/widget/button.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef Button_SetImageList - //MinGW/32-bit has painfully outdated platform headers ... - typedef struct { - HIMAGELIST himl; - RECT margin; - UINT uAlign; - } BUTTON_IMAGELIST, *PBUTTON_IMAGELIST; - - #define BUTTON_IMAGELIST_ALIGN_LEFT 0 - #define BUTTON_IMAGELIST_ALIGN_RIGHT 1 - #define BUTTON_IMAGELIST_ALIGN_TOP 2 - #define BUTTON_IMAGELIST_ALIGN_BOTTOM 3 - #define BUTTON_IMAGELIST_ALIGN_CENTER 4 - - #define BCM_FIRST 0x1600 - #define BCM_SETIMAGELIST (BCM_FIRST+2) - #define Button_SetImageList(hwnd, pbuttonImagelist) (WINBOOL)SNDMSG((hwnd),BCM_SETIMAGELIST,0,(LPARAM)(pbuttonImagelist)) -#endif - -Geometry pButton::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, button.state.text); - - if(button.state.orientation == Orientation::Horizontal) { - geometry.width += button.state.image.width; - geometry.height = max(button.state.image.height, geometry.height); - } - - if(button.state.orientation == Orientation::Vertical) { - geometry.width = max(button.state.image.width, geometry.width); - geometry.height += button.state.image.height; - } - - return { 0, 0, geometry.width + 20, geometry.height + 10 }; -} - -void pButton::setImage(const image &image, Orientation orientation) { - nall::image nallImage = image; - nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - - if(OsVersion() >= WindowsVista) { - hbitmap = CreateBitmap(nallImage); - SendMessage(hwnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmap); - switch(orientation) { - case Orientation::Horizontal: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_TOP); break; - case Orientation::Vertical: SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_TOP); break; - } - } else { - //Windows XP and earlier cannot display bitmaps and text at the same time with BM_SETIMAGE - //Use BCM_SETIMAGELIST instead. It does not support alpha blending, so blend with button color - //The XP theme and above use a gradient fade background, so it won't be a perfect match there - nallImage.alphaBlend(GetSysColor(COLOR_BTNFACE)); - hbitmap = CreateBitmap(nallImage); - himagelist = ImageList_Create(nallImage.width, nallImage.height, ILC_COLOR32, 1, 0); - ImageList_Add(himagelist, hbitmap, NULL); - BUTTON_IMAGELIST list; - list.himl = himagelist; - switch(orientation) { - case Orientation::Horizontal: SetRect(&list.margin, 5, 0, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; break; - case Orientation::Vertical: SetRect(&list.margin, 0, 5, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_TOP; break; - } - Button_SetImageList(hwnd, &list); - } - - setText(button.state.text); //update text to display nicely with image (or lack thereof) -} - -void pButton::setText(const string &text) { - if(text.empty()) { - //bitmaps will not show up if text is empty - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_BITMAP); - } else { - //text will not show up if BS_BITMAP is set - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_BITMAP); - } - - if(OsVersion() >= WindowsVista && button.state.image.empty() == false && text.empty() == false) { - //Vista+ does not add spacing between the icon and text; causing them to run into each other - SetWindowText(hwnd, utf16_t(string{" ", text})); - } else { - SetWindowText(hwnd, utf16_t(text)); - } -} - -void pButton::constructor() { - hwnd = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&button); - setDefaultFont(); - setImage(button.state.image, button.state.orientation); -//setText(button.state.text); //called by setImage(); - synchronize(); -} - -void pButton::destructor() { - if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; } - if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; } - DestroyWindow(hwnd); -} - -void pButton::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/canvas.cpp b/purify/phoenix/windows/widget/canvas.cpp deleted file mode 100644 index f2be9e38..00000000 --- a/purify/phoenix/windows/widget/canvas.cpp +++ /dev/null @@ -1,92 +0,0 @@ -static LRESULT CALLBACK Canvas_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Canvas &canvas = (Canvas&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_PAINT) { - canvas.p.paint(); - return TRUE; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(canvas.onMouseMove) canvas.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(canvas.onMouseLeave) canvas.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(canvas.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: canvas.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: canvas.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: canvas.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(canvas.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: canvas.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: canvas.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: canvas.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -void pCanvas::setSize(const Size &size) { - delete[] data; - data = new uint32_t[size.width * size.height]; -} - -void pCanvas::update() { - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - InvalidateRect(hwnd, 0, false); -} - -void pCanvas::constructor() { - data = new uint32_t[canvas.state.width * canvas.state.height]; - memcpy(data, canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t)); - hwnd = CreateWindow(L"phoenix_canvas", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&canvas); - synchronize(); -} - -void pCanvas::destructor() { - DestroyWindow(hwnd); - delete[] data; -} - -void pCanvas::orphan() { - destructor(); - constructor(); -} - -void pCanvas::paint() { - RECT rc; - GetClientRect(hwnd, &rc); - unsigned width = canvas.state.width, height = canvas.state.height; - - BITMAPINFO bmi; - memset(&bmi, 0, sizeof(BITMAPINFO)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = 32; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biWidth = width; - bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap - bmi.bmiHeader.biSizeImage = sizeof(uint32_t) * width * height; - - PAINTSTRUCT ps; - BeginPaint(hwnd, &ps); - SetDIBitsToDevice(ps.hdc, 0, 0, width, height, 0, 0, 0, height, (void*)data, &bmi, DIB_RGB_COLORS); - EndPaint(hwnd, &ps); -} diff --git a/purify/phoenix/windows/widget/check-box.cpp b/purify/phoenix/windows/widget/check-box.cpp deleted file mode 100644 index 8f0d2eb8..00000000 --- a/purify/phoenix/windows/widget/check-box.cpp +++ /dev/null @@ -1,39 +0,0 @@ -bool pCheckBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pCheckBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, checkBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pCheckBox::setChecked(bool checked) { - SendMessage(hwnd, BM_SETCHECK, (WPARAM)checked, 0); -} - -void pCheckBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pCheckBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_CHECKBOX, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&checkBox); - setDefaultFont(); - if(checkBox.state.checked) setChecked(true); - setText(checkBox.state.text); - synchronize(); - -} - -void pCheckBox::destructor() { - DestroyWindow(hwnd); -} - -void pCheckBox::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/combo-box.cpp b/purify/phoenix/windows/widget/combo-box.cpp deleted file mode 100644 index bff1170d..00000000 --- a/purify/phoenix/windows/widget/combo-box.cpp +++ /dev/null @@ -1,70 +0,0 @@ -void pComboBox::append(const string &text) { - SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(text)); - if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) == 1) setSelection(0); -} - -Geometry pComboBox::minimumGeometry() { - unsigned maximumWidth = 0; - for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(hfont, text).width); - return { 0, 0, maximumWidth + 24, pFont::geometry(hfont, " ").height + 10 }; -} - -void pComboBox::modify(unsigned row, const string &text) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - SendMessage(hwnd, CB_INSERTSTRING, row, (LPARAM)(wchar_t*)utf16_t(text)); - setSelection(position); - locked = false; -} - -void pComboBox::remove(unsigned row) { - locked = true; - unsigned position = selection(); - SendMessage(hwnd, CB_DELETESTRING, row, 0); - if(position == row) setSelection(0); - locked = false; -} - -void pComboBox::reset() { - SendMessage(hwnd, CB_RESETCONTENT, 0, 0); -} - -unsigned pComboBox::selection() { - return SendMessage(hwnd, CB_GETCURSEL, 0, 0); -} - -void pComboBox::setSelection(unsigned row) { - SendMessage(hwnd, CB_SETCURSEL, row, 0); -} - -void pComboBox::constructor() { - hwnd = CreateWindow( - L"COMBOBOX", L"", - WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, - 0, 0, 0, 0, - parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&comboBox); - setDefaultFont(); - for(auto &text : comboBox.state.text) append(text); - setSelection(comboBox.state.selection); - synchronize(); -} - -void pComboBox::destructor() { - DestroyWindow(hwnd); -} - -void pComboBox::orphan() { - destructor(); - constructor(); -} - -void pComboBox::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER); - RECT rc; - GetWindowRect(hwnd, &rc); - unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); - SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); -} diff --git a/purify/phoenix/windows/widget/hex-edit.cpp b/purify/phoenix/windows/widget/hex-edit.cpp deleted file mode 100644 index 789f4faf..00000000 --- a/purify/phoenix/windows/widget/hex-edit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -static LRESULT CALLBACK HexEdit_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - HexEdit &hexEdit = *(HexEdit*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(msg == WM_CHAR) { - if(hexEdit.p.keyPress(wparam)) return 0; - } - return hexEdit.p.windowProc(hwnd, msg, wparam, lparam); -} - -void pHexEdit::setColumns(unsigned columns) { - update(); -} - -void pHexEdit::setLength(unsigned length) { - update(); -} - -void pHexEdit::setOffset(unsigned offset) { - update(); -} - -void pHexEdit::setRows(unsigned rows) { - update(); -} - -void pHexEdit::update() { - if(!hexEdit.onRead) { - SetWindowText(hwnd, L""); - return; - } - - unsigned cursorPosition = Edit_GetSel(hwnd); - - string output; - unsigned offset = hexEdit.state.offset; - for(unsigned row = 0; row < hexEdit.state.rows; row++) { - output.append(hex<8>(offset)); - output.append(" "); - - string hexdata; - string ansidata = " "; - for(unsigned column = 0; column < hexEdit.state.columns; column++) { - if(offset < hexEdit.state.length) { - uint8_t data = hexEdit.onRead(offset++); - hexdata.append(hex<2>(data)); - hexdata.append(" "); - char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 }; - ansidata.append(buffer); - } else { - hexdata.append(" "); - ansidata.append(" "); - } - } - - output.append(hexdata); - output.append(ansidata); - if(offset >= hexEdit.state.length) break; - if(row != hexEdit.state.rows - 1) output.append("\r\n"); - } - - SetWindowText(hwnd, utf16_t(output)); - Edit_SetSel(hwnd, LOWORD(cursorPosition), HIWORD(cursorPosition)); -} - -void pHexEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_READONLY | ES_MULTILINE | ES_WANTRETURN, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&hexEdit); - setDefaultFont(); - update(); - - windowProc = (LRESULT CALLBACK (*)(HWND, UINT, LPARAM, WPARAM))GetWindowLongPtr(hwnd, GWLP_WNDPROC); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)HexEdit_windowProc); - synchronize(); -} - -void pHexEdit::destructor() { - DestroyWindow(hwnd); -} - -void pHexEdit::orphan() { - destructor(); - constructor(); -} - -bool pHexEdit::keyPress(unsigned scancode) { - if(!hexEdit.onRead) return false; - - unsigned position = LOWORD(Edit_GetSel(hwnd)); - unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 2; - unsigned cursorY = position / lineWidth; - unsigned cursorX = position % lineWidth; - - //convert scancode to hex nibble - if(scancode >= '0' && scancode <= '9') scancode = scancode - '0'; - else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10; - else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10; - else return false; - - if(cursorX >= 10) { - //not on an offset - cursorX -= 10; - if((cursorX % 3) != 2) { - //not on a space - bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low - cursorX /= 3; - if(cursorX < hexEdit.state.columns) { - //not in ANSI region - unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX); - - if(offset >= hexEdit.state.length) return false; //do not edit past end of data - uint8_t data = hexEdit.onRead(offset); - - //write modified value - if(cursorNibble == 1) { - data = (data & 0xf0) | (scancode << 0); - } else { - data = (data & 0x0f) | (scancode << 4); - } - if(hexEdit.onWrite) hexEdit.onWrite(offset, data); - - //auto-advance cursor to next nibble or byte - position++; - if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++; - Edit_SetSel(hwnd, position, position); - - //refresh output to reflect modified data - update(); - } - } - } - - return true; -} diff --git a/purify/phoenix/windows/widget/horizontal-scroll-bar.cpp b/purify/phoenix/windows/widget/horizontal-scroll-bar.cpp deleted file mode 100644 index 250ac247..00000000 --- a/purify/phoenix/windows/widget/horizontal-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pHorizontalScrollBar::minimumGeometry() { - return { 0, 0, 0, 18 }; -} - -unsigned pHorizontalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pHorizontalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - horizontalScrollBar.setPosition(0); -} - -void pHorizontalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pHorizontalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | WS_TABSTOP | SBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalScrollBar); - unsigned position = horizontalScrollBar.state.position; - setLength(horizontalScrollBar.state.length); - horizontalScrollBar.setPosition(position); - synchronize(); -} - -void pHorizontalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/horizontal-slider.cpp b/purify/phoenix/windows/widget/horizontal-slider.cpp deleted file mode 100644 index 807086ae..00000000 --- a/purify/phoenix/windows/widget/horizontal-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pHorizontalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pHorizontalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pHorizontalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - horizontalSlider.setPosition(0); -} - -void pHorizontalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pHorizontalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_HORZ, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalSlider); - unsigned position = horizontalSlider.state.position; - setLength(horizontalSlider.state.length); - horizontalSlider.setPosition(position); - synchronize(); -} - -void pHorizontalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pHorizontalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/label.cpp b/purify/phoenix/windows/widget/label.cpp deleted file mode 100644 index 56f0d433..00000000 --- a/purify/phoenix/windows/widget/label.cpp +++ /dev/null @@ -1,64 +0,0 @@ -Geometry pLabel::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, label.state.text); - return { 0, 0, geometry.width, geometry.height }; -} - -void pLabel::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); - InvalidateRect(hwnd, 0, false); -} - -void pLabel::constructor() { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label); - setDefaultFont(); - setText(label.state.text); - synchronize(); -} - -void pLabel::destructor() { - DestroyWindow(hwnd); -} - -void pLabel::orphan() { - destructor(); - constructor(); -} - -static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Window *window = (Window*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam); - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_ERASEBKGND) { - //background is erased during WM_PAINT to prevent flickering - return TRUE; - } - - if(msg == WM_PAINT) { - PAINTSTRUCT ps; - RECT rc; - BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - FillRect(ps.hdc, &rc, window->p.brush ? window->p.brush : GetSysColorBrush(COLOR_3DFACE)); - SetBkColor(ps.hdc, window->p.brush ? window->p.brushColor : GetSysColor(COLOR_3DFACE)); - SelectObject(ps.hdc, ((Widget*)label)->p.hfont); - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); - unsigned height = rc.bottom; - GetClientRect(hwnd, &rc); - rc.top = (rc.bottom - height) / 2; - rc.bottom = rc.top + height; - DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); - EndPaint(hwnd, &ps); - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} diff --git a/purify/phoenix/windows/widget/line-edit.cpp b/purify/phoenix/windows/widget/line-edit.cpp deleted file mode 100644 index eb6a8fb7..00000000 --- a/purify/phoenix/windows/widget/line-edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -Geometry pLineEdit::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, lineEdit.state.text); - return { 0, 0, geometry.width + 12, geometry.height + 10 }; -} - -void pLineEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, 0); -} - -void pLineEdit::setText(const string &text) { - locked = true; - SetWindowText(hwnd, utf16_t(text)); - locked = false; -} - -string pLineEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t text[length + 1]; - GetWindowText(hwnd, text, length + 1); - text[length] = 0; - return (const char*)utf8_t(text); -} - -void pLineEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&lineEdit); - setDefaultFont(); - setEditable(lineEdit.state.editable); - setText(lineEdit.state.text); - synchronize(); -} - -void pLineEdit::destructor() { - lineEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pLineEdit::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/list-view.cpp b/purify/phoenix/windows/widget/list-view.cpp deleted file mode 100644 index 675691e6..00000000 --- a/purify/phoenix/windows/widget/list-view.cpp +++ /dev/null @@ -1,243 +0,0 @@ -unsigned ListView_GetColumnCount(HWND hwnd) { - unsigned count = 0; - LVCOLUMN column; - column.mask = LVCF_WIDTH; - while(ListView_GetColumn(hwnd, count++, &column)); - return --count; -} - -void ListView_SetImage(HWND hwnd, HIMAGELIST imageList, unsigned row, unsigned column, unsigned imageID) { - //if this is the first image assigned, set image list now - //do not set sooner, or image blocks will appear in a list with no images - if(ListView_GetImageList(hwnd, LVSIL_SMALL) != imageList) { - ListView_SetImageList(hwnd, imageList, LVSIL_SMALL); - } - - LVITEM item; - item.mask = LVIF_IMAGE; - item.iItem = row; - item.iSubItem = column; - item.iImage = imageID; - ListView_SetItem(hwnd, &item); -} - -void ImageList_Append(HIMAGELIST imageList, const nall::image &source) { - auto image = source; - if(image.empty()) { - image.allocate(15, 15); - image.clear(GetSysColor(COLOR_WINDOW)); - } - image.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0); - image.scale(15, 15, Interpolation::Linear); - HBITMAP bitmap = CreateBitmap(image); - ImageList_Add(imageList, bitmap, NULL); - DeleteObject(bitmap); -} - -void pListView::append(const lstring &list) { - wchar_t empty[] = L""; - unsigned row = ListView_GetItemCount(hwnd); - LVITEM item; - item.mask = LVIF_TEXT; - item.iItem = row; - item.iSubItem = 0; - item.pszText = empty; - locked = true; - ListView_InsertItem(hwnd, &item); - locked = false; - for(unsigned column = 0; column < list.size(); column++) { - utf16_t wtext(list(column, "")); - ListView_SetItemText(hwnd, row, column, wtext); - } -} - -void pListView::autoSizeColumns() { - unsigned columns = ListView_GetColumnCount(hwnd); - for(unsigned n = 0; n < columns; n++) { - ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER); - } -} - -bool pListView::checked(unsigned row) { - return ListView_GetCheckState(hwnd, row); -} - -void pListView::modify(unsigned row, const lstring &list) { - for(unsigned n = 0; n < list.size(); n++) { - utf16_t wtext(list(n, "")); - ListView_SetItemText(hwnd, row, n, wtext); - } -} - -void pListView::remove(unsigned row) { - ListView_DeleteItem(hwnd, row); -} - -void pListView::reset() { - ListView_DeleteAllItems(hwnd); - buildImageList(); //free previously allocated images -} - -bool pListView::selected() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return true; - } - return false; -} - -unsigned pListView::selection() { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return n; - } - return listView.state.selection; -} - -void pListView::setCheckable(bool checkable) { - ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES | (checkable ? LVS_EX_CHECKBOXES : 0)); -} - -void pListView::setChecked(unsigned row, bool checked) { - locked = true; - ListView_SetCheckState(hwnd, row, checked); - locked = false; -} - -void pListView::setHeaderText(const lstring &list) { - while(ListView_DeleteColumn(hwnd, 0)); - - lstring headers = list; - if(headers.size() == 0) headers.append(""); //must have at least one column - - for(unsigned n = 0; n < headers.size(); n++) { - LVCOLUMN column; - column.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM; - column.fmt = LVCFMT_LEFT; - column.iSubItem = n; - utf16_t headerText(headers[n]); - column.pszText = headerText; - ListView_InsertColumn(hwnd, n, &column); - } - autoSizeColumns(); -} - -void pListView::setHeaderVisible(bool visible) { - SetWindowLong( - hwnd, GWL_STYLE, - (GetWindowLong(hwnd, GWL_STYLE) & ~LVS_NOCOLUMNHEADER) | - (visible ? 0 : LVS_NOCOLUMNHEADER) - ); -} - -void pListView::setImage(unsigned row, unsigned column, const image &image) { - //assign existing image - for(unsigned n = 0; n < images.size(); n++) { - if(images[n] == image) { - imageMap(row)(column) = n; - return ListView_SetImage(hwnd, imageList, row, column, n); - } - } - - //append and assign new image - imageMap(row)(column) = images.size(); - images.append(image); - ImageList_Append(imageList, image); - ListView_SetImage(hwnd, imageList, row, column, imageMap(row)(column)); -} - -void pListView::setSelected(bool selected) { - locked = true; - lostFocus = false; - if(selected == false) { - ListView_SetItemState(hwnd, -1, 0, LVIS_FOCUSED | LVIS_SELECTED); - } else { - setSelection(listView.state.selection); - } - locked = false; -} - -void pListView::setSelection(unsigned row) { - locked = true; - lostFocus = false; - ListView_SetItemState(hwnd, row, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); - locked = false; -} - -void pListView::constructor() { - lostFocus = false; - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", - WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&listView); - setDefaultFont(); - setHeaderText(listView.state.headerText); - setHeaderVisible(listView.state.headerVisible); - setCheckable(listView.state.checkable); - for(auto &text : listView.state.text) append(text); - for(unsigned n = 0; n < listView.state.checked.size(); n++) setChecked(n, listView.state.checked[n]); - buildImageList(); - if(listView.state.selected) setSelection(listView.state.selection); - autoSizeColumns(); - synchronize(); -} - -void pListView::destructor() { - DestroyWindow(hwnd); -} - -void pListView::orphan() { - destructor(); - constructor(); -} - -void pListView::setGeometry(const Geometry &geometry) { - pWidget::setGeometry(geometry); - autoSizeColumns(); -} - -void pListView::buildImageList() { - auto &list = listView.state.image; - unsigned columns = listView.state.text.size(); - unsigned rows = max(1u, listView.state.headerText.size()); - - ListView_SetImageList(hwnd, NULL, LVSIL_SMALL); - if(imageList) ImageList_Destroy(imageList); - imageList = ImageList_Create(15, 15, ILC_COLOR32, 1, 0); - - imageMap.reset(); - images.reset(); - images.append(nall::image()); //empty icon for cells without an image assigned (I_IMAGENONE does not work) - - //create a vector of unique images from all images used (many cells may use the same image) - for(unsigned y = 0; y < list.size(); y++) { - for(unsigned x = 0; x < list[y].size(); x++) { - bool found = false; - for(unsigned z = 0; z < images.size(); z++) { - if(list[y][x] == images[z]) { - found = true; - imageMap(y)(x) = z; - break; - } - } - - if(found == false) { - imageMap(y)(x) = images.size(); - images.append(list[y][x]); - } - } - } - - //build image list - for(auto &imageItem : images) ImageList_Append(imageList, imageItem); - if(images.size() <= 1) return; - - //set images for all cells - for(unsigned y = 0; y < columns; y++) { - for(unsigned x = 0; x < rows; x++) { - ListView_SetImage(hwnd, imageList, y, x, imageMap(y)(x)); - } - } -} diff --git a/purify/phoenix/windows/widget/progress-bar.cpp b/purify/phoenix/windows/widget/progress-bar.cpp deleted file mode 100644 index f4703f1e..00000000 --- a/purify/phoenix/windows/widget/progress-bar.cpp +++ /dev/null @@ -1,25 +0,0 @@ -Geometry pProgressBar::minimumGeometry() { - return { 0, 0, 0, 23 }; -} - -void pProgressBar::setPosition(unsigned position) { - SendMessage(hwnd, PBM_SETPOS, (WPARAM)position, 0); -} - -void pProgressBar::constructor() { - hwnd = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | PBS_SMOOTH, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&progressBar); - SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); - SendMessage(hwnd, PBM_SETSTEP, MAKEWPARAM(1, 0), 0); - setPosition(progressBar.state.position); - synchronize(); -} - -void pProgressBar::destructor() { - DestroyWindow(hwnd); -} - -void pProgressBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/radio-box.cpp b/purify/phoenix/windows/widget/radio-box.cpp deleted file mode 100644 index ebcb1edc..00000000 --- a/purify/phoenix/windows/widget/radio-box.cpp +++ /dev/null @@ -1,43 +0,0 @@ -bool pRadioBox::checked() { - return SendMessage(hwnd, BM_GETCHECK, 0, 0); -} - -Geometry pRadioBox::minimumGeometry() { - Geometry geometry = pFont::geometry(hfont, radioBox.state.text); - return { 0, 0, geometry.width + 20, geometry.height + 4 }; -} - -void pRadioBox::setChecked() { - for(auto &item : radioBox.state.group) { - SendMessage(item.p.hwnd, BM_SETCHECK, (WPARAM)(&item == &radioBox), 0); - } -} - -void pRadioBox::setGroup(const set &group) { -} - -void pRadioBox::setText(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pRadioBox::constructor() { - hwnd = CreateWindow( - L"BUTTON", L"", - WS_CHILD | WS_TABSTOP | BS_RADIOBUTTON, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&radioBox); - setDefaultFont(); - if(radioBox.state.checked) setChecked(); - setText(radioBox.state.text); - synchronize(); -} - -void pRadioBox::destructor() { - DestroyWindow(hwnd); -} - -void pRadioBox::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/text-edit.cpp b/purify/phoenix/windows/widget/text-edit.cpp deleted file mode 100644 index 8e1df517..00000000 --- a/purify/phoenix/windows/widget/text-edit.cpp +++ /dev/null @@ -1,58 +0,0 @@ -void pTextEdit::setCursorPosition(unsigned position) { - if(position == ~0) position >>= 1; //Edit_SetSel takes signed type - Edit_SetSel(hwnd, position, position); - Edit_ScrollCaret(hwnd); -} - -void pTextEdit::setEditable(bool editable) { - SendMessage(hwnd, EM_SETREADONLY, editable == false, (LPARAM)0); -} - -void pTextEdit::setText(const string &text) { - locked = true; - string output = text; - output.replace("\r", ""); - output.replace("\n", "\r\n"); - SetWindowText(hwnd, utf16_t(output)); - locked = false; -} - -void pTextEdit::setWordWrap(bool wordWrap) { - //ES_AUTOHSCROLL cannot be changed after widget creation. - //As a result, we must destroy and re-create widget to change this setting. - orphan(); -} - -string pTextEdit::text() { - unsigned length = GetWindowTextLength(hwnd); - wchar_t buffer[length + 1]; - GetWindowText(hwnd, buffer, length + 1); - buffer[length] = 0; - string text = (const char*)utf8_t(buffer); - text.replace("\r", ""); - return text; -} - -void pTextEdit::constructor() { - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_TABSTOP | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | (textEdit.state.wordWrap == false ? WS_HSCROLL | ES_AUTOHSCROLL : 0), - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&textEdit); - setDefaultFont(); - setCursorPosition(textEdit.state.cursorPosition); - setEditable(textEdit.state.editable); - setText(textEdit.state.text); - synchronize(); -} - -void pTextEdit::destructor() { - textEdit.state.text = text(); - DestroyWindow(hwnd); -} - -void pTextEdit::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/vertical-scroll-bar.cpp b/purify/phoenix/windows/widget/vertical-scroll-bar.cpp deleted file mode 100644 index dcc281f2..00000000 --- a/purify/phoenix/windows/widget/vertical-scroll-bar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -Geometry pVerticalScrollBar::minimumGeometry() { - return { 0, 0, 18, 0 }; -} - -unsigned pVerticalScrollBar::position() { - return GetScrollPos(hwnd, SB_CTL); -} - -void pVerticalScrollBar::setLength(unsigned length) { - length += (length == 0); - SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); - verticalScrollBar.setPosition(0); -} - -void pVerticalScrollBar::setPosition(unsigned position) { - SetScrollPos(hwnd, SB_CTL, position, TRUE); -} - -void pVerticalScrollBar::constructor() { - hwnd = CreateWindow( - L"SCROLLBAR", L"", WS_CHILD | SBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalScrollBar); - unsigned position = verticalScrollBar.state.position; - setLength(verticalScrollBar.state.length); - verticalScrollBar.setPosition(position); - synchronize(); -} - -void pVerticalScrollBar::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalScrollBar::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/vertical-slider.cpp b/purify/phoenix/windows/widget/vertical-slider.cpp deleted file mode 100644 index ac5cb1ce..00000000 --- a/purify/phoenix/windows/widget/vertical-slider.cpp +++ /dev/null @@ -1,39 +0,0 @@ -Geometry pVerticalSlider::minimumGeometry() { - return { 0, 0, 0, 25 }; -} - -unsigned pVerticalSlider::position() { - return SendMessage(hwnd, TBM_GETPOS, 0, 0); -} - -void pVerticalSlider::setLength(unsigned length) { - length += (length == 0); - SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); - SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); - verticalSlider.setPosition(0); -} - -void pVerticalSlider::setPosition(unsigned position) { - SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); -} - -void pVerticalSlider::constructor() { - hwnd = CreateWindow( - TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT, - 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&verticalSlider); - unsigned position = verticalSlider.state.position; - setLength(verticalSlider.state.length); - verticalSlider.setPosition(position); - synchronize(); -} - -void pVerticalSlider::destructor() { - DestroyWindow(hwnd); -} - -void pVerticalSlider::orphan() { - destructor(); - constructor(); -} diff --git a/purify/phoenix/windows/widget/viewport.cpp b/purify/phoenix/windows/widget/viewport.cpp deleted file mode 100644 index c0b13b69..00000000 --- a/purify/phoenix/windows/widget/viewport.cpp +++ /dev/null @@ -1,57 +0,0 @@ -static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - Object *object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); - if(!dynamic_cast(object)) return DefWindowProc(hwnd, msg, wparam, lparam); - Viewport &viewport = (Viewport&)*object; - - if(msg == WM_GETDLGCODE) { - return DLGC_STATIC | DLGC_WANTCHARS; - } - - if(msg == WM_MOUSEMOVE) { - TRACKMOUSEEVENT tracker = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd }; - TrackMouseEvent(&tracker); - if(viewport.onMouseMove) viewport.onMouseMove({ (int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam) }); - } - - if(msg == WM_MOUSELEAVE) { - if(viewport.onMouseLeave) viewport.onMouseLeave(); - } - - if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { - if(viewport.onMousePress) switch(msg) { - case WM_LBUTTONDOWN: viewport.onMousePress(Mouse::Button::Left); break; - case WM_MBUTTONDOWN: viewport.onMousePress(Mouse::Button::Middle); break; - case WM_RBUTTONDOWN: viewport.onMousePress(Mouse::Button::Right); break; - } - } - - if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) { - if(viewport.onMouseRelease) switch(msg) { - case WM_LBUTTONUP: viewport.onMouseRelease(Mouse::Button::Left); break; - case WM_MBUTTONUP: viewport.onMouseRelease(Mouse::Button::Middle); break; - case WM_RBUTTONUP: viewport.onMouseRelease(Mouse::Button::Right); break; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -uintptr_t pViewport::handle() { - return (uintptr_t)hwnd; -} - -void pViewport::constructor() { - hwnd = CreateWindow(L"phoenix_viewport", L"", WS_CHILD | WS_DISABLED, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&viewport); - synchronize(); -} - -void pViewport::destructor() { - DestroyWindow(hwnd); -} - -void pViewport::orphan() { - destructor(); - constructor(); -} \ No newline at end of file diff --git a/purify/phoenix/windows/widget/widget.cpp b/purify/phoenix/windows/widget/widget.cpp deleted file mode 100644 index d8c25c9b..00000000 --- a/purify/phoenix/windows/widget/widget.cpp +++ /dev/null @@ -1,70 +0,0 @@ -bool pWidget::enabled() { - return IsWindowEnabled(hwnd); -} - -bool pWidget::focused() { - return GetFocus() == hwnd; -} - -Geometry pWidget::minimumGeometry() { - return {0, 0, 0, 0}; -} - -void pWidget::setEnabled(bool enabled) { - if(widget.state.abstract) enabled = false; - if(sizable.state.layout && sizable.state.layout->enabled() == false) enabled = false; - EnableWindow(hwnd, enabled); -} - -void pWidget::setFocused() { - SetFocus(hwnd); -} - -void pWidget::setFont(const string &font) { - if(hfont) DeleteObject(hfont); - hfont = pFont::create(font); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -void pWidget::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, geometry.height, SWP_NOZORDER); -} - -void pWidget::setVisible(bool visible) { - if(widget.state.abstract) visible = false; - if(sizable.state.layout && sizable.state.layout->visible() == false) visible = false; - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); -} - -void pWidget::constructor() { - hfont = pFont::create("Tahoma, 8"); - if(widget.state.abstract) { - hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&widget); - } -} - -void pWidget::destructor() { - if(widget.state.abstract) { - DestroyWindow(hwnd); - } -} - -void pWidget::orphan() { - destructor(); - constructor(); -} - -void pWidget::setDefaultFont() { - string description = widget.state.font; - if(description == "") description = "Tahoma, 8"; - hfont = pFont::create(description); - SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0); -} - -//calling Widget::setParent destroys widget and re-creates it: -//need to re-apply visiblity and enabled status; called by each subclassed setParent() function -void pWidget::synchronize() { - widget.setEnabled(widget.enabled()); - widget.setVisible(widget.visible()); -} diff --git a/purify/phoenix/windows/window.cpp b/purify/phoenix/windows/window.cpp deleted file mode 100644 index dc8aea28..00000000 --- a/purify/phoenix/windows/window.cpp +++ /dev/null @@ -1,229 +0,0 @@ -vector pWindow::modal; - -void pWindow::updateModality() { - for(auto &object : pObject::objects) { - if(dynamic_cast(object) == nullptr) continue; - pWindow *p = (pWindow*)object; - if(modal.size() == 0) EnableWindow(p->hwnd, true); - else EnableWindow(p->hwnd, modal.find(p)); - } -} - -static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; -static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; - -Window& pWindow::none() { - static Window *window = nullptr; - if(window == nullptr) window = new Window; - return *window; -} - -void pWindow::append(Layout &layout) { - Geometry geom = window.state.geometry; - geom.x = geom.y = 0; - layout.setGeometry(geom); -} - -void pWindow::append(Menu &menu) { - menu.p.parentWindow = &window; - updateMenu(); -} - -void pWindow::append(Widget &widget) { - widget.p.parentWindow = &window; - widget.p.orphan(); - if(widget.state.font != "") widget.p.setFont(widget.state.font); - else if(window.state.widgetFont != "") widget.p.setFont(window.state.widgetFont); - else widget.p.setFont("Tahoma, 8"); -} - -Color pWindow::backgroundColor() { - if(window.state.backgroundColorOverride) return window.state.backgroundColor; - DWORD color = GetSysColor(COLOR_3DFACE); - return { (uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color >> 0), 255 }; -} - -bool pWindow::focused() { - return (GetForegroundWindow() == hwnd); -} - -Geometry pWindow::frameMargin() { - unsigned style = window.state.resizable ? ResizableStyle : FixedStyle; - if(window.state.fullScreen) style = 0; - RECT rc = { 0, 0, 640, 480 }; - AdjustWindowRect(&rc, style, window.state.menuVisible); - unsigned statusHeight = 0; - if(window.state.statusVisible) { - RECT src; - GetClientRect(hstatus, &src); - statusHeight = src.bottom - src.top; - } - return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 }; -} - -Geometry pWindow::geometry() { - Geometry margin = frameMargin(); - - RECT rc; - if(IsIconic(hwnd)) { - //GetWindowRect returns -32000(x),-32000(y) when window is minimized - WINDOWPLACEMENT wp; - GetWindowPlacement(hwnd, &wp); - rc = wp.rcNormalPosition; - } else { - GetWindowRect(hwnd, &rc); - } - - signed x = rc.left + margin.x; - signed y = rc.top + margin.y; - unsigned width = (rc.right - rc.left) - margin.width; - unsigned height = (rc.bottom - rc.top) - margin.height; - - return { x, y, width, height }; -} - -void pWindow::remove(Layout &layout) { -} - -void pWindow::remove(Menu &menu) { - updateMenu(); -} - -void pWindow::remove(Widget &widget) { - widget.p.orphan(); -} - -void pWindow::setBackgroundColor(const Color &color) { - if(brush) DeleteObject(brush); - brushColor = RGB(color.red, color.green, color.blue); - brush = CreateSolidBrush(brushColor); -} - -void pWindow::setFocused() { - if(window.state.visible == false) setVisible(true); - SetFocus(hwnd); -} - -void pWindow::setFullScreen(bool fullScreen) { - locked = true; - if(fullScreen == false) { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | (window.state.resizable ? ResizableStyle : FixedStyle)); - setGeometry(window.state.geometry); - } else { - SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); - Geometry margin = frameMargin(); - setGeometry({ margin.x, margin.y, GetSystemMetrics(SM_CXSCREEN) - margin.width, GetSystemMetrics(SM_CYSCREEN) - margin.height }); - } - locked = false; -} - -void pWindow::setGeometry(const Geometry &geometry) { - locked = true; - Geometry margin = frameMargin(); - SetWindowPos( - hwnd, NULL, - geometry.x - margin.x, geometry.y - margin.y, - geometry.width + margin.width, geometry.height + margin.height, - SWP_NOZORDER | SWP_FRAMECHANGED - ); - SetWindowPos(hstatus, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); - for(auto &layout : window.state.layout) { - Geometry geom = this->geometry(); - geom.x = geom.y = 0; - layout.setGeometry(geom); - } - locked = false; -} - -void pWindow::setMenuFont(const string &font) { -} - -void pWindow::setMenuVisible(bool visible) { - locked = true; - SetMenu(hwnd, visible ? hmenu : 0); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setModal(bool modality) { - if(modality == false) { - if(auto position = modal.find(this)) modal.remove(position()); - } else { - modal.appendonce(this); - } - updateModality(); -} - -void pWindow::setResizable(bool resizable) { - SetWindowLongPtr(hwnd, GWL_STYLE, window.state.resizable ? ResizableStyle : FixedStyle); - setGeometry(window.state.geometry); -} - -void pWindow::setStatusFont(const string &font) { - if(hstatusfont) DeleteObject(hstatusfont); - hstatusfont = pFont::create(font); - SendMessage(hstatus, WM_SETFONT, (WPARAM)hstatusfont, 0); -} - -void pWindow::setStatusText(const string &text) { - SendMessage(hstatus, SB_SETTEXT, 0, (LPARAM)(wchar_t*)utf16_t(text)); -} - -void pWindow::setStatusVisible(bool visible) { - locked = true; - ShowWindow(hstatus, visible ? SW_SHOWNORMAL : SW_HIDE); - setGeometry(window.state.geometry); - locked = false; -} - -void pWindow::setTitle(const string &text) { - SetWindowText(hwnd, utf16_t(text)); -} - -void pWindow::setVisible(bool visible) { - ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); - if(visible == false) setModal(false); -} - -void pWindow::setWidgetFont(const string &font) { - for(auto &widget : window.state.widget) { - if(widget.state.font == "") widget.setFont(font); - } -} - -void pWindow::constructor() { - brush = 0; - - hwnd = CreateWindow(L"phoenix_window", L"", ResizableStyle, 128, 128, 256, 256, 0, 0, GetModuleHandle(0), 0); - hmenu = CreateMenu(); - hstatus = CreateWindow(STATUSCLASSNAME, L"", WS_CHILD, 0, 0, 0, 0, hwnd, 0, GetModuleHandle(0), 0); - hstatusfont = 0; - setStatusFont("Tahoma, 8"); - - //status bar will be capable of receiving tab focus if it is not disabled - SetWindowLongPtr(hstatus, GWL_STYLE, GetWindowLong(hstatus, GWL_STYLE) | WS_DISABLED); - - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&window); - setGeometry({ 128, 128, 256, 256 }); -} - -void pWindow::destructor() { - DeleteObject(hstatusfont); - DestroyWindow(hstatus); - DestroyMenu(hmenu); - DestroyWindow(hwnd); -} - -void pWindow::updateMenu() { - if(hmenu) DestroyMenu(hmenu); - hmenu = CreateMenu(); - - for(auto &menu : window.state.menu) { - menu.p.update(window); - if(menu.visible()) { - AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR)menu.p.hmenu, utf16_t(menu.state.text)); - } - } - - SetMenu(hwnd, window.state.menuVisible ? hmenu : 0); -} diff --git a/purify/purify.cpp b/purify/purify.cpp deleted file mode 100644 index 698ee8d6..00000000 --- a/purify/purify.cpp +++ /dev/null @@ -1,233 +0,0 @@ -#include -using namespace nall; - -#include -using namespace phoenix; - -#include "resource/resource.cpp" - -struct Application : Window { - library ananke; - - VerticalLayout layout; - HorizontalLayout pathLayout; - Label pathLabel; - LineEdit pathEdit; - Button browseButton; - ListView fileList; - ProgressBar progressBar; - Label libraryPath; - HorizontalLayout controlLayout; - Button selectAllButton; - Button unselectAllButton; - Widget spacer; - Button setPathButton; - Button purifyButton; - - lstring filenameList; - - Application(); - void scanPath(); - void scanPath(const string &path, const string &basepath); - void purify(); -} *application = nullptr; - -Application::Application() { - application = this; - - if(ananke.open("ananke") == false) { - MessageWindow::critical(Window::none(), - "Error: ananke was not found, but is required to use purify.\n\n" - "Please install ananke and then run purify again." - ); - exit(0); - } - - string path = string::read({configpath(), "higan/library.cfg"}).strip(); - if(path.empty()) path = {userpath(), "Emulation/"}; - - setFrameGeometry({64, 64, 720, 480}); - setTitle("purify v03.01"); - - layout.setMargin(5); - pathLabel.setText("Path:"); - browseButton.setText("Browse ..."); - fileList.setCheckable(true); - libraryPath.setText({"Library Path: ", path}); - selectAllButton.setText("Select All"); - unselectAllButton.setText("Unselect All"); - setPathButton.setText("Set Path ..."); - purifyButton.setText("Purify"); - - append(layout); - layout.append(pathLayout, {~0, 0}, 5); - pathLayout.append(pathLabel, {0, 0}, 5); - pathLayout.append(pathEdit, {~0, 0}, 5); - pathLayout.append(browseButton, {80, 0}); - layout.append(fileList, {~0, ~0}, 5); - layout.append(progressBar, {~0, 0}, 5); - layout.append(libraryPath, {~0, 0}, 5); - layout.append(controlLayout, {~0, 0}); - controlLayout.append(selectAllButton, {100, 0}, 5); - controlLayout.append(unselectAllButton, {100, 0}, 5); - controlLayout.append(spacer, {~0, 0}); - controlLayout.append(setPathButton, {100, 0}, 5); - controlLayout.append(purifyButton, {100, 0}); - - setVisible(); - - onClose = &OS::quit; - - pathEdit.onActivate = {&Application::scanPath, this}; - - browseButton.onActivate = [&] { - string path = DialogWindow::folderSelect(*this, userpath()); - if(path.empty() == false) { - pathEdit.setText(path); - scanPath(); - } - }; - - selectAllButton.onActivate = [&] { - for(unsigned n = 0; n < filenameList.size(); n++) fileList.setChecked(n, true); - }; - - unselectAllButton.onActivate = [&] { - for(unsigned n = 0; n < filenameList.size(); n++) fileList.setChecked(n, false); - }; - - setPathButton.onActivate = [&] { - string path = DialogWindow::folderSelect(*this, userpath()); - if(path.empty()) return; - - directory::create({configpath(), "higan/"}); - file::write({configpath(), "higan/library.cfg"}, path); - libraryPath.setText({"Library Path: ", path}); - }; - - purifyButton.onActivate = {&Application::purify, this}; -} - -void Application::scanPath() { - string path = pathEdit.text(); - path.transform("\\", "/"); - if(path.endswith("/") == false) path.append("/"); - pathEdit.setText(path); - - fileList.reset(); - filenameList.reset(); - scanPath(path, path); - selectAllButton.onActivate(); -} - -void Application::scanPath(const string &path, const string &basepath) { - lstring files = directory::icontents(path); - for(auto &file : files) { - if( - directory::exists({path, file}) - && !file.endswith(".fc/") - && !file.endswith(".sfc/") - && !file.endswith(".st/") - && !file.endswith(".bs/") - && !file.endswith(".gb/") - && !file.endswith(".gbc/") - && !file.endswith(".gba/") - ) { - scanPath({path, file}, basepath); - } else if( - directory::exists({path, file}) - ) { - fileList.append(string{path, file}.ltrim<1>(basepath).rtrim<1>("/")); - filenameList.append({path, file}); - if(file::exists({path, file, "unverified"}) == false) { - fileList.setImage(filenameList.size() - 1, 0, {resource::game, sizeof resource::game}); - } else { - fileList.setImage(filenameList.size() - 1, 0, {resource::unverified, sizeof resource::unverified}); - } - } else if( - file.endswith(".fc") || file.endswith(".nes") - || file.endswith(".sfc") || file.endswith(".smc") - || file.endswith(".st") || file.endswith(".bs") - || file.endswith(".gb") - || file.endswith(".gbc") - || file.endswith(".gba") - || file.endswith(".zip") - ) { - fileList.append(string{path, file}.ltrim<1>(basepath)); - filenameList.append({path, file}); - if(file.endswith(".zip") == false) { - fileList.setImage(filenameList.size() - 1, 0, {resource::file, sizeof resource::file}); - } else { - fileList.setImage(filenameList.size() - 1, 0, {resource::archive, sizeof resource::archive}); - } - } - } -} - -struct PurifyContext { - lstring list; - unsigned position; - unsigned size; - - void run() { - function sync = application->ananke.sym("ananke_sync"); - function open = application->ananke.sym("ananke_open"); - - if(!open || !sync) { - position = size; - return; - } - - while(position < size) { - string filename = list[position]; - if(directory::exists(filename)) sync(filename); - else if(file::exists(filename)) open(filename); - position++; - } - } - - PurifyContext(const lstring &list) : list(list) { - position = 0; - size = list.size(); - } -}; - -void Application::purify() { - lstring purifyList; - for(unsigned n = 0; n < filenameList.size(); n++) { - if(fileList.checked(n)) purifyList.append(filenameList[n]); - } - - if(purifyList.size() == 0) { - MessageWindow::information(*this, "Please select at least one file to purify."); - return; - } - - layout.setEnabled(false); - OS::processEvents(); - - PurifyContext purifyContext(purifyList); - nall::thread purifyThread([&] { purifyContext.run(); }); - while(purifyThread.active()) { - OS::processEvents(); - unsigned position = ((unsigned)(double)purifyContext.position / (double)purifyContext.size * 100.0 + 0.5); - progressBar.setPosition(position); - } - purifyThread.join(); - - fileList.reset(); - filenameList.reset(); - progressBar.setPosition(0); - layout.setEnabled(true); -} - -int main(int argc, char **argv) { - #if defined(PLATFORM_WINDOWS) - utf8_args(argc, argv); - #endif - - new Application; - OS::main(); - - return 0; -} diff --git a/purify/resource/archive.png b/purify/resource/archive.png deleted file mode 100644 index 4b55b504..00000000 Binary files a/purify/resource/archive.png and /dev/null differ diff --git a/purify/resource/file.png b/purify/resource/file.png deleted file mode 100644 index 5b7e6491..00000000 Binary files a/purify/resource/file.png and /dev/null differ diff --git a/purify/resource/game.png b/purify/resource/game.png deleted file mode 100644 index 1990dbb8..00000000 Binary files a/purify/resource/game.png and /dev/null differ diff --git a/purify/resource/resource.bml b/purify/resource/resource.bml deleted file mode 100644 index 20a4694f..00000000 --- a/purify/resource/resource.bml +++ /dev/null @@ -1,5 +0,0 @@ -resource name=resource - binary id=game name=game.png - binary id=unverified name=unverified.png - binary id=file name=file.png - binary id=archive name=archive.png diff --git a/purify/resource/resource.cpp b/purify/resource/resource.cpp deleted file mode 100644 index b74d745e..00000000 --- a/purify/resource/resource.cpp +++ /dev/null @@ -1,176 +0,0 @@ -namespace resource { - -const uint8_t game[1490] = { - 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122, - 244,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,0,5,137,73,68,65,84,88,133,237,150,91,108,20, - 231,21,199,127,231,155,155,151,181,124,89,3,181,113,193,183,13,16,81,82,21,225,52,50,1,132,91,53,20,212,132,155, - 212,84,149,18,161,40,82,213,151,72,68,81,108,212,74,121,168,122,81,165,190,24,171,125,141,218,226,66,171,66,91,37, - 65,145,82,225,2,9,6,148,132,40,73,9,55,219,4,112,146,58,49,23,239,125,102,190,62,204,236,120,236,176,182,1, - 169,79,29,233,232,236,203,156,255,239,252,207,249,190,29,248,255,115,31,79,182,135,157,153,94,116,102,47,91,239,181,134, - 186,31,113,173,216,159,173,249,10,90,243,215,76,47,91,254,103,0,217,30,118,106,225,143,183,219,215,219,250,225,103,201, - 180,173,179,53,28,186,23,136,187,6,8,58,151,253,147,233,13,142,151,106,97,226,76,63,238,194,54,50,237,143,222,19, - 132,220,173,56,134,57,144,95,243,3,43,111,8,147,31,253,3,180,7,98,80,189,226,123,152,159,95,102,193,197,227,69, - 129,237,201,95,240,234,124,106,206,219,129,108,47,59,48,204,1,111,211,139,150,145,254,22,217,11,175,160,68,163,148,66, - 137,38,123,225,21,252,133,105,114,233,245,129,19,123,249,238,124,234,206,203,129,108,47,59,180,48,224,111,124,193,150,150, - 46,138,19,23,64,107,4,184,253,225,1,220,155,163,160,65,139,34,153,222,140,57,62,76,213,197,227,69,17,182,37,127, - 206,107,179,213,158,211,129,64,92,6,178,15,108,180,189,134,86,74,19,23,17,64,68,16,17,204,68,93,224,130,161,80, - 2,185,203,175,227,54,180,145,79,175,179,181,230,240,92,78,204,234,64,36,158,126,212,246,83,203,64,187,56,141,107,65, - 160,52,126,142,252,245,147,248,185,207,167,94,208,58,72,8,137,214,110,140,241,17,170,46,189,57,171,19,21,29,200,246, - 176,93,139,12,228,210,235,108,63,245,85,242,163,255,68,187,249,168,115,63,51,6,133,137,160,251,40,12,68,41,148,8, - 249,43,71,241,26,150,145,111,127,196,22,164,226,78,220,17,32,219,195,118,95,228,79,217,116,151,237,213,53,147,191,50, - 136,8,129,128,8,34,10,17,65,41,99,70,168,169,12,20,174,30,195,91,216,66,182,173,211,169,4,241,37,128,178,120, - 174,227,17,219,175,91,66,225,234,49,20,160,68,161,172,5,80,158,125,205,82,204,228,226,105,226,18,101,21,65,20,175, - 158,192,75,45,37,219,182,214,17,228,208,100,15,155,43,2,100,122,217,22,136,63,108,251,117,77,20,174,190,137,8,72, - 185,168,83,27,117,111,47,92,73,242,107,79,97,47,94,61,189,243,16,72,194,113,136,64,113,108,8,175,174,153,108,235, - 26,71,41,57,28,135,136,0,244,75,40,224,80,177,190,209,102,201,215,41,140,157,14,108,151,169,249,154,53,205,136,72, - 232,66,0,34,165,201,169,217,71,89,97,88,85,88,245,29,40,195,10,156,248,236,29,212,3,143,81,168,89,236,136,76, - 45,100,4,32,47,225,227,179,205,158,248,164,40,215,222,193,105,90,19,21,20,81,24,201,69,40,59,137,136,160,115,227, - 228,222,221,71,238,221,126,252,204,245,72,220,176,18,209,8,140,154,165,44,88,190,29,179,182,5,49,76,18,45,221,56, - 185,12,206,237,255,20,181,158,218,133,105,35,72,254,138,191,9,250,251,137,225,51,69,243,198,117,236,198,111,32,202,68, - 148,194,94,180,122,234,4,220,188,140,200,116,203,205,234,38,18,15,61,131,149,90,142,89,221,136,149,90,142,8,36,58, - 182,80,219,245,83,18,84,33,39,250,139,190,231,63,81,253,75,142,68,141,223,233,20,100,122,217,134,200,129,98,251,90, - 219,79,53,225,223,184,68,98,245,110,148,225,128,8,197,243,127,70,231,198,131,113,68,173,88,56,171,118,163,37,236,73, - 107,52,160,18,13,232,145,33,244,241,254,146,246,220,199,227,226,21,1,166,65,164,59,109,107,197,86,84,162,1,9,174, - 64,40,78,226,126,252,6,160,49,106,59,240,198,223,195,88,210,133,170,237,8,133,53,104,144,170,122,244,232,16,254,177, - 59,139,207,10,80,134,208,168,131,170,251,121,75,45,93,131,206,127,17,118,45,248,55,47,66,225,38,102,227,90,180,214, - 81,169,224,183,6,39,20,255,215,190,138,226,115,2,64,120,47,24,230,65,99,211,30,83,39,171,241,174,31,199,168,107, - 71,223,56,15,94,1,107,229,15,65,153,83,215,176,214,96,215,161,71,79,226,205,33,62,47,128,50,132,54,140,3,254, - 242,78,75,234,27,17,237,66,241,22,214,146,46,164,174,131,80,25,173,65,236,26,252,209,33,188,193,190,146,214,238,19, - 115,253,27,206,247,131,196,248,108,15,59,146,85,242,7,86,126,211,182,59,127,140,246,242,168,240,78,40,3,96,85,227, - 141,156,194,27,236,43,77,228,220,93,205,191,225,53,192,3,252,138,133,103,17,85,128,13,84,1,206,175,223,98,244,201, - 85,92,72,101,174,109,241,201,24,102,115,39,248,110,112,52,145,72,188,52,216,231,190,255,169,251,244,131,253,28,5,204, - 80,163,124,220,191,4,82,9,192,2,156,153,241,219,51,92,249,118,27,151,155,115,195,223,145,69,29,134,170,95,134,248, - 46,88,73,252,145,33,74,131,125,238,209,97,247,71,221,47,115,44,38,94,6,80,4,142,135,91,90,25,192,8,1,236, - 88,68,16,47,159,229,90,103,147,30,110,187,117,170,91,26,90,149,212,183,226,143,156,164,56,216,231,30,254,183,187,103, - 215,65,222,10,197,227,162,241,81,107,130,177,204,10,96,134,16,102,8,80,6,114,0,231,192,7,140,173,72,249,87,86, - 76,158,218,160,111,127,170,74,111,255,197,251,253,89,247,39,207,252,157,211,49,209,184,160,31,134,23,203,21,1,252,24, - 189,17,203,101,48,3,176,14,159,99,172,165,198,191,182,218,26,89,255,187,51,254,207,158,59,194,233,25,66,238,140,40, - 197,34,26,193,108,167,160,188,7,118,44,199,195,138,1,150,187,44,11,20,103,68,33,150,167,45,226,124,142,97,121,28, - 54,211,71,83,22,143,47,150,23,235,62,14,51,173,235,187,5,184,211,59,113,241,114,141,153,179,158,215,243,95,119,198, - 63,107,9,247,71,127,0,0,0,0,73,69,78,68,174,66,96,130, -}; - -const uint8_t unverified[1675] = { - 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122, - 244,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,0,6,66,73,68,65,84,88,133,229,151,217,115,84, - 85,30,199,191,231,119,238,146,78,210,183,59,107,147,116,167,151,132,152,72,132,208,128,27,13,9,104,160,28,202,146,161, - 3,79,83,214,164,242,52,207,62,251,224,195,252,13,62,88,53,37,102,134,69,12,250,162,165,14,58,162,65,81,17,179, - 66,7,59,91,111,233,108,244,96,210,33,73,247,237,123,231,161,23,110,98,2,1,103,158,230,86,253,234,156,170,123,239, - 249,124,206,249,253,234,87,117,128,255,247,135,253,158,159,143,118,116,119,106,76,239,37,157,94,253,234,139,191,125,242,36, - 107,208,239,129,103,152,126,94,177,213,32,67,218,135,109,199,186,78,60,201,58,252,73,225,26,99,231,188,190,131,242,169, - 147,29,88,211,56,159,137,70,207,184,234,247,254,28,154,24,8,254,79,5,142,118,116,119,106,132,243,222,67,62,217,225, - 170,195,59,189,223,224,224,179,45,40,85,20,30,143,68,30,91,226,177,4,142,118,116,119,130,211,133,87,94,123,69,42, - 171,182,225,131,43,55,161,105,192,157,169,89,28,122,174,5,102,197,194,167,195,225,199,146,216,182,64,91,71,151,159,56, - 191,248,122,215,105,241,233,150,167,240,246,197,175,0,157,65,32,2,17,67,48,52,7,223,129,93,48,91,44,60,22,10, - 159,113,55,236,187,25,26,239,31,251,175,8,180,117,116,249,193,232,194,159,94,247,75,45,45,77,24,15,207,195,251,180, - 19,7,118,185,112,247,94,18,43,171,105,16,99,24,11,207,227,57,111,19,20,139,149,71,67,83,219,146,120,164,64,91, - 71,151,159,49,186,112,224,240,33,105,207,158,102,68,226,255,6,24,64,44,187,243,249,68,18,139,75,171,16,56,129,24, - 195,100,100,1,251,91,159,202,74,132,31,45,241,80,129,60,124,223,33,159,84,235,172,67,96,124,6,85,21,102,16,17, - 194,211,119,241,237,207,227,152,187,187,4,129,19,4,226,16,136,192,115,239,188,187,119,66,177,150,241,72,40,116,198,221, - 224,221,82,98,203,62,208,126,172,251,20,35,186,224,245,249,164,29,14,59,62,191,54,130,180,154,1,39,2,103,12,137, - 123,247,113,127,37,5,81,224,16,57,135,40,80,97,78,68,184,118,115,12,110,143,27,190,246,118,137,129,125,212,126,188, - 251,15,219,22,104,63,214,125,10,76,191,232,61,152,133,255,235,251,81,112,70,133,99,38,202,206,69,158,135,103,71,129, - 19,132,220,156,51,194,15,131,147,112,215,123,224,59,210,38,211,22,18,191,73,65,30,190,247,69,159,84,227,112,224,155, - 159,126,1,129,65,224,4,119,109,5,170,203,205,32,98,208,52,29,43,43,41,168,25,173,112,244,198,84,8,156,192,25, - 97,110,97,17,187,154,60,80,172,86,33,58,21,58,237,118,183,254,52,53,57,48,182,169,192,145,227,93,127,4,195,251, - 173,47,100,119,254,93,255,120,1,46,16,161,209,85,13,171,82,12,98,12,101,74,49,26,221,54,164,83,42,150,150,215, - 10,223,100,225,188,48,231,68,88,72,36,209,220,232,130,181,204,42,132,67,225,51,70,137,7,41,120,235,45,210,117,246, - 81,149,221,37,181,182,54,227,198,208,36,56,123,144,87,145,115,216,42,20,112,198,178,117,64,12,196,24,86,83,234,186, - 111,178,115,130,73,22,81,91,109,133,44,8,224,140,16,28,159,197,97,223,126,212,185,93,178,78,236,211,223,158,192,213, - 171,122,125,189,119,96,121,121,209,207,4,19,111,110,116,98,62,177,84,200,125,185,165,4,205,245,59,64,68,88,76,174, - 224,202,181,0,198,166,230,145,74,169,133,221,154,100,17,12,217,230,100,171,84,240,236,30,55,146,203,107,72,165,51,216, - 183,219,133,196,92,28,125,125,215,83,200,104,175,230,79,96,93,10,166,38,6,238,120,26,90,71,102,98,81,191,217,98, - 229,77,13,78,220,189,151,4,39,194,174,134,26,84,150,149,130,17,67,40,150,192,226,210,202,131,156,115,66,133,181,4, - 109,207,55,98,109,85,133,36,114,212,213,150,67,49,155,80,93,105,198,254,221,78,68,67,97,156,59,255,97,42,147,86, - 79,94,253,242,236,103,91,22,225,212,248,192,168,167,161,117,36,30,139,250,45,214,50,190,211,227,192,210,242,26,246,63, - 227,130,32,16,136,17,130,147,179,80,85,173,80,108,2,113,232,58,208,224,172,66,173,205,10,103,109,5,44,102,19,136, - 8,149,229,165,24,25,30,197,63,206,93,78,111,132,111,42,96,148,152,142,70,252,86,107,57,63,122,112,55,100,89,0, - 67,182,251,217,42,21,36,147,107,40,41,150,80,95,87,133,213,149,20,158,105,178,67,49,155,10,29,146,136,80,102,41, - 198,224,208,109,244,252,253,114,58,147,86,95,219,8,223,82,96,189,68,180,179,185,201,195,157,142,26,164,83,42,136,8, - 178,40,64,18,57,100,81,64,131,179,26,110,71,37,148,210,34,16,35,176,28,220,170,152,48,56,20,64,79,207,229,116, - 38,157,222,20,254,80,129,188,132,171,222,59,50,60,28,232,116,56,106,72,42,50,97,240,86,12,153,140,134,88,252,30, - 150,146,171,112,218,203,193,11,13,42,11,87,204,121,120,239,67,225,143,20,0,128,208,68,255,168,211,179,119,100,104,232, - 182,159,139,197,188,178,170,28,247,151,83,80,211,26,154,118,238,128,82,106,2,203,117,71,34,6,115,105,81,246,216,123, - 122,211,170,150,57,249,245,23,239,110,9,223,150,64,78,34,104,119,182,4,98,145,200,201,138,138,42,254,114,219,30,216, - 119,88,97,46,41,42,180,102,34,134,210,146,34,12,15,7,240,94,79,111,122,117,109,229,116,223,151,239,253,51,183,132, - 254,36,2,4,64,2,80,4,64,14,79,14,133,170,108,158,224,108,60,126,130,139,37,188,169,209,9,77,211,11,69,87, - 82,44,99,104,56,128,119,123,46,169,139,191,46,252,249,135,190,75,87,1,8,57,70,190,225,105,219,21,16,1,200,27, - 99,58,18,8,91,202,107,39,98,177,217,227,110,151,157,219,107,170,161,105,58,138,77,89,248,217,158,75,234,194,124,244, - 47,253,63,126,220,103,128,231,5,8,217,107,128,110,60,145,205,4,120,78,64,50,68,65,98,102,58,24,43,85,42,38, - 127,25,139,190,228,114,216,169,206,97,195,224,208,109,156,237,185,164,198,167,39,222,24,233,191,114,61,7,55,66,141,247, - 15,29,64,230,81,2,66,78,66,200,9,228,133,100,0,242,220,204,68,188,200,100,14,7,39,166,219,18,137,69,250,248, - 211,43,153,104,248,206,155,163,195,95,223,48,64,141,64,45,23,25,195,184,165,128,102,176,231,134,49,47,198,1,136,11, - 115,161,184,44,149,196,18,191,174,30,142,132,110,253,53,24,184,126,99,3,72,221,16,105,67,20,82,240,176,171,89,190, - 14,36,195,104,12,209,32,152,223,101,30,144,218,16,107,134,113,93,33,110,231,110,152,79,135,132,245,169,201,195,141,133, - 149,49,236,222,40,179,110,215,143,43,176,217,63,70,120,126,141,141,185,222,214,243,31,50,77,124,34,176,20,164,223,0, - 0,0,0,73,69,78,68,174,66,96,130, -}; - -const uint8_t file[844] = { - 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122, - 244,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,0,3,3,73,68,65,84,88,133,229,151,79,110,212, - 48,24,197,127,182,227,56,81,39,116,36,132,0,169,167,226,2,101,209,93,239,192,150,37,171,46,43,245,4,92,164,183, - 40,82,89,21,36,134,84,76,18,59,44,90,91,142,243,103,50,21,59,62,201,138,227,120,236,247,189,247,252,37,3,255, - 123,136,116,224,234,234,234,67,150,101,55,64,165,148,66,74,137,115,14,107,109,104,93,215,133,107,220,95,26,3,118,93, - 215,125,188,185,185,249,26,239,151,141,16,9,113,125,113,113,81,61,247,195,120,223,247,131,121,241,253,202,126,117,121,121, - 121,13,44,3,176,214,110,1,110,111,111,17,66,32,165,12,87,41,37,74,41,148,82,8,33,80,74,177,221,110,209,90, - 15,158,167,125,33,4,251,253,158,166,105,182,233,126,50,29,232,251,30,33,68,104,64,88,208,55,207,78,215,117,24,99, - 70,191,247,109,77,140,24,112,206,133,13,98,6,210,38,165,164,40,138,48,127,42,60,16,159,200,20,168,17,3,206,185, - 17,11,177,4,49,40,231,28,77,211,28,204,114,137,141,17,0,107,109,232,207,177,224,159,41,165,208,90,31,100,97,9, - 200,36,3,233,230,233,189,181,150,60,207,41,203,146,186,174,233,186,46,204,91,202,124,21,0,207,192,156,9,1,140,49, - 20,69,65,93,215,100,89,70,158,231,3,173,231,50,127,17,128,88,123,127,239,105,55,198,96,140,161,109,219,85,174,95, - 13,96,202,132,41,35,62,218,182,5,240,213,110,113,211,163,25,72,179,23,66,208,52,13,90,235,80,92,252,243,199,199, - 199,229,244,97,210,172,7,37,136,93,47,165,164,170,42,178,44,67,8,193,201,201,73,232,151,101,57,152,63,197,194,139, - 37,136,77,168,181,198,90,27,42,97,215,117,97,222,210,113,92,205,128,215,50,205,222,103,16,75,226,156,11,12,120,64, - 62,203,41,38,142,146,32,213,190,239,123,172,181,225,69,228,105,143,193,214,117,141,115,110,86,134,163,0,196,11,11,33, - 200,178,140,170,170,6,115,235,186,14,114,120,79,40,165,70,155,28,205,64,74,181,7,32,165,28,248,195,24,67,158,231, - 1,172,82,106,117,89,158,5,144,158,231,212,7,113,40,165,6,12,120,169,210,170,184,20,171,142,161,47,54,177,254,254, - 236,123,205,227,58,177,219,237,86,3,152,250,34,26,80,37,132,96,179,217,80,150,229,200,96,155,205,6,173,245,96,190, - 49,38,48,177,6,196,162,9,189,15,178,44,27,140,123,96,109,219,142,36,136,95,90,107,98,214,3,177,9,211,240,99, - 190,8,77,197,161,162,52,11,32,149,96,238,37,3,79,18,164,0,60,232,135,135,135,17,107,171,1,132,135,82,6,157, - 227,240,0,119,187,221,8,160,63,5,167,167,167,65,138,163,62,201,226,5,189,235,167,88,232,251,30,173,245,36,56,95, - 71,252,247,229,82,164,167,160,146,82,254,234,251,254,213,217,217,89,24,156,211,185,40,138,197,197,211,242,155,231,249,14, - 120,7,252,4,246,41,128,10,120,115,127,127,255,249,252,252,252,19,80,46,174,190,50,242,60,167,105,26,132,16,127,238, - 238,238,190,0,239,1,5,124,7,92,156,90,14,188,5,94,3,91,192,60,79,252,23,241,135,167,100,107,224,7,240,13, - 248,13,19,127,78,159,55,46,158,1,173,43,103,135,195,1,45,79,180,239,129,96,140,191,182,58,238,12,241,249,173,246, - 0,0,0,0,73,69,78,68,174,66,96,130, -}; - -const uint8_t archive[1067] = { - 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122, - 244,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,0,3,226,73,68,65,84,88,133,237,150,95,136,212, - 85,20,199,63,231,222,251,251,253,102,102,103,255,142,166,27,150,150,88,144,102,127,31,218,40,49,200,36,136,68,200,30, - 20,218,212,13,89,84,8,138,30,138,222,10,122,232,205,212,44,89,55,145,192,146,32,168,232,37,42,208,212,84,212,165, - 32,162,168,101,21,203,221,213,253,51,237,56,51,191,223,189,61,252,134,217,217,117,86,155,26,240,161,253,194,225,222,115, - 239,253,157,251,189,231,158,223,57,23,102,49,139,255,59,228,90,147,189,47,164,151,26,63,120,51,12,243,107,156,184,60, - 14,59,229,75,135,2,130,234,70,5,45,114,196,89,121,233,185,247,198,142,215,68,96,223,150,166,37,126,144,58,168,148, - 190,115,249,163,107,82,205,109,237,68,81,136,32,24,63,0,229,163,76,2,209,1,202,76,138,232,4,202,11,80,58,32, - 180,206,253,240,117,143,244,159,250,232,47,27,113,209,138,125,165,115,87,246,208,117,9,236,239,106,190,77,18,254,137,101, - 43,58,91,231,45,186,67,141,12,156,117,103,15,127,38,78,0,231,112,81,30,163,4,163,193,211,130,209,130,167,193,76, - 235,39,146,45,100,30,123,195,93,56,190,215,133,131,167,213,207,231,70,115,69,203,182,141,239,142,247,84,238,167,43,149, - 3,93,201,5,36,147,199,239,93,221,221,182,248,129,213,122,252,66,31,167,191,249,88,10,133,43,216,40,196,218,8,37, - 160,68,80,10,180,18,148,18,180,2,53,173,47,46,79,225,242,79,114,83,199,139,146,255,227,20,173,137,208,27,30,203, - 175,122,250,65,51,240,233,201,98,223,85,30,120,191,171,97,94,50,149,60,185,108,229,166,246,246,37,29,218,141,253,138, - 23,52,80,140,38,157,100,157,5,107,65,25,68,123,177,168,88,40,181,162,13,136,46,27,78,54,207,167,144,27,167,175, - 119,45,162,52,191,93,24,155,112,214,110,234,220,147,61,88,38,208,179,49,61,55,104,76,29,107,91,176,116,161,56,114, - 67,3,125,233,71,158,121,141,230,185,183,146,27,57,55,121,95,162,64,52,136,138,5,13,74,226,13,69,202,115,18,7, - 40,0,65,67,134,200,193,151,59,214,227,108,33,151,12,252,68,54,151,15,113,172,239,220,147,61,36,123,55,55,181,25, - 99,135,1,252,32,117,62,44,230,191,187,253,190,39,215,221,179,122,27,209,200,47,224,44,206,89,112,46,182,234,92,172, - 151,250,255,100,204,207,220,69,118,228,34,95,125,240,242,69,92,120,38,178,246,9,0,177,108,85,198,68,111,3,160,100, - 205,149,98,126,69,208,152,121,106,249,170,173,68,163,191,99,139,19,216,98,14,23,94,41,139,13,167,233,197,220,117,199, - 242,127,158,165,113,206,34,238,94,185,161,69,180,30,182,74,47,22,56,234,20,59,167,252,5,7,182,207,57,252,248,230, - 221,15,167,51,11,175,153,31,254,11,190,221,191,61,55,116,254,199,141,157,187,42,98,0,96,95,119,211,67,98,237,81, - 165,117,81,68,121,162,52,206,70,53,152,118,51,206,136,196,182,28,46,111,163,40,0,120,126,79,86,166,16,112,32,31, - 118,55,183,0,20,109,116,169,99,237,171,12,28,235,169,110,177,70,220,124,255,58,190,255,124,7,158,210,109,0,158,248, - 197,103,119,13,102,1,76,153,37,56,118,143,94,6,232,221,146,38,145,74,147,76,165,235,66,32,72,54,2,176,161,100, - 191,18,230,170,213,37,40,109,240,147,13,117,33,160,141,55,227,220,140,4,180,241,240,19,245,241,128,54,126,237,4,140, - 246,8,18,245,241,128,249,247,30,184,145,4,60,143,160,78,49,96,252,242,21,248,64,225,90,4,2,160,21,226,138,103, - 252,20,184,90,114,65,21,136,66,169,114,209,189,5,24,3,46,1,81,53,2,205,64,198,41,111,112,184,255,204,220,204, - 194,142,210,112,69,146,113,149,9,199,149,117,87,117,77,220,14,245,247,97,197,27,2,230,151,246,140,74,36,166,16,208, - 37,221,251,226,244,196,91,216,157,175,11,97,75,141,231,173,10,135,25,249,228,196,196,59,64,2,240,168,120,135,76,207, - 249,173,64,166,212,6,196,119,86,15,20,0,5,100,137,79,126,30,40,86,35,0,144,4,90,74,155,207,24,164,53,34, - 36,190,143,81,96,28,38,31,183,215,171,122,245,170,138,51,87,170,89,220,104,252,13,162,179,143,166,193,167,182,66,0, - 0,0,0,73,69,78,68,174,66,96,130, -}; - -}; diff --git a/purify/resource/resource.hpp b/purify/resource/resource.hpp deleted file mode 100644 index 512a061a..00000000 --- a/purify/resource/resource.hpp +++ /dev/null @@ -1,6 +0,0 @@ -namespace resource { - extern const uint8_t game[1490]; - extern const uint8_t unverified[1675]; - extern const uint8_t file[844]; - extern const uint8_t archive[1067]; -}; diff --git a/purify/resource/unverified.png b/purify/resource/unverified.png deleted file mode 100644 index 8a150b84..00000000 Binary files a/purify/resource/unverified.png and /dev/null differ diff --git a/higan/ruby/Makefile b/ruby/Makefile old mode 100755 new mode 100644 similarity index 95% rename from higan/ruby/Makefile rename to ruby/Makefile index 83bb357a..42726af5 --- a/higan/ruby/Makefile +++ b/ruby/Makefile @@ -5,7 +5,7 @@ else endif rubyflags += $(foreach c,$(subst .,_,$(call strupper,$(ruby))),-D$c) -rubyflags += $(if $(finstring .sdl,$(ruby)),`sdl-config --cflags`) +rubyflags += $(if $(findstring .sdl,$(ruby)),`sdl-config --cflags`) rubylink = diff --git a/higan/ruby/audio.hpp b/ruby/audio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio.hpp rename to ruby/audio.hpp diff --git a/higan/ruby/audio/alsa.cpp b/ruby/audio/alsa.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/alsa.cpp rename to ruby/audio/alsa.cpp diff --git a/higan/ruby/audio/ao.cpp b/ruby/audio/ao.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/ao.cpp rename to ruby/audio/ao.cpp diff --git a/higan/ruby/audio/directsound.cpp b/ruby/audio/directsound.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/directsound.cpp rename to ruby/audio/directsound.cpp diff --git a/higan/ruby/audio/openal.cpp b/ruby/audio/openal.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/openal.cpp rename to ruby/audio/openal.cpp diff --git a/higan/ruby/audio/oss.cpp b/ruby/audio/oss.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/oss.cpp rename to ruby/audio/oss.cpp diff --git a/higan/ruby/audio/pulseaudio.cpp b/ruby/audio/pulseaudio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/pulseaudio.cpp rename to ruby/audio/pulseaudio.cpp diff --git a/higan/ruby/audio/pulseaudiosimple.cpp b/ruby/audio/pulseaudiosimple.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/pulseaudiosimple.cpp rename to ruby/audio/pulseaudiosimple.cpp diff --git a/higan/ruby/audio/xaudio2.cpp b/ruby/audio/xaudio2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/xaudio2.cpp rename to ruby/audio/xaudio2.cpp diff --git a/higan/ruby/audio/xaudio2.hpp b/ruby/audio/xaudio2.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/audio/xaudio2.hpp rename to ruby/audio/xaudio2.hpp diff --git a/higan/ruby/implementation.cpp b/ruby/implementation.cpp similarity index 100% rename from higan/ruby/implementation.cpp rename to ruby/implementation.cpp diff --git a/higan/ruby/input.hpp b/ruby/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input.hpp rename to ruby/input.hpp diff --git a/higan/ruby/input/carbon.cpp b/ruby/input/carbon.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/carbon.cpp rename to ruby/input/carbon.cpp diff --git a/higan/ruby/input/directinput.cpp b/ruby/input/directinput.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/directinput.cpp rename to ruby/input/directinput.cpp diff --git a/higan/ruby/input/rawinput.cpp b/ruby/input/rawinput.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/rawinput.cpp rename to ruby/input/rawinput.cpp diff --git a/higan/ruby/input/sdl.cpp b/ruby/input/sdl.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/sdl.cpp rename to ruby/input/sdl.cpp diff --git a/higan/ruby/input/x.cpp b/ruby/input/x.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/x.cpp rename to ruby/input/x.cpp diff --git a/higan/ruby/input/xlibkeys.hpp b/ruby/input/xlibkeys.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/input/xlibkeys.hpp rename to ruby/input/xlibkeys.hpp diff --git a/higan/ruby/ruby.cpp b/ruby/ruby.cpp old mode 100755 new mode 100644 similarity index 99% rename from higan/ruby/ruby.cpp rename to ruby/ruby.cpp index 68d89165..2d98dacd --- a/higan/ruby/ruby.cpp +++ b/ruby/ruby.cpp @@ -184,6 +184,7 @@ bool VideoInterface::init() { void VideoInterface::term() { if(p) { + p->term(); delete p; p = nullptr; } @@ -345,6 +346,7 @@ bool AudioInterface::init() { void AudioInterface::term() { if(p) { + p->term(); delete p; p = nullptr; } @@ -472,6 +474,7 @@ bool InputInterface::init() { void InputInterface::term() { if(p) { + p->term(); delete p; p = nullptr; } diff --git a/higan/ruby/ruby.hpp b/ruby/ruby.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/ruby.hpp rename to ruby/ruby.hpp diff --git a/higan/ruby/video.hpp b/ruby/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video.hpp rename to ruby/video.hpp diff --git a/higan/ruby/video/cgl.cpp b/ruby/video/cgl.cpp similarity index 100% rename from higan/ruby/video/cgl.cpp rename to ruby/video/cgl.cpp diff --git a/higan/ruby/video/direct3d.cpp b/ruby/video/direct3d.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/direct3d.cpp rename to ruby/video/direct3d.cpp diff --git a/higan/ruby/video/directdraw.cpp b/ruby/video/directdraw.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/directdraw.cpp rename to ruby/video/directdraw.cpp diff --git a/higan/ruby/video/gdi.cpp b/ruby/video/gdi.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/gdi.cpp rename to ruby/video/gdi.cpp diff --git a/higan/ruby/video/glx.cpp b/ruby/video/glx.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/glx.cpp rename to ruby/video/glx.cpp diff --git a/higan/ruby/video/opengl/bind.hpp b/ruby/video/opengl/bind.hpp similarity index 100% rename from higan/ruby/video/opengl/bind.hpp rename to ruby/video/opengl/bind.hpp diff --git a/higan/ruby/video/opengl/main.hpp b/ruby/video/opengl/main.hpp similarity index 100% rename from higan/ruby/video/opengl/main.hpp rename to ruby/video/opengl/main.hpp diff --git a/higan/ruby/video/opengl/opengl.hpp b/ruby/video/opengl/opengl.hpp similarity index 100% rename from higan/ruby/video/opengl/opengl.hpp rename to ruby/video/opengl/opengl.hpp diff --git a/higan/ruby/video/opengl/program.hpp b/ruby/video/opengl/program.hpp similarity index 100% rename from higan/ruby/video/opengl/program.hpp rename to ruby/video/opengl/program.hpp diff --git a/higan/ruby/video/opengl/shaders.hpp b/ruby/video/opengl/shaders.hpp similarity index 100% rename from higan/ruby/video/opengl/shaders.hpp rename to ruby/video/opengl/shaders.hpp diff --git a/higan/ruby/video/opengl/surface.hpp b/ruby/video/opengl/surface.hpp similarity index 100% rename from higan/ruby/video/opengl/surface.hpp rename to ruby/video/opengl/surface.hpp diff --git a/higan/ruby/video/opengl/utility.hpp b/ruby/video/opengl/utility.hpp similarity index 100% rename from higan/ruby/video/opengl/utility.hpp rename to ruby/video/opengl/utility.hpp diff --git a/higan/ruby/video/sdl.cpp b/ruby/video/sdl.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/sdl.cpp rename to ruby/video/sdl.cpp diff --git a/higan/ruby/video/wgl.cpp b/ruby/video/wgl.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/wgl.cpp rename to ruby/video/wgl.cpp diff --git a/higan/ruby/video/xshm.cpp b/ruby/video/xshm.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/xshm.cpp rename to ruby/video/xshm.cpp diff --git a/higan/ruby/video/xv.cpp b/ruby/video/xv.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/ruby/video/xv.cpp rename to ruby/video/xv.cpp diff --git a/higan/sfc/Makefile b/sfc/Makefile old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/Makefile rename to sfc/Makefile diff --git a/higan/sfc/alt/cpu/cpu.cpp b/sfc/alt/cpu/cpu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/cpu.cpp rename to sfc/alt/cpu/cpu.cpp diff --git a/higan/sfc/alt/cpu/cpu.hpp b/sfc/alt/cpu/cpu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/cpu.hpp rename to sfc/alt/cpu/cpu.hpp diff --git a/higan/sfc/alt/cpu/dma.cpp b/sfc/alt/cpu/dma.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/dma.cpp rename to sfc/alt/cpu/dma.cpp diff --git a/higan/sfc/alt/cpu/memory.cpp b/sfc/alt/cpu/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/memory.cpp rename to sfc/alt/cpu/memory.cpp diff --git a/higan/sfc/alt/cpu/mmio.cpp b/sfc/alt/cpu/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/mmio.cpp rename to sfc/alt/cpu/mmio.cpp diff --git a/higan/sfc/alt/cpu/serialization.cpp b/sfc/alt/cpu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/serialization.cpp rename to sfc/alt/cpu/serialization.cpp diff --git a/higan/sfc/alt/cpu/timing.cpp b/sfc/alt/cpu/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/cpu/timing.cpp rename to sfc/alt/cpu/timing.cpp diff --git a/higan/sfc/alt/dsp/SPC_DSP.cpp b/sfc/alt/dsp/SPC_DSP.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/SPC_DSP.cpp rename to sfc/alt/dsp/SPC_DSP.cpp diff --git a/higan/sfc/alt/dsp/SPC_DSP.h b/sfc/alt/dsp/SPC_DSP.h old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/SPC_DSP.h rename to sfc/alt/dsp/SPC_DSP.h diff --git a/higan/sfc/alt/dsp/blargg_common.h b/sfc/alt/dsp/blargg_common.h old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/blargg_common.h rename to sfc/alt/dsp/blargg_common.h diff --git a/higan/sfc/alt/dsp/blargg_config.h b/sfc/alt/dsp/blargg_config.h old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/blargg_config.h rename to sfc/alt/dsp/blargg_config.h diff --git a/higan/sfc/alt/dsp/blargg_endian.h b/sfc/alt/dsp/blargg_endian.h old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/blargg_endian.h rename to sfc/alt/dsp/blargg_endian.h diff --git a/higan/sfc/alt/dsp/blargg_source.h b/sfc/alt/dsp/blargg_source.h old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/blargg_source.h rename to sfc/alt/dsp/blargg_source.h diff --git a/higan/sfc/alt/dsp/dsp.cpp b/sfc/alt/dsp/dsp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/dsp.cpp rename to sfc/alt/dsp/dsp.cpp diff --git a/higan/sfc/alt/dsp/dsp.hpp b/sfc/alt/dsp/dsp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/dsp.hpp rename to sfc/alt/dsp/dsp.hpp diff --git a/higan/sfc/alt/dsp/serialization.cpp b/sfc/alt/dsp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/dsp/serialization.cpp rename to sfc/alt/dsp/serialization.cpp diff --git a/higan/sfc/alt/ppu-balanced/memory/memory.cpp b/sfc/alt/ppu-balanced/memory/memory.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/memory/memory.cpp rename to sfc/alt/ppu-balanced/memory/memory.cpp diff --git a/higan/sfc/alt/ppu-balanced/memory/memory.hpp b/sfc/alt/ppu-balanced/memory/memory.hpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/memory/memory.hpp rename to sfc/alt/ppu-balanced/memory/memory.hpp diff --git a/higan/sfc/alt/ppu-balanced/mmio/mmio.cpp b/sfc/alt/ppu-balanced/mmio/mmio.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/mmio/mmio.cpp rename to sfc/alt/ppu-balanced/mmio/mmio.cpp diff --git a/higan/sfc/alt/ppu-balanced/mmio/mmio.hpp b/sfc/alt/ppu-balanced/mmio/mmio.hpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/mmio/mmio.hpp rename to sfc/alt/ppu-balanced/mmio/mmio.hpp diff --git a/higan/sfc/alt/ppu-balanced/ppu.cpp b/sfc/alt/ppu-balanced/ppu.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/ppu.cpp rename to sfc/alt/ppu-balanced/ppu.cpp diff --git a/higan/sfc/alt/ppu-balanced/ppu.hpp b/sfc/alt/ppu-balanced/ppu.hpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/ppu.hpp rename to sfc/alt/ppu-balanced/ppu.hpp diff --git a/higan/sfc/alt/ppu-balanced/render/addsub.cpp b/sfc/alt/ppu-balanced/render/addsub.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/addsub.cpp rename to sfc/alt/ppu-balanced/render/addsub.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/bg.cpp b/sfc/alt/ppu-balanced/render/bg.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/bg.cpp rename to sfc/alt/ppu-balanced/render/bg.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/cache.cpp b/sfc/alt/ppu-balanced/render/cache.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/cache.cpp rename to sfc/alt/ppu-balanced/render/cache.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/line.cpp b/sfc/alt/ppu-balanced/render/line.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/line.cpp rename to sfc/alt/ppu-balanced/render/line.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/mode7.cpp b/sfc/alt/ppu-balanced/render/mode7.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/mode7.cpp rename to sfc/alt/ppu-balanced/render/mode7.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/oam.cpp b/sfc/alt/ppu-balanced/render/oam.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/oam.cpp rename to sfc/alt/ppu-balanced/render/oam.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/render.cpp b/sfc/alt/ppu-balanced/render/render.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/render.cpp rename to sfc/alt/ppu-balanced/render/render.cpp diff --git a/higan/sfc/alt/ppu-balanced/render/render.hpp b/sfc/alt/ppu-balanced/render/render.hpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/render.hpp rename to sfc/alt/ppu-balanced/render/render.hpp diff --git a/higan/sfc/alt/ppu-balanced/render/windows.cpp b/sfc/alt/ppu-balanced/render/windows.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/render/windows.cpp rename to sfc/alt/ppu-balanced/render/windows.cpp diff --git a/higan/sfc/alt/ppu-balanced/serialization.cpp b/sfc/alt/ppu-balanced/serialization.cpp similarity index 100% rename from higan/sfc/alt/ppu-balanced/serialization.cpp rename to sfc/alt/ppu-balanced/serialization.cpp diff --git a/higan/sfc/alt/ppu-performance/background/background.cpp b/sfc/alt/ppu-performance/background/background.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/background/background.cpp rename to sfc/alt/ppu-performance/background/background.cpp diff --git a/higan/sfc/alt/ppu-performance/background/background.hpp b/sfc/alt/ppu-performance/background/background.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/background/background.hpp rename to sfc/alt/ppu-performance/background/background.hpp diff --git a/higan/sfc/alt/ppu-performance/background/mode7.cpp b/sfc/alt/ppu-performance/background/mode7.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/background/mode7.cpp rename to sfc/alt/ppu-performance/background/mode7.cpp diff --git a/higan/sfc/alt/ppu-performance/cache/cache.cpp b/sfc/alt/ppu-performance/cache/cache.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/cache/cache.cpp rename to sfc/alt/ppu-performance/cache/cache.cpp diff --git a/higan/sfc/alt/ppu-performance/cache/cache.hpp b/sfc/alt/ppu-performance/cache/cache.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/cache/cache.hpp rename to sfc/alt/ppu-performance/cache/cache.hpp diff --git a/higan/sfc/alt/ppu-performance/mmio/mmio.cpp b/sfc/alt/ppu-performance/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/mmio/mmio.cpp rename to sfc/alt/ppu-performance/mmio/mmio.cpp diff --git a/higan/sfc/alt/ppu-performance/mmio/mmio.hpp b/sfc/alt/ppu-performance/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/mmio/mmio.hpp rename to sfc/alt/ppu-performance/mmio/mmio.hpp diff --git a/higan/sfc/alt/ppu-performance/ppu.cpp b/sfc/alt/ppu-performance/ppu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/ppu.cpp rename to sfc/alt/ppu-performance/ppu.cpp diff --git a/higan/sfc/alt/ppu-performance/ppu.hpp b/sfc/alt/ppu-performance/ppu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/ppu.hpp rename to sfc/alt/ppu-performance/ppu.hpp diff --git a/higan/sfc/alt/ppu-performance/screen/screen.cpp b/sfc/alt/ppu-performance/screen/screen.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/screen/screen.cpp rename to sfc/alt/ppu-performance/screen/screen.cpp diff --git a/higan/sfc/alt/ppu-performance/screen/screen.hpp b/sfc/alt/ppu-performance/screen/screen.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/screen/screen.hpp rename to sfc/alt/ppu-performance/screen/screen.hpp diff --git a/higan/sfc/alt/ppu-performance/serialization.cpp b/sfc/alt/ppu-performance/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/serialization.cpp rename to sfc/alt/ppu-performance/serialization.cpp diff --git a/higan/sfc/alt/ppu-performance/sprite/sprite.cpp b/sfc/alt/ppu-performance/sprite/sprite.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/sprite/sprite.cpp rename to sfc/alt/ppu-performance/sprite/sprite.cpp diff --git a/higan/sfc/alt/ppu-performance/sprite/sprite.hpp b/sfc/alt/ppu-performance/sprite/sprite.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/sprite/sprite.hpp rename to sfc/alt/ppu-performance/sprite/sprite.hpp diff --git a/higan/sfc/alt/ppu-performance/window/window.cpp b/sfc/alt/ppu-performance/window/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/window/window.cpp rename to sfc/alt/ppu-performance/window/window.cpp diff --git a/higan/sfc/alt/ppu-performance/window/window.hpp b/sfc/alt/ppu-performance/window/window.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/ppu-performance/window/window.hpp rename to sfc/alt/ppu-performance/window/window.hpp diff --git a/higan/sfc/alt/smp/algorithms.cpp b/sfc/alt/smp/algorithms.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/algorithms.cpp rename to sfc/alt/smp/algorithms.cpp diff --git a/higan/sfc/alt/smp/core.cpp b/sfc/alt/smp/core.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core.cpp rename to sfc/alt/smp/core.cpp diff --git a/higan/sfc/alt/smp/core/cc.sh b/sfc/alt/smp/core/cc.sh old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/cc.sh rename to sfc/alt/smp/core/cc.sh diff --git a/higan/sfc/alt/smp/core/generate.cpp b/sfc/alt/smp/core/generate.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/generate.cpp rename to sfc/alt/smp/core/generate.cpp diff --git a/higan/sfc/alt/smp/core/op_misc.b b/sfc/alt/smp/core/op_misc.b old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_misc.b rename to sfc/alt/smp/core/op_misc.b diff --git a/higan/sfc/alt/smp/core/op_misc.cpp b/sfc/alt/smp/core/op_misc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_misc.cpp rename to sfc/alt/smp/core/op_misc.cpp diff --git a/higan/sfc/alt/smp/core/op_mov.b b/sfc/alt/smp/core/op_mov.b old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_mov.b rename to sfc/alt/smp/core/op_mov.b diff --git a/higan/sfc/alt/smp/core/op_mov.cpp b/sfc/alt/smp/core/op_mov.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_mov.cpp rename to sfc/alt/smp/core/op_mov.cpp diff --git a/higan/sfc/alt/smp/core/op_pc.b b/sfc/alt/smp/core/op_pc.b old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_pc.b rename to sfc/alt/smp/core/op_pc.b diff --git a/higan/sfc/alt/smp/core/op_pc.cpp b/sfc/alt/smp/core/op_pc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_pc.cpp rename to sfc/alt/smp/core/op_pc.cpp diff --git a/higan/sfc/alt/smp/core/op_read.b b/sfc/alt/smp/core/op_read.b old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_read.b rename to sfc/alt/smp/core/op_read.b diff --git a/higan/sfc/alt/smp/core/op_read.cpp b/sfc/alt/smp/core/op_read.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_read.cpp rename to sfc/alt/smp/core/op_read.cpp diff --git a/higan/sfc/alt/smp/core/op_rmw.b b/sfc/alt/smp/core/op_rmw.b old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_rmw.b rename to sfc/alt/smp/core/op_rmw.b diff --git a/higan/sfc/alt/smp/core/op_rmw.cpp b/sfc/alt/smp/core/op_rmw.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/op_rmw.cpp rename to sfc/alt/smp/core/op_rmw.cpp diff --git a/higan/sfc/alt/smp/core/opcycle_misc.cpp b/sfc/alt/smp/core/opcycle_misc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/opcycle_misc.cpp rename to sfc/alt/smp/core/opcycle_misc.cpp diff --git a/higan/sfc/alt/smp/core/opcycle_mov.cpp b/sfc/alt/smp/core/opcycle_mov.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/opcycle_mov.cpp rename to sfc/alt/smp/core/opcycle_mov.cpp diff --git a/higan/sfc/alt/smp/core/opcycle_pc.cpp b/sfc/alt/smp/core/opcycle_pc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/opcycle_pc.cpp rename to sfc/alt/smp/core/opcycle_pc.cpp diff --git a/higan/sfc/alt/smp/core/opcycle_read.cpp b/sfc/alt/smp/core/opcycle_read.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/opcycle_read.cpp rename to sfc/alt/smp/core/opcycle_read.cpp diff --git a/higan/sfc/alt/smp/core/opcycle_rmw.cpp b/sfc/alt/smp/core/opcycle_rmw.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/core/opcycle_rmw.cpp rename to sfc/alt/smp/core/opcycle_rmw.cpp diff --git a/higan/sfc/alt/smp/disassembler.cpp b/sfc/alt/smp/disassembler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/disassembler.cpp rename to sfc/alt/smp/disassembler.cpp diff --git a/higan/sfc/alt/smp/memory.cpp b/sfc/alt/smp/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/memory.cpp rename to sfc/alt/smp/memory.cpp diff --git a/higan/sfc/alt/smp/smp.cpp b/sfc/alt/smp/smp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/smp.cpp rename to sfc/alt/smp/smp.cpp diff --git a/higan/sfc/alt/smp/smp.hpp b/sfc/alt/smp/smp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/smp.hpp rename to sfc/alt/smp/smp.hpp diff --git a/higan/sfc/alt/smp/timing.cpp b/sfc/alt/smp/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/alt/smp/timing.cpp rename to sfc/alt/smp/timing.cpp diff --git a/higan/sfc/base/base.hpp b/sfc/base/base.hpp similarity index 100% rename from higan/sfc/base/base.hpp rename to sfc/base/base.hpp diff --git a/higan/sfc/base/satellaview/satellaview.cpp b/sfc/base/satellaview/satellaview.cpp similarity index 100% rename from higan/sfc/base/satellaview/satellaview.cpp rename to sfc/base/satellaview/satellaview.cpp diff --git a/higan/sfc/base/satellaview/satellaview.hpp b/sfc/base/satellaview/satellaview.hpp similarity index 100% rename from higan/sfc/base/satellaview/satellaview.hpp rename to sfc/base/satellaview/satellaview.hpp diff --git a/higan/sfc/cartridge/cartridge.cpp b/sfc/cartridge/cartridge.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cartridge/cartridge.cpp rename to sfc/cartridge/cartridge.cpp diff --git a/higan/sfc/cartridge/cartridge.hpp b/sfc/cartridge/cartridge.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cartridge/cartridge.hpp rename to sfc/cartridge/cartridge.hpp diff --git a/higan/sfc/cartridge/markup.cpp b/sfc/cartridge/markup.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cartridge/markup.cpp rename to sfc/cartridge/markup.cpp diff --git a/higan/sfc/cartridge/serialization.cpp b/sfc/cartridge/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cartridge/serialization.cpp rename to sfc/cartridge/serialization.cpp diff --git a/higan/sfc/cheat/cheat.cpp b/sfc/cheat/cheat.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cheat/cheat.cpp rename to sfc/cheat/cheat.cpp diff --git a/higan/sfc/cheat/cheat.hpp b/sfc/cheat/cheat.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cheat/cheat.hpp rename to sfc/cheat/cheat.hpp diff --git a/higan/sfc/chip/armdsp/armdsp.cpp b/sfc/chip/armdsp/armdsp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/armdsp/armdsp.cpp rename to sfc/chip/armdsp/armdsp.cpp diff --git a/higan/sfc/chip/armdsp/armdsp.hpp b/sfc/chip/armdsp/armdsp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/armdsp/armdsp.hpp rename to sfc/chip/armdsp/armdsp.hpp diff --git a/higan/sfc/chip/armdsp/memory.cpp b/sfc/chip/armdsp/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/armdsp/memory.cpp rename to sfc/chip/armdsp/memory.cpp diff --git a/higan/sfc/chip/armdsp/registers.hpp b/sfc/chip/armdsp/registers.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/armdsp/registers.hpp rename to sfc/chip/armdsp/registers.hpp diff --git a/higan/sfc/chip/armdsp/serialization.cpp b/sfc/chip/armdsp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/armdsp/serialization.cpp rename to sfc/chip/armdsp/serialization.cpp diff --git a/higan/sfc/chip/bsx/bsx.cpp b/sfc/chip/bsx/bsx.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/bsx/bsx.cpp rename to sfc/chip/bsx/bsx.cpp diff --git a/higan/sfc/chip/bsx/bsx.hpp b/sfc/chip/bsx/bsx.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/bsx/bsx.hpp rename to sfc/chip/bsx/bsx.hpp diff --git a/higan/sfc/chip/bsx/serialization.cpp b/sfc/chip/bsx/serialization.cpp similarity index 100% rename from higan/sfc/chip/bsx/serialization.cpp rename to sfc/chip/bsx/serialization.cpp diff --git a/higan/sfc/chip/chip.hpp b/sfc/chip/chip.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/chip.hpp rename to sfc/chip/chip.hpp diff --git a/higan/sfc/chip/epsonrtc/epsonrtc.cpp b/sfc/chip/epsonrtc/epsonrtc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/epsonrtc/epsonrtc.cpp rename to sfc/chip/epsonrtc/epsonrtc.cpp diff --git a/higan/sfc/chip/epsonrtc/epsonrtc.hpp b/sfc/chip/epsonrtc/epsonrtc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/epsonrtc/epsonrtc.hpp rename to sfc/chip/epsonrtc/epsonrtc.hpp diff --git a/higan/sfc/chip/epsonrtc/memory.cpp b/sfc/chip/epsonrtc/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/epsonrtc/memory.cpp rename to sfc/chip/epsonrtc/memory.cpp diff --git a/higan/sfc/chip/epsonrtc/serialization.cpp b/sfc/chip/epsonrtc/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/epsonrtc/serialization.cpp rename to sfc/chip/epsonrtc/serialization.cpp diff --git a/higan/sfc/chip/epsonrtc/time.cpp b/sfc/chip/epsonrtc/time.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/epsonrtc/time.cpp rename to sfc/chip/epsonrtc/time.cpp diff --git a/higan/sfc/chip/event/event.cpp b/sfc/chip/event/event.cpp similarity index 100% rename from higan/sfc/chip/event/event.cpp rename to sfc/chip/event/event.cpp diff --git a/higan/sfc/chip/event/event.hpp b/sfc/chip/event/event.hpp similarity index 100% rename from higan/sfc/chip/event/event.hpp rename to sfc/chip/event/event.hpp diff --git a/higan/sfc/chip/hitachidsp/hitachidsp.cpp b/sfc/chip/hitachidsp/hitachidsp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/hitachidsp/hitachidsp.cpp rename to sfc/chip/hitachidsp/hitachidsp.cpp diff --git a/higan/sfc/chip/hitachidsp/hitachidsp.hpp b/sfc/chip/hitachidsp/hitachidsp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/hitachidsp/hitachidsp.hpp rename to sfc/chip/hitachidsp/hitachidsp.hpp diff --git a/higan/sfc/chip/hitachidsp/memory.cpp b/sfc/chip/hitachidsp/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/hitachidsp/memory.cpp rename to sfc/chip/hitachidsp/memory.cpp diff --git a/higan/sfc/chip/hitachidsp/mmio.hpp b/sfc/chip/hitachidsp/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/hitachidsp/mmio.hpp rename to sfc/chip/hitachidsp/mmio.hpp diff --git a/higan/sfc/chip/hitachidsp/serialization.cpp b/sfc/chip/hitachidsp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/hitachidsp/serialization.cpp rename to sfc/chip/hitachidsp/serialization.cpp diff --git a/higan/sfc/chip/hsu1/hsu1.cpp b/sfc/chip/hsu1/hsu1.cpp similarity index 100% rename from higan/sfc/chip/hsu1/hsu1.cpp rename to sfc/chip/hsu1/hsu1.cpp diff --git a/higan/sfc/chip/hsu1/hsu1.hpp b/sfc/chip/hsu1/hsu1.hpp similarity index 100% rename from higan/sfc/chip/hsu1/hsu1.hpp rename to sfc/chip/hsu1/hsu1.hpp diff --git a/higan/sfc/chip/hsu1/serialization.cpp b/sfc/chip/hsu1/serialization.cpp similarity index 100% rename from higan/sfc/chip/hsu1/serialization.cpp rename to sfc/chip/hsu1/serialization.cpp diff --git a/higan/sfc/chip/icd2/icd2.cpp b/sfc/chip/icd2/icd2.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/icd2.cpp rename to sfc/chip/icd2/icd2.cpp diff --git a/higan/sfc/chip/icd2/icd2.hpp b/sfc/chip/icd2/icd2.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/icd2.hpp rename to sfc/chip/icd2/icd2.hpp diff --git a/higan/sfc/chip/icd2/interface/interface.cpp b/sfc/chip/icd2/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/interface/interface.cpp rename to sfc/chip/icd2/interface/interface.cpp diff --git a/higan/sfc/chip/icd2/interface/interface.hpp b/sfc/chip/icd2/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/interface/interface.hpp rename to sfc/chip/icd2/interface/interface.hpp diff --git a/higan/sfc/chip/icd2/mmio/mmio.cpp b/sfc/chip/icd2/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/mmio/mmio.cpp rename to sfc/chip/icd2/mmio/mmio.cpp diff --git a/higan/sfc/chip/icd2/mmio/mmio.hpp b/sfc/chip/icd2/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/mmio/mmio.hpp rename to sfc/chip/icd2/mmio/mmio.hpp diff --git a/higan/sfc/chip/icd2/serialization.cpp b/sfc/chip/icd2/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/icd2/serialization.cpp rename to sfc/chip/icd2/serialization.cpp diff --git a/higan/sfc/chip/msu1/msu1.cpp b/sfc/chip/msu1/msu1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/msu1/msu1.cpp rename to sfc/chip/msu1/msu1.cpp diff --git a/higan/sfc/chip/msu1/msu1.hpp b/sfc/chip/msu1/msu1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/msu1/msu1.hpp rename to sfc/chip/msu1/msu1.hpp diff --git a/higan/sfc/chip/msu1/serialization.cpp b/sfc/chip/msu1/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/msu1/serialization.cpp rename to sfc/chip/msu1/serialization.cpp diff --git a/higan/sfc/chip/necdsp/necdsp.cpp b/sfc/chip/necdsp/necdsp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/necdsp/necdsp.cpp rename to sfc/chip/necdsp/necdsp.cpp diff --git a/higan/sfc/chip/necdsp/necdsp.hpp b/sfc/chip/necdsp/necdsp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/necdsp/necdsp.hpp rename to sfc/chip/necdsp/necdsp.hpp diff --git a/higan/sfc/chip/necdsp/serialization.cpp b/sfc/chip/necdsp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/necdsp/serialization.cpp rename to sfc/chip/necdsp/serialization.cpp diff --git a/higan/sfc/chip/nss/nss.cpp b/sfc/chip/nss/nss.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/nss/nss.cpp rename to sfc/chip/nss/nss.cpp diff --git a/higan/sfc/chip/nss/nss.hpp b/sfc/chip/nss/nss.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/nss/nss.hpp rename to sfc/chip/nss/nss.hpp diff --git a/higan/sfc/chip/obc1/obc1.cpp b/sfc/chip/obc1/obc1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/obc1/obc1.cpp rename to sfc/chip/obc1/obc1.cpp diff --git a/higan/sfc/chip/obc1/obc1.hpp b/sfc/chip/obc1/obc1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/obc1/obc1.hpp rename to sfc/chip/obc1/obc1.hpp diff --git a/higan/sfc/chip/obc1/serialization.cpp b/sfc/chip/obc1/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/obc1/serialization.cpp rename to sfc/chip/obc1/serialization.cpp diff --git a/higan/sfc/chip/sa1/bus/bus.cpp b/sfc/chip/sa1/bus/bus.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/bus/bus.cpp rename to sfc/chip/sa1/bus/bus.cpp diff --git a/higan/sfc/chip/sa1/bus/bus.hpp b/sfc/chip/sa1/bus/bus.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/bus/bus.hpp rename to sfc/chip/sa1/bus/bus.hpp diff --git a/higan/sfc/chip/sa1/dma/dma.cpp b/sfc/chip/sa1/dma/dma.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/dma/dma.cpp rename to sfc/chip/sa1/dma/dma.cpp diff --git a/higan/sfc/chip/sa1/dma/dma.hpp b/sfc/chip/sa1/dma/dma.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/dma/dma.hpp rename to sfc/chip/sa1/dma/dma.hpp diff --git a/higan/sfc/chip/sa1/memory/memory.cpp b/sfc/chip/sa1/memory/memory.cpp old mode 100755 new mode 100644 similarity index 99% rename from higan/sfc/chip/sa1/memory/memory.cpp rename to sfc/chip/sa1/memory/memory.cpp index 8f24db39..0c563c24 --- a/higan/sfc/chip/sa1/memory/memory.cpp +++ b/sfc/chip/sa1/memory/memory.cpp @@ -94,7 +94,7 @@ uint8 SA1::vbr_read(unsigned addr) { } if((addr & 0x40f800) == 0x003000) { //$00-3f|80-bf:3000-37ff - return iram.read(addr & 0x2047); + return iram.read(addr & 2047); } } diff --git a/higan/sfc/chip/sa1/memory/memory.hpp b/sfc/chip/sa1/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/memory/memory.hpp rename to sfc/chip/sa1/memory/memory.hpp diff --git a/higan/sfc/chip/sa1/mmio/mmio.cpp b/sfc/chip/sa1/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/mmio/mmio.cpp rename to sfc/chip/sa1/mmio/mmio.cpp diff --git a/higan/sfc/chip/sa1/mmio/mmio.hpp b/sfc/chip/sa1/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/mmio/mmio.hpp rename to sfc/chip/sa1/mmio/mmio.hpp diff --git a/higan/sfc/chip/sa1/sa1.cpp b/sfc/chip/sa1/sa1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/sa1.cpp rename to sfc/chip/sa1/sa1.cpp diff --git a/higan/sfc/chip/sa1/sa1.hpp b/sfc/chip/sa1/sa1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/sa1.hpp rename to sfc/chip/sa1/sa1.hpp diff --git a/higan/sfc/chip/sa1/serialization.cpp b/sfc/chip/sa1/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sa1/serialization.cpp rename to sfc/chip/sa1/serialization.cpp diff --git a/higan/sfc/chip/sdd1/decomp.cpp b/sfc/chip/sdd1/decomp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sdd1/decomp.cpp rename to sfc/chip/sdd1/decomp.cpp diff --git a/higan/sfc/chip/sdd1/decomp.hpp b/sfc/chip/sdd1/decomp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sdd1/decomp.hpp rename to sfc/chip/sdd1/decomp.hpp diff --git a/higan/sfc/chip/sdd1/sdd1.cpp b/sfc/chip/sdd1/sdd1.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sdd1/sdd1.cpp rename to sfc/chip/sdd1/sdd1.cpp diff --git a/higan/sfc/chip/sdd1/sdd1.hpp b/sfc/chip/sdd1/sdd1.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sdd1/sdd1.hpp rename to sfc/chip/sdd1/sdd1.hpp diff --git a/higan/sfc/chip/sdd1/serialization.cpp b/sfc/chip/sdd1/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sdd1/serialization.cpp rename to sfc/chip/sdd1/serialization.cpp diff --git a/higan/sfc/chip/sharprtc/memory.cpp b/sfc/chip/sharprtc/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sharprtc/memory.cpp rename to sfc/chip/sharprtc/memory.cpp diff --git a/higan/sfc/chip/sharprtc/serialization.cpp b/sfc/chip/sharprtc/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sharprtc/serialization.cpp rename to sfc/chip/sharprtc/serialization.cpp diff --git a/higan/sfc/chip/sharprtc/sharprtc.cpp b/sfc/chip/sharprtc/sharprtc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sharprtc/sharprtc.cpp rename to sfc/chip/sharprtc/sharprtc.cpp diff --git a/higan/sfc/chip/sharprtc/sharprtc.hpp b/sfc/chip/sharprtc/sharprtc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sharprtc/sharprtc.hpp rename to sfc/chip/sharprtc/sharprtc.hpp diff --git a/higan/sfc/chip/sharprtc/time.cpp b/sfc/chip/sharprtc/time.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/sharprtc/time.cpp rename to sfc/chip/sharprtc/time.cpp diff --git a/higan/sfc/chip/spc7110/alu.cpp b/sfc/chip/spc7110/alu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/alu.cpp rename to sfc/chip/spc7110/alu.cpp diff --git a/higan/sfc/chip/spc7110/data.cpp b/sfc/chip/spc7110/data.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/data.cpp rename to sfc/chip/spc7110/data.cpp diff --git a/higan/sfc/chip/spc7110/dcu.cpp b/sfc/chip/spc7110/dcu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/dcu.cpp rename to sfc/chip/spc7110/dcu.cpp diff --git a/higan/sfc/chip/spc7110/decompressor.cpp b/sfc/chip/spc7110/decompressor.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/decompressor.cpp rename to sfc/chip/spc7110/decompressor.cpp diff --git a/higan/sfc/chip/spc7110/serialization.cpp b/sfc/chip/spc7110/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/serialization.cpp rename to sfc/chip/spc7110/serialization.cpp diff --git a/higan/sfc/chip/spc7110/spc7110.cpp b/sfc/chip/spc7110/spc7110.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/spc7110.cpp rename to sfc/chip/spc7110/spc7110.cpp diff --git a/higan/sfc/chip/spc7110/spc7110.hpp b/sfc/chip/spc7110/spc7110.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/spc7110/spc7110.hpp rename to sfc/chip/spc7110/spc7110.hpp diff --git a/higan/sfc/chip/superfx/bus/bus.cpp b/sfc/chip/superfx/bus/bus.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/bus/bus.cpp rename to sfc/chip/superfx/bus/bus.cpp diff --git a/higan/sfc/chip/superfx/bus/bus.hpp b/sfc/chip/superfx/bus/bus.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/bus/bus.hpp rename to sfc/chip/superfx/bus/bus.hpp diff --git a/higan/sfc/chip/superfx/core/core.cpp b/sfc/chip/superfx/core/core.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/core/core.cpp rename to sfc/chip/superfx/core/core.cpp diff --git a/higan/sfc/chip/superfx/core/core.hpp b/sfc/chip/superfx/core/core.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/core/core.hpp rename to sfc/chip/superfx/core/core.hpp diff --git a/higan/sfc/chip/superfx/disasm/disasm.cpp b/sfc/chip/superfx/disasm/disasm.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/disasm/disasm.cpp rename to sfc/chip/superfx/disasm/disasm.cpp diff --git a/higan/sfc/chip/superfx/disasm/disasm.hpp b/sfc/chip/superfx/disasm/disasm.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/disasm/disasm.hpp rename to sfc/chip/superfx/disasm/disasm.hpp diff --git a/higan/sfc/chip/superfx/memory/memory.cpp b/sfc/chip/superfx/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/memory/memory.cpp rename to sfc/chip/superfx/memory/memory.cpp diff --git a/higan/sfc/chip/superfx/memory/memory.hpp b/sfc/chip/superfx/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/memory/memory.hpp rename to sfc/chip/superfx/memory/memory.hpp diff --git a/higan/sfc/chip/superfx/mmio/mmio.cpp b/sfc/chip/superfx/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/mmio/mmio.cpp rename to sfc/chip/superfx/mmio/mmio.cpp diff --git a/higan/sfc/chip/superfx/mmio/mmio.hpp b/sfc/chip/superfx/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/mmio/mmio.hpp rename to sfc/chip/superfx/mmio/mmio.hpp diff --git a/higan/sfc/chip/superfx/serialization.cpp b/sfc/chip/superfx/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/serialization.cpp rename to sfc/chip/superfx/serialization.cpp diff --git a/higan/sfc/chip/superfx/superfx.cpp b/sfc/chip/superfx/superfx.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/superfx.cpp rename to sfc/chip/superfx/superfx.cpp diff --git a/higan/sfc/chip/superfx/superfx.hpp b/sfc/chip/superfx/superfx.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/superfx.hpp rename to sfc/chip/superfx/superfx.hpp diff --git a/higan/sfc/chip/superfx/timing/timing.cpp b/sfc/chip/superfx/timing/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/timing/timing.cpp rename to sfc/chip/superfx/timing/timing.cpp diff --git a/higan/sfc/chip/superfx/timing/timing.hpp b/sfc/chip/superfx/timing/timing.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/chip/superfx/timing/timing.hpp rename to sfc/chip/superfx/timing/timing.hpp diff --git a/higan/sfc/config/config.cpp b/sfc/config/config.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/config/config.cpp rename to sfc/config/config.cpp diff --git a/higan/sfc/config/config.hpp b/sfc/config/config.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/config/config.hpp rename to sfc/config/config.hpp diff --git a/higan/sfc/controller/controller.cpp b/sfc/controller/controller.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/controller.cpp rename to sfc/controller/controller.cpp diff --git a/higan/sfc/controller/controller.hpp b/sfc/controller/controller.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/controller.hpp rename to sfc/controller/controller.hpp diff --git a/higan/sfc/controller/gamepad/gamepad.cpp b/sfc/controller/gamepad/gamepad.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/gamepad/gamepad.cpp rename to sfc/controller/gamepad/gamepad.cpp diff --git a/higan/sfc/controller/gamepad/gamepad.hpp b/sfc/controller/gamepad/gamepad.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/gamepad/gamepad.hpp rename to sfc/controller/gamepad/gamepad.hpp diff --git a/higan/sfc/controller/justifier/justifier.cpp b/sfc/controller/justifier/justifier.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/justifier/justifier.cpp rename to sfc/controller/justifier/justifier.cpp diff --git a/higan/sfc/controller/justifier/justifier.hpp b/sfc/controller/justifier/justifier.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/justifier/justifier.hpp rename to sfc/controller/justifier/justifier.hpp diff --git a/higan/sfc/controller/mouse/mouse.cpp b/sfc/controller/mouse/mouse.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/mouse/mouse.cpp rename to sfc/controller/mouse/mouse.cpp diff --git a/higan/sfc/controller/mouse/mouse.hpp b/sfc/controller/mouse/mouse.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/mouse/mouse.hpp rename to sfc/controller/mouse/mouse.hpp diff --git a/higan/sfc/controller/multitap/multitap.cpp b/sfc/controller/multitap/multitap.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/multitap/multitap.cpp rename to sfc/controller/multitap/multitap.cpp diff --git a/higan/sfc/controller/multitap/multitap.hpp b/sfc/controller/multitap/multitap.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/multitap/multitap.hpp rename to sfc/controller/multitap/multitap.hpp diff --git a/higan/sfc/controller/superscope/superscope.cpp b/sfc/controller/superscope/superscope.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/superscope/superscope.cpp rename to sfc/controller/superscope/superscope.cpp diff --git a/higan/sfc/controller/superscope/superscope.hpp b/sfc/controller/superscope/superscope.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/superscope/superscope.hpp rename to sfc/controller/superscope/superscope.hpp diff --git a/higan/sfc/controller/usart/usart.cpp b/sfc/controller/usart/usart.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/usart/usart.cpp rename to sfc/controller/usart/usart.cpp diff --git a/higan/sfc/controller/usart/usart.hpp b/sfc/controller/usart/usart.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/controller/usart/usart.hpp rename to sfc/controller/usart/usart.hpp diff --git a/higan/sfc/cpu/cpu.cpp b/sfc/cpu/cpu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/cpu.cpp rename to sfc/cpu/cpu.cpp diff --git a/higan/sfc/cpu/cpu.hpp b/sfc/cpu/cpu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/cpu.hpp rename to sfc/cpu/cpu.hpp diff --git a/higan/sfc/cpu/dma/dma.cpp b/sfc/cpu/dma/dma.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/dma/dma.cpp rename to sfc/cpu/dma/dma.cpp diff --git a/higan/sfc/cpu/dma/dma.hpp b/sfc/cpu/dma/dma.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/dma/dma.hpp rename to sfc/cpu/dma/dma.hpp diff --git a/higan/sfc/cpu/memory/memory.cpp b/sfc/cpu/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/memory/memory.cpp rename to sfc/cpu/memory/memory.cpp diff --git a/higan/sfc/cpu/memory/memory.hpp b/sfc/cpu/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/memory/memory.hpp rename to sfc/cpu/memory/memory.hpp diff --git a/higan/sfc/cpu/mmio/mmio.cpp b/sfc/cpu/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/mmio/mmio.cpp rename to sfc/cpu/mmio/mmio.cpp diff --git a/higan/sfc/cpu/mmio/mmio.hpp b/sfc/cpu/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/mmio/mmio.hpp rename to sfc/cpu/mmio/mmio.hpp diff --git a/higan/sfc/cpu/serialization.cpp b/sfc/cpu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/serialization.cpp rename to sfc/cpu/serialization.cpp diff --git a/higan/sfc/cpu/timing/irq.cpp b/sfc/cpu/timing/irq.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/timing/irq.cpp rename to sfc/cpu/timing/irq.cpp diff --git a/higan/sfc/cpu/timing/joypad.cpp b/sfc/cpu/timing/joypad.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/timing/joypad.cpp rename to sfc/cpu/timing/joypad.cpp diff --git a/higan/sfc/cpu/timing/timing.cpp b/sfc/cpu/timing/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/timing/timing.cpp rename to sfc/cpu/timing/timing.cpp diff --git a/higan/sfc/cpu/timing/timing.hpp b/sfc/cpu/timing/timing.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/cpu/timing/timing.hpp rename to sfc/cpu/timing/timing.hpp diff --git a/higan/sfc/dsp/brr.cpp b/sfc/dsp/brr.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/brr.cpp rename to sfc/dsp/brr.cpp diff --git a/higan/sfc/dsp/counter.cpp b/sfc/dsp/counter.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/counter.cpp rename to sfc/dsp/counter.cpp diff --git a/higan/sfc/dsp/dsp.cpp b/sfc/dsp/dsp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/dsp.cpp rename to sfc/dsp/dsp.cpp diff --git a/higan/sfc/dsp/dsp.hpp b/sfc/dsp/dsp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/dsp.hpp rename to sfc/dsp/dsp.hpp diff --git a/higan/sfc/dsp/echo.cpp b/sfc/dsp/echo.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/echo.cpp rename to sfc/dsp/echo.cpp diff --git a/higan/sfc/dsp/envelope.cpp b/sfc/dsp/envelope.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/envelope.cpp rename to sfc/dsp/envelope.cpp diff --git a/higan/sfc/dsp/gaussian.cpp b/sfc/dsp/gaussian.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/gaussian.cpp rename to sfc/dsp/gaussian.cpp diff --git a/higan/sfc/dsp/misc.cpp b/sfc/dsp/misc.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/misc.cpp rename to sfc/dsp/misc.cpp diff --git a/higan/sfc/dsp/moduloarray.hpp b/sfc/dsp/moduloarray.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/moduloarray.hpp rename to sfc/dsp/moduloarray.hpp diff --git a/higan/sfc/dsp/serialization.cpp b/sfc/dsp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/serialization.cpp rename to sfc/dsp/serialization.cpp diff --git a/higan/sfc/dsp/voice.cpp b/sfc/dsp/voice.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/dsp/voice.cpp rename to sfc/dsp/voice.cpp diff --git a/higan/sfc/interface/interface.cpp b/sfc/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/interface/interface.cpp rename to sfc/interface/interface.cpp diff --git a/higan/sfc/interface/interface.hpp b/sfc/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/interface/interface.hpp rename to sfc/interface/interface.hpp diff --git a/higan/sfc/memory/memory-inline.hpp b/sfc/memory/memory-inline.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/memory/memory-inline.hpp rename to sfc/memory/memory-inline.hpp diff --git a/higan/sfc/memory/memory.cpp b/sfc/memory/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/memory/memory.cpp rename to sfc/memory/memory.cpp diff --git a/higan/sfc/memory/memory.hpp b/sfc/memory/memory.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/memory/memory.hpp rename to sfc/memory/memory.hpp diff --git a/higan/sfc/ppu/background/background.cpp b/sfc/ppu/background/background.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/background/background.cpp rename to sfc/ppu/background/background.cpp diff --git a/higan/sfc/ppu/background/background.hpp b/sfc/ppu/background/background.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/background/background.hpp rename to sfc/ppu/background/background.hpp diff --git a/higan/sfc/ppu/background/mode7.cpp b/sfc/ppu/background/mode7.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/background/mode7.cpp rename to sfc/ppu/background/mode7.cpp diff --git a/higan/sfc/ppu/counter/counter-inline.hpp b/sfc/ppu/counter/counter-inline.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/counter/counter-inline.hpp rename to sfc/ppu/counter/counter-inline.hpp diff --git a/higan/sfc/ppu/counter/counter.hpp b/sfc/ppu/counter/counter.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/counter/counter.hpp rename to sfc/ppu/counter/counter.hpp diff --git a/higan/sfc/ppu/mmio/mmio.cpp b/sfc/ppu/mmio/mmio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/mmio/mmio.cpp rename to sfc/ppu/mmio/mmio.cpp diff --git a/higan/sfc/ppu/mmio/mmio.hpp b/sfc/ppu/mmio/mmio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/mmio/mmio.hpp rename to sfc/ppu/mmio/mmio.hpp diff --git a/higan/sfc/ppu/ppu.cpp b/sfc/ppu/ppu.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/ppu.cpp rename to sfc/ppu/ppu.cpp diff --git a/higan/sfc/ppu/ppu.hpp b/sfc/ppu/ppu.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/ppu.hpp rename to sfc/ppu/ppu.hpp diff --git a/higan/sfc/ppu/screen/screen.cpp b/sfc/ppu/screen/screen.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/screen/screen.cpp rename to sfc/ppu/screen/screen.cpp diff --git a/higan/sfc/ppu/screen/screen.hpp b/sfc/ppu/screen/screen.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/screen/screen.hpp rename to sfc/ppu/screen/screen.hpp diff --git a/higan/sfc/ppu/serialization.cpp b/sfc/ppu/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/serialization.cpp rename to sfc/ppu/serialization.cpp diff --git a/higan/sfc/ppu/sprite/list.cpp b/sfc/ppu/sprite/list.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/sprite/list.cpp rename to sfc/ppu/sprite/list.cpp diff --git a/higan/sfc/ppu/sprite/sprite.cpp b/sfc/ppu/sprite/sprite.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/sprite/sprite.cpp rename to sfc/ppu/sprite/sprite.cpp diff --git a/higan/sfc/ppu/sprite/sprite.hpp b/sfc/ppu/sprite/sprite.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/sprite/sprite.hpp rename to sfc/ppu/sprite/sprite.hpp diff --git a/higan/sfc/ppu/window/window.cpp b/sfc/ppu/window/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/window/window.cpp rename to sfc/ppu/window/window.cpp diff --git a/higan/sfc/ppu/window/window.hpp b/sfc/ppu/window/window.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/ppu/window/window.hpp rename to sfc/ppu/window/window.hpp diff --git a/higan/sfc/profile-accuracy.hpp b/sfc/profile-accuracy.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/profile-accuracy.hpp rename to sfc/profile-accuracy.hpp diff --git a/higan/sfc/profile-balanced.hpp b/sfc/profile-balanced.hpp similarity index 100% rename from higan/sfc/profile-balanced.hpp rename to sfc/profile-balanced.hpp diff --git a/higan/sfc/profile-performance.hpp b/sfc/profile-performance.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/profile-performance.hpp rename to sfc/profile-performance.hpp diff --git a/higan/sfc/random/random.cpp b/sfc/random/random.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/random/random.cpp rename to sfc/random/random.cpp diff --git a/higan/sfc/random/random.hpp b/sfc/random/random.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/random/random.hpp rename to sfc/random/random.hpp diff --git a/higan/sfc/scheduler/scheduler.cpp b/sfc/scheduler/scheduler.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/scheduler/scheduler.cpp rename to sfc/scheduler/scheduler.cpp diff --git a/higan/sfc/scheduler/scheduler.hpp b/sfc/scheduler/scheduler.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/scheduler/scheduler.hpp rename to sfc/scheduler/scheduler.hpp diff --git a/higan/sfc/sfc.hpp b/sfc/sfc.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/sfc.hpp rename to sfc/sfc.hpp diff --git a/higan/sfc/slot/satellaview/satellaview.cpp b/sfc/slot/satellaview/satellaview.cpp similarity index 100% rename from higan/sfc/slot/satellaview/satellaview.cpp rename to sfc/slot/satellaview/satellaview.cpp diff --git a/higan/sfc/slot/satellaview/satellaview.hpp b/sfc/slot/satellaview/satellaview.hpp similarity index 100% rename from higan/sfc/slot/satellaview/satellaview.hpp rename to sfc/slot/satellaview/satellaview.hpp diff --git a/higan/sfc/slot/slot.hpp b/sfc/slot/slot.hpp similarity index 100% rename from higan/sfc/slot/slot.hpp rename to sfc/slot/slot.hpp diff --git a/higan/sfc/slot/sufamiturbo/serialization.cpp b/sfc/slot/sufamiturbo/serialization.cpp similarity index 100% rename from higan/sfc/slot/sufamiturbo/serialization.cpp rename to sfc/slot/sufamiturbo/serialization.cpp diff --git a/higan/sfc/slot/sufamiturbo/sufamiturbo.cpp b/sfc/slot/sufamiturbo/sufamiturbo.cpp similarity index 100% rename from higan/sfc/slot/sufamiturbo/sufamiturbo.cpp rename to sfc/slot/sufamiturbo/sufamiturbo.cpp diff --git a/higan/sfc/slot/sufamiturbo/sufamiturbo.hpp b/sfc/slot/sufamiturbo/sufamiturbo.hpp similarity index 100% rename from higan/sfc/slot/sufamiturbo/sufamiturbo.hpp rename to sfc/slot/sufamiturbo/sufamiturbo.hpp diff --git a/higan/sfc/smp/memory.cpp b/sfc/smp/memory.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/smp/memory.cpp rename to sfc/smp/memory.cpp diff --git a/higan/sfc/smp/serialization.cpp b/sfc/smp/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/smp/serialization.cpp rename to sfc/smp/serialization.cpp diff --git a/higan/sfc/smp/smp.cpp b/sfc/smp/smp.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/smp/smp.cpp rename to sfc/smp/smp.cpp diff --git a/higan/sfc/smp/smp.hpp b/sfc/smp/smp.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/smp/smp.hpp rename to sfc/smp/smp.hpp diff --git a/higan/sfc/smp/timing.cpp b/sfc/smp/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/smp/timing.cpp rename to sfc/smp/timing.cpp diff --git a/higan/sfc/system/audio.cpp b/sfc/system/audio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/audio.cpp rename to sfc/system/audio.cpp diff --git a/higan/sfc/system/audio.hpp b/sfc/system/audio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/audio.hpp rename to sfc/system/audio.hpp diff --git a/higan/sfc/system/input.cpp b/sfc/system/input.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/input.cpp rename to sfc/system/input.cpp diff --git a/higan/sfc/system/input.hpp b/sfc/system/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/input.hpp rename to sfc/system/input.hpp diff --git a/higan/sfc/system/serialization.cpp b/sfc/system/serialization.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/serialization.cpp rename to sfc/system/serialization.cpp diff --git a/higan/sfc/system/system.cpp b/sfc/system/system.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/system.cpp rename to sfc/system/system.cpp diff --git a/higan/sfc/system/system.hpp b/sfc/system/system.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/system.hpp rename to sfc/system/system.hpp diff --git a/higan/sfc/system/video.cpp b/sfc/system/video.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/video.cpp rename to sfc/system/video.cpp diff --git a/higan/sfc/system/video.hpp b/sfc/system/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/sfc/system/video.hpp rename to sfc/system/video.hpp diff --git a/shaders/Curvature.OpenGL.shader b/shaders/Curvature.OpenGL.shader deleted file mode 100644 index 2a7083a5..00000000 --- a/shaders/Curvature.OpenGL.shader +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/shaders/Curvature.shader/curvature.fs b/shaders/Curvature.shader/curvature.fs new file mode 100644 index 00000000..751f59b3 --- /dev/null +++ b/shaders/Curvature.shader/curvature.fs @@ -0,0 +1,21 @@ +#version 150 +#define distortion 0.2 + +uniform sampler2D source[]; +uniform vec4 sourceSize[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +vec2 radialDistortion(vec2 coord) { + vec2 cc = coord - vec2(0.5); + float dist = dot(cc, cc) * distortion; + return coord + cc * (1.0 - dist) * dist; +} + +void main() { + fragColor = texture2D(source[0], radialDistortion(texCoord)); +} diff --git a/shaders/Curvature.shader/manifest.bml b/shaders/Curvature.shader/manifest.bml new file mode 100644 index 00000000..7bec4709 --- /dev/null +++ b/shaders/Curvature.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: border + fragment: curvature.fs diff --git a/shaders/Edge Detection.shader/edge-detection.fs b/shaders/Edge Detection.shader/edge-detection.fs new file mode 100644 index 00000000..f2087df9 --- /dev/null +++ b/shaders/Edge Detection.shader/edge-detection.fs @@ -0,0 +1,25 @@ +#version 150 + +uniform sampler2D source[]; +uniform vec4 sourceSize[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +vec3 grayscale(vec3 color) { + return vec3(dot(color, vec3(0.3, 0.59, 0.11))); +} + +void main() { + vec2 offset = fract(texCoord * sourceSize[0].xy) - 0.5; + offset /= sourceSize[0].xy; + + vec3 cx = texture2D(source[0], texCoord - offset).xyz; + vec3 cy = texture2D(source[0], texCoord).xyz; + vec3 cz = vec3(5.0 * grayscale(abs(cx - cy))); + + fragColor = vec4(clamp(cz, 0.0, 1.0), 1.0); +} diff --git a/shaders/Edge Detection.shader/manifest.bml b/shaders/Edge Detection.shader/manifest.bml new file mode 100644 index 00000000..166db6de --- /dev/null +++ b/shaders/Edge Detection.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: edge + fragment: edge-detection.fs diff --git a/shaders/HQ2x.OpenGL.shader b/shaders/HQ2x.OpenGL.shader deleted file mode 100644 index ef507728..00000000 --- a/shaders/HQ2x.OpenGL.shader +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - diff --git a/shaders/Makefile b/shaders/Makefile new file mode 100644 index 00000000..80d315c8 --- /dev/null +++ b/shaders/Makefile @@ -0,0 +1,5 @@ +install: + if [ -d /usr/share/higan/Video\ Shaders ]; then sudo rm -r /usr/share/higan/Video\ Shaders; fi + sudo mkdir -p /usr/share/higan/Video\ Shaders + sudo cp -r *.shader /usr/share/higan/Video\ Shaders + sudo chmod -R 777 /usr/share/higan/Video\ Shaders diff --git a/shaders/Pixellate.OpenGL.shader b/shaders/Pixellate.OpenGL.shader deleted file mode 100644 index 4ddcae18..00000000 --- a/shaders/Pixellate.OpenGL.shader +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - diff --git a/shaders/Scale2x.OpenGL.shader b/shaders/Scale2x.OpenGL.shader deleted file mode 100644 index cfe0e689..00000000 --- a/shaders/Scale2x.OpenGL.shader +++ /dev/null @@ -1,55 +0,0 @@ - - - - - = 0.5) { tmp = colB; colB = colH; colH = tmp; } //E1 (or E3): swap B and H - if(sel.x >= 0.5) { tmp = colF; colF = colD; colD = tmp; } //E2 (or E3): swap D and F - - if(colB == colD && colB != colF && colD != colH) { //do the Scale2x rule - col = colD; - } - - gl_FragColor = col; - } - ]]> - diff --git a/shaders/Scanline.shader/manifest.bml b/shaders/Scanline.shader/manifest.bml new file mode 100644 index 00000000..a5db6351 --- /dev/null +++ b/shaders/Scanline.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: border + fragment: scanline.fs diff --git a/shaders/Scanline.shader/scanline.fs b/shaders/Scanline.shader/scanline.fs new file mode 100644 index 00000000..c35fca1f --- /dev/null +++ b/shaders/Scanline.shader/scanline.fs @@ -0,0 +1,20 @@ +#version 150 + +uniform sampler2D source[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +void main() { + vec4 rgba = texture2D(source[0], texCoord); + vec4 intensity; + if(fract(gl_FragCoord.y * (0.5 * 4.0 / 3.0)) > 0.5) { + intensity = vec4(0); + } else { + intensity = smoothstep(0.2, 0.8, rgba) + normalize(rgba); + } + fragColor = intensity * -0.25 + rgba * 1.1; +} diff --git a/shaders/Sepia.Direct3D.shader b/shaders/Sepia.Direct3D.shader deleted file mode 100644 index 1fa725e2..00000000 --- a/shaders/Sepia.Direct3D.shader +++ /dev/null @@ -1,30 +0,0 @@ - - - ; }; - float3 LightColor = { 1.0, 0.7, 0.5 }; - float3 DarkColor = { 0.2, 0.05, 0.0 }; - - float4 DiffColorPass(in float2 Tex : TEXCOORD0) : COLOR0 - { - vec.x = 0.5; - vec.y = 1.0; - float3 scnColor = LightColor * tex2D(s0, Tex).xyz; - float3 grayXfer = float3(0.3, 0.59, 0.11); - float gray = dot(grayXfer, scnColor); - float3 muted = lerp(scnColor, gray.xxx, vec.x); - float3 sepia = lerp(DarkColor, LightColor, gray); - float3 result = lerp(muted, sepia, vec.y); - return float4(result, 1); - } - - Technique T0 - { - pass p0 { PixelShader = compile ps_2_0 DiffColorPass(); } - } - ]]> - diff --git a/higan/target-ethos/Makefile b/target-ethos/Makefile old mode 100755 new mode 100644 similarity index 99% rename from higan/target-ethos/Makefile rename to target-ethos/Makefile index 2a3a3acc..0c1c4072 --- a/higan/target-ethos/Makefile +++ b/target-ethos/Makefile @@ -7,7 +7,6 @@ include fc/Makefile include sfc/Makefile include gb/Makefile include gba/Makefile -# include nds/Makefile ui_objects := ui-ethos ui-configuration ui-interface ui-utility ui_objects += ui-input ui-window ui-general ui-settings ui-tools diff --git a/higan/target-ethos/bootstrap.cpp b/target-ethos/bootstrap.cpp old mode 100755 new mode 100644 similarity index 84% rename from higan/target-ethos/bootstrap.cpp rename to target-ethos/bootstrap.cpp index 55386183..5b14e25e --- a/higan/target-ethos/bootstrap.cpp +++ b/target-ethos/bootstrap.cpp @@ -2,7 +2,6 @@ #include #include #include -//#include void Program::bootstrap() { interface = new Interface; @@ -11,7 +10,6 @@ void Program::bootstrap() { emulator.append(new SuperFamicom::Interface); emulator.append(new GameBoy::Interface); emulator.append(new GameBoyAdvance::Interface); -//emulator.append(new NintendoDS::Interface); for(auto& system : emulator) system->bind = interface; } diff --git a/higan/target-ethos/configuration/configuration.cpp b/target-ethos/configuration/configuration.cpp old mode 100755 new mode 100644 similarity index 90% rename from higan/target-ethos/configuration/configuration.cpp rename to target-ethos/configuration/configuration.cpp index 420a206d..5f886d04 --- a/higan/target-ethos/configuration/configuration.cpp +++ b/target-ethos/configuration/configuration.cpp @@ -2,7 +2,7 @@ ConfigurationSettings* config = nullptr; ConfigurationSettings::ConfigurationSettings() { - video.append(video.driver = ruby::video.optimalDriver(), "Driver"); + video.append(video.driver = ruby::video.safestDriver(), "Driver"); video.append(video.synchronize = false, "Synchronize"); video.append(video.shader = "Blur", "Shader"); video.append(video.scaleMode = 0, "ScaleMode"); @@ -17,7 +17,7 @@ ConfigurationSettings::ConfigurationSettings() { video.append(video.startFullScreen = false, "StartFullScreen"); append(video, "Video"); - audio.append(audio.driver = ruby::audio.optimalDriver(), "Driver"); + audio.append(audio.driver = ruby::audio.safestDriver(), "Driver"); audio.append(audio.synchronize = true, "Synchronize"); audio.append(audio.frequency = 48000, "Frequency"); audio.append(audio.latency = 60, "Latency"); @@ -26,7 +26,7 @@ ConfigurationSettings::ConfigurationSettings() { audio.append(audio.mute = false, "Mute"); append(audio, "Audio"); - input.append(input.driver = ruby::input.optimalDriver(), "Driver"); + input.append(input.driver = ruby::input.safestDriver(), "Driver"); input.focus.append(input.focus.pause = false, "Pause"); input.focus.append(input.focus.allow = false, "AllowInput"); input.append(input.focus, "Focus"); diff --git a/higan/target-ethos/configuration/configuration.hpp b/target-ethos/configuration/configuration.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/configuration/configuration.hpp rename to target-ethos/configuration/configuration.hpp diff --git a/higan/target-ethos/ethos.cpp b/target-ethos/ethos.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/ethos.cpp rename to target-ethos/ethos.cpp diff --git a/higan/target-ethos/ethos.hpp b/target-ethos/ethos.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/ethos.hpp rename to target-ethos/ethos.hpp diff --git a/higan/target-ethos/general/browser.cpp b/target-ethos/general/browser.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/browser.cpp rename to target-ethos/general/browser.cpp diff --git a/higan/target-ethos/general/browser.hpp b/target-ethos/general/browser.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/browser.hpp rename to target-ethos/general/browser.hpp diff --git a/higan/target-ethos/general/dip-switches.cpp b/target-ethos/general/dip-switches.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/dip-switches.cpp rename to target-ethos/general/dip-switches.cpp diff --git a/higan/target-ethos/general/dip-switches.hpp b/target-ethos/general/dip-switches.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/dip-switches.hpp rename to target-ethos/general/dip-switches.hpp diff --git a/higan/target-ethos/general/general.cpp b/target-ethos/general/general.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/general.cpp rename to target-ethos/general/general.cpp diff --git a/higan/target-ethos/general/general.hpp b/target-ethos/general/general.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/general.hpp rename to target-ethos/general/general.hpp diff --git a/higan/target-ethos/general/presentation.cpp b/target-ethos/general/presentation.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/presentation.cpp rename to target-ethos/general/presentation.cpp diff --git a/higan/target-ethos/general/presentation.hpp b/target-ethos/general/presentation.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/general/presentation.hpp rename to target-ethos/general/presentation.hpp diff --git a/higan/target-ethos/input/hotkeys.cpp b/target-ethos/input/hotkeys.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/input/hotkeys.cpp rename to target-ethos/input/hotkeys.cpp diff --git a/higan/target-ethos/input/input.cpp b/target-ethos/input/input.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/input/input.cpp rename to target-ethos/input/input.cpp diff --git a/higan/target-ethos/input/input.hpp b/target-ethos/input/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/input/input.hpp rename to target-ethos/input/input.hpp diff --git a/higan/target-ethos/interface/interface.cpp b/target-ethos/interface/interface.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/interface/interface.cpp rename to target-ethos/interface/interface.cpp diff --git a/higan/target-ethos/interface/interface.hpp b/target-ethos/interface/interface.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/interface/interface.hpp rename to target-ethos/interface/interface.hpp diff --git a/higan/target-ethos/resource.rc b/target-ethos/resource.rc old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/resource.rc rename to target-ethos/resource.rc diff --git a/higan/target-ethos/resource/folder.png b/target-ethos/resource/folder.png similarity index 100% rename from higan/target-ethos/resource/folder.png rename to target-ethos/resource/folder.png diff --git a/higan/target-ethos/resource/game.png b/target-ethos/resource/game.png similarity index 100% rename from higan/target-ethos/resource/game.png rename to target-ethos/resource/game.png diff --git a/higan/target-ethos/resource/home.png b/target-ethos/resource/home.png old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/resource/home.png rename to target-ethos/resource/home.png diff --git a/higan/target-ethos/resource/resource.bml b/target-ethos/resource/resource.bml similarity index 100% rename from higan/target-ethos/resource/resource.bml rename to target-ethos/resource/resource.bml diff --git a/higan/target-ethos/resource/resource.cpp b/target-ethos/resource/resource.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/resource/resource.cpp rename to target-ethos/resource/resource.cpp diff --git a/higan/target-ethos/resource/resource.hpp b/target-ethos/resource/resource.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/resource/resource.hpp rename to target-ethos/resource/resource.hpp diff --git a/higan/target-ethos/resource/unverified.png b/target-ethos/resource/unverified.png similarity index 100% rename from higan/target-ethos/resource/unverified.png rename to target-ethos/resource/unverified.png diff --git a/higan/target-ethos/resource/up.png b/target-ethos/resource/up.png old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/resource/up.png rename to target-ethos/resource/up.png diff --git a/higan/target-ethos/settings/advanced.cpp b/target-ethos/settings/advanced.cpp similarity index 100% rename from higan/target-ethos/settings/advanced.cpp rename to target-ethos/settings/advanced.cpp diff --git a/higan/target-ethos/settings/advanced.hpp b/target-ethos/settings/advanced.hpp similarity index 100% rename from higan/target-ethos/settings/advanced.hpp rename to target-ethos/settings/advanced.hpp diff --git a/higan/target-ethos/settings/audio.cpp b/target-ethos/settings/audio.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/audio.cpp rename to target-ethos/settings/audio.cpp diff --git a/higan/target-ethos/settings/audio.hpp b/target-ethos/settings/audio.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/audio.hpp rename to target-ethos/settings/audio.hpp diff --git a/higan/target-ethos/settings/hotkey.cpp b/target-ethos/settings/hotkey.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/hotkey.cpp rename to target-ethos/settings/hotkey.cpp diff --git a/higan/target-ethos/settings/hotkey.hpp b/target-ethos/settings/hotkey.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/hotkey.hpp rename to target-ethos/settings/hotkey.hpp diff --git a/higan/target-ethos/settings/input.cpp b/target-ethos/settings/input.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/input.cpp rename to target-ethos/settings/input.cpp diff --git a/higan/target-ethos/settings/input.hpp b/target-ethos/settings/input.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/input.hpp rename to target-ethos/settings/input.hpp diff --git a/higan/target-ethos/settings/server.cpp b/target-ethos/settings/server.cpp similarity index 100% rename from higan/target-ethos/settings/server.cpp rename to target-ethos/settings/server.cpp diff --git a/higan/target-ethos/settings/server.hpp b/target-ethos/settings/server.hpp similarity index 100% rename from higan/target-ethos/settings/server.hpp rename to target-ethos/settings/server.hpp diff --git a/higan/target-ethos/settings/settings.cpp b/target-ethos/settings/settings.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/settings.cpp rename to target-ethos/settings/settings.cpp diff --git a/higan/target-ethos/settings/settings.hpp b/target-ethos/settings/settings.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/settings.hpp rename to target-ethos/settings/settings.hpp diff --git a/higan/target-ethos/settings/timing.cpp b/target-ethos/settings/timing.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/timing.cpp rename to target-ethos/settings/timing.cpp diff --git a/higan/target-ethos/settings/timing.hpp b/target-ethos/settings/timing.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/timing.hpp rename to target-ethos/settings/timing.hpp diff --git a/higan/target-ethos/settings/video.cpp b/target-ethos/settings/video.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/video.cpp rename to target-ethos/settings/video.cpp diff --git a/higan/target-ethos/settings/video.hpp b/target-ethos/settings/video.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/settings/video.hpp rename to target-ethos/settings/video.hpp diff --git a/higan/target-ethos/tools/cheat-database.cpp b/target-ethos/tools/cheat-database.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/cheat-database.cpp rename to target-ethos/tools/cheat-database.cpp diff --git a/higan/target-ethos/tools/cheat-database.hpp b/target-ethos/tools/cheat-database.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/cheat-database.hpp rename to target-ethos/tools/cheat-database.hpp diff --git a/higan/target-ethos/tools/cheat-editor.cpp b/target-ethos/tools/cheat-editor.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/cheat-editor.cpp rename to target-ethos/tools/cheat-editor.cpp diff --git a/higan/target-ethos/tools/cheat-editor.hpp b/target-ethos/tools/cheat-editor.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/cheat-editor.hpp rename to target-ethos/tools/cheat-editor.hpp diff --git a/higan/target-ethos/tools/state-manager.cpp b/target-ethos/tools/state-manager.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/state-manager.cpp rename to target-ethos/tools/state-manager.cpp diff --git a/higan/target-ethos/tools/state-manager.hpp b/target-ethos/tools/state-manager.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/state-manager.hpp rename to target-ethos/tools/state-manager.hpp diff --git a/higan/target-ethos/tools/tools.cpp b/target-ethos/tools/tools.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/tools.cpp rename to target-ethos/tools/tools.cpp diff --git a/higan/target-ethos/tools/tools.hpp b/target-ethos/tools/tools.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/tools/tools.hpp rename to target-ethos/tools/tools.hpp diff --git a/higan/target-ethos/utility/utility.cpp b/target-ethos/utility/utility.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/utility/utility.cpp rename to target-ethos/utility/utility.cpp diff --git a/higan/target-ethos/utility/utility.hpp b/target-ethos/utility/utility.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/utility/utility.hpp rename to target-ethos/utility/utility.hpp diff --git a/higan/target-ethos/window/window.cpp b/target-ethos/window/window.cpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/window/window.cpp rename to target-ethos/window/window.cpp diff --git a/higan/target-ethos/window/window.hpp b/target-ethos/window/window.hpp old mode 100755 new mode 100644 similarity index 100% rename from higan/target-ethos/window/window.hpp rename to target-ethos/window/window.hpp